Results 1 to 7 of 7

Thread: adding controls on the fly to dialogs

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    10

    Question adding controls on the fly to dialogs

    Hi,

    Could anyone please tell me how to add controls to dialogs dynamically? (I'm using VC++ not VB.)

    If anyone here has used Photoshop, what I'm trying to achieve is something like the Layers toolbox in Photoshop, where layer names appear dynamically when the user creates them.

    I did see a solution to this problem at http://www.mooremvp.freeserve.co.uk/Win32/w32tip57.htm but I'm a beginner and I don't understand how to use the supplied code in MFC.

    Could someone please help me? Thanks very much in advance.

    Murli.

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169

    Re: adding controls on the fly to dialogs

    Originally posted by murli
    (I'm using VC++ not VB.)
    Hmm, I wondered why you posted this in C++

    If you look in the Platform SDK it tells you how Windows creates a dialogue:

    1. Read resource info
    2. Create all the child windows (i.e. controls) using CreateWindow
    3. Send messages like WM_INITDIALOG
    4. Give you the window back

    So what you can do is just call CreateWindow again, passing the window handle from CreateDialog [sic].
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    10
    hey thanks for replying.
    since the time i posted my message, i'd already discovered what you told me in your post.
    there's still a problem tho' -- i'm not even that familiar with visual c++ yet so i definitely don't know where SDK enters the picture or even what exactly SDK is. don't look so shocked there are dunces like me around!
    as far as i can make out, i need to define a dialog resource template in memory and use it instead of defining the template in the dialog editor beforehand. is that right?
    assuming i'm right, how do i define a template in memory? the code at http://msdn.microsoft.com/library/en...ource_86yb.asp seems to be what i want. could you please tell me where i'm supposed to use this code and whether i can use vc++ for this? the code in the docs is c++ code afaik, so how/why is sdk different from visual c++?
    thanks for reading this.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Visual C++ is a compiler/IDE.

    SDK == Software Development Kit

    The Win32 API is mostly supported by the PSDK - the Platform SDK. This encompasses the MSDN documentation for nearly everything of interest to Win32 developers.

    It's available as a download, and also comes with updated headers/libraries so you can take early advantage of improvements to the API.

    However, what you can do easily is to define your dialogue resource using the editor, then update the actual WINDOW (the HWND) using CreateWindow. There is a way to assign an ID to a child window (i.e. a control) using CreateWindow but I can't remember off the top of my head.

    However, the code in the SDK is more likely to be C, rather than C++.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    10

    Unhappy

    thanks that explains a lot

    what you can do easily is to define your dialogue resource using the editor, then update the actual WINDOW (the HWND) using CreateWindow.
    CreateWindow is still not part of VC++, right? so i still have to download the SDK? i'm guessing that this is so since HWND enters the picture. Or can HWND objects be directly manipulated in VC?

    Sorry if these are very dumb questions.

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Of course it's part of VC++.

    EVERY windows program has to call CreateWindow at some point, even MFC (even though it's miles down the layers).

    An HWND is actually just an arbitrary numeric value chosen to represent the window (i.e. Windows knows what window it refers to, but you don't until you call some functions using it).

    Basically, just call CreateWindow.

    The SDK has updated headers, as well as the documentation.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2001
    Posts
    10

    Talking

    wonderful! thanks a lot!
    that simplifies things quite a bit for me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width