the problem is : where should i put the lines of drawing ? in OnPaint() only? what else should i do ?
i wish to draw the titlebar of one SDI program. but i met some problems.
here is how i do it as following:
i add lines in the CMainFrame::OnPaint() :
<br />
CFrameWnd::OnPaint();<br />
<br />
if (IsIconic()) return;<br />
<br />
RECT stRect1;<br />
<br />
::GetWindowRect(m_hWnd, &stRect1);<br />
<br />
CRgn m_rgn0;<br />
m_rgn0.CreateRectRgn(0,8,stRect1.right-stRect1.left,stRect1.bottom- stRect1.top);<br />
<br />
SetWindowRgn(m_rgn0,1);<br />
<br />
<br />
RECT stRect;<br />
<br />
CRect rect;<br />
<br />
<br />
CDC *pDC;<br />
pDC = GetWindowDC();<br />
<br />
<br />
<br />
<br />
::GetWindowRect(m_hWnd, &stRect);<br />
<br />
<br />
<br />
rect.SetRect(0,0,stRect.right - stRect.left,stRect.bottom - stRect.top);<br />
<br />
HDC hDC = ::GetWindowDC(m_hWnd);<br />
<br />
HPEN hPen;<br />
hPen = CreatePen(PS_INSIDEFRAME, 1* GetSystemMetrics(SM_CXBORDER), <br />
RGB(123, 200, 243));<br />
<br />
CPen pen;<br />
<br />
pen.CreatePen(PS_INSIDEFRAME, 1* GetSystemMetrics(SM_CXBORDER), <br />
RGB(123, 220, 233));<br />
<br />
<br />
pDC->SelectObject(&pen);<br />
<br />
<br />
<br />
<br />
<br />
HPEN hOldPen = (HPEN)SelectObject(hDC, hPen);<br />
HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH));<br />
<br />
stRect.bottom = stRect.bottom-stRect.top;<br />
stRect.right = stRect.right-stRect.left;<br />
<br />
int btm = stRect.bottom;<br />
<br />
CRgn m_rgn6,m_rgn5,m_rgn7;<br />
<br />
m_rgn6.CreateRectRgn(0,0,4,stRect.bottom);<br />
m_rgn5.CreateRectRgn(stRect.right -4,0,stRect.right,stRect.bottom);<br />
m_rgn7.CreateRectRgn(0,stRect.bottom-4,stRect.right,stRect.bottom);<br />
<br />
stRect.left = 0 ;<br />
stRect.top = 0 ;<br />
stRect.bottom = 29;<br />
<br />
<br />
<br />
m_rgn2.CreateRectRgn(stRect.left,stRect.top,stRect.right,stRect.bottom);<br />
<br />
m_rgn2.CombineRgn(&m_rgn2,&m_rgn,RGN_DIFF);<br />
m_rgn2.CombineRgn(&m_rgn2,&m_rgn6,RGN_OR);<br />
m_rgn2.CombineRgn(&m_rgn2,&m_rgn5,RGN_OR);<br />
m_rgn2.CombineRgn(&m_rgn2,&m_rgn7,RGN_OR);<br />
<br />
SelectClipRgn(hDC,HRGN(m_rgn2));<br />
<br />
<br />
CBrush brush;<br />
<br />
brush.CreateSolidBrush(RGB(255,255,255));<br />
<br />
<br />
<br />
<br />
FillRgn(hDC,HRGN(m_rgn2),HBRUSH(brush));<br />
<br />
brush.CreateStockObject(NULL_BRUSH);<br />
<br />
int i = 0;<br />
<br />
for (i; i < btm;i)<br />
{<br />
MoveToEx(hDC,0,i,NULL);<br />
LineTo(hDC,stRect.right,i); <br />
i += 2;<br />
}<br />
<br />
hPen = CreatePen(PS_INSIDEFRAME, 2* GetSystemMetrics(SM_CXBORDER), <br />
RGB(33, 120, 120));<br />
<br />
SelectObject(hDC, hPen);<br />
<br />
MoveToEx(hDC,2,28,NULL);<br />
LineTo(hDC,stRect.right-2,28);<br />
<br />
<br />
MoveToEx(hDC,3,28,NULL);<br />
LineTo(hDC,3,btm-3);<br />
<br />
MoveToEx(hDC,stRect.right-3,28,NULL);<br />
LineTo(hDC,stRect.right-3,btm-3);<br />
<br />
MoveToEx(hDC,3,btm-4,NULL);<br />
LineTo(hDC,stRect.right-3,btm-4);<br />
<br />
<br />
MoveToEx(hDC,0,0,NULL);<br />
LineTo(hDC,0,btm);<br />
<br />
MoveToEx(hDC,stRect.right,0,NULL);<br />
LineTo(hDC,stRect.right,btm);<br />
<br />
<br />
::ReleaseDC(m_hWnd,hDC);<br />
<br />
SelectObject(hDC, hOldPen);<br />
SelectObject(hDC, hOldBrush);<br />
<br />
DeleteObject(hPen);<br />
DeleteObject(hDC);
it works well at most times, but when the window lost focus or reactiviate, it doesn't redraw. when u drag this window, it doesn't redraw after it moves from top-outside area back, either.
Jiang
|