dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: drawing problems Property Page

Hybrid View

  1. #1
    Join Date
    Dec 2008
    Posts
    1

    drawing problems Property Page

    I have a property page with a static control area defined as

    CONTROL "",IDC_TEMP_GRPH,"Static",SS_GRAYFRAME,154,44,135,129

    I am handling WM_PAINT message and the following piece of code gets executed:

    CDC* pDC = new CDC(GetDC(this->m_hWnd));
    HWND hStatic = GetDlgItem(m_hWnd,IDC_TEMP_GRPH);
    RECT pirect;
    GetClientRect(hStatic,&pirect);
    COLORREF bkColor; bkColor = RGB(225,0,0);
    HBRUSH hBrush = ::CreateSolidBrush(bkColor);
    ::FillRect(GetDC(hStatic),&pirect,hBrush);

    The problem is I am not able to see this solid color block. It appears blinking while I drag the Property Sheet but disappears when I switch to next page and switch back to that page. Can anyone please tell me what is missing here?
    Last edited by koumodaki; December 17th, 2008 at 06:18 AM.

  2. #2
    Join Date
    Aug 2008
    Location
    Germany / NRW
    Posts
    37

    Re: drawing problems Property Page

    Within a WM_PAINT, you have to draw to the DC returned
    by BeginPaint().

    Code:
    case WM_PAINT:{
    		PAINTSTRUCT ps;
                    HDC myDC = BeginPaint(hWnd, &ps);
    
                    // do whatever
                    // cleanup
                    EndPaint(hWnd, &ps);
                    return(0);
    }

  3. #3
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,917

    Re: drawing problems Property Page

    From your code snippet Code snippet it does not look like your app is Win32 application.

    Where is this code residing? If this is in a handler of the parent window, that is your problem.
    Besides, your code creates GDI resources leaks. GetDC requires ReleaseDC. Allocating CDC object on the heap without releasing, creates memory leaks. Both happen each time that piece of code is executed.

    I am not sure why do you want to use a static control with gray frame and change control’s color.
    You would be better off by creating regular static control and handle WM_CTLCOLOR or WM_CTLCOLORSTATIC message in the parent window.

    If this approach is not feasible, derive own class from CStatic subclass control you need to handle differently and handle WM_PAINT in derived class.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)