Thread: How to tell when a window is moved? (MFC)

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    34

    How to tell when a window is moved? (MFC)

    I am pretty new to Windows programming, but not to C++ in general. I am trying to figure out how, in my program, I would be able to tell when a window is moved; as in the user just clicking the title bar and dragging the window around. Is SetWindowPos called by the OS? I am trying to learn how to tell when this occurs and then get the window's new coordinates. I am trying to use this to then recalculate coordinates local to the application/program window. I have a 2D graphic element within the window that has it's own coordinates that I will be using, but I need to be able to tell if the window has moved to recalculate these coordinates in relation to the screen's pixel coordinates. Thank you for any help you might be able to give me.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You will receive a WM_MOVE message in your event loop.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    34
    Thank you Mats for the simple and concise answer. I appreciate it. I am however having a difficult time locating the event loop in this particular program. I am basically doing maintenance and bug fixing but have never had to mess with this sort of area of the code before. I was wondering if anyone would be able to tell me how I might be able to find it easier. I've been using VS' "find in files" option to search for various words or phrases that might lead me to the loop, but have been unable to find it thus far. Searched for things like DispatchMessage, Run, CWinApp, WindowProc (on the off chance they didn't give it a custom name). Any help would be greatly appreciated, thank you.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, in MFC, you would probably do "onMove" or some such. Sorry, I missed that bit.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    34
    Thank you again Mats. I guess I should have been able to figure out from all the message maps that in MFC messages are handled differently on the surface, since it hides the details (I think). Thank you for all your help.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Moving a window is going to use a non-client area message since you must click on the title bar which is a non-client area in order to move it. Once you catch this message you can then do anything you want. I seem to remember that you must override the CWnd MsgProc in order to receive the message. There are certain Windows messages that do not get routed through MFC's normal message routing system and I believe this may be one of them.

  7. #7
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I doubt it is, since this message is essential for many applications and blocking it from the message handler wouldn't be a wise thing to do by MFC.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  2. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 02:39 PM
  3. Window Resize question (MFC)
    By IfYouSaySo in forum Windows Programming
    Replies: 2
    Last Post: 11-16-2005, 12:34 PM
  4. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 07:23 AM
  5. Enable/Disable A Window in SplitView :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 05-06-2002, 10:26 PM