|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 额外减小 于 2023-10-1 21:44 编辑
rt.
求评分啊啊啊我想申精啊
如有评分,我会尽量帮你回本(育碧,荣誉)
Update. 各位下载后最好自己重新编译一次,因为各种电脑的编译环境可能不太一样。
另外,大家可以把位置参数稍微改成适合自己电脑的参数,因为各个电脑分辨率可能不同。
C++写的,众所周知用 windows.h 写代码是相对来说较为复杂的。
因为在班级中,经常需要选出一些人干活 / 做电子小报 / 做一些特殊任务,所以这个抽号器的运用是相当广泛的。
大家可以把这个抽号器拷贝到班级的电脑上(bushi)
因为该程序用到了图片资源,所以大家可以下载下面的集成资源包。
已撒币,想申精,求评分
效果展示:
源代码:
- /*
- * 感谢您的使用。
- *
- * __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);
- }
复制代码
集成资源包:
drawer.zip
(139.03 KB, 下载次数: 12)
|
评分
-
查看全部评分
|