-
September 14th, 2012, 11:00 AM
#1
Is there any difference between the functions Create and CreateIndirect?
In what situation I need to call CreateIndirect to create a modaless dialog? Thanks.
-
September 14th, 2012, 11:11 AM
#2
Re: Is there any difference between the functions Create and CreateIndirect?
Come on Larry, isn't MSDN available in your country? From MSDN:
MFC
Call this member function to create a modeless dialog box from a dialog-box template in memory
or if you actually use Win32
Creates a modeless dialog box from a dialog box template in memory
-
September 14th, 2012, 11:40 AM
#3
Re: Is there any difference between the functions Create and CreateIndirect?
Originally Posted by S_M_A
Come on Larry, isn't MSDN available in your country? From MSDN:
MFC or if you actually use Win32
Probably I had a too general title for my question. Actually I know the difference in superficial sense as MSDN points out. One is used to create a modaless dialog from resource and another one is used to create a modaless dialog from memory. But the REAL question is why would we create a modaless dialog from memory?Does it imply sometimes it fails to create a modaless dialog from resource so CreateIndirect comes to remedy?
BTW, I assume this forum is a quality forum.
-
September 14th, 2012, 02:10 PM
#4
Re: Is there any difference between the functions Create and CreateIndirect?
Originally Posted by LarryChen
But the REAL question is why would we create a modaless dialog from memory?
Try to create your own resource editor program or a program that builds and runs dialogs on the fly. You don't know beforehand the number of edit controls, list boxes, combo boxes, static text, etc. and you don't know the positions, sizes and tab order of these controls. All of that information is only known at runtime when the user has selected the controls and characteristics of each control.
So the only way to get something like this to work is to build the resources yourself at runtime, in memory. Granted that it isn't trivial to do (to build your own resource from scratch was something that required knowledge of the internals of the resources), but Windows allows you to create dialogs without a physical resource defined, and CreateDialogIndirect() is the hook into doing this. If you did a web search on "Dynamic Dialog Boxes", you should find code on how this is done.
Hopefully that answers your question.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; September 17th, 2012 at 03:56 AM.
-
September 17th, 2012, 02:55 AM
#5
Re: Is there any difference between the functions Create and CreateIndirect?
It can also be needed if you load the resource template into memory yourself, do some changes to it (such as changing the font to match the system font, or changing/removing/adding controls), then create the dialog from the modified resource in memory.
-
September 17th, 2012, 03:30 AM
#6
Re: Is there any difference between the functions Create and CreateIndirect?
Originally Posted by LarryChen
Does it imply sometimes it fails to create a modaless dialog from resource so CreateIndirect comes to remedy?
This may imply most probably that CreateDialog makes use of CreateDialogIndirect internally. The action appears to be two-phased, first it loads resource to memory, and then it creates the dialog window by the in-memory template as is. As long as there may be some use of CreateDialogIndirect itself (what Paul and OReubens have already explained), the API is exposed as an independent and standalone entry.
This multi phase approach is very typical for API design, not only Windows but of any kind.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|