Is there any difference between the functions Create and CreateIndirect?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Is there any difference between the functions Create and CreateIndirect?

  1. #1
    Join Date
    Jul 2005
    Posts
    965

    Is there any difference between the functions Create and CreateIndirect?

    In what situation I need to call CreateIndirect to create a modaless dialog? Thanks.

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,634

    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
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    http://www.microsoft.com/visualstudio/eng/downloads

  3. #3
    Join Date
    Jul 2005
    Posts
    965

    Re: Is there any difference between the functions Create and CreateIndirect?

    Quote Originally Posted by S_M_A View Post
    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.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,444

    Re: Is there any difference between the functions Create and CreateIndirect?

    Quote Originally Posted by LarryChen View Post
    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 04:56 AM.

  5. #5
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,061

    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.

  6. #6
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,050

    Re: Is there any difference between the functions Create and CreateIndirect?

    Quote Originally Posted by LarryChen View Post
    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center