There are currently 2 posts.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
1264 1
【示例】C++模仿JavaScript的alert和confirm函数
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 12/5/15 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;
}
【运行结果】

巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 12/5/15 14:52
当点击Yes:

当点击No:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 1264 Replies: 1
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 12/5/15 14:52
Bar Good Posts
Announcements