How to hide or show button from another class MFC vc++
-
How can I access controls of one class from another class. Example, Initially the button is hidden. I tried to make it visible from another class by doing like this
GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);
inside a function. But this doesn't seem to work. How can I make it visible from another class. Thanks in advance.
-
How can I access controls of one class from another class. Example, Initially the button is hidden. I tried to make it visible from another class by doing like this
GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);
inside a function. But this doesn't seem to work. How can I make it visible from another class. Thanks in advance.
Member 14575556 wrote:
But this doesn't seem to work.
What exactly "doesn't seem to work"? Could you show your code?
-
Member 14575556 wrote:
But this doesn't seem to work.
What exactly "doesn't seem to work"? Could you show your code?
There are two button in Dialog 1.
BOOL CMyFirstDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
GetDlgItem(IDC_BUTTON)->ShowWindow(FALSE);ShowWindow(SW_MINIMIZE);
return TRUE;
}When I click one button i want to make the other button visible again.
void CMyFirstDlg::OnBnClickedButton()
{
CSecondDlg* Obj = new CSecondDlg();
Obj->DisplayButton();
}Inside the DisplayButton function which is in another class there is
GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);
-
There are two button in Dialog 1.
BOOL CMyFirstDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
GetDlgItem(IDC_BUTTON)->ShowWindow(FALSE);ShowWindow(SW_MINIMIZE);
return TRUE;
}When I click one button i want to make the other button visible again.
void CMyFirstDlg::OnBnClickedButton()
{
CSecondDlg* Obj = new CSecondDlg();
Obj->DisplayButton();
}Inside the DisplayButton function which is in another class there is
GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);
Member 14575556 wrote:
When I click one button i want to make the other button visible again.
void CMyFirstDlg::OnBnClickedButton()
{
CSecondDlg* Obj = new CSecondDlg();
Obj->DisplayButton();
}You created the object of CSecondDlg class but you have not created the window of this dialog!
-
How can I access controls of one class from another class. Example, Initially the button is hidden. I tried to make it visible from another class by doing like this
GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);
inside a function. But this doesn't seem to work. How can I make it visible from another class. Thanks in advance.
Member 14575556 wrote:
How can I access controls of one class from another class.
Your question should probably be something like, "How can I access controls on one dialog from a separate dialog?" While it is not a good idea to do so directly (see "loose coupling"), a better way would be to send a message to the parent (the one that owns the control) dialog.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
There are two button in Dialog 1.
BOOL CMyFirstDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
GetDlgItem(IDC_BUTTON)->ShowWindow(FALSE);ShowWindow(SW_MINIMIZE);
return TRUE;
}When I click one button i want to make the other button visible again.
void CMyFirstDlg::OnBnClickedButton()
{
CSecondDlg* Obj = new CSecondDlg();
Obj->DisplayButton();
}Inside the DisplayButton function which is in another class there is
GetDlgItem(IDC_BUTTON)->ShowWindow(TRUE);
Member 14575556 wrote:
CSecondDlg* Obj = new CSecondDlg(); Obj->DisplayButton();
See here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
-
Member 14575556 wrote:
How can I access controls of one class from another class.
Your question should probably be something like, "How can I access controls on one dialog from a separate dialog?" While it is not a good idea to do so directly (see "loose coupling"), a better way would be to send a message to the parent (the one that owns the control) dialog.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
Thank you for the pointing me to the right direction. :) I'll read about "loose coupling" and to be honest I don't really get how to send message as of now, so I'll read about that too. I've solve my problem in a naive way for now but i'll definitely follow your suggestions. Thanks again.