Fensterposition unter Maus herausfinden

So nach langem Googeln bin ich zu diesem Code gekommen:
Code:
HWND hwnd = FindWindow("firefox.exe",NULL);
RECT *rect = (RECT*)malloc(sizeof(RECT));

system("cls");
GetWindowRect(hwnd,rect);

cout<<"X: "<<rect->left<<endl
<<"Y: "<<rect->top<<endl
<<"X + Fensterbreite: "<<rect->right<<endl
<<"Y + Fensterhoehe: "<<rect->bottom;

nur bekomm ich da irgentwie als ergebniss:
Code:
X: 25263848
Y: 25246744
X + Fensterbreite: 1935438711
Y + Fensterhoehe: 1702130553

was is da falsch o.O?
 
hab jetzt über einen Handle es geschaft das er das Program findet nur das Problem ist das der Handle 3 mal vorhanden ist wie kann ich auf einen bestimmten zugreifen ?

code zum rausfinden:

Code:
HWND w=FindWindowEx(NULL, NULL, NULL, NULL);
  char TName[512];
  while(w)
  {
      GetWindowText(w, TName, 512);

      if(strstr(TName, "Firefox"))
      {
             GetClassName(w,TName, 512);
             cout << TName << endl;
      }
       
      w=GetNextWindow(w, GW_HWNDNEXT);
  }
 
Durch zufall bin ich auf
Code:
HWND handle=WindowFromPoint(POINT*)
gestoßen damit kann ich mein Fenster auswählen muss nur noch rausfinden wie ich einen Mausklick abfragen kann :D aber wird schon irgentwie gehen ^^
 
C++:
const ::HWND GetCursorPosWindow()
{
    ::POINT mouse_position = {};
    if (!::GetCursorPos(&mouse_position)) throw std::runtime_error("unknown error");

    return ::WindowFromPoint(mouse_position);
}
...

C++:
int main()
{
    const ::HWND window(GetCursorPosWindow());
    if (window == NULL) return std::cerr << "FEHLER: Es liegt kein Fenster an dieser Stelle!" << std::endl, 1;

    ::RECT rect = {};
    ::GetWindowRect(window, &rect);

    std::cout << "x: " << rect.left << " y: " << rect.top << " width: " << rect.right - rect.left << " height: " << rect.bottom - rect.top << std::endl;
}
...
 
Zuletzt bearbeitet:
Zurück