Question

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?
Was it helpful?

Solution

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.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top