PhotoShaman

Коорд. курсора относительно консоли

Nov 27th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <windows.h>
  4. using namespace std;
  5.  
  6. HWND GetConsoleHwnd()
  7. {
  8.         #define MY_BUFSIZE 1024
  9.         HWND hwndFound;        
  10.         char pszNewWindowTitle[MY_BUFSIZE];
  11.         char pszOldWindowTitle[MY_BUFSIZE];
  12.         GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
  13.         wsprintf(pszNewWindowTitle,"%d/%d",
  14.         GetTickCount(),
  15.         GetCurrentProcessId());
  16.         SetConsoleTitle(pszNewWindowTitle);
  17.         Sleep(1);
  18.         hwndFound=FindWindow(NULL, pszNewWindowTitle);
  19.         SetConsoleTitle(pszOldWindowTitle);
  20.         return(hwndFound);
  21. }
  22.  
  23. int main()
  24. {
  25.         //GetStdHandle(STD_OUTPUT_HANDLE)
  26.         RECT r;
  27.         POINT p;
  28.         HWND wh=GetConsoleHwnd();
  29.         COORD c={1,1};
  30.         while(1){
  31.                 GetWindowRect(wh, &r);
  32.                 GetCursorPos(&p);
  33.                 //SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
  34.                 //cout << p.x - r.left << ":" << p.y - r.top << "    ";
  35.                 SetCursorPosition((p.x - r.left - 9) / 8, (p.y - r.top - 30) / 12); //Для вин7
  36.         }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment