How to create check box on new dialog
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: How to create check box on new dialog

  1. #1
    Join Date
    Dec 2008
    Posts
    2

    How to create check box on new dialog

    why check box not created on new dialog
    for all help me , thank you very much

    my code

    void CProjecttestDlg::OnLoaddialogbutton()
    {
    CNewdialog *newDialog;
    newDialog = new CNewdialog;

    CButton *myCheck;
    myCheck = new CButton;

    myCheck->Create(_T("dog") , WS_VISIBLE|BS_AUTOCHECKBOX , CRect(10 , 30 , 100 , 70) ,newDialog ,800);

    newDialog->DoModal();
    }

  2. #2
    Join Date
    Dec 2008
    Posts
    144

    Re: How to create check box on new dialog

    For example you can add this code into the CProjecttestDlg::OnCreate handler
    Code:
    CButton *myCheck;
    myCheck = new CButton;
    
    myCheck->Create(_T("dog") , WS_VISIBLE|BS_AUTOCHECKBOX , CRect(10 , 30 , 100 , 70) ,newDialog ,800);

  3. #3
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,915

    Re: How to create check box on new dialog

    Quote Originally Posted by Nikitozz View Post
    For example you can add this code into the CProjecttestDlg::OnCreate handler

    Button creation will still fail.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  4. #4
    Join Date
    May 1999
    Location
    DELAWARE, USA
    Posts
    9,915

    Re: How to create check box on new dialog

    freedomtoome
    First of all. you are allocating dialog and button object on the heap. Why? It is unnecessary and requires you to remember to free memory allocated by explicitly calling delete. C++ does not have garbage collector.

    Why not to use dialog editor and place check box in a dialog?

    If you must for some weird reason create button at the run time, note following.

    1. You are using Create to create button abd that implies a child window, despite a fact that you did not specify WS_CHILD style; Create function adds that style.
    2. You pass pointer to a MFC dialog object that does not have window attached to it, hence m_hWnd of the dialog is NULL.
    3. Create call fails since Windows cannot create a child as a top-level window (parentís handle is NULL).

    Change code to call Create member of the button class after dialog has window attached to it. The best place is in a WM_INITDIALOG handler.

    Again, restrain from allocating any object on the heap. Allocate it on the stack frame as a variable within a scope of another object that has a life span needed for a button to exist.
    For example: declare CButton as a member variable of the CNewdialog class.

    Declare CNewdialog object as local variable of the OnLoaddialogbutton. You need this dialog to be alive only within this function.

    In both cases, memory is released automatically.
    There are only 10 types of people in the world:
    Those who understand binary and those who do not.

  5. #5
    Join Date
    Dec 2008
    Posts
    2

    Re: How to create check box on new dialog

    Thank you very much, JohnCz

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