#include <graphics.h> #include <stdio.h> void main() { initgraph(640, 480); // 初始化繪圖窗口 HWND hwnd = GetHWnd(); // 獲取繪圖窗口句柄 POINT point; TCHAR s[10]; while(true) { GetCursorPos(&point); // 獲取鼠標指針位置(屏幕坐標) ScreenToClient(hwnd, &point); // 將鼠標指針位置轉換為窗口坐標 // 獲取鼠標按鍵狀態可以用 GetAsyncKeyState 函數,這里不再詳述。 // 輸出鼠標坐標 sprintf(s, _T("%05d"), point.x); outtextxy(0, 0, s); sprintf(s, _T("%05d"), point.y); outtextxy(0, 20, s); // 適當延時 Sleep(10); } }