📄 win.c
字号:
#include <windows.h>
#include <stdio.h>
POINT ptOrigin,ptCurrent;
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_ARROW);
wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
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,
0,0,600,400,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
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
)
{
HBRUSH hBrush;
HPEN hPen;
HDC hDC;
tch(uMsg)
{
case WM_LBUTTONDOWN:
GetCursorPos(&ptOrigin); //得到鼠标按下时的点坐标
break;
case WM_CHAR:
break;
case WM_LBUTTONUP:
hDC=GetDC(hwnd);
hPen=CreatePen(PS_SOLID,5,RGB(255,0,0));
hBrush=(HBRUSH)GetStockObject(BLACK_BRUSH);
GetCursorPos(&ptCurrent);
SelectObject(hDC,hPen);
SelectObject(hDC,hBrush);
ScreenToClient(hwnd,&ptOrigin);//坐标转换
ScreenToClient(hwnd,&ptCurrent);
Rectangle(hDC,ptOrigin.x,ptOrigin.y,ptCurrent.x,ptCurrent.y);
DeleteObject(hPen);
DeleteObject(hBrush);
DeleteDC(hDC);
break;
case WM_PAINT:
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -