Results 1 to 9 of 9

Thread: Got Focus?

  1. #1

    Thread Starter
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    In an app I have an icon on the tray which will make a window visible again using ShowWindow API.
    This all works fine. Only thing is the window doesn't really have the focus - it is the topmost window
    (I use SetForegroundWindow API to get it there), but the titlebar isn't colored until I click it.
    Is there a way to get this window selected, i.e. in the state is was before it was hidden?

    I tried Putfocus API, didn't work.

    Maybe generating a mouse click at it?

    P.S.
    What's the best way of reading a windows size (not just min or max), position, etc and
    restoring a hidden window to the state it was before being hidden? The ShowWindow API restores
    the window to a min size.

    [Edited by dsy5 on 09-28-2000 at 07:49 PM]
    Donald Sy - VB (ab)user

  2. #2
    Lively Member
    Join Date
    Sep 2000
    Location
    NC, USA
    Posts
    102

    Question

    Can you just use the setfocus method of the form? i.e. frmMain.SetFocus

  3. #3

    Thread Starter
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Originally posted by KillemAll
    Can you just use the setfocus method of the form? i.e. frmMain.SetFocus
    I guess I wasn't too clear here. It is not the form I want to show, it is a running app
    which was previously hidden.

    [Edited by dsy5 on 09-28-2000 at 07:52 PM]
    Donald Sy - VB (ab)user

  4. #4
    Lively Member
    Join Date
    Sep 2000
    Location
    NC, USA
    Posts
    102
    so the hidden app is not part of the same application in VB that you are trying to do this with? like, you are trying to bring up an external hidden application from your programs icon in the systray? is that it?

  5. #5
    Guest
    The SetForegroundWindow api function works for me.

    Code:
    Private Declare Function FindWindow Lib "user32.dll" _
    Alias "FindWindowA" (ByVal lpClassName As Any, ByVal _
    lpWindowName As Any) As Long
    
    Declare Function SetForegroundWindow Lib "user32.dll" _
     (ByVal hwnd As Long) As Long
    
    
    Private Sub Command1_Click()
    
    h = FindWindow(vbNullString, "Calculator") 'Find Calculator
    x = SetForegroundWindow(h) 'Give it focus
    
    End Sub

  6. #6

    Thread Starter
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Matthew
    It works if you just call the function from code, but when you are clicking an icon in
    the system tray, I believe the Mousemove event for the icon that instantiates the
    SetForegroundWindow receives the focus even after you set the handle to the program
    to receive focus. Am I making sense here?

    At any event, the SetForegroundWindow doesn't work here.

    Killemall
    Yes, that's what I'm trying to do.

    [Edited by dsy5 on 09-28-2000 at 08:19 PM]
    Donald Sy - VB (ab)user

  7. #7
    Guest
    Argh, making life harder, aye?

    How about actually putting the code into a Command Button. And calling it in the menu property?

    Code:
    Private Sub menu_Click()
    Command1_Click
    End Sub

  8. #8

    Thread Starter
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    Originally posted by Matthew Gates
    Argh, making life harder, aye?

    How about actually putting the code into a Command Button. And calling it in the menu property?

    Code:
    Private Sub menu_Click()
    Command1_Click
    End Sub
    I do have a right button menu on the icon that has the code in one of its selections and it works.

    Its the fact that I would like to just click the icon and perform a toggle of hiding
    and showing by clicking the icon. May not be possible due to that Mouse_move event of the icon itself.

    Any ideas on saving and restoring the window's size possition, etc when showing with ShowWindow API?

    Maybe the ShowWindowPos API?
    Donald Sy - VB (ab)user

  9. #9

    Thread Starter
    Hyperactive Member dsy5's Avatar
    Join Date
    Jul 2000
    Location
    Lockport, NY
    Posts
    362
    It will work in Windows 95, so I think that with the new support for a more "friendly"
    (yeah, right) system tray with Win98+, it has some different results. (Hours to find a workaround await... <sigh>)
    Donald Sy - VB (ab)user

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