flat assembler
Message board for the users of flat assembler.

Index > Windows > MessageBox/position

Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 09 Oct 2011, 11:45

How to change the position (on the screen) of a MessageBox ?

is this possible ? Confused

thank you all.

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 09 Oct 2011, 11:45
View user's profile Send private message Send e-mail Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 09 Oct 2011, 12:10
maybe SetWindowPos ? Smile
Post 09 Oct 2011, 12:10
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 09 Oct 2011, 12:13
Code:
proc msgbox
     invoke MessageBox,0,text,title,MB_OK+MB_ICONERROR
   ret
endp
proc thread1 ;call it with CreateThread.
     invoke FindWindow,0,title
     test eax,eax
     jz thread1
     invoke SetWindowPos,eax,HWND_TOP,[xValue],[yValue],0,0,SWP_NOSIZE
   ret
endp    
Post 09 Oct 2011, 12:13
View user's profile Send private message Reply with quote
dancho



Joined: 06 Mar 2011
Posts: 74
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...
Post 09 Oct 2011, 14:47
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 09 Oct 2011, 15:39

thank you Overflowz, and dancho.

it works fine Razz
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    
question:
But after "messageBox", should I destroy this thread? like this,
Code:
       invoke  GetExitCodeThread,x,x
       invoke  TerminateThread,x,x
 invoke  CloseHandle,x    
??

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 09 Oct 2011, 15:39
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
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 .
Post 09 Oct 2011, 17:56
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1694
Location: Toronto, Canada
AsmGuru62 10 Oct 2011, 11:30
Never use TerminateThread() - it will cause instability in KERNEL32.DLL loaded into your process.
Post 10 Oct 2011, 11:30
View user's profile Send private message Send e-mail Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
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
    


_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 11 Oct 2011, 09:32
View user's profile Send private message Send e-mail Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
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 Very Happy I'm using it in my program and when window appears, it just finds and moves it to right place Wink
Post 11 Oct 2011, 19:44
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 11 Oct 2011, 19:51
mov eax,[title]
invoke FindWindow,0,eax
try
invoke FindWindow,0,title
Post 11 Oct 2011, 19:51
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
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
    
I don't understand your suggestion!
it does not compile (obviously)

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 11 Oct 2011, 20:13
View user's profile Send private message Send e-mail Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4354
Location: Now
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...
Post 11 Oct 2011, 21:31
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 11 Oct 2011, 22:01

yes, of course!
It is possible to place a window where you want, and as you want!

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 11 Oct 2011, 22:01
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2909
Location: 0x77760000
typedef 12 Oct 2011, 01:12
ouadji wrote:

@Overflowz
it depends on your program!
in my case, it can happen.

@typedef
Code:
proc x  y:dword
invoke FindWindow,0,y
    
I don't understand your suggestion!
it does not compile (obviously)


you are passing a DWORD (Unless the DWORD is valid string pointer) then it won't work.
Post 12 Oct 2011, 01:12
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji 12 Oct 2011, 01:33
Quote:
then it won't work.
Of course it works.
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
absolutely not, I'm passing a pointer, a pointer to a string.

[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    



_________________
I am not young enough to know everything (Oscar Wilde)- Image


Last edited by ouadji on 12 Oct 2011, 08:07; edited 2 times in total
Post 12 Oct 2011, 01:33
View user's profile Send private message Send e-mail Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 295
Alphonso 12 Oct 2011, 07:41
And what happens if you have more than one window with the same name Very Happy

Why is this topic under Main and not Windows ?
Post 12 Oct 2011, 07:41
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 12 Oct 2011, 14:34
Good question, I'll fix it now.
Post 12 Oct 2011, 14:34
View user's profile Send private message Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 244
Location: US
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
Post 14 Oct 2011, 04:14
View user's profile Send private message Reply with quote
Alphonso



Joined: 16 Jan 2007
Posts: 295
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'    
Post 14 Oct 2011, 07:50
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.