Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VC6 MFC
I need to create a button dynamically in mfc dialog form by using following code..
 
CButton myButton1, myButton2, myButton3, myButton4;
 

myButton1.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
CRect(10,10,100,30), pParentWnd, 1);
 
In this code i got an error pParentwnd as not a member.. how can i clear this error?
Posted 8-Apr-13 4:54am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You may just pass this (that is the pointer to the CDialog itself) instead of pParentWnd.
 

[Update]
Please note myButton shouldn't be a local variable (it should be a class member).
I used the following code in the about dialog of a MFC SDI application:
class CAboutDlg : public CDialog
{
  CButton myButton;
//...
 

BOOL CAboutDlg::OnInitDialog()
{
  CDialog::OnInitDialog();
  myButton.Create(_T("My button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
  CRect(10,10,100,30), this, 1);
  return TRUE;  
}
It is working fine (it shows the button).
[/Update]
  Permalink  
v2
Comments
Sergey Alexandrovich Kryukov at 8-Apr-13 10:14am
   
Of course, a 5.
—SA
CHill60 at 8-Apr-13 10:22am
   
And my 5
gurunbr1 at 9-Apr-13 2:11am
   
This code was accepted my compiler, but i couldn't visible button on dialog at runtime?
gurunbr1 at 9-Apr-13 4:46am
   
i use dialog forms, not SDI..
CPallini at 9-Apr-13 5:02am
   
That is irrelevant: I used the code inside a dialog, after all. Make sure your button variable is a member of the (dialog) class.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,192
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 9 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100