 |
|
 |
I'm trying to add scroll bars at the initial call if the window is bigger than the desk top. In the initial setup, I checked to see if the window was bigger than the desk top and if so used SetWindowPos to resize it. That seems to work well except that if for example a vertical scroll bar is needed, that reduces the horizontal extend of the window so that a horizontal scroll bar is also needed so I get both. I could allow for that if I knew what the dimensions of a scroll bar is and increase the horizontal width accordingly.
|
|
|
|
 |
|
 |
You can call GetSystemMetrics[^] function with parameters: SM_CXVSCROLL, SM_CYHSCROLL.
|
|
|
|
 |
|
 |
I found AdjustWindowRect which calculates the size of the window needed to contain the dialog. As you pointed out, one still needs to account for the scroll bars. I put your code into a class so the following isn't a direct replacement for your initialize routine but for what it's worth here's my initialize code.
void SD_Initialize (HWND hwnd)
{
s_prevx = 1;
s_prevy = 1;
GetClientRect (hwnd, &InitialRect);
GetClientRect (GetDesktopWindow(), &DesktopRect);
SIZE DlgSz = { InitialRect.right - InitialRect.left + 1,
InitialRect.bottom - InitialRect.top + 1};
const int Slop = 40;
const SIZE DskSz = { DesktopRect.right - DesktopRect.left + 1 - Slop,
DesktopRect.bottom - DesktopRect.top + 1 - Slop};
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
si.nPos = si.nMin = 1;
si.nMax = DlgSz.cx;
si.nPage = DlgSz.cx;
SetScrollInfo (hwnd, SB_HORZ, &si, FALSE);
si.nMax = DlgSz.cy;
si.nPage = DlgSz.cy;
SetScrollInfo (hwnd, SB_VERT, &si, FALSE);
const int YOvr = GetSystemMetrics (SM_CYHSCROLL); const int XOvr = GetSystemMetrics (SM_CXVSCROLL); bool HScroll = FALSE, VScroll = FALSE;
AdjustWindowRect (&InitialRect, GetWindowLong (hwnd, GWL_STYLE), FALSE);
DlgSz.cx = InitialRect.right - InitialRect.left + 1;
DlgSz.cy = InitialRect.bottom - InitialRect.top + 1;
if (DlgSz.cy > DskSz.cy) {
VScroll = TRUE; DlgSz.cy = DskSz.cy; DlgSz.cx += XOvr; }
if (DlgSz.cx > DskSz.cx) {
HScroll = TRUE; DlgSz.cx = DskSz.cx; DlgSz.cy += YOvr; if (!VScroll && (DlgSz.cy > DskSz.cy))
{ VScroll = TRUE; DlgSz.cy = DskSz.cy; }
else if (DlgSz.cy > DskSz.cy)
{
DlgSz.cy = DskSz.cy; }
}
if (HScroll || VScroll)
{
SetWindowPos (hwnd,HWND_TOP,0,0,DlgSz.cx,DlgSz.cy,SWP_NOMOVE | SWP_NOREPOSITION | SWP_SHOWWINDOW);
}
}
|
|
|
|
 |
|
 |
It would be nice if the maximize button restored the original size of the dialog box, not expanded it to the size of the screen.
Thanks very much for this code! I needed it because I had a large dialog that did not completely display on short wide screens.
|
|
|
|
 |
|
 |
You're welcome.
If you need different functionality for the maximize button, then you also should paint it differently, so it won't confuse the user.
|
|
|
|
 |
|
 |
You are right, now that I added the scroll bars initially, I like the way maximize works.
|
|
|
|
 |
|
 |
the static variables
static int s_prevx = 1;
static int s_prevy = 1;
must resets before re-show dialog box (in other projects), otherwise scroll bar out of sync with window content.
|
|
|
|
 |
|
 |
Yes, you're right. Most likely in the production environment these variables would be kept as a class members and not as statics.
|
|
|
|
 |
|
 |
To use this code on WinCE platform needed use ScrollWindowEx(hwnd, cx, cy, NULL, NULL, NULL, NULL, SW_SCROLLCHILDREN) instead ScrollWindow
|
|
|
|
 |
|
 |
Thanks for clarification. I appreciate it.
|
|
|
|
 |
|
|
 |
|
 |
there is a good guide for begginer.
|
|
|
|
 |
|
 |
I was looking very hard for some example like this one, because
I'am using win32++ library for my project, which is basicaly c++
wrappers over c winapi code.
Also idea of message cracker is completely new for my, but I
really like it.
Thank you a lot.
|
|
|
|
 |
|
 |
Thanks.
|
|
|
|
 |
|
 |
please help, I don't know how to fix it...
but cool work ! thanks.
|
|
|
|
 |
|
 |
Thanks for pointing this out. The bug is in SD_OnSize function. In addition to existing check for required scroll the client area must be scrolled on maximize event, too. So, the if condition inside SD_OnSize should be something like this:
const bool needToScroll =
(si.nPos != si.nMin && si.nPos == maxScrollPos) ||
(state == SIZE_MAXIMIZED);
if(needToScroll)
{
SD_ScrollClient(hwnd, bar[i], si.nPos);
}
...
I'll update the sample project, as well.
|
|
|
|
 |
|
 |
There is no useful information.
|
|
|
|
 |
|
 |
Will you write an anticle at here?
though it means nothing to you, but It may be help to others. why you often think fo yourself?
|
|
|
|
 |
|
 |
4to tebja zastavilo ne postavit' dlg.h file, gde vse definitions?
Hello world
|
|
|
|
 |
|
 |
What? What dlg.h file? Which definitions?
|
|
|
|
 |
|
 |
Message Automatically Removed
|
|
|
|
 |