比如一个listbox控件程序来试验wndproc(UNIT msg){
LPDRAWITEMSTRUCT pDi
char value[20];
hwnd hListbox;
switch(msg){
case WM_CREATE:
         hListbox=createwindow("listbox",NULL....);
case WM_DRAWITEM:
if((UINT) wParam==ID_LIST)
pDI=(LPDRAWITEMSTRUCT) lParam;
         wsprintf(value,"%d",pDI->hDC);
         messageboxA(NULL,value,NULL,MB_OK);
         return 0;
}
}
我测试了下,每次WM_DRAWITEM的pDI->hDC都不一样,请问有没有办法再不触发WM_DRWAITEM的情况下获得其hdc,我用getDC(hListbox)这种获得的hDC和WM_DRAWITEM消息里的pDI->hDC出入每次都很大,应该不是这样获得,我需要经常重画listbox,却无法再不触发WM_DRWAITEM的情况下获得其正确的hDC

解决方案 »

  1.   

    GetDC
    The GetDC function retrieves a handle to a display device context (DC) for the client area of a specified window or for the entire screen. You can use the returned handle in subsequent GDI functions to draw in the DC. The GetDCEx function is an extension to GetDC, which gives an application more control over how and whether clipping occurs in the client area. HDC GetDC(
      HWND hWnd   // handle to window
    );