简体   繁体   中英

Visual C++ open Dialog Box when button clicked

So I am new to programming in C++ and new to using Visual Studio 2010. Basically I have a FLIR thermal camera; and I need to edit a GUI provided in an eBUS SDK that suits my needs.

What I want to do is open a new dialog box when I click the settings button. I am just not sure what code to use in the button handler to make the dialog box open. I have put different code in the button handler to test it and the settings button works fine.

This is the button handler that the code needs to go into.

void PvSimpleUISampleDlg::OnBnClickedSettings()
{

}

This is the dialog box in the resource file that I want to connect the button to. It is called IDD_SETTINGS . The actual button is called IDB_SETTINGS , not sure if that's relevant.

IDD_SETTINGS DIALOGEX 0, 0, 506, 300
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Settings"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,449,279,50,14

END

I am not sure what other code to add, but I am completely new so any help/advice you can give no matter how small would be greatly appreciated.

If you are using the MFC framework (the CDialog class), then you can create a new CDialog object using the settings-dialog resource you've created.

The CDialog::DoModal() function is what you want, if you want a simple popup box that grabs your attention until it is dismissed with OK or Cancel.

In your source file:

void PvSimpleUISampleDlg::OnBnClickedSettings()
{
    CDialog mySettings( IDD_SETTINGS );
    INT_PTR returnCode = -1;
    returnCode = mySettings.DoModal();

    switch( returnCode ) {
    case IDOK :
      //gather your input fields here 

      break;
    case IDCANCEL :
      //do something
      break;

    case -1:
    default:
       //error creating box
    }
}

Here is a link for using the CDialog class as a starting point for extracting information from the box once OK is clicked: https://msdn.microsoft.com/en-us/library/619z63f5.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM