News:

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

Pop up a menu to run an external program...

Started by jmkve, June 30, 2007, 06:35:52 AM

Previous topic - Next topic

jmkve

Hello, this is my first time here. I am working with the IDE called Easy Code Masm. I created the interface, but I can't seem to figure out how to make the menu AND then run the programs in my menu. The idea here is to make a menu autorun on a CD and it run my little assembly program that would be the menu to click on wich program i want to run from there.

It's all in 32-Bit. Please help. Thank you.
JW

jmkve

Well, I see people viewing this link.. but not one has an idea yet..  oh well, i'll keep on waiting I guess..   :(

JW

Tedd

Maybe if you describe in a little more detail? Draw a picture of what you imagine :wink
Do you simply mean a popup-menu that appears when the CD is insert (and autorun) or a program that starts and a window appears with 'buttons' to select from..? What programs would you like it to start?
No snowflake in an avalanche feels responsible.

jmkve

Yes, the autorun.inf will start my "Startup" file that I made in assembly. That file will then point me to everything i want to choose from on the CD / DVD that I want to run / execute. The "Startup" file is nothing more then a MENU. AndI want to make it in assembly.

So what I'm asking is what is the code in assembly (Masm32) that will allow me to Launch another program from my "Startup" Menu program?

Thank you.
JW

Tedd

Well, to start another program you would use the "CreateProcess" function (it has a lot of parameters, but you can just set most of them to NULL and it works fine.)

As for the menu (as in a popup-menu, such as the start menu, or File->...) you could either create it when the program starts ("CreatePopupMenu", and then "InsertMenu" for each menu item) or define a popup menu resource and use "LoadMenu" to get a handle for it. Once you have a menu handle, "GetCursorPos" to get the current mouse-cursor position (so it can pop-up there) and "TrackPopupMenu" will show it and return when a selection has been made. You do need an actual window to receive the menu selection (it posts a WM_COMMAND message), but you can just hide it so it doesn't show -- you then start the appropriate program when handling the wm_command message.

There, that's everything but the code itself :P
No snowflake in an avalanche feels responsible.

jmkve

Ahh thank you..   "CreateProcess" function might be what i'm looking for.. i'll check into that. Thank you.

As far as the menu, I have already created the interface. I have made the buttons on a Windows Form. But all I needed was the button to launch a program..

Thanks again, i'll try it out and let you know how it went.

JW

kennie

I used something like:

(immediate return):
GetStartupInfo,..
CreateProcess,..
GetExitCodeProcess,..

(return after new process was terminated)
GetStartupInfo,..
CreateProcess,..
WaitForSingleObject,hProcess,INFINITE
GetExitCodeProcess






jmkve

Here is my code so far....


.Const

.Data?

.Data

.Code

Window1Procedure Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
   .If uMsg == WM_CREATE

      Return TRUE
   .ElseIf uMsg == WM_CLOSE
      Invoke IsModal, hWnd
      .If Eax
         Invoke EndModal, hWnd, IDCANCEL
         Return TRUE
      .EndIf
   .EndIf
   Return FALSE
Window1Procedure EndP

Window1Static1 Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
   Return FALSE
Window1Static1 EndP

Window1Button1 Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
   Return FALSE
Window1Button1 EndP


See my problem so far? (By the way, again, I thoght I would meantion it's Masm32 and EASY CODE - Which is a Visual Assembler)

JW

Vortex

This procedure can be used to wait the termination of the child process :

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

    .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

jmkve

so in your code this ----->  "lpfilename" I would replace that with the actual name of my program ?

Also, your using GeneSys. I'm not.. I'm using the Masm32 version of the Easy Coder.

But thanks your code looks good so far. I just want to make sure i'm reading it correct.

thanks
JW

Vortex

Quoteso in your code this ----->  "lpfilename" I would replace that with the actual name of my program ?

That's right.

You can replace GeneSys with masm32, it will work :

    include \masm32\include\windows.inc
    include \masm32\include\kernel32.inc

jmkve

Ok, this is what I have...


    .486                      ; create 32 bit code
    Option CaseMap :none      ; case sensitive
.Data
.Code

Window1Procedure Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
   .If uMsg == WM_CREATE

      Return TRUE
   .ElseIf uMsg == WM_CLOSE
      Invoke IsModal, hWnd
      .If Eax
         Invoke EndModal, hWnd, IDCANCEL
         Return TRUE
      .EndIf
   .EndIf
   Return FALSE
Window1Procedure EndP

Window1Button1 Proc Private hWnd:HWND, uMsg:ULONG, wParam:WPARAM, lParam:LPARAM
Shell Proc help.txt: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, [help.txt], 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
Window1Button1 EndP



Now these are the errors I get...


Window1.asm(21) : error A2008: syntax error : .
Window1.asm(28) : error A2006: undefined symbol : help
Window1.asm(28) : error A2114: INVOKE argument type mismatch : argument : 2
Window1.asm(32) : error A2006: undefined symbol : dwTimeOut
Window1.asm(32) : error A2114: INVOKE argument type mismatch : argument : 2
Window1.asm(43) : fatal error A1010: unmatched block nesting : Shell



Now all I have is a GUI window with 1 button on it. If you push the button it's supposed to execute "help.txt". (I will also be using this for EXEs as well as PDFs.)
Thanks for your help so far...
JW

Vortex

jmkve,

You didn't specify the header files in your code.