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();
}
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);
Re: How to create check box on new dialog
Quote:
Originally Posted by
Nikitozz
For example you can add this code into the CProjecttestDlg::OnCreate handler
:confused:
Button creation will still fail.
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.
Re: How to create check box on new dialog
Thank you very much, JohnCz