-
December 13th, 2008, 02:49 AM
#1
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();
}
-
December 13th, 2008, 04:53 AM
#2
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);
-
December 14th, 2008, 01:00 PM
#3
Re: How to create check box on new dialog
Originally Posted by Nikitozz
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.
-
December 14th, 2008, 01:02 PM
#4
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.
-
December 14th, 2008, 09:35 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|