关于OnPaint()和OnQueryDragIcon()两个函数
希望高手能够解释一下。// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.
void CAPIHook_EXEDlg::OnPaint()
{
 if (IsIconic())
 {
  CPaintDC dc(this); // device context for painting
  
  SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);//这里调用什么意思
  
  // Center icon in client rectangle
  int cxIcon = GetSystemMetrics(SM_CXICON);//这里调用什么意思
  int cyIcon = GetSystemMetrics(SM_CYICON);
  CRect rect;
  GetClientRect(&rect);
  int x = (rect.Width() - cxIcon + 1) / 2;//这里调用什么意思
  int y = (rect.Height() - cyIcon + 1) / 2;//
  
  // Draw the icon
  dc.DrawIcon(x, y, m_hIcon);//这里调用什么意思
 }
 else
 {
  CDialog::OnPaint();
 }
}// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CAPIHook_EXEDlg::OnQueryDragIcon()
{
 return (HCURSOR) m_hIcon;//这里调用什么意思
}

解决方案 »

  1.   

    1.OnPaint() 和OnQueryDragIcon() 这2个消息什么意思啊,具体在网上找了下
    OnPaint()是重绘,大小...。
    CWnd::OnQueryDragIcon   ()其实是一个回调函数,就是当鼠标拖动到CWnd的窗口上的时候,系统自动调用这个函数来确定显示什么样的拖动图标。
       OnQueryDragIcon:The   framework   calls   this   member   function   by   a   minimized   (iconic)   window   that   does   not   have   an   icon   defined   for   its   class.   The   system   makes   this   call   to   obtain   the   cursor   to   display   while   the   user   drags   the   minimized   window.但是还不怎么理解这2个消息什么意思啊。OnPaint()为WM_PAIN消息,那OnQueryDragIcon   ()是什么消息2.1.发送擦除背景的图片的消息,要进行背景图片的更换; 
    2.得到图片的宽高; //得到那个图片啊,这里也没指定那个图片啊
    3.图片将要显示的位置; 
    4.在指定的位置显示图片; 
    5.显示鼠标的图标 //我在一些自己建的工程中也没这个消息啊,可是也可以找到鼠标啊能不能讲的具体点啊  谢谢了
      

  2.   

    CWnd::OnQueryDragIcon   ()其实是一个回调函数,就是当鼠标拖动到CWnd的窗口上的时候,系统自动调用这个函数来确定显示什么样的拖动图标。但是我还是不理解~·
      

  3.   

    ON_WM_PAINT只有当需要对窗口进行绘制时才有用,你如果不做任何绘制工作,这个函数自然没用;   
      ON_WM_ERASEBKGND当背景擦除时被调用,你如果不需要定制背景,DefWindowProc自然会用窗口类的刷子绘制背景,你也不必操心;   
      ON_WM_QUERYDRAGICON只有窗口在最小化时被拖动、而且窗口类没有注册缺省图标时才有用,而事实上,MFC的窗口类总是会注册图标的(DefWindowProc会返回这个图标),即使没有,Windows也会使用系统缺省图标,因此没有它也无关紧要