SystemBar显示的一点问题
今天调试SystemBar,主要功能是: 由主页面发送WM_COPYDATA消息给SystemBar,传递一个结构,结构中包含了要用到的图标,窗口句柄,自定义的消息等等内容,问题是,我在SystemBar中总是不能正确的显示出图标来。
1 case WM_PAINT: 2 hdc = BeginPaint(hWnd, &ps); 3 dwErrorCode = GetLastError(); 4 if (hdc && pThis) 5 { 6 int left = ps.rcPaint.left; 7 int top = ps.rcPaint.top; 8 int width = ps.rcPaint.right - left; 9 int height = ps.rcPaint.bottom - top; 10 BitBlt(hdc, left, top, width, height, pThis->m_hMemDC, left, top, SRCCOPY); 11 } 12 EndPaint(hWnd, &ps); 13 break;
这样简单的一段代码却总是不能正常显示,感觉是MemDC出了问题,这个还没有解决,最后被迫在绘制的地方使用了硬件DC。代码如下:
1 LRESULT CSystemBar::Draw() 2 { 3 //add code here... 4 HDC hDC = GetDC(m_hwndHost); 5 for (int i = 0; i < m_iconList.count; i++) 6 { 7 int iconIndex = m_iconList.IconArray[i].index; 8 RECT rc; 9 rc.left = SYSTEM_BAR_ICON_START_POS + i*(SYSTEM_BAR_ICON_WIDTH + SYSTEM_BAR_ICON_INTERSPACE); 10 rc.right = rc.left + SYSTEM_BAR_ICON_WIDTH; 11 rc.top = m_iDisplayHeight - BAR_HEIGHT + (BAR_HEIGHT - SYSTEM_BAR_ICON_HIGHT)/2; 12 rc.bottom = rc.top + SYSTEM_BAR_ICON_HIGHT; 13 HBITMAP hBmp = LoadBitmap(g_hInst, MAKEINTRESOURCE(iconIndex)); 14 HDC hMemDC = CreateCompatibleDC(hDC); 15 DWORD dwErrorCode = GetLastError(); 16 HGDIOBJ hOldBmp = SelectObject(hMemDC,hBmp); 17 BitBlt(hDC, 0, 0, 56, 30, hMemDC, 0, 0, SRCCOPY); 18 SelectObject(hMemDC,hOldBmp); 19 DeleteObject(hBmp); 20 DeleteDC(hMemDC); 21 } 22 ReleaseDC(m_hwndHost,hDC); 23 return 0; 24 }
本来想让硬件DC当作参数传进来,但不知道为什么总是无效句柄,难道是因为我的硬件DC是在窗口PROC里边获取的,而PROC不属于这个类引起的?后来只好根据窗口句柄重新获取DC,这才搞定。
Mark一下,以防自己忘记~~~