Thread: Using a Device Control Handle outside WM_PAINT

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    610

    Using a Device Control Handle outside WM_PAINT

    i've created a handle in within WM_PAINT message handler..

    Code:
    case WM_PAINT:
    {
    		hdc=BeginPaint(hwnd, &pntS);
    
                    .............
                    .............
     
    		DisplayResults(hwnd, hdc, output, rsltFont);
    
    		EndPaint(hwnd, &pntS);
    }
    return 0;
    But now the function DisplayResults() need to be called somewhere else, say within WM_COMMAND: when a button is pressed... The problem is it needs the hdc created in WM_PAINT to be able to repaint the results after changes...

    Q. Is it possible to use hdc somewhere else?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yes, it's possible to create a DC somewhere else, but the problem is that every time you need to repaint the area on the window where that paint was, it will be erased. So if you window gets hidden, moved off screen, etc, it will be gone.
    There it is always best to do the writing from WM_PAINT.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Invalid Handle Error
    By smarta_982002 in forum Windows Programming
    Replies: 2
    Last Post: 03-24-2008, 10:48 AM
  2. Getting other processes class names
    By Hawkin in forum Windows Programming
    Replies: 3
    Last Post: 03-20-2008, 04:02 PM
  3. tab control
    By tyouk in forum Windows Programming
    Replies: 6
    Last Post: 02-07-2005, 11:47 PM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. g_hWndMain = hWnd;error C2065,C2440
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2001, 03:36 PM