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:
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
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).
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"