Link to home
Start Free TrialLog in
Avatar of salted
salted

asked on

Finding the 'real' height of a window that has scroll bars

Hi,

carrying on from this question: https://www.experts-exchange.com/questions/21806920/GetClientRect-Win-API-Call-from-C.html

I'm trying to find the true height and width (or what i thought would be the client rect) of a window owned by another process using windows api calls.

I can get it's height and width, but only as it's displayed, i want it's height if the scroll bars were no longer needed, if you see what i mean.

So a document that's 500 x 2000 is in a window that's 500 x 1000, I need a way to find the 500 x 2000 height, but GetClientRect is only returning the 500 x 1000 bit, including the scroll bars etc.

The end result will be to enlarge this window enough so that it has no scroll bars anymore (in the example above i would resize enough so that the window was 500 x 2000).

(I'm using c# btw)

Any ideas?
Avatar of WelkinMaze
WelkinMaze

Not a very clever but a "why not":
You can resize it to some big numbers - for example 10000x10000 (or whatever you think could be the possible maximum in your case). Then the method you've talked about has to return the size you want, rigth? After that you just have to resize it to the returned values.
Hope that helps! :)
Avatar of salted

ASKER

Hmmm... nice idea WelkinMaze, unfortuantely GetClientRect returned: 0,0,10000,10000
ASKER CERTIFIED SOLUTION
Avatar of WelkinMaze
WelkinMaze

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of salted

ASKER

Well, you can check if a window has scroll bars in C#, but the problem here is that the window isn't a .net control - it's just a window in another process (which could be written in any language, i guess). I'm using windows APIs to get the window, and it's at that point where it all goes wrong ;)

Thanks for your help anyway :)
Avatar of Mike Tomlinson
Why did you close the question without a solid resolution?...

Use the GetScrollInfo() API to find the Min/Max of the scroll bars and the Page size (size of the "thumb"):
https://www.experts-exchange.com/questions/20850011/Windows-app-ListView-Control-Scroll-position.html

Then you can make the necessary calculations to find the true size of the window and resize it...
You can use code like this to determine if scrollbars are visible on a window:

        [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
        public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

        public const int GWL_STYLE = (-16);
        public const int WS_HSCROLL = 0x100000;
        public const int WS_VSCROLL = 0x200000;

        private void button1_Click(object sender, EventArgs e)
        {
            int mystyle = GetWindowLong(this.Handle, GWL_STYLE);
            bool vert = (mystyle & WS_VSCROLL) == WS_VSCROLL;
            bool horz = (mystyle & WS_HSCROLL) == WS_HSCROLL;
            Debug.Print("vert = " + vert.ToString());
            Debug.Print("horz = " + horz.ToString());          
        }