Settings | Sign in | Sign up

There are currently 2 posts.

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

Floor 1 巨大八爪鱼 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;
}
【运行结果】

Floor 2 巨大八爪鱼 12/5/15 14:52
当点击Yes:

当点击No:

Content converter:

Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.