flat assembler
Message board for the users of flat assembler.
Index
> Windows > EnumWindows not working |
Author |
|
bitshifter 14 Jun 2011, 22:57
Q: Are you using unicode?
Non-Unicode: Code: format PE GUI 4.0 entry start include 'win32a.inc' section '.text' code readable executable start: invoke EnumWindows,EnumWindowsProc,0 invoke MessageBox,HWND_DESKTOP,_sb,_ct,MB_ICONINFORMATION or MB_OK invoke ExitProcess,0 proc EnumWindowsProc, hWnd, lParam invoke GetWindowText,[hWnd],_wt,128 test eax,eax jz @f invoke lstrcat,_sb,_wt invoke lstrcat,_sb,_nl @@: mov eax,TRUE ret endp section '.data' data readable writeable _ct db "xxx",0 _nl db 13,10,0 _sb rb 4096 ;careful!!! _wt rb 128 section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'api\kernel32.inc' include 'api\user32.inc' |
|||
14 Jun 2011, 22:57 |
|
asmMe 14 Jun 2011, 23:56
thx for the reply.
don't know if I'm using unicode or not? Anyway, it appears I misunderstood exactly what EnumWindows returns. Quote: The EnumWindows function enumerates all top-level windows on the screen by passing the handle of each window, in turn, to an application-defined callback function. I assumed this meant that if I had 8 items on the taskbar, it would return 8 handles. I wrote a little extra code to write all the handles and window titles to a file. With 8 apps on taskbar, I got 99 handles ¿¿¿ A lot of them had no titles (this is why I thought I was doing something wrong). I also got these (amongst others) Quote:
strange but, at least the real open windows were there with titles so I can continue with what I was doing thx again |
|||
14 Jun 2011, 23:56 |
|
bitshifter 15 Jun 2011, 00:17
Unicode uses multibyte characters for languages with many chars.
In english we use ASCII characters, in other countries, sometimes not. To make a program unicode compatible we can include "win32w.inc" and use TCHAR data types instead of regular bytes with db See FASM example EXAMPLES/TEMPLATE/TEMPLATE.ASM for a basic Windows app which is unicode compatible. Have Fun |
|||
15 Jun 2011, 00:17 |
|
AsmGuru62 15 Jun 2011, 00:38
You got all tasks and services enumerated, probably. When you get an HWND into your callback - check if it has an extended style of WS_EX_APPWINDOW - that will be the taskbar item most likely.
|
|||
15 Jun 2011, 00:38 |
|
asmMe 15 Jun 2011, 08:38
thx bitshifter, no, I'm not using unicode then
AsmGuru62: Thought your idea sounded promising but, unfortunately, it doesn't hold true. Very few apps set the WS_EX_APPWINDOW style, just search the boards for createwindowex to see how many have the ext style as 0. It appears the only way is to cycle through the titles to find what I'm looking for. thx again |
|||
15 Jun 2011, 08:38 |
|
cod3b453 15 Jun 2011, 17:11
If oyu looking for all "normal" windows, I think the WS_VISIBLE style flag should be ok for this (and possibly WS_MINIMISED ?).
If you're looking for a specific window, it might be better to use FindWindow(Ex). |
|||
15 Jun 2011, 17:11 |
|
asmMe 15 Jun 2011, 19:37
thx cod, I'll check out those flags. FindWindow would be no use for my purpose as I would only know part of the windows name (title).
Just as a note for anyone using the EnumWindows function, make sure your EnumWindowsProc returns with edi unchanged or thou shalt crash 'n' burn. update preserve all registers except eax or EnumWindows skips some of the open windows. |
|||
15 Jun 2011, 19:37 |
|
bitshifter 15 Jun 2011, 22:08
You only need to preserve ESI, EDI, EBX like any other Win32 proc should.
|
|||
15 Jun 2011, 22:08 |
|
vid 15 Jun 2011, 22:23
Quote: You only need to preserve ESI, EDI, EBX like any other Win32 proc should. Also EBP (and ESP of course) |
|||
15 Jun 2011, 22:23 |
|
asmMe 15 Jun 2011, 22:26
Sounds fair enough bitshifter
I assumed that EnumWindowsProc, being my own procedure could do as the info on it says Quote: Remarks and that windows would look after itself. Apparently not so for a callback proc Oh well, I suppose a couple of extra lines of code to look after Bill will do no harm |
|||
15 Jun 2011, 22:26 |
|
AsmGuru62 16 Jun 2011, 10:57
Any callback function must preserve ESI,EDI,EBX,EBP and DF must be 0. If your code uses STD - DF must be restored with CLD. Callback is any procedure address passed to Windows to be called back (like a structure member or as any function parameter).
|
|||
16 Jun 2011, 10:57 |
|
asmMe 16 Jun 2011, 18:18
thx guru, vid & bit for the clarification
So if I use this template for all my procs I shouldn't go far wrong Code: proc whateverProc locals endl push ebx edi esi . . ; whatever code . . .finished: pop esi edi ebx cld ret endp |
|||
16 Jun 2011, 18:18 |
|
bitshifter 16 Jun 2011, 18:50
Keep the template in your head and only use the parts
that are needed for each implementation thereof. No sense in useless instructions laying around, right. |
|||
16 Jun 2011, 18:50 |
|
asmMe 16 Jun 2011, 19:58
thx bit
|
|||
16 Jun 2011, 19:58 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.