1

So I have this code

CButton details;
details.Create(_T("details"),WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON,CRect(120,100,100,30), this, 15000);

but it doesn't do anything(created button is not visible after creating it). What am I missing?

EDIT: The code is in a dialog based application's OnInitDialog function. What it should do is to display the button.

mistily
  • 63
  • 2
  • 8
  • This question cannot be answered as it is. You need to provide more context. Where is `details` declared? Is it a class member? A local variable? Where are you calling `Create`? Consider providing an [SSCCE](http://sscce.org) that illustrates the problem. – IInspectable Nov 24 '13 at 17:54

4 Answers4

3

Your CButton is created with automatic storage duration. So it is destroyed when OnInitDialog returns. (Which is before the dialog is visible.) Make the CButton a member variable instead.

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15
0

The values under CRect provided by you is incorrect, it must be CRect(120, 100, 220, 130).

HariDev
  • 508
  • 10
  • 28
0

this is depending to declaring CButton details;! you must declare CButton details; as general instance(not local instance)

define your CButton details; instance as general, so your problem will solved! bellow code work 100 percentage :

#define BBB 10000
CButton c;
void CThreadsDlg::OnBnClickedButton1()
{
    bool a = c.Create(_T("new button"), WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON, CRect(100, 100, 220, 230), this, BBB);
}

if c button created, a variable will be true.

0

My experience: nothing is shown if your dialog is inherited from CDHtmlDialog, but works OK with normal CDialog. So change the first line in OnInitDialog()


//CDHtmlDialog::OnInitDialog();
CDialog::OnInitDialog();

and of course, the button variable should be global or class member, not local.

VooV.Rat
  • 1
  • 1