/*
* 感谢您的使用。
*
* __Jianbing_Juan__
*
* 我是蒟蒻,不喜勿喷
*/
#include <windows.h>
#include <gdiplus.h> //graphics
#include <cstdio> //sprintf
#include <cstdlib> //atoi , itoa
#include <random> //random_shuffle
#include <algorithm> //random_shuffle
#include <ctime> //srand
#include <cstring> //string operations
using namespace std;
using namespace Gdiplus;
int nums[100];
const LPARAM linebreak=(LPARAM)'\n';
const int total_num=54;
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,PSTR szCmdLine,int iCmdShow)
{
static TCHAR szAppName[]=TEXT("MyWindowClass");
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szAppName;
if(!RegisterClass(&wndclass))
return 0;
hwnd=CreateWindow(szAppName,TEXT("抽号器"),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,350,400,NULL,NULL,hInstance,NULL);
GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
GdiplusStartup(&gdiplusToken,&gdiplusStartupInput,nullptr);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
for(int i=0;i<total_num;i++)
{
nums[i]=i+1;
}
while(GetMessage(&msg,NULL,0,0))
{
SetFocus(hwnd);
TranslateMessage(&msg);
DispatchMessage(&msg);
}
GdiplusShutdown(gdiplusToken);
return msg.wParam;
}
HWND hInputBox,hOutputBox;
char num[5];
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc=BeginPaint(hwnd,&ps);
Graphics graphics(hdc);
Image image(L"unforgettable.png");
graphics.DrawImage(&image,200,80);
RECT rect={160,10,330,35};
DrawText(hdc,TEXT("输入需要抽取的人数"),-1,&rect,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
EndPaint(hwnd,&ps);
break;
}
case WM_CREATE:
{
hInputBox=CreateWindow(TEXT("EDIT"),TEXT(""),WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL|ES_READONLY,10,10,150,24,hwnd,NULL,NULL,NULL);
hOutputBox=CreateWindow(TEXT("EDIT"),TEXT(""),WS_CHILD|WS_VISIBLE|WS_BORDER|WS_VSCROLL|ES_AUTOVSCROLL|ES_MULTILINE|ES_READONLY,10,50,150,300,hwnd,NULL,NULL,NULL);
break;
}
case WM_KEYDOWN:
{
if(wParam==VK_RETURN)
{
SendMessage(hOutputBox,WM_SETTEXT,0,(LPARAM)"");
GetWindowText(hInputBox,num,5);
int iNum=atoi(num);
if(iNum>54 or iNum==0)
{
MessageBox(hwnd," 非法输入 ","提示",MB_OK|MB_ICONERROR);
}
else
{
srand(time(nullptr));
random_shuffle(nums,nums+total_num);
char out_str[5];
for(int i=0;i<iNum;i++)
{
itoa(nums[i],out_str,10);
int l=strlen(out_str);
SendMessage(hOutputBox,EM_REPLACESEL,true,(LPARAM)out_str);
SendMessage(hOutputBox,EM_REPLACESEL,true,(LPARAM)"\r\n");
}
}
SendMessage(hInputBox,WM_SETTEXT,0,(LPARAM)"");
}
else if(wParam==VK_BACK)
{
int nStart,nEnd;
SendMessage(hInputBox,EM_GETSEL,(WPARAM)&nStart,(LPARAM)&nEnd);
nStart--;
nEnd=nStart+1;
SendMessage(hInputBox,EM_SETSEL,nStart,nEnd);
SendMessage(hInputBox,EM_REPLACESEL,true,(LPARAM)"");
}
else if(wParam>='0' and wParam<='9')
{
SendMessage(hInputBox,EM_REPLACESEL,true,(LPARAM)&wParam);
}
else if(wParam>=96 and wParam<=105)
{
WPARAM wTmp=wParam;
wTmp-=48;
SendMessage(hInputBox,EM_REPLACESEL,true,(LPARAM)&wTmp);
}
break;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hwnd,message,wParam,lParam);
}