GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 22-Aug-2005, 06:22
markiv markiv is offline
New Member
 
Join Date: Aug 2005
Posts: 3
markiv is on a distinguished road

moving a window without using the title bar


hello...

I want the user to be able to move my application's window by clicking anywhere on the window area and draggin it around....

here is the code i'm currently usin in my main window procedure:

CPP / C++ / C Code:
	               
case WM_LBUTTONDOWN:
       GetWindowRect(hWnd, &MainRect);
      
      //save current cursor coordinate
      GetCursorPos(&point);
     
      ScreenToClient(hWnd, &point);
      break;

case WM_MOUSEMOVE :
     
      GetCursorPos(&curpoint);
      if(wParam==MK_LBUTTON)
      {     
            MoveWindow(hWnd, curpoint.x - point.x, curpoint.y - point.y, 
            MainRect.right - MainRect.left, MainRect.bottom - MainRect.top,  
            TRUE);
      }
      break;


(hWnd is the main window, curpoint and point are POINT variables)

now this works, but not very well. If the mouse is moved around too fast while draggin the window gets stuck.... same thing happens if some part of the window is moved outside the viewable area of the screen...

Is there a better way to do this?
Last edited by LuciWiz : 22-Aug-2005 at 06:52. Reason: Please insert your C++ code between [c++] & [/c++] tags
  #2  
Old 07-Jun-2006, 13:50
Liox Liox is offline
New Member
 
Join Date: Jun 2006
Posts: 1
Liox is on a distinguished road

Re: moving a window without using the title bar


Hay, the window starts freezing becouse as you move the mouse faster the mouse moves off the window and the move mouse message no longer gets sent to your windows window procedure, to fix this u can use the SetCapture(hWnd); command which tells the program tht no matter where the mouse is it only works for your window add this under the case WM_LBUTTONDOWN, also dont forget to add case WM_LBUTTONUP with ReleaseCapture(); in it becouse other wize the mouse wont work out side ur window once u release the button. to ellaborate

CPP / C++ / C Code:
	               
case WM_LBUTTONDOWN:
       SetCapture( hWnd );
       GetWindowRect(hWnd, &MainRect);
      
      //save current cursor coordinate
      GetCursorPos(&point);
     
      ScreenToClient(hWnd, &point);
      break;

case WM_MOUSEMOVE :
     
      GetCursorPos(&curpoint);
      if(wParam==MK_LBUTTON)
      {     
            MoveWindow(hWnd, curpoint.x - point.x, curpoint.y - point.y, 
            MainRect.right - MainRect.left, MainRect.bottom - MainRect.top,  
            TRUE);
      }
      break;

case WM_LBUTTONUP:
       ReleaseCapture();
break;

sowi if this is abit confusing i have alwayz been bad at explaining stuff hope it helps
 
 

Recent GIDBlogUS Elections and the ?Voter?s Responsibility? by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to minimize a application to the system tray? Thomas555 C++ Forum 12 20-May-2005 14:35
Win32 Window Shading behavior (like linux) WillyumYum C++ Forum 3 18-Apr-2005 15:36
#including resource file causing window procedure to be undeclared??? ubergeek C++ Forum 3 07-Feb-2005 15:39
Changing window start colour Rosdahale C++ Forum 5 19-Jan-2005 16:51
Can someone check to see if my program is correct tommy69 C Programming Language 2 12-Apr-2004 21:36

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 09:55.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.