Results 1 to 5 of 5

Thread: FindWindowEx "qwerk"

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Wisconsin
    Posts
    64

    FindWindowEx "qwerk"

    While trying to use the FindWindow (and FindWindowEx) APIs to get the hWnd for the SysTray clock, I ran into a problem. The original (and, for some strange reason, non-working) code is:
    VB Code:
    1. Dim tmpWnd&
    2. tmpWnd = FindWindow("Shell_TrayWnd", "") 'Task bar
    3. tmpWnd = FindWindowEx(tmpWnd, 0&, "TrayNotifyWnd", "") 'System tray
    4. trayClock = FindWindowEx(tmpWnd, 0&, "TrayClockWClass", "") 'System tray clock
    However, when I added to it to look like the following:
    VB Code:
    1. Dim tmpWnd&, clsName As String * 100, clsLen&
    2. tmpWnd = FindWindow("Shell_TrayWnd", "") 'Task bar
    3. tmpWnd = FindWindowEx(tmpWnd, 0&, "TrayNotifyWnd", "") 'System tray
    4. trayClock = FindWindowEx(tmpWnd, 0&, "TrayClockWClass", "") 'System tray clock
    5. If trayClock = 0 Then
    6.     tmpWnd = GetWindow(tmpWnd, GW_CHILD)
    7.     Do While tmpWnd <> 0
    8.         clsLen = GetClassName(tmpWnd, clsName, 100)
    9.         If Left(clsName, clsLen) = "TrayClockWClass" Then
    10.             trayClock = tmpWnd
    11.             Exit Do
    12.         End If
    13.         tmpWnd = GetWindow(tmpWnd, GW_HWNDNEXT)
    14.     Loop
    15. End If
    it works just fine. In fact, the first child of TrayNotifyWnd (the system tray) is the SysTray clock. Any idea why the first didn't work? (P.S. trayClock is a Public variable and I'm 100% positive that the SysTray clock's class name is TrayClockWClass, thanks to a "WindowSpy" example program I have)

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Use vbNullString instead of ""
    VB Code:
    1. Dim tmpWnd&
    2.    
    3.     tmpWnd = FindWindow("Shell_TrayWnd", vbNullString)  'Task bar
    4.     tmpWnd = FindWindowEx(tmpWnd, 0&, "TrayNotifyWnd", vbNullString) 'System tray
    5.     trayclock = FindWindowEx(tmpWnd, 0&, "TrayClockWClass", vbNullString) 'System tray clock
    6.  
    7.     MsgBox trayclock
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Mar 2001
    Location
    Wisconsin
    Posts
    64

    ***?

    Why does vbNullString make it work when "" doesn't?

  4. #4
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Because a null string is much different than an empty string. vbNullString doesn't point to anything in memory.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  5. #5
    Hyperactive Member
    Join Date
    Aug 2002
    Posts
    416
    VB Code:
    1. ShellTrayWnd& = FindWindow("Shell_TrayWnd", vbNullString)
    2. TrayNotifyWnd& = FindWindowEx(ShellTrayWnd&, 0&, "TrayNotifyWnd", vbNullString)
    3. TrayClockWClass& = FindWindowEx(TrayNotifyWnd&, 0&, "TrayClockWClass", vbNullString)

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