what's a quick way to display dialogbox and grab input?

Started by drarem, December 21, 2004, 05:44:21 AM

Previous topic - Next topic

drarem

Using radAsm/masm32, I've created an additional dialogbox using the resource editor containing two edit boxes on them.

On testing a file that does not exist, I would like this box to pop up, the user enter data into both boxes press the ok, it goes away and processing continues.

I'm thinking modal, it's been awhile since I played with any of it - is there a clear cut tutorial on this or example? I'm thinking maybe

invoke DialogBoxParam ....,  dialogProc,...

And how do i make sure the thread is dead once they close the input box? Does it die automatically?

Thanks.

Extra credit:  I want to do a callback procedure to display FTP file transfer progress - I understand I should do it in chunks and report on it so it doesn't look like it crashed :) uploading at a blazing 42k/seconds.  How would I set that up, subclassing? Examples?

No this isn't homework, it's a simple utility for work so coworkers and I don't have to email back and forth 10 Mb of a tickets database - long story.  I'm trying to set it up to be as user friendly as possible. Tis also a chance for me to get some brownie points - everyone else beats me to them.

drarem

I've tried this:
   invoke CreateDialogParam,hInstance,1002,NULL,addr lpDlgInput,NULL

and this:
   invoke CreateDialogParam,hInstance,1002,hWnd,addr lpDlgInput,NULL

When I hit the 'close' button on the dialogbox, it closes out the entire app.  What is wrong? I have this:


lpDlgInput proc hWin:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL hwndDlg:DWORD

      .if uMsg==WM_INITDIALOG
      invoke GetDlgItem,hWin,1008     ;1008 = first editbox on dialogbox
      invoke SetFocus,eax
      .elseif uMsg==WM_CLOSE
      invoke EndDialog,hWin,NULL
      mov hwndDlg,0

      .endif         
   
        mov  eax,TRUE
        ret
lpDlgInput endp

hutch--

First thing I would do is return ZERO in the dialog proc otherwise you can get diaplay and other problems.

    xor eax, eax
    ret
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

drarem

Thanks but it happens - I close the dialogbox and it closes the main program too.

hutch--

The initial dialog usually does not have a parent handle but the child dialog should use the handle of the parent. Make sure they have different DialogProc procedures.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

drarem

Sorry to be a pain.. parent of window - hInstance? hWnd? I'm using both, and the input on the second dialogbox will respond to messages from the main one.
What is the addr DlgName I see - some of the examples I only find the name in there yet it knows which resource to pull up?


invoke GetModuleHandle,NULL
mov    hInstance,eax
invoke GetCommandLine
mov CommandLine,eax

..
..
invoke RegisterClassEx,addr wc
;open main window, it happens to be a dialogbox
invoke CreateDialogParam,hInstance,IDD_DLG1,NULL,addr WndProc,NULL
mov  hWnd,eax
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd
invoke FileExists,hWnd,CmdShow
.WHILE TRUE
                INVOKE GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                .if hwndDlg!=0
                        invoke IsDialogMessage,hwndDlg,ADDR msg
                        .if eax==TRUE
                                .continue
                        .endif
                .endif
                INVOKE TranslateMessage, ADDR msg
                INVOKE DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret

WinMain endp
..
..

FileExists proc hWin:DWORD,CmdShow:DWORD
LOCAL ofn:DWORD
   
invoke CreateDialogParam,hInstance,2000,hWnd,OFFSET lpDlgInput,NULL
mov hwndDlg,eax
..
..


drarem

Alright, after continual digging thru the archives, I found if I remove the class name of the dialog box 'pop-up' - it should be blank - everything works as expected. Thanks for your help, it has been an enlightening experience for me.

hutch--

The difference between an "instance" handle and a "window" handle need to be understood.

An instance handle, usually supplied by the application or by an API (GetModuleHandle) is the actual load address of the executable file and you use it among other things for resource based API functions where the actual start address is required.

A "window" handle is a unique identifier supplied by the OS for EVERY window that is created. When you use a parent handle to a dialog, it must be the window handle of the window that it is called from. If it is the starting dialog in a dlg app, it will have zero (0) as its handle but when you create a child dialog, it must use the handle of its parent in the API call that creates it. This ensures that it behaves like a child window of the calling window or dialog.

Now importantly in this situation, you must have a seperate DialogProc for each dialog.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php