SetActiveWindow-VBForums
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
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,334
    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.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.