Created
November 24, 2021 18:03
-
-
Save core-hacked/7c3fbcd032375820e852b890d7efc7c2 to your computer and use it in GitHub Desktop.
C++ kind of user friendly simple message box caller for windows...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
int main() { | |
/* | |
usage example: | |
MsgBox("Your title", "Your description", "the type of icon", "the-buttons"); | |
Available options: | |
Type: warn, info, question, error | |
warning - displays an exclamation-point icon in the message box. | |
information - displays an icon consisting of a lowercase letter i in a circle inside of the message box. | |
question - displays a question-mark icon inside of the message box.. | |
error - displays a stop-sign icon in the message box. | |
Buttons: ok, ok-cancel, yes-no, yes-no-cancel, retry-cancel, cancel-retry-continue, help, abort-retry-ignore | |
The buttons all are descriptive enough, the option 'help' adds a Help button to the message box. When the user clicks the Help button or presses F1, the system sends a WM_HELP message to the owner. | |
*/ | |
MsgBox("Example warning title", "Example warning description", "warn", "ok"); | |
} | |
VOID MsgBx(string Title, string Message, string Type, string Buttons) { | |
// process the message box title | |
std::string TitleTxt = Title; | |
LPWSTR ws = new wchar_t[TitleTxt.size()]; | |
copy(TitleTxt.begin(), TitleTxt.end(), ws); | |
ws[TitleTxt.size()] = 0; | |
// process the message box description | |
std::string MsgTxt = Title; | |
LPWSTR ws2 = new wchar_t[MsgTxt.size()]; | |
copy(MsgTxt.begin(), MsgTxt.end(), ws2); | |
ws2[MsgTxt.size()] = 0; | |
// process the type of icon to display and then the buttons corresponding to the message box | |
if (Type == "information") { | |
if (Buttons == "abort-retry-ignore") { | |
MessageBox(NULL, ws, ws2, MB_ICONINFORMATION | MB_ABORTRETRYIGNORE); | |
} | |
else if (Buttons == "cancel-retry-continue") { | |
MessageBox(NULL, ws, ws2, MB_ICONINFORMATION | MB_CANCELTRYCONTINUE); | |
} | |
else if (Buttons == "help") { | |
MessageBox(NULL, ws, ws2, MB_ICONINFORMATION | MB_HELP); | |
} | |
else if (Buttons == "ok") { | |
MessageBox(NULL, ws, ws2, MB_ICONINFORMATION | MB_OK); | |
} | |
else if (Buttons == "ok-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONINFORMATION | MB_OKCANCEL); | |
} | |
else if (Buttons == "retry-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONINFORMATION | MB_RETRYCANCEL); | |
} | |
else if (Buttons == "yes-no") { | |
MessageBox(NULL, ws, ws2, MB_ICONINFORMATION | MB_YESNO); | |
} | |
else if (Buttons == "yes-no-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONINFORMATION | MB_YESNOCANCEL); | |
} | |
else { | |
MessageBox(NULL, ws, ws2, MB_ICONINFORMATION | MB_OK); | |
} | |
} | |
else if (Type == "warning") { | |
if (Buttons == "abort-retry-ignore") { | |
MessageBox(NULL, ws, ws2, MB_ICONEXCLAMATION | MB_ABORTRETRYIGNORE); | |
} | |
else if (Buttons == "cancel-retry-continue") { | |
MessageBox(NULL, ws, ws2, MB_ICONEXCLAMATION | MB_CANCELTRYCONTINUE); | |
} | |
else if (Buttons == "help") { | |
MessageBox(NULL, ws, ws2, MB_ICONEXCLAMATION | MB_HELP); | |
} | |
else if (Buttons == "ok") { | |
MessageBox(NULL, ws, ws2, MB_ICONEXCLAMATION | MB_OK); | |
} | |
else if (Buttons == "ok-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONEXCLAMATION | MB_OKCANCEL); | |
} | |
else if (Buttons == "retry-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONEXCLAMATION | MB_RETRYCANCEL); | |
} | |
else if (Buttons == "yes-no") { | |
MessageBox(NULL, ws, ws2, MB_ICONEXCLAMATION | MB_YESNO); | |
} | |
else if (Buttons == "yes-no-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONEXCLAMATION | MB_YESNOCANCEL); | |
} | |
else { | |
MessageBox(NULL, ws, ws2, MB_ICONEXCLAMATION | MB_OK); | |
} | |
} | |
else if (Type == "question") { | |
if (Buttons == "abort-retry-ignore") { | |
MessageBox(NULL, ws, ws2, MB_ICONQUESTION | MB_ABORTRETRYIGNORE); | |
} | |
else if (Buttons == "cancel-retry-continue") { | |
MessageBox(NULL, ws, ws2, MB_ICONQUESTION | MB_CANCELTRYCONTINUE); | |
} | |
else if (Buttons == "help") { | |
MessageBox(NULL, ws, ws2, MB_ICONQUESTION | MB_HELP); | |
} | |
else if (Buttons == "ok") { | |
MessageBox(NULL, ws, ws2, MB_ICONQUESTION | MB_OK); | |
} | |
else if (Buttons == "ok-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONQUESTION | MB_OKCANCEL); | |
} | |
else if (Buttons == "retry-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONQUESTION | MB_RETRYCANCEL); | |
} | |
else if (Buttons == "yes-no") { | |
MessageBox(NULL, ws, ws2, MB_ICONQUESTION | MB_YESNO); | |
} | |
else if (Buttons == "yes-no-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONQUESTION | MB_YESNOCANCEL); | |
} | |
else { | |
MessageBox(NULL, ws, ws2, MB_ICONQUESTION | MB_OK); | |
} | |
} | |
else if (Type == "error") { | |
if (Buttons == "abort-retry-ignore") { | |
MessageBox(NULL, ws, ws2, MB_ICONERROR | MB_ABORTRETRYIGNORE); | |
} | |
else if (Buttons == "cancel-retry-continue") { | |
MessageBox(NULL, ws, ws2, MB_ICONERROR | MB_CANCELTRYCONTINUE); | |
} | |
else if (Buttons == "help") { | |
MessageBox(NULL, ws, ws2, MB_ICONERROR | MB_HELP); | |
} | |
else if (Buttons == "ok") { | |
MessageBox(NULL, ws, ws2, MB_ICONERROR | MB_OK); | |
} | |
else if (Buttons == "ok-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONERROR | MB_OKCANCEL); | |
} | |
else if (Buttons == "retry-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONERROR | MB_RETRYCANCEL); | |
} | |
else if (Buttons == "yes-no") { | |
MessageBox(NULL, ws, ws2, MB_ICONERROR | MB_YESNO); | |
} | |
else if (Buttons == "yes-no-cancel") { | |
MessageBox(NULL, ws, ws2, MB_ICONERROR | MB_YESNOCANCEL); | |
} | |
else { | |
MessageBox(NULL, ws, ws2, MB_ICONERROR | MB_OK); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment