Results 1 to 10 of 10

Thread: SetActiveWindow

  1. #1

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384

    SetActiveWindow

    In a window, i try to set the focus on another window here's my code :

    VB Code:
    1. Private Declare Function SetActiveWindow Lib "user32.dll" (ByVal hWnd As Long) As Long
    2.  
    3. '...
    4. SetActiveWindow lhWnd  
    5. 'lhWnd is a  variable containing the hwnd of the form i want to set focus on

    But for a reason or another the focus stays on the window in wich i called this function. is there something wrong here? thanks
    COBOL sa suce !!!

  2. #2
    jim mcnamara
    Guest
    MSDN description of the function
    The SetActiveWindow function activates a window. The window must be attached to the calling thread's message queue.
    In other words, the window you are messing with has to belong to your current application.

    Try this where:
    hWnd = other window
    Me.hWnd - current window's hWnd

    Code:
    Private Const WM_KILLFOCUS = &H8
    Private Const WM_SETFOCUS = &H7
    Private Declare Function SendMessage Lib "user32" _
    Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As _
    Long, ByVal wParam As Long, lParam As Any) As Long
    Dim retval
    retval= SendMessage( Me.hWnd, WM_KILLFOCUS,0&,0&)
    
    retval= SendMessage( hWnd, WM_SETFOCUS,0&,0&)

  3. #3

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384
    Can this function work with MDI childs
    COBOL sa suce !!!

  4. #4
    jim mcnamara
    Guest
    Yes, it will work on any window.

  5. #5

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384
    it's weird because when I use those functions, it execute the activate of the form i want the focus on but it doesn't set the focus. No mather when during that I print the MDIMother.ActiveFOrm.Name it gives me the name of the form from the one I want focus is called
    COBOL sa suce !!!

  6. #6
    Megatron
    Guest
    Try the SetForegroundWindow function.

  7. #7

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384
    well there must be soimething weird in my code cuz
    all the above don't work + setfocus (API) don't work
    COBOL sa suce !!!

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Post all of your code maxl, not just a portion of it, and we will take a look. I ask this because the responses I've seen from Megatron and jim mcnamara make sense, based on your original question. If their code/suggestions are not working then me thinks their might be variables in your equation that haven't been shown.
    Last edited by Hack; May 8th, 2002 at 06:05 PM.

  9. #9

    Thread Starter
    Hyperactive Member maxl's Avatar
    Join Date
    Jan 2002
    Location
    Montréal
    Posts
    384
    Anyway, I found a way to make it work without api so Thanks everybody for your response there must have been something weird in my code somewhere. Thanks again
    COBOL sa suce !!!

  10. #10
    Megatron
    Guest
    I hope it's not too late, but you could also use VB's ZOrder method too (is this what you're using now?).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width