News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Using dialog boxes in resource files

Started by Lightman, October 31, 2015, 12:30:27 AM

Previous topic - Next topic

Lightman

Hello Everybody,

I'm seeking a little bit of advice with compiled resource files. I'm following Iczelion's tutorial series and using RadASM to implement my examples and I'm having problems understanding some of the aspects of the compiled resource files it uses.

Here is my understanding about the use of resource files in RadASM... If I create a blank project based on the DialogAsMain template I can go to the resource editor and place buttons and other widgets on my form. The RadASM resource editor is a nice front end tool that creates a text file in the background. When I compile and run the program my form design is compiles onto a resource and added to my program... And Lo! A nice pretty dialog box that was easy to create.

But... When I run my program, I can't actually interact with my widgets. They are just painted there. To communicate with them I need to get their handles. So, in my code I can call a function called GetDlgItem.


invoke   GetDlgItem, hWnd, IDC_ID
mov      hHandle, eax


I pass though my program's handle and the ID of the widget, which I defined in my .inc file,  and I get a handle back. I can then use this handle to communicate with my widgets with functions like SendMessage and the like. 

Or.. at least it should. I think I am missing something somewhere....

Consider Iczelion's Tutorial 18. In this I am going to create some common controls and interact with them. In the original tutorial the CreateWindowEx function is used to create the controls. I figure I don't need to use this as I've used the resource editor - they are already drawn and ready. I just need to get their respective handles to take control over them...

Needless to say, my version does not work. Do I still need to use the CreateWindowEx function even though the widgets appear without it?

Attached is my interpretation of Tutorial 18...

As you can tell, I am a little confused. Any advice is welcome here...

Regards,

Lightman.
Regards,

Lightman

dedndave

you're kind of mixing windows with dialog boxes

when you create a dialog box, the operating system provides certain aspects of the window code
among them, the actual WndProc is provided for
it handles WM_CREATE for you
once it has handled WM_CREATE, it will send your DlgProc a WM_INITDIALOG message

you should put all your init code in the WM_INITDIALOG handler   :biggrin:
i am guessing that the control has not yet been created at the time you make the call

if you create your own window (CreateWindowEx), you can handle WM_CREATE

Lightman

Hi,

Thank for that dedndave....

I moved my WM_CREATE code into WM_INITDIALOG and it worked. Yay...

So, when I create a dialog box Windows does the WM_CREATE stuff for me, but in doing so it means I can't use it? And so RadASM creates me a INITDIALOG by default.

It would also explain some of the hit-and-miss errors I have had in the past. If I create my own program from scratch, I'll use the WM_INITDIALOG as its part of the template. When following the tutorials I'll use WM_CREATE as I'm following the example.

Regards,

Lightman
Regards,

Lightman

dedndave

the operating system does all this stuff, not RadAsm
RadAsm is a handy tool for creating resource files, though
otherwise, you do it with a text editor (the hard way, like me)

and, WM_CREATE is sent by the operating system to the DlgProc,
in the event that you may want to execute some code prior to all the controls being created (and whatever else happens)
(border or title bar stuff, maybe - rarely used, from what i've seen)

you can probably read a lot of documentation about dialog boxes and still not get a clear picture of the order of events - lol

if you really want to learn about resources, you can dig into the EXE format, and examine the binary information created in the resource portion of the EXE
it is interesting to see what is actually created

also, much of the stuff you can create in resource can be created in code, as well
for example, all the controls can be created by using CreateWindowEx and the appropriate class string
(the classes are pre-defined by the OS)
menus can be created by code, and so on

i often prefer to create all my controls via CreateWindowEx   :biggrin:
but, i'm a strange person - most forum members don't follow everything i do   :lol: