08-26-2009, 02:29 AM
How to find a string in a window , or rather on a windows form/menu
like for example , if i would like to find the "Format" menu button on a "Notepad" window, and see if its present in any window currently open?
is this possible, iv tried different methodes but with no luck as to find a specefied text string and return its value so i can do something if i find it.
the deal here is that i want to find a window witch i maby dont know the name of the title exatly but if i can find a matching string with i would search for for all open windows , then i can find the right window am looking for.
Decleration in my module:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal Classname As String, ByVal WindowName As String) As Long
And i have this on my form:
Dim my MyStrW As String
MyStrW = FindWindow(vbNullString, "Untitled - Notepad", sSearchstring = "Format")
Any help is appriciated!
08-26-2009, 03:29 AM
I read your post three times and still have no clear idea of what you are trying to do. :confused:
What result are you after, i.e. what should be the value of MyStrW if this did work? Are you looking for a window/menu handle or for a string, and which one, specifically?
08-26-2009, 05:11 AM
Hey! sorry i dident make it more clear.
what i would like to do is search for a window/menu,
example let's say you have 5 to 6 windows open on your pc and you dont know what the title of that window out of those 5 to 6 windows that you want to get, but you know one of those windows is the one you want, and you know it's got a menu with a button that says for example "open" , so you search for a "text" in a window and the ones it found what window title that contains this Text in its menu, then you know what the window title of that programs window is.
hope that is more clear, this is just as an example as iam sure there is many windows that can contain the menu word "open" but it was just to explain what am wanting to do.
the example above does not work the varible is just as a test. i need to know how to search thrue the current windows so i can get the one i am after.
08-26-2009, 05:33 AM
what i would like to do is search for a window/menu
What do you want to do with the window, once you've found it? The standard case is that one is looking for its handle (hWnd), to be used in subsequent API calls, but you're not mentioning that, so I'm still not quite sure I grasped your goal. :)
08-26-2009, 11:06 AM
I just want to know wich one of these windows as in the example,
witch of these contains the menu Text i am searching for,
I know how to get a handle for a window title, but i need to find the right handle by searching the specific text in all open windows, that way i will know what handle i am after.
I know how to find a window handle, but thats not the case , i want to find
a special one, one that i dont know the title of , by searching for a menu text and ones i found that i know that it exist and is one of those open windows, thats all i wish to do, nothing more mysterious about it.
so all i am after is searching for a menu text in all open window titles, ones i find it, i know it exist. and thats the important part.
thanks for trying to help here!, i just cant explain it better.
there is nothing particular that i want to do with the window, just find the right one by searching for a menu with a specific text in it.
to put it simple, just to find out if a special text in a menu exist in any of the open windows.
08-26-2009, 12:07 PM
to put it simple, just to find out if a special text in a menu exist in any of the open windows
See, that one sentence is a much better explanation than the rest of the three posts put together. ;)
I'd say you need to do this in two steps: Loop over all windows, and examine each window's menu. The first step is accomplished via one or a combination of these APIs: EnumWindows, EnumChildWindows and EnumThreadWindows. For each window thus retrieved, GetMenu gives you a handle to the menu bar, if there is one. Finally, you loop over the menu items using GetMenuItemCount and GetMenuItemInfo on the handle, which gives you a MenuItemInfo container for each. One of the container's members is dwTypeData, a pointer to the string that is displayed.
Yes, this is a little tedious, the menu APIs are not particularly convenient to use from a VB programmer's point of view. But AFAIK there are no real shortcuts here. :-\
08-26-2009, 02:02 PM
Thank's i was hoping it was easier, well well, i will get started, and look around about this!