corfmanr@gtephx.UUCP (Russ Corfman) (02/01/91)
Hi, I'm trying to get my application's window to be a certain size. It is going to have a number of controls in it, so I used the dialog editor to design the client area. Using the dialog editor, I came up with the placement of all the controls and the size (in dialog units) of the client area. Next, I converted the client area from dialog units to device units then attempted to get the window's needed dimensions (client area plus borders, menu, and caption) using the AdjustWindowRect function. After that, I created the window using the (supposedly) adjusted rectangle. My problem is that the window's final size was exactly the size of the wanted client area. I verified this by moving the application window over the working window in the dialog editor. It appears that the AdjustWindowRect did not adjust the rectangle at all. The code I used is as follows: RECT Rect; long dlg_units; /* figure out how big the client area needs to be */ dlg_units = GetDialogBaseUnits(); Rect.left = 0; Rect.top = 0; Rect.right = ((X_LEN * LOWORD(dlg_units)) / 4); Rect.bottom = ((Y_LEN * HIWORD(dlg_units)) / 8); /* adjust the size of the window to fit the client area */ AdjustWindowRect(&Rect, WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, TRUE); /* create the window */ hWnd = CreateWindow("MyWClass", "My Window", WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, Rect.right, Rect.bottom, Null, MyMenu, hInstance, NULL); I tried changing the window style passed to AdjustWindowRect with no change. I also passed FALSE (no menu) and again no change. The documentation doesn't really explain where the adjusted rectangle ends up. The function is a void. It would have been nice if it returned the adjusted rectangle. I assumed it just modified the passed rectangle. One thing I just thought of is that it may have modified the upper left corner of the rectangle. I was assuming it modified the lower right since client windows always have an upper left corner of (0,0). If this is the case, it seems a bit inconsistent to me. I'll try that tonight with the following: hWnd = CreateWindow("MyWClass", "My Window", WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, /* change */ Rect.right - Rect.left, /* change */ Rect.bottom - Rect.top, Null, MyMenu, hInstance, NULL); If that solves the problem, sorry to bother everyone, except any readers from Microsoft. Please if this is the case, have someone update the manual to explain how the function returns the adjusted rectangle! Ciao, -- Russell Corfman (corfmanr@gtephx) UUCP: {ncar!noao!asuvax | uunet!zardoz!hrc}!gtephx!corfmanr AG Communication Systems (formerly GTE), Phoenix (602) 581-4403
johnm@spudge.UUCP (John Munsch) (02/06/91)
In article <175@maillot_.gtephx.UUCP> corfmanr@gtephx.UUCP (Russ Corfman) writes: > I'm trying to get my application's window to be a certain size. [Lots trimmed for brevity.] >passed rectangle. One thing I just thought of is that it may have >modified the upper left corner of the rectangle. I was assuming it >modified the lower right since client windows always have an upper >left corner of (0,0). If this is the case, it seems a bit inconsistent >to me. Inconsistency is the name of the game with the Microsoft SDK. An excerpt from some of my own code: // Figure out what the new size of the window should be, taking // into account things like menus and title bars, etc. GetWindowRect(hOutputWnd, (LPRECT) &CurrentWndRect); WndRect.left = WndRect.top = 0; WndRect.bottom = image_descriptor.height; WndRect.right = image_descriptor.width; AdjustWindowRect((LPRECT) &WndRect, WS_OVERLAPPEDWINDOW, TRUE); // Resize the window to accomodate the new image size. MoveWindow(hOutputWnd, CurrentWndRect.left, CurrentWndRect.top, abs(WndRect.right - WndRect.left), abs(WndRect.bottom - WndRect.top), TRUE); It is perfectly normal for AdjustWindowRect() to return negative values for top and left. John Munsch