News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

About Window Handle..

Started by ragdogz, January 28, 2009, 08:28:23 AM

Previous topic - Next topic

ragdogz

Hi, i want to know what happened with hWnd and hwwnd in this following code..

DlgProc PROTO:DWORD,:DWORD,:DWORD,:DWORD
ProcessOne PROTO:DWORD,:DWORD

.data?
hwwnd dd ?

.const
TIMER1 equ 100

.code
start:
...
...
...

DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.if uMsg==WM_INITDIALOG
...
...
invoke SetTimer,hWnd,TIMER1,10000,0
...
...
...
elseif uMsg==WM_COMMAND
...
...
if ax==IDC_BUTTON1
invoke KillTimer,hWnd,TIMER1
...
...
DlgProc endp


that's just fine until here. now i want to activate TIMER1 again in ProcessOne

ProcessOne proc hwdl:DWORD, userInput:DWORD
...
...
invoke SetTimer,hWnd,TIMER1,10000,0
...
...
ProcessOne endp


now the assemble tells me there's an error: undefined symbol : hWnd in this syntax: invoke SetTimer,hWnd,TIMER1,10000,0.
to correct this, i change hWnd to hwwnd and it works fine.

so what's all about those 2 words, hWnd and hwwnd? they're window handle, aren't they?
why can't i use hWnd in the ProcessOne proc?
although the program works properly, is there any effect caused by changing the hWnd to hwwnd in the ProcessOne proc?

i'm sorry if my question sounds like extremely newbie..  :green2
thx..

ToutEnMasm

Hello,
hwwnd is defined in the general data section and can be read by all the code in the source file.
The data section is a zone of memory where we can write and read some values.
hWnd is defined in the proc DlgProc,the value is pushed into the stack when the proc is called.When the proc is finished ,the stack memory is freed of the proc data.
hWnd is a local value and can be read only in the proc.






ragdogz

global and local..
okay i understand now..
thx..

my next question..

DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
...
...
.elseif uMsg==WM_TIMER
invoke EndDialog, hWnd,NULL
...
...
DlgProc endp

ProcessOne proc hwdl:DWORD, userInput:DWORD
...
...
invoke SetTimer,hwwnd,TIMER1,10000,0
...
...
ProcessOne endp


after 10 seconds the program will be closed. is it possible to launch the program automatically?
so after 10 seconds, the program will be closed and will be loaded again by itself..

ToutEnMasm


You have to made another  program  who launch this one at each time you need it.
Not very useful except if the called program used a lot of memory.In this case,the caller (very small) is of good help.


ragdogz

yes i have another program (the caller) built with VB. but with this concept (caller and called program), i have to monitor the called program using windows API SendMessage and a timer, or even window hook which i don't fully understand. i just think if the program can load itself automatically after closing, then it would be very good for me..

anyway, thx again for your explanation.. :U

ragdogz

Hi, i've found what i was looking for from this topic: http://www.masm32.com/board/index.php?topic=7564.0

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    .486                      ; create 32 bit code
    .model flat, stdcall      ; 32 bit memory model
    option casemap :none      ; case sensitive

    include \GeneSys\include\windows.inc
    include \GeneSys\include\kernel32.inc

    .code

;----------------------------------------------------------------------------;
; This is a translation of a shell script originally written by Edgar Hansen ;
; in GoASM code. Translation by Paul E. Brennick  <pebrennick@verizon.net>   ;
;                                                                            ;
; Shell:      This function will run an executable and wait until it has     ;
;             finished before continuing. The function provides for a time   ;
;             out for a maximum wait period.                                 ;
; Parameters: lpfilename = The fully qualified path to an executable to run  ;
;             dwTimeOut = The amount of time in milliseconds to wait, -1 for ;
;             no timeout                                                     ;
; Returns:    0 if successful, STATUS_TIMEOUT if the timeout has elapsed     ;
;             -1 if there was an error creating the process                  ;
;                                                                            ;
;----------------------------------------------------------------------------;
Shell PROC lpfilename:DWORD, dwTimeOut:DWORD
    LOCAL   Sh_st_info :STARTUPINFO
    LOCAL   Sh_pr_info :PROCESS_INFORMATION

    mov     DWORD PTR [Sh_st_info.cb], SIZEOF STARTUPINFO
    invoke  GetStartupInfoA, ADDR Sh_st_info
    mov     DWORD PTR [Sh_st_info.lpReserved], 0
    invoke  CreateProcessA, 0, [lpfilename], 0, 0, 0, 0, 0, 0, \
            ADDR Sh_st_info, ADDR Sh_pr_info
    test    eax, eax
    jz ERROR
    invoke  WaitForSingleObject, [Sh_pr_info.hProcess], [dwTimeOut]
    push    eax
    invoke  CloseHandle, [Sh_pr_info.hThread]
    invoke  CloseHandle, [Sh_pr_info.hProcess]
    pop     eax
    test    eax, eax
    RET
ERROR:
    xor     eax, eax
    sub     eax, 1
    RET
Shell ENDP


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    end


now i can relaunch the program using Shell function posted by vortex. i just add:

Shell   PROTO:DWORD,:DWORD

and the rest:

.data
ThisAppFile  db "test.exe",0

DlgProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
...
...
.elseif uMsg==WM_TIMER
invoke Shell,addr ThisAppFile,1
invoke EndDialog, hWnd,NULL
...
...
DlgProc endp

ProcessOne proc hwdl:DWORD, userInput:DWORD
...
...
invoke SetTimer,hwwnd,TIMER1,10000,0
...
...
ProcessOne endp


now the program will first launch itself before closing itself..
but then i found this syntax in autotype by vortex:

invoke WinExec,addr ThisAppFile,SW_SHOW

using that 1 line syntax then the result is the same with using Shell function.
what's the difference between them?

btw, why isn't there spoiler feature in this forum to hide some text for reference?