Jun 21st, 2001, 12:59 PM
#9
Thread Starter
Hyperactive Member
Ok Now I'm getting fustrated. LOL
Ok I don't know why this isn't working. It was working when I tried it a while back. here's my code.
Code:
#include <windows.h>
#include "resource.h"
static char g_szClassName[] = "MyWindowClass";
static HINSTANCE g_hInst = NULL;
HBITMAP MainBitmap;
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_CREATE:
MainBitmap= LoadBitmap(g_hInst, "MAIN_BITMAP");
if(!MainBitmap){
MessageBox(hwnd, "Resource Loading failed.", "Oops",
MB_OK | MB_ICONEXCLAMATION);
}
break;
case WM_PAINT:
if(MainBitmap)
{
PAINTSTRUCT ps;
HDC hdcMemory, hdcWindow;
BITMAP bm;
hdcWindow = BeginPaint(hwnd, &ps);
hdcMemory = CreateCompatibleDC(hdcWindow);
SelectObject(hdcMemory, MainBitmap);
GetObject(MainBitmap, sizeof(bm), &bm);
BitBlt(hdcWindow, 0, 0, bm.bmWidth, bm.bmHeight, hdcMemory, 0, 0, SRCCOPY);
DeleteDC(hdcMemory);
EndPaint(hwnd, &ps);
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
DeleteObject(MainBitmap);
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndClass;
HWND hwnd;
MSG Msg;
g_hInst = hInstance;
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = NULL;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = g_hInst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndClass))
{
MessageBox(0, "Could Not Register Window", "Oops",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
hwnd = CreateWindowEx(
WS_EX_CLIENTEDGE,
g_szClassName,
"Test",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 320, 240,
NULL, NULL, g_hInst, NULL);
if(hwnd == NULL)
{
MessageBox(0, "ERROR Window Was Not Created", "Oops",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&Msg, NULL, 0, 0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
I've also inlcuded the project that I did. Its probably the wrong way to do bitblt or something in c++. I forgot where I learned this, I think it was from winprog.org, but not sure.
Attached Files
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width