Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have done a GUI with main dialog box with one button. if I press that button I will get modeless another dialog box with one button and edit box. My aim is if I press main dialog box button the button should access the another dialog box button .

Generally Button function is in protected mode by default, how to access protected afx button function in main dialog box button function.

What I have tried:

I created object of another dialog box in public mode in main dialog box. Thru that object I tired to access another dialog box protected function.
Posted
Updated 10-Nov-17 0:51am

Make an accessor (a public method) in order to manipulate the protected property.
 
Share this answer
 
So you have a main dialog which creates another (modeless) dialog upon a button press (or hopefully activates the modeless dialog if it exists already).

In such cases your main dialog usually contains a member for the second dialog. You can use that member to access the other dialog and it's public members. For access to protected members you can add functions that allow general access (return a pointer to the member) or functions that perform specific actions.

If you refer to a message handler by "afx button function", just send the corresponding message to the window. If you want for example to simulate a button click in the modeless dialog all you need is the CWnd of that dialog and the ID of the button:
C++
m_pModelessDialog->SendMessage(
    WM_COMMAND,
    MAKEWPARAM(ID_OF_BUTTON, BN_CLICKED),
    // May also pass NULL here (works in most cases)
    m_pModelessDialog->GetDlgItem(ID_OF_BUTTON)->GetSafeHwnd()
);
 
Share this answer
 
Comments
Member 12208944 10-Nov-17 7:16am    
Thanks Jochen it is worked with public member

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900