回复 5楼 tang12
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
图片附件: 游客没有浏览图片的权限,请
登录 或
注册
#include <stdio.h>
#include <windows.h>
void _CursorPos(HWND hwnd)
{
char buf[100];
POINT p;
GetCursorPos(&p);
sprintf(buf, "x=%d, y=%d\n", p.x, p.y);
SetWindowText(hwnd, buf);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
switch(Message)
{
case WM_LBUTTONDOWN:
{
_CursorPos(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;
wc.hInstance
= hInstance;
wc.hCursor
= LoadCursor(NULL, IDC_ARROW);
wc.lpszClassName = "WindowClass";
if(!RegisterClassEx(&wc))
{
MessageBox(NULL, "注册窗口失败!", "Error!", MB_OK);
return 0;
}
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, "WindowClass", "点击显示鼠标坐标", WS_VISIBLE|WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, NULL, NULL, hInstance, NULL);
if(hwnd == NULL)
{
MessageBox(NULL, "创建窗口失败!", "Error!", MB_OK);
return 0;
}
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}