Thread: Gdiplus question

  1. #1
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310

    Red face Gdiplus question

    This works great!
    Code:
    case WM_PAINT:
            {
                PAINTSTRUCT ps;
                BeginPaint(hWndParent, &ps);
                Image img(L"png.png");
                Graphics graphics(ps.hdc);
                graphics.DrawImage(&img, 1, 1);
                EndPaint(hWndParent, &ps);
                return TRUE;
           }
    But...
    Code:
    WM_CREATE:
    {
    HDC hdc = GetDC(hWndParent);
    Image img(L"png.png");
    Graphics graphics(hdc);
    graphics.DrawImage(&img, 1, 1);
    ReleaseDC(hWndParent, hdc);
    }
    so.. hdc is different in each message... or am I using the wrong API?

  2. #2
    *this
    Join Date
    Mar 2005
    Posts
    498
    Declare hdc AND ps in the beginning of your callback function.

    Code:
    return TRUE;
    is supposed to be:
    Code:
    return 0;

  3. #3
    *this
    Join Date
    Mar 2005
    Posts
    498
    so.. hdc is different in each message... or am I using the wrong API?
    HDC is the handle to the device context so that means that if you wish to call WM_CREATE you need to call it, if you wish to paint you need to call it; because your changing the device context for what your currently doing.

    You need to declare all your variables in the beginning of CALLBACK procedure, if you ever need to keep them each time a message is processed than make them static.
    Last edited by JoshR; 07-10-2005 at 05:56 PM.

  4. #4
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    because your changing the device context for what your currently doing.
    Got it
    Thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM