예제 #1
0
    BOOL onCommand(WPARAM wParam, LPARAM lParam)
    {
        switch (LOWORD(wParam))
        {
        case ID_BN_CBTMSGBOX:
            {
            //
            CBTMessageBox(*this, "CBTMsgBox", "info", MB_OK);
            return FALSE;
            }
        case ID_BN_MSGBOX:
            {
            //
            showMsg(_T("hello!"));

            //
            showMsgFormat(_T("Formated Message"), _T("%d -- %d"), 22, 100);

            //
            showCustomMsgBox(_T("Customized Message"));

            //
            ColorMessageBox(NULL,
                "You can see the color!",
                "Color",
                MB_OK,
                huys::xpblue,
                huys::white);

            return FALSE;
            }
        case ID_BN_ERROR:
            {
            //
            showError(_T("Error:"));

            //
            showErrorByNum(22);
            return FALSE;
            }
        case ID_BN_TIMEDMB:
            {
            //
            UINT uiResult;

            //
            // Ask the user a question. Give the user five seconds to
            // answer the question.
            uiResult = TimedMessageBox( *this,
                                "Does a triangle have three sides?",
                                "Quiz",
                                MB_YESNO,
                                // NULL first parameter is important.
                                5000);

            switch (uiResult)
            {
            case IDYES:
                MessageBox( NULL,
                    "That's right!",
                    "Result",
                    MB_OK);
                break;

            case IDNO:
                MessageBox(NULL,
                     "Believe it or not, triangles "
                     "really do have three sides.",
                     "Result",
                     MB_OK);
                break;

            case -1:
                MessageBox(NULL,
                     "I sensed some hesitation there.  "
                     "The correct answer is Yes.",
                     "Result",
                     MB_OK);
                break;
            }
            return FALSE;
            }
        default:
            return UBaseWindow::onCommand(wParam, lParam);
        }
    }
예제 #2
0
/** Does the message box thingy to show the error.
 *
 * @returns True if program should continue going forward.
 */
bool ErrorSystem::execLastError() {
	if (errorCount == 0) return true;

	string concatError = lastError.title + " -- " + lastError.heading;
	if (lastError.message != "") {
		concatError += " -- " + lastError.message;
	}

	// If this error is not fatal and it is set to be suppressed, return true here already
	if (!lastError.fatal && this->isSuppressed(concatError)) {
		return true;
	}

#ifdef _WIN32
	// Windows wants it's console output in codepage 1252
	std::cerr << utf8toCP1252(concatError) << std::endl;
#else
	std::cerr << concatError << std::endl;
#endif

	if (lastError.fatal) {
		al_show_native_message_box(
					cb->gfxInterface->getWindow(),
					lastError.title.c_str(),
					lastError.heading.c_str(),
					lastError.message.c_str(),
					NULL,
					ALLEGRO_MESSAGEBOX_ERROR
		);
		cb->stop();
		return false;
	}
#ifndef _WIN32 // Allegro doesn't support custom messagebox buttons with Windows
	int ret = al_show_native_message_box(
				cb->gfxInterface->getWindow(),
				lastError.title.c_str(),
				lastError.heading.c_str(),
				lastError.message.c_str(),
				"Abort|Continue|Suppress this error",
				ALLEGRO_MESSAGEBOX_OK_CANCEL
	);
	switch (ret) {
		case 0: // No buttons clicked
		case 2: // User clicked continue
			return true;
		case 1: // User clicked abort
			cb->stop();
			return false;
		case 3: // Suppress errors
			this->suppressError(concatError);
			return true;
		default:
			FIXME("Undefined messagebox return value %i in ErrorSystem::execLastError()", ret);
			cb->stop();
			return false;
	}
#else
	string message;
	if (lastError.message.empty()) {
		message = lastError.heading;
	}
	else {
		message = lastError.heading + "\n\n" + lastError.message;
	}

	// Convert message and title to utf-16 with the amazing UTF8-CPP library
	wstring wideMsg = utf8ToUtf16(message);
	wstring wideTitle = utf8ToUtf16(lastError.title);

    int ret = CBTMessageBox(al_get_win_window_handle(cb->gfxInterface->getWindow()), &wideMsg[0], &wideTitle[0], MB_ABORTRETRYIGNORE | MB_ICONERROR);
	switch (ret) {
		case 0: // No buttons clicked
		case IDRETRY: // User clicked continue
			return true;
		case IDABORT: // User clicked abort
			cb->stop();
			return false;
		case IDIGNORE: // Suppress errors
			this->suppressError(concatError);
			return true;
		default:
			FIXME("Undefined messagebox return value %i in ErrorSystem::execLastError()", ret);
			cb->stop();
			return false;
	}
#endif // _WIN32
}