Thread: Windows Messages

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    Windows Messages

    I was wondering if anyone could tell me the Messages sent to a window for the following events:

    1/ Window Gains Focus
    2/ Window Loses Focus
    3/ Mouse Button Released OUTSIDE of Window

    Ive tried every possible combination and none worked, WM_ACTIVATE doesnt seem to get sent when my window is created.

    By the way the window is a custom control class, so its a window in a window, im not sure if that makes a difference though.

    -PaYnE

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Use SetFocus() to give keyboard focus to the specified window.
    This will then send out WM_KILLFOCUS and WM_SETFOCUS.

    Use SetCapture() to achieve 3.

    gg

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    For the SetFocus() Part, what if I dont call it, is there any other way of knowing if the window has been Focused?

    Also for the SetCapture(), do I use it in the WM_MOUSEMOVE message?

    And if so, how exactly do i do that, since the WM_MOUSEMOVE message is only sent when the mouse moves inside the window...

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    For a custom control, you will have to call SetFocus() if you want it to have keyboard input.
    If you are extending Edit box or something like that, you should be able to intercept WM_SETFOCUS.

    The SetCapture() reference has example code you can play with.

    gg

  5. #5
    Registered User Dante Shamest's Avatar
    Join Date
    Apr 2003
    Posts
    970
    For the SetFocus() Part, what if I dont call it, is there any other way of knowing if the window has been Focused?
    As Codeplug said, your window is sent a WM_SETFOCUS message when it receives the focus.

    3.1.3 How do I know when the mouse has left my window?

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    I kinda have a bit of a problem, it is a custom control, but the Messages dont exactly get handled perfectly, like if i click very fast in a row i dont always receive the WM_LBUTTONUP and WM_LBUTTONDOWN messages.

    I handle it using translatemessage() and dispatchmessage() then its passed into the Proc and the messages arrive but sometimes they are umm delayed..

    Also i dont get a WM_SETFOCUS message at all, ive tried at startup, destruction, everything.

    No WM_SETFOCUS message is ever received
    Last edited by X PaYnE X; 01-10-2004 at 04:26 AM.

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Originally posted by X PaYnE X
    i click very fast in a row i dont always receive the WM_LBUTTONUP and WM_LBUTTONDOWN messages.
    WM_LBUTTONDBLCLK
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  8. #8
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> Also i dont get a WM_SETFOCUS message at all, ive tried at startup, destruction, everything.
    You'll never receive them unless someone calls SetFocus() on that window.
    Are you calling SetFocus() anywhere?

    gg

  9. #9
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    Ok thanx for the replies guyz, ill try them out first thing tomorrow (school), and lol im sorry i forgot about the double click message

    1 Last thing, how can i tell if the window needs repainting without overpainting?

    I tried using 2 variables, currentState and lastState, but they dont affect the paint if the window was covered by another window, therefore just leaving a blank window.

    What im trying to ask, is there a function i can run during the WM_PAINT message is being handled, to find out if the window really needs to be painted? I dont want to waste time/resources on painting it, if its already painted.

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Read over the WM_PAINT reference again (I usually have to).
    Use GetUpdateRect() to only paint the area the needs it.
    Then read this technical article.

    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sending windows messages
    By Ideswa in forum Windows Programming
    Replies: 2
    Last Post: 03-02-2006, 01:27 PM
  2. Menu Item Caption - /a for right aligned Accelerator?
    By JasonD in forum Windows Programming
    Replies: 6
    Last Post: 06-25-2003, 11:14 AM
  3. Windows Rant followed by installation question
    By confuted in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 06-21-2003, 04:42 PM
  4. Codec Bitrates?
    By gvector1 in forum C# Programming
    Replies: 2
    Last Post: 06-16-2003, 08:39 AM
  5. Manipulating the Windows Clipboard
    By Johno in forum Windows Programming
    Replies: 2
    Last Post: 10-01-2002, 09:37 AM