gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
hi! i am writing some c++ code, and i am trying to have a CDialog window pop up and ask…
- User
hi! i am writing some c++ code, and i am trying to have a CDialog window pop up and ask for two strings from the user. once the user enters them and clicks 'ok', i want the window to close, and to have access to those two strings. how would i do this?
- Assistant
To achieve this in C++, you can follow these steps:
- Create a dialog resource in your project's resource file (.rc) using a resource editor, such as Visual Studio's built-in resource editor.
- Add two Edit controls to the dialog resource, one for each string that you want the user to enter.
- In your C++ code, define a class derived from CDialog to handle the dialog functionality. For example:
class MyDialog : public CDialog { public: CString str1; CString str2; protected: virtual void DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text(pDX, IDC_EDIT1, str1); // Bind str1 to the first Edit control DDX_Text(pDX, IDC_EDIT2, str2); // Bind str2 to the second Edit control } virtual BOOL OnInitDialog() { CDialog::OnInitDialog(); return TRUE; } afx_msg void OnOK() { CDialog::OnOK(); } DECLARE_MESSAGE_MAP() }; BEGIN_MESSAGE_MAP(MyDialog, CDialog) END_MESSAGE_MAP() - User
that worked, thanks!
- Assistant
You're welcome! I'm glad to hear that it worked for you. If you have any more questions, feel free to ask. Happy coding!