为什么不能在屏幕上画线   
HWND hWnd=::GetDesktopWindow();//
HDC hdc= ::GetDC(hWnd);
        ::MoveToEx(hdc,100,120,NULL);
        ::LineTo(hdc,900,900);        ReleaseDC(hWnd,hdc);
如果把HDC hdc= ::GetDC(hWnd);改成::GetDC(NULL);就行?我觉得是窗口的HWND没有获取对?

解决方案 »

  1.   

    HDC GetDC(
      HWND hWnd   // handle to window
    );
    hWnd 
    [in] Handle to the window whose DC is to be retrieved. If this value is NULL, GetDC retrieves the DC for the entire screen. 
      

  2.   


    hWnd
    设备上下文环境被检索的窗口的句柄,如果该值为NULL,GetDC则检索整个屏幕的设备上下文环境。 
      

  3.   

    问题是HWND hWnd=::GetDesktopWindow();//
    HDC hdc= ::GetDC(hWnd);
    为什么不行
      

  4.   

    如果你一定要用GetDesktopWindow();
    要这样写
    HWND hWnd=::GetDesktopWindow();//
    HDC hdc= ::GetWindowDC(hWnd);
    而不是GetDC();