-
December 17th, 2008, 05:43 AM
#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.
-
December 17th, 2008, 12:11 PM
#2
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);
}
-
December 21st, 2008, 07:40 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|