Click to See Complete Forum and Search --> : Yonatan, Helta Skelta, List Box, Findwindow, getwindow, EX ??? blah blah
MMMM
Aug 25th, 1999, 06:08 AM
Can someone tell me the difference between findwindow and FindWindowEx, and getwindow , etc. ?How do i find a window of a particualar type (eg listbox, commandbutton etc).
Also what is the difference between a ThunderRT6ListBox and a "ListBox"
The code that you have posted works only if the form has just a list box. ie if the form has a list box + buttons + something else then findwindow EX returns a 0?..why..what can you do then?.
also the first findwindow ex doesnt look into child windows .. so if your listbox is on a child window...what do you do.. i guess you would need to give findwindowex a few parameters (window class )
can someone tell me about window classes and what are the constants for them..(to look for in api text viewer).
Also are there any constants for listboxes , commandbuttons etc. ?
Thanks MMMM
Yonatan
Aug 25th, 1999, 06:41 AM
You asked many questions so I just copied your post, hope you don't mind.
>Can someone tell me the difference between findwindow and FindWindowEx, and getwindow , etc. ?
FindWindow finds the handle of a window, searches by ClassName and/or WindowName.
FindWindowEx (Find Window Extended) does the same as FindWindow but has 2 extra options:
1) Find items (= forms, controls) in parents. (With FindWindow the parent was always the Desktop)
2) Find items but begin searching after a particular item (if parent has 2 buttons and you want the second)
GetWindow finds the handle of a window. You need to give the function:
1) The handle of another window.
2) Search command (search others of same window, search for this window in other MDI forms etc.)
>How do i find a window of a particualar type (eg listbox, commandbutton etc).
Put the type you want as the ClassName (lpsz1 for FindWindowEx).
>Also what is the difference between a ThunderRT6ListBox and a "ListBox"
A ListBox is a ListBox belonging to a VC++ application.
A ThunderRT6ListBox is a ListBox belonging to a VB6 application.
Note: The 6 stands for the VB version number.
>The code that you have posted works only if the form has just a list box. ie if the form
>has a list box + buttons + something else then findwindow EX returns a 0?..why..what
>can you do then?.
If it has more than just a listbox it's still supposed to work... It works for me! What is your code?
>also the first findwindow ex doesnt look into child windows .. so if your listbox is
>on a child window...what do you do.. i guess you would need to give findwindowex a few
>parameters (window class )
hWndMDIForm = FindWindowEx(0, 0, "Classname of MDI Parent", "Windowname of MDI Parent")
hWndMDIChild = FindWindowEx(hwndMDIForm, 0, "Classname of MDI Child", "Windowname of MDI Child")
hWndListBox = FindWindowEx(hwndMDIChild, 0, "ListBox", "")
>can someone tell me about window classes and what are the constants for them..(to
>look for in api text viewer).
You can find ClassNames using a nice handy program called Spy++.
>Also are there any constants for listboxes , commandbuttons etc. ?
Constants for SendMessage, you mean?
There are many ListBox constants, all constants in API Viewer which begin with LB_ but as for CommandButton...
I tried looking at the CB_ constants but those aren't CommandButton, those are ComboBox.
CommandButton don't really need any constants... Except maybe WM_LBUTTONDOWN followed by WM_LBUTTONUP for a click... But those aren't CommandButton constants, those are constants for each of the controls.
------------------
Yonatan
Teenage Programmer
E-Mail: RYonatan@newmail.net
ICQ: 19552879 (http://www.icq.com/19552879)
[This message has been edited by Yonatan (edited 08-25-1999).]
Serge
Aug 25th, 1999, 03:16 PM
Little correction:
For a button - WM_LBUTTONUP and WM_LBUTTONDOWN not always work. But you can always use virtual keys to achieve this.
Example:
Call SendMessage(ButtonHwnd, WM_KEYDOWN, VK_SPACE, 0&)
Call SendMessage(ButtonHwnd, WM_KEYUP, VK_SPACE, 0&)
As you can see this button is being pressed using the virtual SPACE key.
------------------
Serge
Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
If I have a button in a frame in a frame etc, in a window and only know the window caption and button caption (and most importantly--don't know how many frames or it's not really a frame class, but a different class which I don't know);
how do I find the button?
I'm expecting some recursive or nested FindWindowEx solution.
Yonatan
Dec 14th, 1999, 01:52 AM
That would work, but there's a simpler solution:
Module Code...
Option Explicit
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function EnumChildWindows Lib "user32" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public sCaptionToLookFor As String
Public hWndFound As Long
Sub StripNulls(sBuffer As String)
Dim iPos As Long
iPos = InStr(sBuffer, vbNullChar)
If iPos > 0 Then sBuffer = Left(sBuffer, iPos - 1)
End Sub
Function EnumChildProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
Dim sBuffer As String
sBuffer = String(255, vbNullChar)
Call GetWindowText(hWnd, sBuffer, 255)
Call StripNulls(sBuffer)
If sBuffer = sCaptionToLookFor Then
hWndFound = hWnd
Else
EnumChildProc = True
End If
End Function
Function FindWindowByCaption(ByVal sCaption As String, ByVal hWndForm As Long) As Long
sCaptionToLookFor = sCaption
hWndFound = 0
Call EnumChildWindows(hWndForm, AddressOf EnumChildProc, 0)
FindWindowByCaption = hWndFound
End Function
Form Code...
Option Explicit
Private Sub Form_Load()
' This sample form needs a CommandButton named Command1 with whatever caption...
' Put it in a bunch of frames-in-frames to test this...
AutoRedraw = True
Print "Command1.hWnd = " & Command1.hWnd
Print "FindWindowByCaption return value = " & FindWindowByCaption(Command1.Caption, hWnd)
End Sub
P.S. Some notes:
This code only works on VB5 or later. (The AddressOf operator hasn't been invented earlier)
The sCaption argument of FindWindowByCaption stands for the caption of the button (or whatever it is you're looking for).
The hWndForm argument of FindWindowByCaption stands for the hWnd of the form or window in which the button is located. If the button is (for example) in a frame which is in a frame which is in a frame which is in a form... hWndForm could be the Form's hWnd or the hWnd of either one of the frames.
That's all folks!
------------------
Yonatan
Teenage Programmer
E-Mail: RZvika@netvision.net.il
ICQ: 19552879 (http://www.icq.com/19552879)
AIM: RYoni69
[Nobody's ever even begun to think about editing this message!]
[This message has been edited by Yonatan (edited 12-14-1999).]
I appreciate the code, but does this execute for you?
I have to put "Private" in front of the "Declare"'s or I get "...not allowed as Public members of object modules".
In Form_Load I replaced hWnd in FindWindowByCaption(Command1.Caption, hWnd) with my hWnd of the window with the nested frames that I am testing against.
I have VB6 but it doesn't like your AddressOf usage.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.