-
Stupid Graphics!
Okay this is getting really annoying....I've been trying for so long to get graphics to work. and they still won't :mad: Can someone give me an example? Preferably having it redraw during WM_PAINT.....every tme I try I either get errors or just nothing happens.....All I want to do is show a bitmap!
-
I hate WM_PAINT :) Ooh that rhymes :p
Are you trying to display a bitmap from a file, or from a resource?
-
I've only really tried resource...
-
Here is a quick example:
Code:
#include <windows.h>
#include "resource.h"
static char g_szClassName[] = "MyWindowClass";
static HINSTANCE hinst = NULL;
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HWND hwnd;
PAINTSTRUCT ps;
HDC hdc, memhdc;
HBITMAP mybmp;
BITMAP bm;
//MYBMP is a bitmap in the resource file
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX WndClass;
MSG Msg;
hinst = hInstance;
mybmp = LoadBitmap(hinst, MAKEINTRESOURCE(MYBMP));
WndClass.cbSize = sizeof(WNDCLASSEX);
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hinst;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = g_szClassName;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
if(!RegisterClassEx(&WndClass))
{
MessageBox(0, "Window Registration Failed! :(", "Error!",
MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
return 0;
}
hwnd = CreateWindowEx(
NULL,
g_szClassName,
"Coloured Shapes Generator",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 320, 240,
NULL, NULL, hinst, NULL);
if(hwnd == NULL)
{
MessageBox(0, "Window Creation Failed! :(", "Error!",
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;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wparam, LPARAM lparam)
{
switch(Message)
{
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
memhdc = CreateCompatibleDC(hdc);
SelectObject(memhdc, mybmp);
//Draws the bitmap on the memory DC
GetObject(mybmp, sizeof(bm), &bm);
//Gets the info about the bitmap and stores that in "bm"
BitBlt(hdc, 0,0, bm.bmWidth, bm.bmHeight, memhdc, 0,0, SRCCOPY);
//Draws the bitmap on the window from the memory DC
DeleteDC(memhdc);
EndPaint(hwnd, &ps);
return 0;
case WM_CLOSE:
DeleteObject(mybmp);
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, Message, wparam, lparam);
}
return 0;
}
:p
-
Oops...forgot to say we solved it on MSN :(
The code was basically identical apart from I had the window procedure first in the file ;) Hee hee....
-
Yeah sorry forgot to mention that....sorry I left and didn't think about posting...Im on my grandparents computer now with 32 megs RAM!!!! IM GOING NUTS!
Thanks Guys :D :D :D