Hey
I did your BitBlt tutorial(which is excellent for me as a beginner :)
Anyways, when I run the program, the window shows for less that a second, and unloads right away. I checked with the code from the tutorial, and it is exactly the same.
Printable View
Hey
I did your BitBlt tutorial(which is excellent for me as a beginner :)
Anyways, when I run the program, the window shows for less that a second, and unloads right away. I checked with the code from the tutorial, and it is exactly the same.
Where is the tutorial located(I would like to take a look, as I'm not that good in graphics)?
there it is:
http://www.technocracy.f2s.com/Basic%20BitBlt.html
:)
I just tried it, and it works fine... Perhaps you accidently deleted break; from the WM_CREATE case?
Nope, it's there :(
Here's the one I made(copied & pasted directly from the tutorial), it works just fine.
I don't see any difference!?
here is my code
You screwed up your message loop, here is what you had:
And here's what you need:Code:while(&msg,NULL,0,0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
After you make this change, everything should work fine :).Code:while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
And Dennis, you just screwed yours up :DGetMessage can return -1, which will cause your code to go round in circles and hang :(Code:while(GetMessage(&msg,NULL,0,0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
I didn't do that, Technocrat did!
take a look at main.cpp
http://www.technocracy.f2s.com/Basic%20BitBlt.html
Cool, glad to see the tutorial worked for some one. Like I said in there I did not put in how to keep the screen on.
Just catch WM_PAINT
like so:
PHP Code:case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
BitBlt(whatever.....
EndPaint(hwnd,&ps);
break;
}
Finally, thanks Dennis, it worked. Thanks technocrat for the tut. :) Do you know of more advanced ones? Thanks
Amon Ra
Acutually I use:
NowPHP Code:while(TRUE)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
But:
Should work because GetMessage only return a BOOL and a -1 if error. -1 and 0 would kick out of the While() right because neither one is truePHP Code:while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
I don't care who wrote it, it needs correcting ;)
Look up GetMessage in MSDN if you don't believe me :D
No I dont know of anymore advanced ones and I have not gotten around to writing the advanced version of mine.Quote:
Originally posted by Amon Ra
Finally, thanks Dennis, it worked. Thanks technocrat for the tut. :) Do you know of more advanced ones? Thanks
Amon Ra
Technocrat: How would you keep the picture from disapearing when another window overlaps it? The bit of code you posted to put in WM_PAINT doesn't do that.
All be damned......
From MSDN:
Note that the function return value can be nonzero, zero, or -1. Thus, you should avoid code like this:
while (GetMessage( lpMsg, hWnd, 0, 0)) ...
The possibility of a -1 return value means that such code can lead to fatal application errors.
In Ivor Horton's book it has it as:
while (GetMessage( lpMsg, hWnd, 0, 0))
Dirty book taught me to program wrong :mad:
It says to use something like this instead:
Code:BOOL bRet;
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
The urge to say "I told you so" runs high.... ;)
As for windows being covered up, can't you use CS_SAVEBITS?
Oh, Technocrat - doesn't PeekMessage return immediately? I hate to think what the CPU usage of that one is like :eek: I think you need a WaitMessage or something like that in there.
If I hadn't been in such a hurry to go to lunch........
Here it what is should be:
PHP Code:while(TRUE)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
WaitMessage();
}
Thats what Tricks of the Windows Game Programming Gurus by Andre Lamothe, shows to use while making windows programs. That book kicks ass by the way.
As for keeping the image on the screen, once again, to much in a hurry. Funny how when you are in a hurry you can get so many things wrong. :(
Ok I personally found how to do it this way, but someone else once told me you can use InvalidateRect() to work also, but I have never tried it.
But here is how I do it
If some knows how to do it with InvalidateRect or knows of a better I would like to know it.PHP Code:case WM_PAINT:
{
PAINTSTRUCT ps;
//We run this to have whatever paint job windows is requesting released.
BeginPaint(hwnd,&ps); //The hWnd here is the one that is passed into the MessageProc
EndPaint(hwnd,&ps);
BeginPaint(hwnd_Window, &ps); //Begin Painting the window we want the BitBlt Image to stay on
BitBlt(whatever.....
EndPaint(hwnd_Window,&ps); //End Painting
break;
}
Ok then, all is forgiven :)Quote:
Originally posted by Technocrat
If I hadn't been in such a hurry to go to lunch........
I was actually 10 mins late because of you people :rolleyes:
Since I program on my laptop and use the internet on my desktop I always have to retype everything and I always missing something.