Prompting a user with an input box? [C++]

后端 未结 8 853
遥遥无期
遥遥无期 2020-12-11 15:17

My goal is to simply use a pop-up box to ask the user for an input. I\'ve searched around quite a bit and pretty much all the results say that creating a messageBox is reall

相关标签:
8条回答
  • 2020-12-11 15:54

    I have to admit that I haven't really done much in the way of input boxes in ages, but you basically have to go outside C++ in order to get any kind of graphical input box. There's simply no mechanism built into the language for that kind of stuff for portability reasons. I don't remember if it applied to C++ as well, but C doesn't even assume you have a console. Anyway, your best bet would be something along the lines you were already trying: Win32 API, Qt, etc. If you can use the console, however, feel free to just use the iostream library to get the job done.

    0 讨论(0)
  • 2020-12-11 15:55

    Unlike Visual Basic and other languages, there is no "built in" Input Box like command in c++. Unlike MessageBox that can be just invoked, InputBox() needs to be written. In fact, I have done so. The following article describes how to implement such InputBox as part of a small Static Library that can be used, with no Resources, from any Win32 c++ program. Source code at Github. It can be used as follow:

    LPWSTR GetString(LPCTSTR szCaption, LPCTSTR szPrompt, LPCTSTR szDefaultText = L"");
    

    For example:

    LPWSTR result = SG_InputBox::GetString(
         L"Code Project Demo", 
         L"What is your name");
    
    0 讨论(0)
提交回复
热议问题