[C++] 纯文本查看 复制代码
#include <windows.h>
#include <iostream>
using namespace std;
string greetings[] = {
"月圆家圆人圆事圆,祝你每天如意吉祥!",
"祝你的月饼香甜可口,家庭幸福美满!",
"中秋佳节,愿你合家欢乐,幸福美满,好运连连!",
"月圆梦圆情圆,祝你事业顺利,万事如意,梦想成真!",
"中秋佳节到来之际,祝福你事业成功,家庭和睦,快乐幸福!",
"祝你中秋佳节人月两团圆,幸福快乐每一天!",
"祝你中秋节快乐,万事如意,笑容如花,家庭美满!",
"祝你在这个中秋佳节里,身体健康,合家欢乐,事业有成!",
"中秋佳节,愿你的生活如月明水清,事业如月中折桂,幸福如月色满园!"
};
int win_w,win_h;
HWND label,wish;
HCRYPTPROV prov;
int random() {
if (prov == NULL)
if (!CryptAcquireContext(&prov, NULL, NULL, PROV_RSA_FULL, CRYPT_SILENT | CRYPT_VERIFYCONTEXT))
ExitProcess(1);
int out;
CryptGenRandom(prov, sizeof(out), (BYTE *)(&out));
return out & 0x7fffffff;
}
void get_rand(){
SetWindowText(wish,greetings[random()%((int)(sizeof(greetings)/sizeof(greetings[0])))].c_str());
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
switch(Message) {
case WM_CREATE: {
static HFONT hFont = CreateFont(40,0,0,0,0,FALSE,FALSE,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,"微软雅黑");//创建字体
// label
label = CreateWindow("static", TEXT("中秋节祝福"), WS_CHILD | WS_VISIBLE | SS_CENTER, 0, 0, win_w, 45, hwnd,
(HMENU)1,((LPCREATESTRUCT)lParam)->hInstance,NULL);
SendMessage(label,WM_SETFONT,(WPARAM)hFont,TRUE);
// wish
static HFONT hFont2 = CreateFont(25,0,0,0,0,FALSE,FALSE,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH|FF_SWISS,"微软雅黑");//创建字体
wish = CreateWindow("static", TEXT(""), WS_CHILD | WS_VISIBLE | SS_CENTER, 0, 50, win_w, 45, hwnd,
(HMENU)1,((LPCREATESTRUCT)lParam)->hInstance,NULL);
SendMessage(wish,WM_SETFONT,(WPARAM)hFont2,TRUE);
CreateWindow("button", TEXT("随机"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , 100, 150, 100, 45, hwnd,
(HMENU)1001,((LPCREATESTRUCT)lParam)->hInstance,NULL);
CreateWindow("button", TEXT("退出"), WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON , 300, 150, 100, 45, hwnd,
(HMENU)1002,((LPCREATESTRUCT)lParam)->hInstance,NULL);
LONG style = GetWindowLong(hwnd, GWL_STYLE);
style &= ~(WS_MAXIMIZEBOX|WS_SIZEBOX|WS_MINIMIZE);
SetWindowLong(hwnd, GWL_STYLE, style);
get_rand();
break;
}
case WM_COMMAND: {
if(LOWORD(wParam)==1001){
get_rand();
}
else if (LOWORD(wParam)==1002) {
DestroyWindow(hwnd);
}
break;
}
case WM_DESTROY: {
PostQuitMessage(0);
break;
}
default:
return DefWindowProc(hwnd, Message, wParam, lParam);
}
return 0;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
WNDCLASSEX wc;
HWND hwnd;
MSG Msg;
memset(&wc,0,sizeof(wc));
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpfnWndProc = WndProc; /* insert window procedure function here */
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszClassName = "WindowClass";
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* use "A" as icon name when you want to use the project icon */
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); /* as above */
if(!RegisterClassEx(&wc)) {
MessageBox(NULL, "Window Registration Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
win_h = 240;
win_w = 640;
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE,"WindowClass","中秋节祝福",WS_VISIBLE|WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,win_w,win_h,NULL,NULL,hInstance,NULL);
if(hwnd == NULL) {
MessageBox(NULL, "Window Creation Failed!","Error!",MB_ICONEXCLAMATION|MB_OK);
return 0;
}
while(GetMessage(&Msg, NULL, 0, 0) > 0) {
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}