标题:绘制bezier曲线时如何触发wm_paint
只看楼主
zwdbxlt
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2015-1-1
结帖率:100%
 问题点数:0 回复次数:1 
绘制bezier曲线时如何触发wm_paint
在看windows编程绘制bezier曲线时遇到一个小疑问。过程函数如下
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
     static POINT apt[4] ;
     HDC          hdc ;
     int          cxClient, cyClient ;
     PAINTSTRUCT  ps ;
     
     switch (message)
     {
     case WM_SIZE:
          cxClient = LOWORD (lParam) ;
          cyClient = HIWORD (lParam) ;
         
          apt[0].x = cxClient / 4 ;
          apt[0].y = cyClient / 2 ;
         
          apt[1].x = cxClient / 2 ;
          apt[1].y = cyClient / 4 ;
         
          apt[2].x =     cxClient / 2 ;
          apt[2].y = 3 * cyClient / 4 ;
         
          apt[3].x = 3 * cxClient / 4 ;
          apt[3].y =     cyClient / 2 ;
         
          return 0 ;

     case WM_LBUTTONDOWN:
     case WM_RBUTTONDOWN:
     case WM_MOUSEMOVE:
          if (wParam & MK_LBUTTON || wParam & MK_RBUTTON)
          {
               hdc = GetDC (hwnd) ;
               
               SelectObject (hdc, GetStockObject (WHITE_PEN)) ;
               DrawBezier (hdc, apt) ;
               
               if (wParam & MK_LBUTTON)
               {
                    apt[1].x = LOWORD (lParam) ;
                    apt[1].y = HIWORD (lParam) ;
               }
               
               if (wParam & MK_RBUTTON)
               {
                    apt[2].x = LOWORD (lParam) ;
                    apt[2].y = HIWORD (lParam) ;
               }
               
               SelectObject (hdc, GetStockObject (BLACK_PEN)) ;
               DrawBezier (hdc, apt) ;
               ReleaseDC (hwnd, hdc) ;
          }

          return 0 ;
         
     case WM_PAINT:
          InvalidateRect (hwnd, NULL, TRUE) ;
         
          hdc = BeginPaint (hwnd, &ps) ;
         
          DrawBezier (hdc, apt) ;
         
          EndPaint (hwnd, &ps) ;
          return 0 ;
         
     case WM_DESTROY:
          PostQuitMessage (0) ;
          return 0 ;
     }
鼠标左键和右键那段没看明白,我没看到上面有使画面无效的函数,但是为什么我右键或左键就能使画面立刻重绘呢?求大神解救。
搜索更多相关主题的帖子: windows message 如何 
2015-03-21 14:03
zwdbxlt
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2015-1-1
得分:0 
sorry,我脑袋混了。。。。
2015-03-21 14:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-442895-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012982 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved