Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't get hold of LPRECT structure data, what I'm doing wrong?

Tags:

c++

winapi

It should be working without issue:

#include <iostream>
#define _WIN32_WINNT 0x501
#include <windows.h>

using namespace std;

int main() {
  HWND consoleWindow = GetConsoleWindow();
  LPRECT lpRect;
  GetWindowRect(consoleWindow,lpRect);
  cout << lpRect.top <<endl;
}

but instead I get this:

error: request for member 'top' in 'lpRect', which is of non-class type 'LPRECT {aka tagRECT*}'
like image 371
rsk82 Avatar asked Jun 01 '12 13:06

rsk82


2 Answers

Your code is wrong. Windows expects a valid Rect here. LPRECT is just a pointer and you haven't initialized it. Please modify it like this.

HWND consoleWindow = GetConsoleWindow();
RECT aRect;
GetWindowRect(consoleWindow,&aRect);
cout << aRect.top <<endl;
like image 156
PermanentGuest Avatar answered Nov 15 '22 00:11

PermanentGuest


The LPRECT type is a pointer to RECT. This is (unfortunately, in my opinion) common in the Win32 API, that they play "hide the asterisk" on you. It makes for more confusion, since the asterisk is important in C.

So, anyway, you need to use an actual RECT to have somewhere to store the result:

RECT rect; /* An actual RECT, with space for holding a rectangle. */

/* The type of &rect is LPRECT. */
GetWindowRect(consoleWindow, &rect);
like image 42
unwind Avatar answered Nov 14 '22 23:11

unwind