flat assembler
Message board for the users of flat assembler.
Index
> Windows > CreateThread with STARTUPINFO Goto page 1, 2, 3 Next |
Author |
|
vid 22 Nov 2010, 14:06
MessageBox is just an API (wrapper to CreateWindow), not an executable. Since this wrapper doesn't provide functionality you need (setting window position), you need to use CreateWindow directly.
|
|||
22 Nov 2010, 14:06 |
|
Overflowz 22 Nov 2010, 14:17
vid
Can I create invisible window ? and just point msgbox to point in that place ? or how people are doing that ? :/ |
|||
22 Nov 2010, 14:17 |
|
vid 22 Nov 2010, 15:27
Window painted by MessageBox is just a plain window, as you can create with CreateWindow API. MessageBox function just supplies all the extra arguments, window procedure, etc. If MessageBox (wrapper over CreateWindow) doesn't do what you need, use CreateWindow directly. Go to MSDN, read description of that API, look up some "Hello world" examples of using it, etc. etc.
Maybe there is some simpler way, but I am not aware of it. |
|||
22 Nov 2010, 15:27 |
|
Overflowz 22 Nov 2010, 17:58
vid
Thanks, I'll try that. |
|||
22 Nov 2010, 17:58 |
|
vid 22 Nov 2010, 19:58
You may also have easier job using dialog instead of generic window - saves you part of your job, and there should be plenty of examples of dialog with static text and button(s).
|
|||
22 Nov 2010, 19:58 |
|
Alphonso 23 Nov 2010, 12:33
Just a quick play,
Code: format PE GUI 4.0 include 'win32a.inc' ;------------------------------------------- section '.text' code readable executable ;=========================================== invoke GetCurrentThreadId ; set up hook invoke SetWindowsHookEx,WH_CBT,CBTProc,0,eax ; cmp eax,0 jz WhatWentWrong? mov [hHook],eax invoke MessageBox,0,Mess,Title,MB_TOPMOST ; positionable msgbox invoke UnhookWindowsHookEx,[hHook] ; clean up WhatWentWrong?: invoke ExitProcess,0 ;------------------------------------------- proc CBTProc, nCode,wparam,lparam push ebx esi edi cmp [nCode],HCBT_ACTIVATE jne finish invoke SetWindowPos,[wparam],0,20,20,0,0,\ ; Xoffset,Yoffset,0,0 SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE finish: xor eax,eax ; 0 = All ok pop edi esi ebx ret endp ;------------------------------------------- section '.data' data readable writeable ;=========================================== Title db 'Hello',0 Mess db 'Put me where',10 db 'you want ',0 align 8 hHook dd ? ;------------------------------------------- section '.idata' import data readable writeable ;=========================================== library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'api\kernel32.inc' include 'api\user32.inc' |
|||
23 Nov 2010, 12:33 |
|
Overflowz 23 Nov 2010, 14:40
Alphonso
Okay but can't it be done without hooking ? Cause I don't understand what Hook means and what the point of that. |
|||
23 Nov 2010, 14:40 |
|
Alphonso 23 Nov 2010, 17:14
It was just an example of showing messagebox placement. I'm probably not the best person to explain but basically Windows sends a message that it's going to activate the messagebox and by "hooking" we become part of that message chain. If everyone in the chain passes the message as ok then it gets activated. Before we pass on the message however we have decided we want to reposition where the message box will appear by using the setwindowpos call.
By creating your own window or dialog box as Vid suggested you'll be able to do much more than using a simple messagebox so if hooking is confusing don't worry about it for now, it will become clearer later on. Then you can tell me how it works hehe |
|||
23 Nov 2010, 17:14 |
|
Overflowz 23 Nov 2010, 17:40
Alphonso
And is there way to do that with CreateThread ? Cause I wan't tu show up 2 messageboxes same time. |
|||
23 Nov 2010, 17:40 |
|
vid 24 Nov 2010, 00:05
Do the same thing in each thread.
|
|||
24 Nov 2010, 00:05 |
|
Alphonso 24 Nov 2010, 05:39
Vid speaks much wisdom. Must... listen.. to him.
Using msgboxes is IMHO ermm, not very elegant. The example was supposed by be a sort of proof of concept. If you follow Vid's earlier advice I think you'll have something much nicer with good structure. But since you asked... Code: format PE GUI 4.0 entry start include 'win32a.inc' Xspan = 180 ; x spacing of msbox Yspan = 180 ; y spacing XNum = 5 ; number of boxes per row Freds = 17 ; 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: mov ebx,Freds mov esi,XOrigin ; Top left display offsets mov edi,YOrigin ; @@: mov [ebx*4+XOffset-4],esi ; Create messagebox positions mov [ebx*4+YOffset-4],edi ; lea eax,[ebx*4+ThreadID-4] ; ThreadID pointer invoke CreateThread,0,0,CpuThread,ebx,0,eax mov [ebx*4+hThread-4],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: dec ebx jnz @b mov esi,10 ; number of counts till timed out @@: invoke WaitForMultipleObjects,Freds,hThread,1,1000 ; count interval 1000ms (1 second) dec esi jz @f ; reached our 10 second timeout cmp eax,102h ; 1000ms passed je @b @@: mov ebx,Freds @@: invoke UnhookWindowsHookEx,[ebx*4+hHook-4] ; clean up hooks dec ebx jnz @b mov edi,MessAllDone cmp esi,0 jnz ThatsAllFolks mov ebx,Freds ; close boxes if timed out @@: invoke TerminateThread,[ebx*4+hThread-4],0 dec ebx jnz @b mov edi,MessTimeout ThatsAllFolks: invoke MessageBox,0,edi,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-4],eax sub esp,64 ; some buffer area for message text mov esi,esp cinvoke wsprintf,esi,wsformat,[ThreadNo] invoke MessageBox,0,esi,Title,0 add esp,64 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 mov ebx,Freds @@: cmp [ebx*4+ThreadID-4],eax ; enum from which thread je .FoundThreadNum dec ebx jnz @b jmp finish ; should not happen :/ .FoundThreadNum: invoke SetWindowPos,[wparam],0,\ [ebx*4+XOffset-4],[ebx*4+YOffset-4],\ ; Xoffset,Yoffset,0,0 0,0,SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE 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 MessTimeout db '10 Second Timeout',0 wsformat db 'Thread No. %u',0 align 4 Timeout dd ? ThreadID rd Freds hThread rd Freds hHook rd Freds XOffset rd Freds YOffset rd Freds Buff rb 100 ;---------------------------------------- section '.idata' import data readable writeable ;---------------------------------------- library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'api\kernel32.inc' include 'api\user32.inc' EDIT: Fix stack error, thanks bitRAKE for pointing that out, and strange Sleep call. Last edited by Alphonso on 24 Nov 2010, 15:17; edited 3 times in total |
|||
24 Nov 2010, 05:39 |
|
bitRAKE 24 Nov 2010, 07:27
Haha! Time to play a trick on someone.
|
|||
24 Nov 2010, 07:27 |
|
bitRAKE 24 Nov 2010, 08:02
Code: mov esi,esp sub esp,64 ; some buffer area for message text cinvoke wsprintf,esi,wsformat,[ThreadNo] invoke MessageBox,0,esi,Title,MB_SYSTEMMODAL mov esp,esi Code: add esp,-128 ; some buffer area for message text mov esi,esp cinvoke wsprintf,esi,wsformat,[ThreadNo] invoke MessageBox,0,esi,Title,MB_SYSTEMMODAL mov esp,esi sub esp,-128 |
|||
24 Nov 2010, 08:02 |
|
Overflowz 24 Nov 2010, 10:29
Alphonso
Well.. Thank you for code but it's hard for me.. I should more learn about Win32API-s and then post questions like this. Thank you all. |
|||
24 Nov 2010, 10:29 |
|
vid 24 Nov 2010, 10:40
That's definitively a good idea. There are plenty of tutorials which teach basics of WinAPI GUI programming, specifically with regard to generic windows and dialogs - exactly what you need.
|
|||
24 Nov 2010, 10:40 |
|
Overflowz 24 Nov 2010, 21:29
Hey, I've added some functions by my guess.. But I have questions and problems here. I've copied hook example but code fails. Can someone fix what I'm doing wrong ? Thanks.
Code: format PE GUI 4.0 include 'win32a.inc' entry main ;------------------------------------------- section '.text' code readable executable ;=========================================== proc startHook invoke GetCurrentThreadId ; set up hook invoke SetWindowsHookEx,WH_CBT,CBTProc,0,eax ; ;cmp eax,0 ;jz WhatWentWrong? mov [hHook],eax invoke MessageBox,0,Mess,Title,MB_TOPMOST ; positionable msgbox invoke UnhookWindowsHookEx,[hHook] ; clean up endp ; WhatWentWrong?: ; invoke ExitProcess,0 ;------------------------------------------- proc main invoke CreateThread,NULL,0,MSGProc,NULL,NULL,tid invoke SetWindowsHookEx,WH_CBT,CBTProc,0,tid invoke UnhookWindowsHookEx,eax ret endp proc MSGProc invoke MessageBox,0,Mess,Title,MB_OK ret endp proc CBTProc, nCode,wparam,lparam ; push ebx esi edi cmp [nCode],HCBT_ACTIVATE jne finish invoke SetWindowPos,[wparam],0,20,20,0,0,\ ; Xoffset,Yoffset,0,0 SWP_NOSIZE Or SWP_NOZORDER Or SWP_NOACTIVATE finish: xor eax,eax ; 0 = All ok ;pop edi esi ebx ret endp ;------------------------------------------- section '.data' data readable writeable ;=========================================== Title db 'Hello',0 Mess db 'Put me where',10 db 'you want ',0 ;align 8 hHook dd ? tid dd ? ;------------------------------------------- section '.idata' import data readable writeable ;=========================================== library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL' include 'api\kernel32.inc' include 'api\user32.inc' |
|||
24 Nov 2010, 21:29 |
|
vid 24 Nov 2010, 23:53
Overflowz: I suggest you to get OllyDBg and learn to use it. It's really simple, just open the file you want to trace, and then keep hitting F7 (step into) or F8 (step over). This way you will learn asm, see result of every API call (and compare to expected result), and usually be able to figure problem very quickly. Learning to debug/trace code is a must-do for every programmer, and pays back greatly.
|
|||
24 Nov 2010, 23:53 |
|
Overflowz 25 Nov 2010, 11:35
People, PLEASE STOP ASKING ME FOR OllyDBG! I have already it and using but I don't understand still! And I'm posting after that. I know how to use OllyDBG BUT I Don't understand and posting here.
|
|||
25 Nov 2010, 11:35 |
|
revolution 25 Nov 2010, 11:55
Overflowz: If you refuse to learn how to use a debugger then you will be forever lost with assembly.
People are suggesting you to use a debugger because it is often the only way to move forward with assembly. While the posters here have been extremely patient with you (for the most part) I suggest that that that can't last forever. Newbies are encouraged and helped here, as a general rule, but there is also an expectation that they can grow from there and begin to help themselves solve problems. At some point you will have start diagnosing your own problems. Not only will it be faster for you solve things it will also give you control over your own coding. I'm sure you have heard the phrase: "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for life". Well, we are trying to teach you to fish. Learn OllyDbg. |
|||
25 Nov 2010, 11:55 |
|
Goto page 1, 2, 3 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.