flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
ouadji 09 Oct 2011, 11:45
How to change the position (on the screen) of a MessageBox ? is this possible ? ![]() thank you all. |
|||
![]() |
|
Overflowz 09 Oct 2011, 12:10
maybe SetWindowPos ?
![]() |
|||
![]() |
|
dancho 09 Oct 2011, 14:47
well you need to hook a messagebox,
I have this link saved for a while but never tried to convert to fasm : http://www.catch22.net/tuts/custom-messagebox btw search masm forum,there is couple examples there... |
|||
![]() |
|
ouadji 09 Oct 2011, 15:39
thank you Overflowz, and dancho. it works fine ![]() but not with "jz thread1" (crash in this case) but ok with "jz @B" (..this is normal) Code: invoke CreateThread,NULL,1000h,thread1,[infoword.startbuffer],0,0 invoke MessageBox,0,text,[infoword.startbuffer],MB_OK ..... proc thread1 title:dword ;+ title:dword @@: mov eax,[title] invoke FindWindow,0,eax test eax,eax jz @B ;- jz thread1 / + jz @B invoke SetWindowPos,eax,HWND_TOP,50,50,0,0,SWP_NOSIZE ret endp But after "messageBox", should I destroy this thread? like this, Code: invoke GetExitCodeThread,x,x invoke TerminateThread,x,x invoke CloseHandle,x |
|||
![]() |
|
typedef 09 Oct 2011, 17:56
no, just
Code: invoke CloseHandle,x In the parent scope. The ret in the thread proc will terminate it of course . |
|||
![]() |
|
AsmGuru62 10 Oct 2011, 11:30
Never use TerminateThread() - it will cause instability in KERNEL32.DLL loaded into your process.
|
|||
![]() |
|
ouadji 11 Oct 2011, 09:32
if the window title does not match, (FindWindow does not find the window) "thread1" runs in an endless loop. The solution : a watchdog. (it works fine) Code: ;for me, if all goes well, ;"FindWindow" finds the window after about twenty iterations proc thread1 title:dword local MB_dog dd ? mov [MB_dog],5000 @@: mov eax,[title] invoke FindWindow,0,eax dec [MB_dog] jz .end ;----------> or eax,eax jz @B mov [MB_h],eax .... .end: ret |
|||
![]() |
|
Overflowz 11 Oct 2011, 19:44
I don't get the reason why FindWindow can't find window, if you are using it in your program
![]() ![]() |
|||
![]() |
|
typedef 11 Oct 2011, 19:51
mov eax,[title]
invoke FindWindow,0,eax try invoke FindWindow,0,title |
|||
![]() |
|
ouadji 11 Oct 2011, 20:13
@Overflowz it depends on your program! in my case, it can happen. @typedef Code: proc x y:dword invoke FindWindow,0,y it does not compile (obviously) |
|||
![]() |
|
edfed 11 Oct 2011, 21:31
can it be possible then to dynamically change the coordinates of a window? for example, make a ping pong window in the screen...
|
|||
![]() |
|
ouadji 11 Oct 2011, 22:01
yes, of course! It is possible to place a window where you want, and as you want! |
|||
![]() |
|
typedef 12 Oct 2011, 01:12
ouadji wrote:
you are passing a DWORD (Unless the DWORD is valid string pointer) then it won't work. |
|||
![]() |
|
ouadji 12 Oct 2011, 01:33
Quote: then it won't work. Code: invoke CreateThread,NULL,\ 1000h,thread1,[infoword.startbuffer],0,conv_IN proc thread1 title:dword mov edi,[title] invoke FindWindow,0,edi ;or invoke FindWindow,0,[title] Quote: you are passing a DWORD [infoword.startbuffer] == my_string *my_ptr [title] == [ebp+8] == my_ptr Code: ;that said, this below does not compile proc x y:dword ;macro/proc32.inc/push arg/invalid value invoke A,y ;this does compile proc x y:dword invoke A,[y] or mov reg,[y] invoke,A,reg or lea reg,[y] invoke A,[reg] ;but not invoke A,y Last edited by ouadji on 12 Oct 2011, 08:07; edited 2 times in total |
|||
![]() |
|
Alphonso 12 Oct 2011, 07:41
And what happens if you have more than one window with the same name
![]() Why is this topic under Main and not Windows ? |
|||
![]() |
|
LocoDelAssembly 12 Oct 2011, 14:34
Good question, I'll fix it now.
|
|||
![]() |
|
Yardman 14 Oct 2011, 04:14
[ Post removed by author. ]
Last edited by Yardman on 04 Apr 2012, 03:51; edited 1 time in total |
|||
![]() |
|
Alphonso 14 Oct 2011, 07:50
There was a post some time back on here about msgbox positioning. Here's some rough code from that time.
Code: format PE GUI 4.0 ;laa stack 1000h,1000h entry start include 'win32a.inc' Xspan = 20 ; x spacing of msbox Yspan = 20 ; y spacing XNum = 40 ; number of boxes per row Freds = 200 ; number of threads/boxes (no more than 63 for WFMO) XOrigin = 20 ; X origin offset on display YOrigin = 20 ; Y origin offset on display ;---------------------------------------- section '.text' code readable executable ;---------------------------------------- start: xor ebx,ebx mov esi,XOrigin ; Top left display offsets mov edi,YOrigin ; @@: mov [ebx*4+XOffset],esi ; Create messagebox positions mov [ebx*4+YOffset],edi ; lea eax,[ebx*4+ThreadID] ; ThreadID pointer invoke CreateThread,0,0,CpuThread,ebx,0,eax cmp eax,0 jz ThreadTerm mov [ebx*4+hThread],eax add esi,Xspan ; add some different positions cmp esi,Xspan*XNum+XOrigin ; Next box position jb .SameRow mov esi,XOrigin ; New row add edi,Yspan .SameRow: inc ebx cmp ebx,Freds jb @b invoke Sleep,10000 ; run for 10secs ThreadTerm: xor ebx,ebx @@: invoke TerminateThread,[ebx*4+hThread],0 ; oooww... inc ebx cmp ebx,Freds jb @b invoke Sleep,1000 ThatsAllFolks: invoke MessageBox,0,MessAllDone,Title,MB_SYSTEMMODAL exit: invoke ExitProcess,0 ;---------------------------------------- align 16 proc CpuThread,ThreadNo push ebx esi edi mov ebx,[ThreadNo] invoke GetCurrentThreadId ; set up hook invoke SetWindowsHookEx,WH_CBT,CBTProc,0,eax ; mov [ebx*4+hHook],eax cmp eax,0 jnz @f @@: sub esp,64 ; some buffer area for message text mov esi,esp cinvoke wsprintf,esi,wsformat,[ThreadNo] inc [Count] invoke MessageBox,0,esi,Title,0 add esp,64 mov [ebx*4+hThread],0 pop edi esi ebx ret endp ;---------------------------------------- align 16 proc CBTProc,nCode,wparam,lparam push ebx esi edi cmp [nCode],HCBT_ACTIVATE jne finish invoke GetCurrentThreadId xor ebx,ebx @@: cmp [ebx*4+ThreadID],eax ; enum from which thread je .FoundThreadNum inc ebx cmp ebx,Freds jb @b jmp finish .FoundThreadNum: invoke SetWindowPos,[wparam],0,\ [ebx*4+XOffset],[ebx*4+YOffset],\ ; Xoffset,Yoffset,0,0 0,0,SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE invoke UnhookWindowsHookEx,[ebx*4+hHook] ; clean up hooks finish: xor eax,eax ; probably should be nice and chain, oh well pop edi esi ebx ret endp ;---------------------------------------- section '.data' data readable writeable ;---------------------------------------- Title db 'Message Box',0 MessAllDone db 'All done.',0 wsformat db 'Thread %u',0 align 4 Count dd ? ThreadID rd Freds hThread rd Freds hHook rd Freds XOffset rd Freds YOffset rd Freds ;---------------------------------------- section '.idata' import data readable writeable ;---------------------------------------- library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'api\kernel32.inc' include 'api\user32.inc' |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.