目前共有2篇帖子。 内容转换:不转换▼
 
点击 回复
145 1
【示例】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:

回复帖子

内容:
用户名: 您目前是匿名发表
验证码:
(快捷键:Ctrl+Enter)
 

本帖信息

点击数:145 回复数:1
评论数: ?
作者:巨大八爪鱼
最后回复:巨大八爪鱼
最后回复时间:2015-12-5 14:52
 
©2010-2024 Arslanbar Ver2.0
除非另有声明,本站采用知识共享署名-相同方式共享 3.0 Unported许可协议进行许可。