• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

Global GDI+ Graphics object

Hi,

I tried to create a global graphics object but it is not working:


//IN GLOBAL
HDC *graHDC;
Graphics graphics(graHDC);

//OnPaint fuction
VOID OnPaint(Graphics* g){
.............
}

//IN WinMain
graHDC = GetDC(hWnd);

//IN WM_PAINT
OnPaint(graphics);

It give this error :
error C2664: 'OnPaint' : cannot convert parameter 2 from 'class Gdiplus::Graphics' to 'class Gdiplus::Graphics *'  No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called Error executing cl.exe.

Or maybe graphics cannot be create in this way?

Regards
0
iphone
Asked:
iphone
1 Solution
 
AlexFMCommented:
To fix compilation error you need to write:
OnPaint(&graphics);

But I don't think that this will work at runtime. Graphics object must be created in every WM_PAINT message handler by the following way:

LRESULT APIENTRY WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
    Graphics* pGraphics;
 
    switch (message)
    {
        case WM_PAINT:
            hdc = BeginPaint(hwnd, &ps);
            pGraphics = Graphics::FromHDC(hdc);
            OnPaint(pGraphics);
            delete pGraphics;
            EndPaint(hwnd, &ps);
            return 0L;

        // Process other messages.  
    }
}
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now