我在一个菜单命令中,想要刷新客户区中的内容,调用UpdateWindow(hWnd),不能实现想要的效果,直接的发送消息也不能实现SendMessage(hWnd,WM_PAINT,0,0),
后来用InvalidateRect(..)就可以了,为什么呢???

解决方案 »

  1.   

    UpdateWindow(hWnd),也是发WM_PAINT消息,只重写无效区,只有InvalidateRect(..)使窗体无效系统自已会发WM_PAINT重绘窗体的
      

  2.   

    The UpdateWindow function updates the client area of the specified window by sending a WM_PAINT message to the window if the window's update region is not empty. The function sends a WM_PAINT message directly to the window procedure of the specified window, bypassing the application queue. If the update region is empty, no message is sent. 
    The InvalidateRect function adds a rectangle to the specified window's update region. The update region represents the portion of the window's client area that must be redrawn. 
      

  3.   

    谢谢。楼上的,你发的贴我在MSDN里也读过,不过,不是怎么能理解,你能再说细一点吗?
      

  4.   

    在窗口中存在无效区域的时候,UpdateWindow函数才会立即发送一个WM_PAINT消息,要是窗口中不存在无效区域,UpdateWindow基本上什么也不做
      

  5.   

    什么是无效区域:
    收到WM_PAINT消息后绘制客户区,很多时候只需要更新很小的一个区域就可以了。例如
    当某小窗口覆盖了部分客户区的时候情况就是如此。关闭小窗口,需要重画的只是先前被小窗口遮住的矩形区域。这个区域:“无效区域”
      

  6.   

    LRESULT CALLBACK MainWndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
      ......
      case WM_COMMAND:
           wmId    = LOWORD(wParam); 
           wmEvent = HIWORD(wParam); 
           // 分析菜单选择:
           switch (wmId)
          {
          case IDM_ADDRECORD://这是菜单ID
               在这里的操作是新建一个结点,添加到一个列表中,然后使窗口刷新。
               //我调用的是UpdateWindow(hWnd).结果是没能实现窗口的刷新。
          ...
    }
    seu07201213(【卐】〖汪洋中的一片叶子〗≈^︵^≈):
      是不是这个时候,我的窗口中没有存在无效区,所以,调用UpdateWindow(hWnd)是没用的?
    而只能用InvalidateWindowRect(...)来强行的使整个客户区无效(我要重绘客户区中的所有内容)?