-
April 28th, 2009, 03:11 AM
#1
Paint outside of WNDPROC
Basically i have a standard window where i want to draw some balls too, but the painting messages will not be handled in the Window Processor as WM_PAINT or WM_TIMER messages, instead i have a message loop like this:
while(true)
{
starting_point = GetTickCount();//frame limiter
if(PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
else if( !TranslateAccelerator (hwnd, hAccel, &msg) )
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
}
if(!opt.bPause );//simulation is not on pause
//RENDER FRAME() !!!PROBLEM AREA
while ((GetTickCount() - starting_point) < 1000/opt.REFRESH); //frame limiter
}
in the RenderFrame function i want to make a GDI back buffer, draw to it and swap it with a front buffer, but for that i need a DC. The problem is that all the functions for getting a DC, like GetDC and BeginPaint need a handle to the window. My question is, is it possible to save the windows handle global, or is it changing all the time, and if it is, are there any other optios to paint a window outside of it's WindowProc?
Thanks in advance
-
April 28th, 2009, 02:35 PM
#2
Re: Paint outside of WNDPROC
Once a window handle is generated by the OS, it represents that window for the duration of it's existence, until it's destroyed.
There are many ways to provide access to that or the encapsulating object that represents a window (assuming you're using some kind of framework). A global variable is not the better choice, but it would work if you chose to use it.
The general topic you're considering, it seems to me, is known as a client DC - typically used for painting at times other than paint message.
If my post was interesting or helpful, perhaps you would consider clicking the 'rate this post' to let me know (middle icon of the group in the upper right of the post).
-
April 30th, 2009, 05:28 AM
#3
Re: Paint outside of WNDPROC
My question is, is it possible to save the windows handle global, or is it changing all the time, and if it is, are there any other optios to paint a window outside of it's WindowProc?
Thanks in advance
No need to declare the Window handle itself Global. Instead you can have a dummy temp HWND variable as global, and just assign the Handle to it. So, you can use the copy of original hWnd variable for global uses like use in Functions etc.
It cannot be confirmly said that a Windows handle remains constant, as it may vary ofcourse at some instance, if Sufficient memory is not available and the paging is used.
"I studied everything but never topped. Today, toppers of the world's best universities are my employees"
-William Henry Gates (Bill Gates)
-
April 30th, 2009, 06:53 AM
#4
Re: Paint outside of WNDPROC
You can retrieve the current windows handle with GetActiveWindow(), e.g.
Code:
HWND hwnd;
HDC hdc;
hwnd = GetActiveWindow();
hdc = GetDC(hwnd);
....
ReleaseDC(hwnd, hdc);
-
April 30th, 2009, 09:51 AM
#5
Re: Paint outside of WNDPROC
Originally Posted by CoolPG
No need to declare the Window handle itself Global. Instead you can have a dummy temp HWND variable as global, and just assign the Handle to it.
I don't see the difference between storing a window handle in a global variable, or a copy of that handle.
Originally Posted by CoolPG
It cannot be confirmly said that a Windows handle remains constant, as it may vary ofcourse at some instance, if Sufficient memory is not available and the paging is used.
This is incorrect. Window handle doesn't change ever, not even while paging.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
April 30th, 2009, 09:57 AM
#6
Re: Paint outside of WNDPROC
Originally Posted by olivthill2
You can retrieve the current windows handle with GetActiveWindow()...
What is "current window"? You can get *active* window handle with tht call, may not be the one you wanted to paint.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
May 2nd, 2009, 02:25 AM
#7
Re: Paint outside of WNDPROC
Originally Posted by VladimirF
This is incorrect. Window handle doesn't change ever, not even while paging.
OK Vlad.. can you be a lil more specific?
because i have read somewhere that a Window's handle can change dynamically... i hope, its in an MSDN article or somewhere...
So, can you please provide correct info?
"I studied everything but never topped. Today, toppers of the world's best universities are my employees"
-William Henry Gates (Bill Gates)
Tags for this Thread
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
|