2015-04-05 34 views
1

我在用窗戶搞亂,截至目前,我確實有一個出現的聲音,當我點擊(按鈕按下)並拖動,然後鬆開(按鈕),我們有一個正方形......如何當我調整它消失的窗口大小?爲什麼?我錯過了什麼?感謝您花時間審閱這篇文章。Buit矩形(我自己的類型),不會調整窗口大小?

//LEFT BUTTON DOWN MOVEMENT 
    case WM_LBUTTONDOWN: 
     // if not drwing then save start poostion and set drawing flag 
     // goes here startPosition 
     if(! isDrawing) 
     { 
     startPosition = MAKEPOINTS(lParam);// poiint where the mouseis clicked 
     isDrawing = true; 
     } 
     else{ 
     // how did I get a button down while I was drawing 
     } 
     break; 

//when the button is let up the message is sent, its a drawing mode or not drawing, or draging draw..... 
// LEFT BUTTON UP movement 
    case WM_LBUTTONUP: 
     // if drawing is not occuring, then 
     // if I am drawing then save endeding point(position), draw a rectangle (startPositon and endPoistion) 
     // 
     if(isDrawing) 
     { 
     endPosition = currentPosition = MAKEPOINTS(lParam); 

     //draw rectangle here. 
     // This is what we had 1st.... RectType rect(startPosition.x, startPosition.y, endPosition.x, endPosition.y); 
     RectType rec(startPosition , endPosition);// this is what we want...need to write teh code for this. 

     //something and I cant call beginPaint(),and end paint(); 
     if(hdc = GetDC(hWnd)) 
     { 
      ::Rectangle(hdc, rec.myRect.left, rec.myRect.top, rec.myRect.right, rec.myRect.bottom); 
      ReleaseDC(hWnd, hdc);// this is how we call on paint with out being in WM_Paint 
     } 
     isDrawing = false;  // this is the flag.    
     } 
     break; 

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 
{ 
    int wmId, wmEvent; 
    PAINTSTRUCT ps; 
    HDC hdc; 

    switch (message) 
    { 

//LEFT BUTTON DOWN MOVEMENT 
    case WM_LBUTTONDOWN: 
     // if not drwing then save start poostion and set drawing flag 
     // goes here startPosition 
     if(! isDrawing) 
     { 
     startPosition = MAKEPOINTS(lParam);// poiint where the mouseis clicked 
     isDrawing = true; 
     } 
     else{ 
     // how did I get a button down while I was drawing 
     } 
     break; 

//when the button is let up the message is sent, its a drawing mode or not drawing, or draging draw..... 
// LEFT BUTTON UP movement 
    case WM_LBUTTONUP: 
     // if drawing is not occuring, then 
     // if I am drawing then save endeding point(position), draw a rectangle (startPositon and endPoistion) 
     // 
     if(isDrawing) 
     { 
     endPosition = currentPosition = MAKEPOINTS(lParam); 

     //draw rectangle here. 
     // This is what we had 1st.... RectType rect(startPosition.x, startPosition.y, endPosition.x, endPosition.y); 
     RectType rec(startPosition , endPosition);// this is what we want...need to write teh code for this. 

     //something and I cant call beginPaint(),and end paint(); 
     if(hdc = GetDC(hWnd)) 
     { 
      ::Rectangle(hdc, rec.myRect.left, rec.myRect.top, rec.myRect.right, rec.myRect.bottom); 
      ReleaseDC(hWnd, hdc);// this is how we call on paint with out being in WM_Paint 
     } 
     isDrawing = false;  // this is the flag.    
     } 
     break; 
    case WM_MOUSEMOVE: 
     //if I am drawing... 
     //if I am not drawing save current postion, and latested or endingPositon 
     // darw rectangle(StartPos, latestPos) 
     if(isDrawing)// 
     { 
     currentPosition = MAKEPOINTS(lParam); 
     RectType rec(startPosition , currentPosition);// this is what we want. 
     //draw rectangle here. 
     if(hdc = GetDC(hWnd)) // GetDC is the window function.... 
     { 
      POINTS prevPosition = currentPosition; 
      currentPosition = MAKEPOINTS(lParam); 
      RectType rec(startPosition , currentPosition); 
      RectType prevRec(startPosition, prevPosition); 

      HDC dc = GetDC(hWnd); 

      HPEN pen = CreatePen(PS_DASH, 0, RGB(0, 0, 0)); 
       HBRUSH brush = CreateSolidBrush(RGB(rand()%255, rand()%255, rand()%255) );//---------------------------------------------NEWWWWWWWWWWWWRGB(200,0,0) 
      SelectObject(hdc,pen); 
//give us a quaiz hollow square.below. 
      SelectObject(hdc,GetStockObject(HOLLOW_BRUSH) ); 
      //::SetROP2(hdc, R2_XORPEN);//these use exclusive OR bit wise logical operator...try R2_NOT,for later 
// 1^0 = 1...so if the comparing two are differnet 1 and 0 we have 1 
// 1^1 = 0...if we have all the same 0,0 then it would be 1.... 

      ::Rectangle(hdc, prevRec.myRect.left, prevRec.myRect.top , prevRec.myRect.right, prevRec.myRect.bottom); 
      ::Rectangle(hdc, rec.myRect.left, rec.myRect.top , rec.myRect.right, rec.myRect.bottom); 
      ReleaseDC(hWnd, hdc);// this is how we call on paint with out being in WM_Paint 
     } 
     } 
     break; 

回答

0

您需要處理WM_PAINT並在WM_MOUSEMOVE中進行繪製。在WM_MOUSEMOVE(或其他地方)調用::當你移動矩形時失效。這將導致Windows發送WM_PAINT消息。