設置 | 登錄 | 註冊

目前共有2篇帖子。

【示例】C++模仿JavaScript的alert和confirm函数

1樓 巨大八爪鱼 2015-12-5 14:51
【代码】
#include <Windows.h>
#include <CommCtrl.h>

#pragma comment(lib, "Comctl32.lib")
#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

#define TITLE L"Hello"

void alert(LPWSTR message)
{
    MessageBox(NULL, message, TITLE, MB_ICONWARNING);
}

BOOL confirm(LPWSTR message)
{
    return (MessageBox(NULL, message, TITLE, MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2) == IDYES);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    if (confirm(L"Are you sure you want to say hello?"))
        alert(L"Hello World!");
    else
        alert(L"You are not welcome.");
    return 0;
}
【运行结果】

2樓 巨大八爪鱼 2015-12-5 14:52
当点击Yes:

当点击No:

內容轉換:

回覆帖子
內容:
用戶名: 您目前是匿名發表。
驗證碼:
看不清?換一張
©2010-2025 Purasbar Ver3.0 [手機版] [桌面版]
除非另有聲明,本站採用知識共享署名-相同方式共享 3.0 Unported許可協議進行許可。