views:

141

answers:

3

I have a toolbar developed under older versions of Windows that is largely cut off under Vista due to the window new border padding. With the default border padding of 4, the everything on the toolbar is shoved four pixels down and to the right, and then everything is cropped four pixels from the bottom and right sides. I don't really care about the horizontal dimension as much, but vertically this means the application loses eight pixels of visible content.

By "toolbar" I mean a window created similar to the following:

APPBARDATA  AppBarData;
AppBarData.hWnd = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TOPMOST, MAIN_WNDCLASS,
                                 "", WS_POPUP | WS_THICKFRAME | WS_CLIPCHILDREN,
                                 0, 0, 400, TOOLBAR_HEIGHT, NULL, NULL,
                                 AppInstance, NULL);
// more initialization  ....
SHAppBarMessage(ABM_NEW, &AppBarData);

Since border padding is a configuration item seemingly new to Vista, how can an application that runs in both XP and Vista handle this? My questions are:

  1. Is it possible for a toolbar to tell Vista "Ignore the 'border padding' setting; my border padding is 0"?
  2. If not, how does an application figure out what the border padding is set to so it can make its window taller by twice that amount?
  3. For both questions, how do you do this in a way that allows the same executable to operate under XP, Vista, Win2003, and so on?
+1  A: 

one option is to play with different window styles, starting with WS_THICKFRAME.

to figure out the padding try using GetClientRect and GetWindowRect and subtract one from the other.

Jewel S
+1. Removing WS_THICKFRAME solved it for me.
Eddie
+1  A: 

Another thing to note separately is that if you are already trying to take into account the window border by using GetSystemMetrics or similar, the subsystem you compile to makes a difference in how the borders impact your client area.

A link at objectmix tries to explain this. By subsystem, I believe what they mean is the /subsystem flag when you link the .exe, or the corresponding setting in Visual Studio.

~jewels

Jewel S
I figured out from those links that if I compile with the subsystem minimum version 6.0, then the application can get the border size successfully. This would allow it to compensate for the border. However, the application then will not run under anything earlier than Vista, which isn't acceptable. There must be a way to solve this, but I cannot find it.
Eddie
A: 

Well, I figured it out, sort if. In my case, the cause of the problem was use of WS_THICKFRAME when calling CreateWindowEx(), which I didn't need. This setting was used, previously, to center everything vertically in the toolbar. I guess under WinXP (classic view) and earlier, a WS_THICKFRAME predictably added 3 pixels of padding on all sizes.

Thus, I removed that option and changed the code to move everything three pixels down and to the right. Now the toolbar looks identical under WinXP and Vista and I don't have the annoying and unnecessary (for this toolbar) extra padding.

This doesn't solve the general case, but since my answer may help others who run into this, I thought I'd post my solution. I hope this helps someone else.

Eddie
you're welcome. glad you figured it out.between my WS_THICKFRAME suggestion and /subsystem hint (which, even though it didn't directly help your exact scenario, but is so subtle that nobody else would have figured it out, i'm glad my comments were worth zero to negative points.
Jewel S
also, subtracting the client area from the non-client area as I suggested below should *always* work. if that is not the case send me the source and i will make it work.generally application developers don't need to deal with this at all -- even the very very subtle /subsystem thing -- unless they're doing wonky manual calculations with the padding.
Jewel S
The negative points are not from me. I have not yet voted on any of these answers. People downvote for all sorts of silly and surprising reasons. You unfortunately have to get used to it on StackOverflow and related sites.
Eddie