|
-
Jul 21st, 2001, 02:46 PM
#1
Thread Starter
Frenzied Member
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 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!
-
Jul 21st, 2001, 03:00 PM
#2
Monday Morning Lunatic
I hate WM_PAINT Ooh that rhymes 
Are you trying to display a bitmap from a file, or from a resource?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 21st, 2001, 03:06 PM
#3
Thread Starter
Frenzied Member
I've only really tried resource...
-
Jul 21st, 2001, 05:11 PM
#4
PowerPoster
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;
}
-
Jul 21st, 2001, 05:23 PM
#5
Monday Morning Lunatic
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....
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jul 21st, 2001, 07:08 PM
#6
Thread Starter
Frenzied Member
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
|