Discussion:
Creating a dialogBox dynamically...
(too old to reply)
Kellie Fitton
2005-03-21 18:01:30 UTC
Permalink
Hello Everyone,

I am calling the win32 API DialogBoxIndirectParam with the extended
templates DLGTEMPLATEEX (header) and DLGITEMTEMPLATEEX (array) so
I can create a dialogBox dynamically. When I call the function
with the header template Only, I get an empty dialogBox that looks
fine accordingly, However, when I include the control template to
the array so I can add a button for example, the function call
retuns an error code -1, which means failed, and when I call the
win32 API GetLastError I would get an error text message that say:
"Cannot Find Window Class". I think am doing something wrong with
the second structure, even though I got it aligned on a DWORD.
I am hoping someone here can help me to correctly define the array
"DLGITEMTEMPLATEEX"? your help will be appreciated. Regards.

Kellie.
Lucian Wischik
2005-03-21 21:24:08 UTC
Permalink
Post by Kellie Fitton
I am calling the win32 API DialogBoxIndirectParam with the extended
templates DLGTEMPLATEEX (header) and DLGITEMTEMPLATEEX (array) so
I can create a dialogBox dynamically. I think am doing something wrong with
the second structure, even though I got it aligned on a DWORD.
I am hoping someone here can help me to correctly define the array
"DLGITEMTEMPLATEEX"? your help will be appreciated. Regards.
This is how I did it. Other people might complain that my code is too
dense or cryptic. But it works! and I think it's more elegant to do it
this way, with static stack-based layout of the template, rather than
messing with memory allocation and pointers.

typedef struct {DLGITEMTEMPLATE dli; WORD ch; WORD c; WORD t; WORD
dummy; WORD cd;} TDlgItem;

typedef struct {DLGTEMPLATE dlt; WORD m; WORD c; WCHAR t[8]; WORD pt;
WCHAR f[14]; TDlgItem ia; TDlgItem ib; TDlgItem ic;} TDlgData;

TDlgData dtp={{DS_MODALFRAME|DS_3DLOOK|DS_SETFONT|DS_CENTER|
WS_POPUP|WS_CAPTION|WS_SYSMENU|WS_VISIBLE,0,3,0,0,278,196},
0,0,L"Preview",8,L"MS Sans Serif",

{{BS_DEFPUSHBUTTON|WS_CHILD|WS_VISIBLE,0,113,175,50,14,IDOK},0xFFFF,0x0080,0,0,0},

{{SS_BLACKRECT|WS_CHILD|WS_VISIBLE,0,7,7,264,152,3},0xFFFF,0x0082,0,0,0},

{{SS_CENTER|WS_CHILD|WS_VISIBLE,0,7,162,264,8,2},0xFFFF,0x0082,0,0,0}};

DialogBoxIndirect(hInstance,(DLGTEMPLATE*)&dtp,hwnd,MyDialogProc);


--
Lucian
Kellie Fitton
2005-03-22 19:53:31 UTC
Permalink
Hi Lucian,

thanks for the help.

Kellie.
r***@pen_fact.com
2005-03-23 21:45:49 UTC
Permalink
On 21 Mar 2005 10:01:30 -0800, "Kellie Fitton"
Post by Kellie Fitton
Hello Everyone,
I am calling the win32 API DialogBoxIndirectParam with the extended
templates DLGTEMPLATEEX (header) and DLGITEMTEMPLATEEX (array) so
I can create a dialogBox dynamically. When I call the function
with the header template Only, I get an empty dialogBox that looks
fine accordingly, However, when I include the control template to
As I said in your thread called "What is the Ordinal value (hex) of a
GroupBox.", I use a template to create an empty dialog box, then use
CreateWindow and MoveWindow to add, then size and position, each
control. Depending on the dialog box, that may mean quite a few
function calls, but it means I don't have to deal with the intricacies
of templates and don't really deal with Dialog Box units.
Post by Kellie Fitton
Kellie.
-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com
Kellie Fitton
2005-03-25 16:11:31 UTC
Permalink
Hi Robert,

thanks for the help.

Kellie.
Severian
2005-03-25 16:30:54 UTC
Permalink
Post by r***@pen_fact.com
On 21 Mar 2005 10:01:30 -0800, "Kellie Fitton"
Post by Kellie Fitton
Hello Everyone,
I am calling the win32 API DialogBoxIndirectParam with the extended
templates DLGTEMPLATEEX (header) and DLGITEMTEMPLATEEX (array) so
I can create a dialogBox dynamically. When I call the function
with the header template Only, I get an empty dialogBox that looks
fine accordingly, However, when I include the control template to
As I said in your thread called "What is the Ordinal value (hex) of a
GroupBox.", I use a template to create an empty dialog box, then use
CreateWindow and MoveWindow to add, then size and position, each
control. Depending on the dialog box, that may mean quite a few
function calls, but it means I don't have to deal with the intricacies
of templates and don't really deal with Dialog Box units.
Hmm. I'm sure I prefer laying out the 350 dialog boxes in my
application visually in the resource editor! And they scale properly
for different system font sizes. There are few applications as
irritating as those that ignore the Large Font setting on a high-res
display.

If I did need to create DLGTEMPLATEEX/DLGITEMTEMPLATEX structures in C
or C++ (for inclusion in a .OBJ or .LIB), I would write a converter to
translate the RC file to the proper structures. I think I could do
that as quickly as laying out 10 complex dialog boxes manually with
CreateWindow/MoveWindow for each control.

--
Sev
r***@pen_fact.com
2005-03-25 19:20:26 UTC
Permalink
On Fri, 25 Mar 2005 16:30:54 GMT, Severian
Post by Severian
Post by r***@pen_fact.com
On 21 Mar 2005 10:01:30 -0800, "Kellie Fitton"
Post by Kellie Fitton
Hello Everyone,
I am calling the win32 API DialogBoxIndirectParam with the extended
templates DLGTEMPLATEEX (header) and DLGITEMTEMPLATEEX (array) so
I can create a dialogBox dynamically. When I call the function
with the header template Only, I get an empty dialogBox that looks
fine accordingly, However, when I include the control template to
As I said in your thread called "What is the Ordinal value (hex) of a
GroupBox.", I use a template to create an empty dialog box, then use
CreateWindow and MoveWindow to add, then size and position, each
control. Depending on the dialog box, that may mean quite a few
function calls, but it means I don't have to deal with the intricacies
of templates and don't really deal with Dialog Box units.
Hmm. I'm sure I prefer laying out the 350 dialog boxes in my
application visually in the resource editor! And they scale properly
for different system font sizes.
Do they scale for different monitor sizes and shapes?
Post by Severian
Post by r***@pen_fact.com
There are few applications as
irritating as those that ignore the Large Font setting on a high-res
display.
My controls generally reset their font as they resize. So anything
that changes the size of a control will change the size of the font.
I'm pretty sure that will work well for all the apps I've written.
I've explicitly changed font size on my monitor a few times to test,
and I liked the way my apps responded. But I _do_ ignore Large Font
setting, so I might run into problems sometime. So, thanks for the
reminder.
Post by Severian
If I did need to create DLGTEMPLATEEX/DLGITEMTEMPLATEX structures in C
or C++ (for inclusion in a .OBJ or .LIB), I would write a converter to
translate the RC file to the proper structures. I think I could do
that as quickly as laying out 10 complex dialog boxes manually with
CreateWindow/MoveWindow for each control.
I have a bunch of functions that take care of details, and really
speed up the coding. I haven't used a resource editor to layout a
dialog box in a while, but I'm pretty sure I take about as long with
my current method as I did with the resource editor. One big win for
me is that I automatically cover an infinite collection of monitor
shapes and resolution because my dialogs scale automatically. Some
also change shape. And some add tools as they become bigger. Another
big win is that I can reuse dialog boxes in multiple apps.

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com
Severian
2005-03-25 19:57:18 UTC
Permalink
Post by r***@pen_fact.com
On Fri, 25 Mar 2005 16:30:54 GMT, Severian
Post by Severian
Post by r***@pen_fact.com
On 21 Mar 2005 10:01:30 -0800, "Kellie Fitton"
Post by Kellie Fitton
Hello Everyone,
I am calling the win32 API DialogBoxIndirectParam with the extended
templates DLGTEMPLATEEX (header) and DLGITEMTEMPLATEEX (array) so
I can create a dialogBox dynamically. When I call the function
with the header template Only, I get an empty dialogBox that looks
fine accordingly, However, when I include the control template to
As I said in your thread called "What is the Ordinal value (hex) of a
GroupBox.", I use a template to create an empty dialog box, then use
CreateWindow and MoveWindow to add, then size and position, each
control. Depending on the dialog box, that may mean quite a few
function calls, but it means I don't have to deal with the intricacies
of templates and don't really deal with Dialog Box units.
Hmm. I'm sure I prefer laying out the 350 dialog boxes in my
application visually in the resource editor! And they scale properly
for different system font sizes.
Do they scale for different monitor sizes and shapes?
Post by Severian
Post by r***@pen_fact.com
There are few applications as
irritating as those that ignore the Large Font setting on a high-res
display.
My controls generally reset their font as they resize. So anything
that changes the size of a control will change the size of the font.
I'm pretty sure that will work well for all the apps I've written.
I've explicitly changed font size on my monitor a few times to test,
and I liked the way my apps responded. But I _do_ ignore Large Font
setting, so I might run into problems sometime. So, thanks for the
reminder.
Post by Severian
If I did need to create DLGTEMPLATEEX/DLGITEMTEMPLATEX structures in C
or C++ (for inclusion in a .OBJ or .LIB), I would write a converter to
translate the RC file to the proper structures. I think I could do
that as quickly as laying out 10 complex dialog boxes manually with
CreateWindow/MoveWindow for each control.
I have a bunch of functions that take care of details, and really
speed up the coding. I haven't used a resource editor to layout a
dialog box in a while, but I'm pretty sure I take about as long with
my current method as I did with the resource editor. One big win for
me is that I automatically cover an infinite collection of monitor
shapes and resolution because my dialogs scale automatically. Some
also change shape. And some add tools as they become bigger. Another
big win is that I can reuse dialog boxes in multiple apps.
It sounds like you're working on full-screen dialog boxes for
handheld, CE or special devices? This would be a different matter
altogether and I might adopt a similar approach to yours!

(I assume this because a standard Windows application would not have
to scale dialogs for different monitor shapes, since desktop
application dialogs are designed to fit on any Windows desktop).

--
Sev
Kellie Fitton
2005-03-25 20:26:23 UTC
Permalink
Hi Severian,

just out of curiosity, why would you write
a converter in C++ to translate the .RC file into
the proper structure --- instead of just calling the
win32 API MapDialogRect, and have it convert the
.RC file numbers into the proper pixels units.
remember though, the information in the .RC file
are dialogBox units? Also, what happen if you
want to create a dialogBox and some controls
on-the-fly during the runtime, based on some
events or responses from the end-user? Regards.

Kellie.
Severian
2005-03-25 20:49:04 UTC
Permalink
On 25 Mar 2005 12:26:23 -0800, "Kellie Fitton"
Post by Kellie Fitton
Hi Severian,
just out of curiosity, why would you write
a converter in C++ to translate the .RC file into
the proper structure --- instead of just calling the
win32 API MapDialogRect, and have it convert the
.RC file numbers into the proper pixels units.
remember though, the information in the .RC file
are dialogBox units? Also, what happen if you
want to create a dialogBox and some controls
on-the-fly during the runtime, based on some
events or responses from the end-user? Regards.
An earlier discussion (not sure if it was related to this one) was
about embedding dialog boxes in .lib files for static linking, which
is not possible using RC files.

Also, I regularly create dialog boxes in the resource editor, and
delete/create/move/resize controls at run-time. The controls are just
windows, after all.

--
Sev
Sarge
2005-03-25 21:20:44 UTC
Permalink
Post by Severian
On 25 Mar 2005 12:26:23 -0800, "Kellie Fitton"
Post by Kellie Fitton
Hi Severian,
just out of curiosity, why would you write
a converter in C++ to translate the .RC file into
the proper structure --- instead of just calling the
win32 API MapDialogRect, and have it convert the
.RC file numbers into the proper pixels units.
remember though, the information in the .RC file
are dialogBox units? Also, what happen if you
want to create a dialogBox and some controls
on-the-fly during the runtime, based on some
events or responses from the end-user? Regards.
An earlier discussion (not sure if it was related to this one) was
about embedding dialog boxes in .lib files for static linking, which
is not possible using RC files.
Also, I regularly create dialog boxes in the resource editor, and
delete/create/move/resize controls at run-time. The controls are just
windows, after all.
--
Sev
Sev is right - the resource editor is much faster for developing dialog
boxes and you can ensure that your dialogs look professional, not like a
cheesy shareware or cross-platform app.

And for changing the controls in a dialog on the fly,

ShowWindow(hControl, SW_SHOW / SW_HIDE);

works great if the controls are already laid out in the resource editor.

--Sarge

Loading...