Most of the Desktop checks would really not be an issue with regards to Poggle, but it is best to get into the habit of checking anyways.
The maximum width bounded by the desktop is found by using GetSystemMetrics(SM_CXMAXTRACK).
On the other hand, the height of the desktop is found using a different systems function. This is found using the function SystemParametersInfo() with the action SPI_GETWORKAREA. This will get the Rect denoting all the desktop that is NOT covered by the taskbar or by any application desktop toolbar. The function will need a temporary CRect object to store the retrieved value.
Finally, the function SetWindowPos() needs to be called to set the program's dimensions. This function can be used via the Windows pointer from AfxGetMainWnd(). There are some differences using SetWindowPos() between the initial update and the user demanded updates that will be explained below.
Step 9: The Initial Update.
Call the View class's CView::OnInitialUpdate() function.
Get and adjust the size of the Board object as mentioned earlier.
Set the Window size with AfxGetMainWnd()->SetWindowPos(NULL, 0, 0, adjustedSize.cx, adjustedSize.cy, SWP_NOMOVE | SWP_NOZORDER).
Step 10: The On-Demand Updates.
void CPoggleView::OnUpdate(CView* , LPARAM lHint, CObject*)
{
The only function parameter we are interested in the lParam lHint for communication between the Document and View.
Test lHint for the value specifying that the View needs resizing. (I used an enum to create a named constant in Poggle's Document class for this.) If so, then
{
Get and adjust the size of the Board object as mentioned earlier.
Set the Window size with AfxGetMainWnd()->SetWindowPos(NULL, 0, 0, adjustedSize.cx, adjustedSize.cy, SWP_NOMOVE | SWP_NOZORDER | SWP_NOCOPYBITS).
}
In any case Invalidate() and redraw everything.
}
Note: The flags in SetWindowPos (last parameter) specify the following:
SWP_NOZORDER - Leaves the program in the z-order it currently is placed, If top-most it stays top-most. This flag causes the function to ignore the first parameter (pointer to reference Window pointer, here NULL.
SWP_NOMOVE - Keep position. (Actually leave top-left corner of window in same position.) This flag causes function to ignore the second and third parameters (here 0 and 0).
SWP_NOCOPYBITS - Discards everything within the GUI. The program MUST redraw itself to show any changes.
No comments:
Post a Comment