News:

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

Help adding another dialog...

Started by tanto, February 14, 2005, 03:00:13 PM

Previous topic - Next topic

tanto

Newbie problem.

In WM_COMMAND I have the following:


if edx==BN_CLICKED
.if eax==bnOptions
invoke ShowOptionsDialog
.endif
.endif


bnOptions is a button which I'd like to use for invoking a new dialog within my application.

What would be the best procedure for doing this?

Right now I do this:

1) In RadASM I add another dialog as resource.
2) I add the controls to it that should go there.
3) In my declarations file (the [PROGNAME].INC-file for my main dialog) I add the "IDD_DLG1  equ  2000" and let the StartID for my controls be 2001
4) I write pretty much an exact replica of the init-operations as for my original dialog and I invoke those i ShowOptionsDialog proc per code above
i.e. the regular wc-dot stuff


...
mov wc.cbSize,sizeof WNDCLASSEX
mov wc.style,CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc,offset Dlg2WndProc
... etc etc etc...


Is this the way to do it? Am I doing something redundant here?

Any URL to a tutorial for using multiple dialogs in a "DialogAsMain"-app would be much appreciated. Thank you.

petezl

Hi tanto
This is Masm32 code:
In your rc file add the Dialog resource
Example
MyDialog DIALOG 10, 10, 205, 60
STYLE 0x0004 | DS_CENTER | WS_CAPTION | WS_MINIMIZEBOX |
WS_SYSMENU | WS_VISIBLE | WS_OVERLAPPED | DS_MODALFRAME | DS_3DLOOK
CAPTION "Our Second Dialog Box"
BEGIN
END

In your inc file or in the main asm
DlgProc PROTO :HWND, :DWORD, :DWORD, :DWORD
and under .data
DlgName db "MyDialog",0
You can of course use a number instead of an ID! If you do theres no need for the above line.
To call the dialog use this as your button handler
.if ax==IDM_ABOUT
invoke DialogBoxParam,hInstance, addr DlgName,hWnd,OFFSET DlgProc,NULL

Now you just need to add your new DialogProc. If you already have one then just change the name slightly like Dlg_1Proc.
Example:
DlgProc PROC hWnd:HWND,iMsg:DWORD,wParam:WPARAM, lParam:LPARAM
.if iMsg==WM_INITDIALOG
;Do something
.elseif iMsg==WM_CLOSE
invoke EndDialog,hWnd,NULL
.elseif iMsg==WM_COMMAND
mov eax,wParam
mov edx,eax
shr edx,16
.if dx==BN_CLICKED
;do something more
.endif
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp

As you can see above, there are several ways to trap a button, none are right or wrong, just personal preference.
Peter.
Cats and women do as they please
Dogs and men should realise it.

pbrennick

petezl,
You do realize that is not a 'Dialog As Main' example, I hope.  If nothing is added by the time I return from the hospital, I will post an example of this type of code, no time now.
Paul

petezl

Paul,
I read it as: tanto already has a Dialog as main and wants to call an extra dialog.
Peter.
Cats and women do as they please
Dogs and men should realise it.

pbrennick

tanto,
Since you are using RadASM, I am including a GoASM project originally designed by XTREME that shows a demonstartion of the principal.  It is very involved and robust but I believe you can learn from it.  I like it very much.

Paul

pbrennick

petezl,
I could be wrong, but I read he wants to replace it.
Paul

tanto

Thanks for the replies.

The case is actually that I do have a "Dialog As Main" and to that I have a button that I want to use to pop up another dialog. Basically an "options"-dialog to point to a couple of things and then close it and keep running the "Main Dialog" i.e. I use the MainDialog as a regular app. Think of it as me having a MainMenu with "..." items that pops up dialogs for setting preferences of the app running.

Peter:  I tried your code and please bare with me as I'm very new to this but when running that (practically a replica of the original dialog WndProc), the new dialog opens and immediately freezes and is not painted correctly and the application stops responding. I'm doing something wrong here I'm sure. Just can't see what I'm missing. Need I add another "mainloop" for this dialog dispatching messages to the new DlgWndProc, is that where I'm going wrong?

Paul: You wrote "I am including a GoASM project originally designed by XTREME that shows a demonstartion of the principal.  It is very involved and robust but I believe you can learn from it.  I like it very much." My newbie question to you would be, where did you include it i.e. how do I download or see what's included in a forum post? Or am I misreading you?

Many thanks.

petezl

tanto,
Dialogs don't use a message loop as they are primarily intended for input/ output. You have jumped in the deep end with a Dialog as main window because it's a bit more complicated but they have the advantage that you can use the benefits of both windows and dialogs. You can call as many extra dialogs as you like. You can even call dialogs from dialogs.
regarding your problem, it could be any of several things, make sure that you have no duplication in the extra code. Ie. All ID numbers need to be unique. If you have altered the code then make sure that the changes have been updated in all the necessary places. If that doesn't work post the code.

What I posted was masm32 so if your main code is RadAsm then post it in the other forum.

Peter.
Cats and women do as they please
Dogs and men should realise it.

petezl

Find attached a Dialog as main window that can call an extra dialog.
As you asked, I have used a unique number as the dialog ID so the call for the dialog in WndProc also needs this number.
Hope this helps...
Peter.

[attachment deleted by admin]
Cats and women do as they please
Dogs and men should realise it.

tanto

Peter,

your code worked like a charm. I got it working in my project as well. Thanks much.

Just a couple of check questions so I can learn for the future, answer if you have the time:

1) Why don't I have to declare the WndProc (the message loop for the main dialog - the app) with PROTO when i have to declare all other procedures with that? In your code I see only two [procedure]  PROTO in the header of your file.

2) In your earlier comment you said that your code was MASM32. Well, I'm using that too but I'm developing in RadAsm environment. Is there a difference between using MASM32 standalone and creating a MASM32 project within RadAsm IDE?

Again, thanks much for your help.

petezl

tanto,

All procedures require a prototype. Have a look at the text file "\masm32\include\User32.inc" it supplies your program with most of the standard procedure prototypes. Any procedures that are not declared there or elsewhere plus any you create yourself then you will have to manually add their prototypes or you will get compile errors.

It's also educational to have a glance at "\masm32\include\Windows.inc". This is where many of the key words are defined as numbers or other words. Typical examples being <WM_CREATE equ 1h> and <CHAR typedef BYTE> respectively.



I'm sorry, I can't answer your RadAsm question because I have never used it...
Peter.
Cats and women do as they please
Dogs and men should realise it.