CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2004
    Posts
    62

    I have a questoin about the resources...

    Hi,

    When I create a Dialog and put some Edit-Controls on it and connect them to a CEdit member variable, where exactly does the program create that CEdit member variable ?

    There is no code in my Dialog for the creation and initalisation of the CEdit (position, WS_VISIBLE, etc...) , so I suppose it happens in some Windows-class/-function when I call DoModal() in the main program. I want to catch the creation of those controls and modify them, but therefore I need to know where I should to this...

    And I need to do this before they are being created. Creating my own controls is also no solution since I want to use those in the "dialog.rc" which have been placed with the Visual Studio Resource Editor.

    Any help or advice on this would be very appreciated...

  2. #2
    Join Date
    Nov 2001
    Posts
    323

    Re: I have a questoin about the resources...

    the control variable should appear in CDialog class
    and I believe you override PreCreateWindow to modify the dialog
    to initialize the dialog override OnInitialDialog

    I hope this helps,
    Best Regards,

    --Zim
    If you find this post useful, please rate it.
    _________________________________
    "Have you the brain worms?!?!?"

  3. #3
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: I have a questoin about the resources...

    Actually all settings to these controls are stored in .rc file and is embedded as "application-resource" into binary bundle. It is specific to Windows which reads that resource automatically. We just pass the ID of dialog itself into constructor (or to Create - if modeless dialog is being created) -the rest is done by MFC and Windows.

    Further, if you need to setup controls before they "appear" you can do so in "OnInitDialog" (WM_INITDIALOG message). All the settings (most of) can be set in resource editor itself.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  4. #4
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: I have a questoin about the resources...

    Quote Originally Posted by Zaph-0
    ...Creating my own controls is also no solution since I want to use those in the "dialog.rc" which have been placed with the Visual Studio Resource Editor.
    ...
    You can create your own controls, like a CMyEdit that's derived from a CEdit, and use them without difficulty on a dialog. That's precisely what the MFC framework is designed to do.

    It works seamlessly, with almost no work on your part. For VC++ version 6.0, derive your CMyEdit class first, and in the resource editor for the dialog, add an edit control (let's say its resource ID is IDC_EDIT_FIRST). Then, from the ClassWizard for the dialog class, add a variable corresponding to IDC_EDIT_FIRST, select "control" from the drop-down box (as opposed to "variable"), and then from the drop-down box underneath select "CMyEdit" (as opposed to "CEdit"). That's it.

    Mike

    PS: Maybe you knew this already (if so, then sorry) and you truly did want to include the control's name in the *.rc file. You should understand that MFC relies on a system called "window sub-classing" to assign a C++ MFC object to an actual Windows window object. These two things are distinct, and one of the benefits of MFC is that it makes them appear to be the same. Anyway, sub-classing is used to assign the Windows "EDIT" class window to an MFC CEdit object, and as far as MFC is concerned, it doesn't care if it's assigned to a CEdit or to a CMyEdit.

  5. #5
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354

    Re: I have a questoin about the resources...

    Quote Originally Posted by Zaph-0
    Hi,

    When I create a Dialog and put some Edit-Controls on it and connect them to a CEdit member variable, where exactly does the program create that CEdit member variable ?
    MFC does not do anything with creating CEdit member variable. It is all done by your code when you add a DDX_Control for the edit. So, as soon as you create an instance of the dialog class , you are creating instances of edit control C++ objects etc... Now, what MFC does is to associate the C++ objects to the appropriate window handles. This is done by subclassing.

    I want to catch the creation of those controls and modify them, but therefore I need to know where I should to this...

    And I need to do this before they are being created. Creating my own controls is also no solution since I want to use those in the "dialog.rc" which have been placed with the Visual Studio Resource Editor.
    What exactly do you want to change ? Note that, some properties cannot be changed once created.. if that is so, the only option for you is to NOT have it in resource, but create it dynamically. So, if you can do something or not depends on what you intend to do.

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

Featured