简体   繁体   English

单击按钮时,Visual C++ 打开对话框

[英]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;所以我是 C++ 编程的新手,也是 Visual Studio 2010 的新手。基本上我有一个 FLIR 热像仪; and I need to edit a GUI provided in an eBUS SDK that suits my needs.我需要编辑适合我需要的 eBUS SDK 中提供的 GUI。

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 .它被称为IDD_SETTINGS The actual button is called IDB_SETTINGS , not sure if that's relevant.实际按钮称为IDB_SETTINGS ,不确定是否相关。

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.如果您使用的是 MFC 框架(CDialog 类),那么您可以使用您创建的设置对话框资源创建一个新的 CDialog 对象。

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. CDialog::DoModal()函数就是你想要的,如果你想要一个简单的弹出框来吸引你的注意力,直到它被 OK 或 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这是一个链接,用于在单击“确定”后使用 CDialog 类作为从框中提取信息的起点: https : //msdn.microsoft.com/en-us/library/619z63f5.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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