Paint outside of WNDPROC
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Paint outside of WNDPROC

  1. #1
    Join Date
    Apr 2009
    Posts
    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

  2. #2
    Join Date
    Nov 2006
    Posts
    1,611

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

  3. #3
    Join Date
    Apr 2009
    Location
    Cochin
    Posts
    83

    Smile 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)

  4. #4
    Join Date
    Apr 2009
    Posts
    598

    Smile 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);

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,526

    Re: Paint outside of WNDPROC

    Quote Originally Posted by CoolPG View Post
    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.
    Quote Originally Posted by CoolPG View Post
    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:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,526

    Re: Paint outside of WNDPROC

    Quote Originally Posted by olivthill2 View Post
    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:
    FeinViewer - an integrated GDI objects viewer for Visual C++ Debugger, and more...

  7. #7
    Join Date
    Apr 2009
    Location
    Cochin
    Posts
    83

    Smile Re: Paint outside of WNDPROC

    Quote Originally Posted by VladimirF View Post
    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center