//通过线程不停的绘制界面50ms
unsigned int _stdcall BeginDrawProc(void *param)
{
CDrawWnd *pThis = (CDrawWnd*)param;
while (1)
{
pThis->Draw();
Sleep(50);
}
}
//然后在Draw中实现要绘制的控件如按钮,背景等
void CDrawWnd::Draw()
{
HDC hDC = GetDC(m_hWnd);
if (hDC == NULL)
return;
RECT rect;
GetClientRect(m_hWnd, &rect);
HDC hMemDC = CreateCompatibleDC(hDC);
HBITMAP hBitmap = CreateCompatibleBitmap(hDC, 400, 300);
SelectObject(hMemDC, hBitmap);
HBRUSH hBrushBack = CreateSolidBrush(RGB(255, 255, 255));
SelectObject(hMemDC, hBrushBack);
FillRect(hMemDC, &rect, hBrushBack);
//画背景
HDC dcTmp = CreateCompatibleDC(NULL);
//HBITMAP hBitmapBK = (HBITMAP)LoadImage(m_hInstance, MAKEINTRESOURCE(IDB_BK_BMP), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
//获取位图信息
//SelectObject(dcTmp, hBitmapBK);
if (m_hBitmapBK == NULL)
{
DeleteDC(dcTmp);
DeleteDC(hMemDC);
return;
}
SelectObject(dcTmp, m_hBitmapBK);
BitBlt(hMemDC, 0, 0, 400, 65, dcTmp, 0, 0, SRCCOPY);
//画关闭按钮
DrawCloseBtn(hMemDC);
//画表格
if (m_bClickTraffic)
{
DrawTrafficLine(hMemDC);
}
else
{
DrawChangeBtn(hMemDC);
//画点击按钮
DrawBtn(hMemDC);
//画文本
DrawText(hMemDC);
//华编辑框
DrawEdit(hMemDC);
//输出编辑框的结果
DrawResult(hMemDC);
}
BitBlt(hDC, 0, 0, 400, 300, hMemDC, 0, 0, SRCCOPY);
DeleteObject(hBrushBack);
DeleteObject(hBitmap);
DeleteObject(dcTmp);
DeleteDC(hMemDC);
ReleaseDC(m_hWnd, hDC);
}
//一个Btn的双缓冲的实现
void CDrawWnd::DrawBtn(HDC hDC)
{
RECT rcClient;
POINT pt;
GetWindowRect(m_hWnd, &rcClient);
GetCursorPos(&pt);
HDC hTmpDC = CreateCompatibleDC(NULL);
//HBITMAP hBitmap = (HBITMAP)LoadImage(m_hInstance, MAKEINTRESOURCE(IDB_EXCUTE_BMP), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
#if _DEBUG
if (m_hExecuteBmp == NULL)
{
MessageBox(NULL, _T("位图文件加载失败"), _T("温馨提示"), MB_ICONERROR);
DeleteDC(hTmpDC);
return;
}
#else
if (m_hExecuteBmp == NULL)
{
//MessageBox(NULL, _T("位图文件加载失败"), _T("温馨提示"), MB_ICONERROR);
DeleteDC(hTmpDC);
return ;
}
#endif
SelectObject(hTmpDC, m_hExecuteBmp);
if ((m_CursorPt.x > 310 && m_CursorPt.x<370) &&
(m_CursorPt.y>218 && m_CursorPt.y < 270) && PtInRect(&rcClient, pt))
{
BitBlt(hDC, 310, 218, 62, 62, hTmpDC, 0, 0, SRCCOPY);
//printf("Selected!\n");
}
else
{
BitBlt(hDC, 310 - 5, 218, 62, 62, hTmpDC, 62, 0, SRCCOPY);
//printf("Not Selected!\n");
}
//DeleteObject(hBitmap);
DeleteDC(hTmpDC);
}