📄 winmain.cpp
字号:
#include <windows.h>
#include <stdio.h>
#include <Dbt.h>
#include <WINBASE.h>
#include <winioctl.h>
//#include <AFX.h>
LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line
int nCmdShow // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground= (HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc= WinSunProc;
wndcls.lpszClassName="Weixin2003";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls);
HWND hwnd;
hwnd=CreateWindow("Weixin2003","北京维新科学技术培训中心",WS_OVERLAPPEDWINDOW,
100,100,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
//POINT k;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
char HCName[16];
int HCNum;
HANDLE hHCDev;
switch(uMsg)
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"weixin",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","weixin",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"计算机编程语言培训",strlen("计算机编程语言培训"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"维新培训",strlen("维新培训"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","weixin",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_DEVICECHANGE:
{
switch(wParam)
{
case DBT_DEVICEARRIVAL: //插入
{
// MessageBox("USB设备插入");
/*
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,150,"USB设备插入",strlen("USB设备插入"));
ReleaseDC(hwnd,hdc);
*/
for (HCNum = 0; HCNum < 10; HCNum++)
{
wsprintf(HCName, "\\\\.\\I:", HCNum);
hHCDev = CreateFile(HCName,
GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
// hHCDev1 = INVALID_HANDLE_VALUE;
if (hHCDev != INVALID_HANDLE_VALUE)
{
//strShow.Format("\r\n找到USB控制器:%d\r\n",HCNum+1);
//ShowMessage(strShow);
if(IDOK==MessageBox(hwnd,"USB设备插入","USB",MB_OK)) //break;
{
HDC hdc;
DWORD junk;
hdc=GetDC(hwnd);
TextOut(hdc,0,200,HCName,strlen("HCName"));
ReleaseDC(hwnd,hdc);
DISK_GEOMETRY pdg;
BOOL bResult = DeviceIoControl(hHCDev, // device to be queried
IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform
NULL, 0, // no input buffer
&pdg, sizeof(pdg), // output buffer
&junk, // # bytes returned
(LPOVERLAPPED) NULL); // synchronous I/O
continue;
}
}
}
// if(IDOK==MessageBox(hwnd,"USB设备插入","USB",MB_OK))
if(HCNum == 10)
break;
}
case DBT_DEVICEREMOVECOMPLETE: //移除
// ShowMessage("USB设备移除");
{
/*
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,200,"USB设备移除",strlen("USB设备移除"));
ReleaseDC(hwnd,hdc);
*/
if(IDOK==MessageBox(hwnd,"USB设备移除","USB",MB_OK))
break;
}
}
}
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -