client rectangle size problems, so cliché

This is a discussion on client rectangle size problems, so cliché within the Windows Programming forums, part of the Platform Specific Boards category; I searched for this problem, because I know it's been asked, it may have even been me who asked it, ...

  1. #1
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401

    client rectangle size problems, so cliché

    I searched for this problem, because I know it's been asked, it may have even been me who asked it, but couldn't find the thread. I'm trying to size a child control to cover the entire client area of a window, but the height is somehow not correct. A small gap (big enough to be a problem) is between the bottom edge of the child window and the bottom edge of the client area. This is my code:

    Code:
    GetClientRect(hwnd,&rc);
    SetWindowPos(hList,NULL,0,0,rc.right,rc.bottom,SWP_NOOWNERZORDER);
    Is there a solution here?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is ScreenToClient().

    Kuphryn

  3. #3
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Kuphyrn, I don't understand how that function can help in my case. Do you want me to obtain screen co-ordinates, or something similar? If I were to use GetWindowRect() on the top-level window, the .right and .bottom members would give me screen co-ordinates of the outer edge of the window, not the edge of the client area. Since the size of the frame is not always the same, using that method will not be completely accurate.

    Isn't there any way to get the REAL size of the client rectangle?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  4. #4
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Something's coming back to me. I seem to remember that specifying a height for a window, ie, in SetWindowPos, doesn't offset properly from (0,0) of the client rectangle. When I checked the return values from GetClientRect(), they were 100% accurate. But putting the rc.bottom value into SetWindowPos() for the list box window still left a gap at the bottom. Hmmm.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  5. #5
    Just one more wrong move. -KEN-'s Avatar
    Join Date
    Aug 2001
    Posts
    3,230
    Just hardcode something stupid like rc.bottom+15

  6. #6
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Okay, now this really sucks. If I create a small window, in terms of height, there is no gap. The higher it is, the larger the gap gets. I'm officially lost here.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  7. #7
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Here's a little cheap-assed code I whipped up, but hopefully there is a better way:

    Code:
    RECT rcClient;
    RECT rcActual:
    int actualHeight;
    int heightDiff;
    
    GetClientRect(hwnd,&rcClient);
    SetWindowPos(hList,NULL,0,0,rcClient.right,rcClient.bottom,SWP_NOOWNERZORDER);
    GetWindowRect(hList,&rcActual);
    actualHeight=rcActual.bottom-rcActual.top;
    heightDiff=rcClient.bottom-actualHeight;
    SetWindowPos(hList,NULL,0,0,rcClient.right,rcClient.bottom+heightDiff,...);
    It works, but it's messy.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  8. #8
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Okay, that code ended up not working in every possible case. But I did find something interesting. It will only allign perfectly if the client rectangle height is 6 plus a multiple of 16
    Ie, client rectangle heights of 470, 486, 502, etc, all worked fine. I think this all might have something to do with the size of the scroll bars or something. Any ideas?
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Is it an edit control?
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    No it's a list box control. Don't worry, I found out the reason. The top and bottom edges both take 3 pixels, and there are 16 pixels for each list box item. I've made some code that adjusts the parent window height so that the list box fits perfectly. To do it, I made a rounding function, here's the thread: Maths: nearest multiple, using offsets.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    There is something in the back of my mind. Basically it is that by default controls are sized to display complete lines of text, the height of the control is adjusted so the there is not a partial line at the bottom. The offset is proportional to the font size, thus what you are doing will work as long as the vertical height of the font doesn't change.

    Somewhere, and I'm racking my brain to think of it, there is a way of turning that off so it will draw partial lines. I've been dredging MSDN edit controls though.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Try setting the LBS_NOINTEGRALHEIGHT style and see if that does it.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  13. #13
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    Yeah that worked Adrian. Either way is good though. You can resize the window and have no partial items, or if you want, leave it as is and have partial items. Thanks.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

  14. #14
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    BTW, if at all possible, can people avoid extended ASCII characters in posts? I can't even open this thread on my main computer because the default language is Japanese and the "e with accent" character messes up things bigtime. I had to go onto a PC with English as the default just to see any of the posts.

  15. #15
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    >>> can people avoid extended ASCII characters in posts

    I will raise this on the moderators board.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Heapsort
    By xENGINEERx in forum C Programming
    Replies: 2
    Last Post: 03-30-2008, 07:17 PM
  3. AdjustWindowRect/Setting client size
    By JaWiB in forum Windows Programming
    Replies: 4
    Last Post: 06-23-2006, 11:43 PM
  4. More Problems with OpenGL and the Client Area
    By Niytaan in forum Windows Programming
    Replies: 2
    Last Post: 11-06-2002, 02:24 PM
  5. Problems Drawing OpenGL to the Client Area
    By Niytaan in forum Windows Programming
    Replies: 3
    Last Post: 10-27-2002, 06:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21