What I wish to do is, after creating a dialog box with DoModal()
and pressing OK in the box to exit it, to have a custom value returned. For example, a couple of strings the user would input in the dialog.
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- 如何让cmd.exe 执行 UNICODE 文本格式的批处理?
- 怎么把Windows开机按钮通过修改注册表指向我自己的程序
- Warning : HTML 1300 Navigation occured?
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
I was looking for an answer and agree that in most cases that you would not change the standard behavior of a dialog. But there might be a case where you would like to pick what the user is actually responding say if you had several buttons and want specifically that they picked the OK at the top versus the OK at the bottom. You know for metrics.
Or say if you wanted to have slightly different results if the dialog caused an error when running on of your functions. It would be nice to return a value that is not IDOK but maybe some other value.
I found
Dialog::EndDialog()
with details and an example of usage here: MSDN: Dialog::EndDialogYou can't change the return value of the
DoModal()
function, and even if you could, I wouldn't recommend it. That's not the idiomatic way of doing this, and if you changed its return value to a string type, you would lose the ability to see when the user canceled the dialog (in which case, the string value returned should be ignored altogether).Instead, add another function (or multiple) to your dialog box class, something like
GetUserName()
andGetUserPassword
, and then query the values of those functions afterDoModal
returnsIDOK
.For example, the function that shows the dialog and processes user input might look like this:
I don't think it is possible (or reasonable). DoModal returns an INT_PTR, which is usually used to know what the user did to exit the dialog (press OK, Cancel, there was an error...). The way to do it is have public members or functions which the dialog set and the caller of the dialog can access to know the values. Like so:
It's the way you would use CFileDialog, for example.