flat assembler
Message board for the users of flat assembler.

Index > Windows > How to close or send button clicks to window or child window

Author
Thread Post new topic Reply to topic
Walkerboh



Joined: 08 Jul 2010
Posts: 17
Walkerboh
How do I close a window or click a button on a window after enumerating it's handle? For example I have a window handle and the windows name
328272
winHandles.txt - Notepad

Shouldn't the following code close notepad?

Code:
format PE GUI 4.0
include 'win32ax.inc'

section '.text' code readable executable

  start:
        invoke  PostMessage,328272,WM_CLOSE,0,0
        invoke  ExitProcess, 0

section '.data' data readable writeable



section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',msvcrt,'msvcrt.dll',user32,'USER32.DLL'
  include 'api\kernel32.inc'
  include 'api\user32.inc'
  import  msvcrt,itoa,'_itoa',getchar,'getchar'    


[Edit by Loco: Added code tags]
Post 16 Jul 2011, 14:22
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
WM_CLOSE works for me:
Code:
include 'win32axp.inc'

TITLE_TO_FIND equ 'Sin título - Bloc de notas' ; This is the Spanish title when you open notepad without opening any text file, change as necessary.

proc start

      invoke  PostMessage, <invoke FindWindow, NULL, TITLE_TO_FIND>, WM_CLOSE, 0, 0
      invoke  ExitProcess, 0
endp


.end start    
If it still doesn't work for you try using WM_DESTROY which also worked for me.

I'm using WinXP 32-bit BTW.
Post 16 Jul 2011, 17:22
View user's profile Send private message Reply with quote
Walkerboh



Joined: 08 Jul 2010
Posts: 17
Walkerboh
Thanks LocoDelAssembly, invoking FindWindow from the parameter field of PostMessage worked for me. I did something wrong when I used ITOA to convert the window handle to a string and then manually input that number as the handle parameter for my PostMessage.
Post 16 Jul 2011, 21:39
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.