Hi all,
Working on a project that lists all active window names. Could someone possibly point me in the right direction (API wise). Have no idea where to start when it comes to the api involved in this. Just want to list active ones. Like game window names, Internet Explorer window names, folder names, etc. Thanks a lot

RIF
Posted on 2003-12-28 22:41:49 by resistance_is_futile
Use the EnumWindows callback and use GetWindowText to retrieve the name of the window.
invoke EnumWindows,OFFSET EnumWindowsProc, 0


EnumWindowsProc proc hWnd,lParam
local winname[256] :BYTE


invoke GetWindowText,hWnd,ADDR winname,255
invoke MessageBox,NULL,ADDR winname,NULL,NULL
xor eax,eax
inc eax
ret
EnumWindowsProc endp
Posted on 2003-12-28 22:54:33 by donkey


invoke GetWindowText,hWnd,ADDR winname,255


that returns my window name 255 times lol. Need something that will show visible/active window names..
Posted on 2003-12-28 23:14:08 by resistance_is_futile
The 255 is the maximum size of the buffer in chars specified by ADDR winname, I tested the routine and it works fine, perhaps you made an error when copying it to your code. If you wish to show only visible/active windows you have only to check the style of the windows passed to the enumerator. For example:

invoke EnumWindows,OFFSET EnumWindowsProc, 0


EnumWindowsProc proc hWnd,lParam
local winname[256] :BYTE

invoke GetWindowLong,hWnd,GWL_STYLE
.IF eax&WS_VISIBLE
invoke GetWindowText,hWnd,ADDR winname,255
invoke MessageBox,NULL,ADDR winname,NULL,NULL
.ENDIF
xor eax,eax
inc eax
ret
EnumWindowsProc endp
Posted on 2003-12-28 23:32:17 by donkey
okay well I did change one thing in your source when i copied it and that was this line



EnumWindowsProc proc hWnd,lParam


and I changed it to:



EnumWindowsProc proc


because it is giving a symbol redefinition error so I simply took it out. And that next code doesnt do anything. No MessageBox comes up. Here is my source:




WndProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

mov eax,uMsg
.if eax==WM_INITDIALOG
push hWin
pop hWnd
invoke EnumWindows,OFFSET EnumWindowsProc, 0

.endif


then a little bit further down after WndpProc endp:




EnumWindowsProc proc
local winname[256] :BYTE


invoke GetWindowLong,hWnd,GWL_STYLE
.IF eax&WS_VISIBLE
invoke GetWindowText,hWnd,ADDR winname,255
invoke MessageBox,NULL,ADDR winname,NULL,NULL
.ENDIF

xor eax,eax
inc eax
ret
EnumWindowsProc endp


Does nothing??
Posted on 2003-12-28 23:46:07 by resistance_is_futile
Thats the same method I used in my popup killer, except that I began with the desktop window handle HWND_DESKTOP, and enumerated its children.
Posted on 2003-12-29 05:50:15 by Homer

okay well I did change one thing in your source when i copied it and that was this line



EnumWindowsProc proc hWnd,lParam


and I changed it to:



EnumWindowsProc proc



Hi resistance_is_futile,

You cannot change the number of parameters passed to the EnumWindowsProc, you can change the labels but the parameters are decided by Windows and your program could GPF if you do that, actually I am surprised that it didn't as the return address on the stack would be wrong. All enumerations have a set number of parameters they pass to their EnumProc and it is not you who gets to decide. You can use EnumDesktopWindows as EvilHomer2K said:

Invoke GetThreadDesktop, ADDR hDesktop

Invoke EnumDesktopWindows, hDesktop, Offset EnumWindowsProc, 0


But the EnumWindowsProc procedure must remain the same
Posted on 2003-12-29 10:57:31 by donkey
hmm, well how can I get rid of the redefinition error I described above?
Posted on 2003-12-29 15:54:39 by resistance_is_futile
I wrote a little app the lists active window names and their child windows using the EnumWindows function. Maybe you can have a look at the source. It's in HLA but it's close to what it would have looked like in masm so you should be able to understand it. :)

http://www.asmcommunity.net/board/attachment.php?s=&postid=126820
Posted on 2003-12-29 17:01:34 by Odyssey

hmm, well how can I get rid of the redefinition error I described above?

Hi,

As I said just change the label names:

invoke EnumWindows,OFFSET EnumWindowsProc, 0


EnumWindowsProc proc enumhWnd,enumlParam
local enumwinname[256] :BYTE

invoke GetWindowLong,enumhWnd,GWL_STYLE
.IF eax&WS_VISIBLE
invoke GetWindowText,enumhWnd,ADDR enumwinname,255
invoke MessageBox,NULL,ADDR enumwinname,NULL,NULL
.ENDIF
xor eax,eax
inc eax
ret
EnumWindowsProc endp
Posted on 2003-12-29 18:06:45 by donkey
Thanks a bunch.... It worked..:grin:
Posted on 2003-12-29 20:29:52 by resistance_is_futile