My application is using the following static control
CONTROL "", DISPLAY, "STATIC", SS_BLACKRECT, 10, 10, 300, 200
My application plota a line in this area, when I clear the line by setting the color to black and replotting the line the liane are is darker.
To resolve this I draw a rectngle using the black brush.
Where do I put the code so the drawing occurs as soon as the Dialog is visable, I tried using the WM_PAINT message but the results were not pretty.
static BOOL CALLBACK DialogFunc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)<br />
{<br />
switch (msg) {<br />
<br />
case WM_INITDIALOG:<br />
InitializeApp(hwndDlg,wParam,lParam);<br />
hDisplayArea = GetDlgItem(hwndDlg, DISPLAY);<br />
<br />
hdcDisplay = GetDC(hDisplayArea);<br />
GetClientRect(hDisplayArea, &rDisplayRect);<br />
hBrush = GetStockObject(BLACK_BRUSH);<br />
SelectObject(hdcDisplay, hBrush);<br />
Rectangle(hdcDisplay, rDisplayRect.left, rDisplayRect.top, rDisplayRect.right, rDisplayRect.bottom);<br />
<br />
<br />
return TRUE;<br />
<br />
case WM_COMMAND:<br />
switch (LOWORD(wParam)) {<br />
case IDOK:<br />
<br />
<br />
int x, y, i;<br />
int nNumHDivisions = 10;<br />
int nNumVDivisions = 10;<br />
int nPixBetHDivisions = 0;<br />
int nPixBetVDivisions = 0;<br />
int nTimeBase = 10;<br />
int nPosition = 0;<br />
int nScaleFactor = 1;<br />
int nXoffset = 100;<br />
int nStartData = 0, nEndData = 0;<br />
<br />
hpBlack = CreatePen(PS_SOLID,1,crBLK);<br />
hpPen[0] = CreatePen(PS_SOLID,1,crWHT);<br />
hpPen[1] = CreatePen(PS_DASH,1,crWHT);<br />
hpPen[2] = CreatePen(PS_SOLID,1,crGRN);<br />
hpPen[3] = CreatePen(PS_DASH,1,crGRN);<br />
hpPen[4] = CreatePen(PS_SOLID,1,crBLU);<br />
hpPen[5] = CreatePen(PS_DASH,1,crYEL);<br />
hpPen[6] = CreatePen(PS_SOLID,1,crRED);<br />
hpPen[7] = CreatePen(PS_DASH,1,crRED);<br />
<br />
hDisplayArea = GetDlgItem(hwndDlg, DISPLAY);<br />
<br />
hdcDisplay = GetDC(hDisplayArea);<br />
GetClientRect(hDisplayArea, &rDisplayRect);<br />
hBrush = GetStockObject(BLACK_BRUSH);<br />
SelectObject(hdcDisplay, hBrush);<br />
Rectangle(hdcDisplay, rDisplayRect.left, rDisplayRect.top, rDisplayRect.right, rDisplayRect.bottom);<br />
<br />
nPixBetHDivisions = rDisplayRect.right / nNumHDivisions;<br />
nPixBetVDivisions = rDisplayRect.bottom / nNumVDivisions;<br />
nXoffset = rDisplayRect.bottom / 2;<br />
nPosition = nXoffset - nPosition;<br />
<br />
for(x = nPixBetHDivisions; x < rDisplayRect.right; x += nPixBetHDivisions)<br />
{<br />
MoveToEx(hdcDisplay, x, 0, NULL);<br />
for(y = 10; y < rDisplayRect.bottom; y=y+10)<br />
SetPixel(hdcDisplay, x, y, crWHT);<br />
MoveToEx(hdcDisplay, x, 0, NULL);<br />
}<br />
for(y = nPixBetVDivisions; y < rDisplayRect.bottom; y+= nPixBetVDivisions)<br />
{<br />
MoveToEx(hdcDisplay, 0, y, NULL);<br />
for(x = 10; x < rDisplayRect.right; x=x+10)<br />
SetPixel(hdcDisplay, x, y, crGRN);<br />
}<br />
for(i=0; i<MAX_POINTS; i++)<br />
{<br />
Data[i].x = i;<br />
Data[i].y = (int) (sin(3.14 * i)/MAX_POINTS);<br />
}<br />
<br />
for(i=0; i<rDisplayRect.right; i=i+nTimeBase)<br />
{<br />
DrawLine(hdcDisplay, rDisplayRect.bottom, i, Data[nStartData].y, i + nTimeBase, Data[nStartData + 1].y, nPosition, nScaleFactor, crRED);<br />
nStartData++;<br />
}<br />
<br />
SetROP2(hdcDisplay, R2_XORPEN);<br />
nStartData = 0;<br />
sleep(100);<br />
for(i=0; i<rDisplayRect.right; i=i+nTimeBase)<br />
{<br />
DrawLine(hdcDisplay, rDisplayRect.bottom, i, Data[nStartData].y, i + nTimeBase, Data[nStartData + 1].y, nPosition, nScaleFactor, crRED);<br />
nStartData++;<br />
}<br />
ReleaseDC(hwndDlg, hdcDisplay);<br />
return 1;<br />
case IDCANCEL:<br />
EndDialog(hwndDlg,0);<br />
return 1;<br />
}<br />
break;<br />
<br />
case WM_CLOSE:<br />
EndDialog(hwndDlg,0);<br />
return TRUE;<br />
<br />
}<br />
return FALSE;<br />
}<br />
<br />
As always any help is greatly appreciated.
Tom
|