Advertisement

I'm desperate for some help :) But aren't we all.

Started by March 17, 2000 11:28 PM
8 comments, last by LordDeath 24 years, 7 months ago
I posted this in the graphics forum, but I am not sure which one it really belongs to. I''m thinking this may have been the more apropriate one. Can anyone help me? ---------- I''m loading several .bmp files into a simple windows program with the hopes that eventually, depending on where I click on the screen, it will change the bitmaps that are displayed (a simple "hot-spot" interface). Here''s some of the code of what I''m doing, with explanation to follow below it: ---------------------------------------------- HBITMAP hred, hgreen, hblue; // These are global HDC hdc_current; HDC hdc; PAINTSTRUCT ps; int num=1; // end of global stuff // I''m not going to print the entire thing. // Just the relevant stuff. // This is all in the WindowsProc function: case WM_CREATE: { hred = (HBITMAP)LoadImage(hinstance, "red.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); hgreen = (HBITMAP)LoadImage(hinstance, "green.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); hblue = (HBITMAP)LoadImage(hinstance, "blue.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); hdc = GetDC(hwnd); hdc_current = CreateCompatibleDC(hdc); SelectObject(hdc_current, hred); return(0); } break; case WM_PAINT: { hdc = BeginPaint(hwnd,&ps); BitBlt( hdc, 0, 0, 189, 300, hdc_current, 0, 0,SRCCOPY ); EndPaint(hwnd,&ps); return(0); } break; case WM_LBUTTONDOWN: { num++; if ( num > 3 ) { num -= 3; } if ( num == 1 ) { SelectObject(hdc_current, hred); } if ( num == 2 ) { SelectObject(hdc_current, hgreen); } if ( num == 3 ) { SelectObject(hdc_current, hblue); } SendMessage(hwnd, WM_PAINT, 0, 0); return(0); } case WM_DESTROY: { ReleaseDC(hwnd, hdc_current); DeleteDC(hdc_current); ReleaseDC(hwnd, hdc); DeleteDC(hdc); PostQuitMessage(0); return(0); } break; ------------------------------------------ I hope that displayed properly. What this is supposed to do is load the bitmaps into the HBITMAPs. This works fine. Then I create the hdc_current for the BitBlt function. Then I select the red bitmap (chose this randomly) into the hdc_current handle to device context. In the WM_PAINT I blt the bmp to the window, and it does display correctly. However, when I click the left mouse, it is SUPPOSED to select a different bitmap so that one will be displayed when WM_PAINT is called, but the bmp is never changed. I am able to display all 3 at once, if I create three hdc''s for them "hdc_red, hdc_blue, hdc_green" for example, but I would MUCH MUCH MUCH MUCH rather use one, and switch between which bmp is selected to it (for our simple game, this would be much better). I''m pretty new at the windows programming stuff, but I really am VERY limited on time. We have about 4 weeks left on this project and this part needs to get done soon so if anyone can help me out at all I would GREATLY appreciate it. Thanks!
Try this, it may not work, but I tried this and SendMessage and only this way worked in a similar situation so I hope it does, instead of SendMessage(hwnd,WM_PAINT,0,0); put :

InvalidateRect(hwnd,NULL,FALSE);

Hope this helps =)
Chris
Advertisement
Oh, and one more thing, you don''t need a return and a break, please, for my own selfishness take out one or the other (I''d suggest taking out the return myself, just put one return at the end of the function), you SHOULD be getting warnings about unreachable code, this will fix them.
Chris
Well... if I create separate HDC''s for each bitmap (which will number around 35 for this project, and I''d rather not), this works with the invalidateRect function and it draws them one at a time. However, its still not swapping the bitmaps when i just use the single hdc "hdc_current" as shown in the code...

i'm sorry i can't really help with that.. I've done only the most basic graphics with GDC (Graphics Device Context, of course, not Game Developers Conference ).. I don't know, perhaps you need to validate the whole window? (I haven't used Bitblt() so i may be way off)

but BraveZeus, he'd have to take out the break, not the return.. return(0) from the WindowProc function tells windows the message has been handled, and if it doesn't handle the message (i.e. the switch statement doesn't take care of it), it returns the message and windows takes care of it.. but since you've already taken care of it, you don't want windows screwing around with it..

Edited by - fuzzyai on 3/18/00 12:55:11 AM
Ok, dude, I used your code and made my own similar program using HBITMAPs and most of the code you posted, though I loaded them differently(with LoadBitmap but that shouldn''t matter), but I had to use InvalidateRect() (cause of my compiler?) but it works just fine, and I can see nothing wrong with the code you posted so I''m absolutely stumped, the only other possibility I can think of is you don''t have a "blue.bmp" or "green.bmp", but I highly doubt that...
Chris
Advertisement
yo, fuzzyai, I know you need a return, but you only need one...like this (dunno why I can't let this go =) ) :

LRESULT CALLBACK WndProc(....)
{
switch(message){
case WM_CREATE:...
break;
default:
return DefWindowProc(...);
}
return 0;
}

Edited by - BraveZeus on 3/18/00 1:01:06 AM
Chris
Also, LordDeath, what exactly is this project anyway, and can I try to help in any other way?
Chris
The project is a simple strategy (turn based) game, with a simple "hot spot" interface. Its simple, if you couldn''t tell. Hehe.

BraveZeus, could you post the code to your similar project, or perhaps email it to me (mhanson@eng.utoledo.edu) ? That way maybe I could see what the difference was between yours and my programs. Thanks, I really appreciate your help.
I decided not to send by e-mail cause you may have a different compiler, and I used a project set-up, and it won't work with non-Borland compilers, anyway....to the code, sorry if it's hard to read, but I didn't want to take up too much space =) (took me a while to get it right =) )


#include windows.h

HDC hDC;
HDC hcurrentDC;
HBITMAP hred,hblue;
int num=1;

LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
WNDCLASS wc;
MSG msg;
HWND hWnd;
BOOL quit=FALSE;

wc.style = CS_OWNDC;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(hInstance,IDC_ARROW);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.hbrBackground = NULL;
wc.lpszClassName = "My Window";
wc.lpszMenuName = NULL;
RegisterClass(&wc);

hred = LoadBitmap(hInstance, "hred");
hblue = LoadBitmap(hInstance, "hblue");

hWnd = CreateWindowEx(WS_EX_DLGMODALFRAME,"My Window","My Window",
WS_POPUPWINDOW / WS_VISIBLE / WS_CAPTION,
0,0,600,400,
NULL,NULL,hInstance,NULL);

while(!quit){
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
if(msg.message == WM_QUIT)
quit = TRUE;
else{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
DestroyWindow(hWnd);
return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message){
case WM_CLOSE:
PostQuitMessage(0);
return 0;
case WM_CREATE:
hDC = GetDC(hWnd);
hcurrentDC = CreateCompatibleDC(hDC);
SelectObject(hcurrentDC,hred);
return 0;
case WM_DESTROY:
ReleaseDC(hWnd,hDC);
DeleteDC(hcurrentDC);
return 0;
case WM_ERASEBKGND:
return TRUE;
case WM_LBUTTONDOWN:
num++;
if ( num > 2 ) { num -= 2; }
if ( num == 1 ) { SelectObject(hcurrentDC, hred); }
if ( num == 2 ) { SelectObject(hcurrentDC, hblue); }
//SendMessage(hWnd, WM_PAINT, 0, 0);
InvalidateRect(hWnd, NULL, FALSE);
return 0; case WM_PAINT:
PAINTSTRUCT ps;
RECT rect;
BeginPaint(hWnd,&ps);
GetClientRect(hWnd,▭);
FillRect(hDC,▭,CreateSolidBrush(0x0000FF00));
BitBlt( hDC, 0, 0, 189, 300, hcurrentDC, 0, 0,SRCCOPY );
EndPaint(hWnd,&ps);
return 0;
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}

}

Edited by - BraveZeus on 3/18/00 2:00:14 PM
Chris

This topic is closed to new replies.

Advertisement