[C++] 纯文本查看 复制代码
#include <windows.h>
#include <iostream>
using namespace std;
string greetings[] = {
"1. 月到中秋分外明,情侣家人皆共庆。中秋节快乐!",
"2. 中秋之际,愿你的生活圆圆满满,幸福甜蜜。",
"3. 皓月当空,星光闪烁,愿你的未来一片光明,中秋快乐!",
"4. 月圆人团圆,愿你和家人团团圆圆,幸福美满。",
"5. 中秋佳节,赏月品茶,愿你的日子也如这一轮明月般辉煌。",
"6. 满地银光照人眼,愿你的前程一片光明。",
"7. 月是故乡明,人是故乡情。中秋快乐,思念故乡的亲人。",
"8. 中秋团圆夜,星光闪烁亮晶晶。愿你的人生也一片美好。",
"9. 五谷丰登的季节,愿你的生活也充满丰收和幸福。",
"10. 在这个特别的日子里,愿你的每一天都充满温馨和快乐。",
"11. 中秋节,愿你的工作事业和家庭生活都步步高升。",
"12. 月圆人更圆,愿你的幸福也如月亮一样圆满。"
};
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;
}