简体   繁体   中英

Visual C++ Data in MFC Dialog Box not Displaying

I am new to C++ and I am playing around with GUI's in MFC. I have a dialog box that displays the information of a camera when you connect it.

在此处输入图片说明

This is the resource code for that dialog box

IDD_PVSIMPLEUISAMPLE DIALOGEX 0, 0, 575, 284
STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_APPWINDOW
CAPTION "PvSimpleUISample"
FONT 8, "MS Shell Dlg", 0, 0, 0x1
BEGIN
    PUSHBUTTON      "Select / Connect",IDC_CONNECT_BUTTON,10,16,86,16
    PUSHBUTTON      "Disconnect",IDC_DISCONNECT_BUTTON,97,16,87,16,WS_DISABLED
    LTEXT           "IP address",IDC_STATIC,10,41,45,8
    EDITTEXT        IDC_IP_EDIT,65,37,119,14,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
    LTEXT           "MAC address",IDC_STATIC,10,58,50,8
    EDITTEXT        IDC_MAC_EDIT,65,55,119,14,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
    LTEXT           "Manufacturer",IDC_STATIC,10,75,50,8
    EDITTEXT        IDC_MANUFACTURER_EDIT,65,72,119,14,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
    LTEXT           "Model",IDC_STATIC,10,93,44,8
    EDITTEXT        IDC_MODEL_EDIT,65,90,119,14,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
    LTEXT           "Name",IDC_STATIC,10,110,44,8
    EDITTEXT        IDC_NAME_EDIT,65,107,119,14,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
    GROUPBOX        "Connection",IDC_STATIC,4,4,187,123
    LTEXT           "Mode",IDC_STATIC,10,144,55,8
    COMBOBOX        IDC_MODE,66,141,118,30,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
    LTEXT           "Channel",IDC_STATIC,9,160,56,8
    OMBOBOX        IDC_CHANNEL,66,157,118,30,CBS_DROPDOWNLIST | CBS_SORT | WS_DISABLED | WS_VSCROLL | WS_TABSTOP
    CONTROL         "Play",IDC_START,"Button",BS_OWNERDRAW | WS_TABSTOP,13,171,44,26
    CONTROL         "Stop",IDC_STOP,"Button",BS_OWNERDRAW | WS_TABSTOP,75,172,42,26
    CONTROL         "Settings",IDC_SETTINGS,"Button",BS_OWNERDRAW | WS_TABSTOP,135,172,43,26
    GROUPBOX        "Parameters and Controls",IDC_CONTROL_GROUP,4,206,187,73
    PUSHBUTTON      "Communication control",IDC_LINK_BUTTON,10,218,174,17,WS_DISABLED
    PUSHBUTTON      "Device control",IDC_DEVICE_BUTTON,10,237,174,17,WS_DISABLED
    PUSHBUTTON      "Image stream control",IDC_STREAMPARAMS_BUTTON,10,256,174,17,WS_DISABLED
    GROUPBOX        "Display",IDC_DISPLAY_GROUP,198,4,371,275
    PUSHBUTTON      "Display",IDC_DISPLAYPOS,205,17,355,254,NOT WS_VISIBLE | WS_DISABLED
    GROUPBOX        "Acquisition Control",IDC_CONTROL_GROUP2,4,128,187,77
END

I then made a new dialog box that opens when you click on the settings button. I copied a few of the lines over to the new dialog box but the actual data that is transmitted from the camera doesn't appear.

在此处输入图片说明

Here is the code for the settings dialog box

IDD_SETTINGS DIALOGEX 0, 0, 444, 319
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Settings"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,205,298,50,14
    LTEXT           "IP address",IDC_STATIC,10,41,45,8
    EDITTEXT        IDC_IP_EDIT,65,37,119,14,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
    LTEXT           "MAC address",IDC_STATIC,10,58,50,8
    EDITTEXT        IDC_MAC_EDIT,65,55,119,14,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
    LTEXT           "Manufacturer",IDC_STATIC,10,75,50,8
    EDITTEXT        IDC_MANUFACTURER_EDIT,65,72,119,14,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
    LTEXT           "Model",IDC_STATIC,10,93,44,8
    EDITTEXT        IDC_MODEL_EDIT,65,90,119,14,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
    LTEXT           "Name",IDC_STATIC,10,110,44,8
    EDITTEXT        IDC_NAME_EDIT,65,107,119,14,ES_AUTOHSCROLL | ES_READONLY | WS_DISABLED
END

How do I get the data to appear in the dialog box? Do I need to make a whole class for it? Any help/advice would be aprreciated.

In first dialog, you can declare a second dialog's class object, use the object obtain the item control object then set data. So you can do like this, in the setting button's callback function, add these codes:

CAAADialog::OnXXXButton()
{
     CBBBDialog dlgb;
     dlgb.DoModal();
     dlgb.GetDlgItem(IDC_IP_EDIT)->SetWindowText(m_strIp);
     dlgb.GetDlgItem(IDC_MAC_EDIT)->SetWindowText(m_strMac);
     dlgb.GetDlgItem(IDC_MANUFACTURER_EDIT)->SetWindowText(m_strManufacture);
     dlgb.GetDlgItem(IDC_NAME_EDIT)->SetWindowText(m_strName);
}

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