11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6. Dialog Box<br />

Dialog Box Unit<br />

When creating a dialog template, we can read its dimension in the status bar of Developer Studio<br />

(Figure 6-1). However this size is measured in dialog box unit rather than screen pixels. This means if we<br />

create a dialog template with a size of 100×100 (measured in dialog box unit), its actual size will not be 100<br />

pixel × 100 pixel. For any dialog template, its horizontal base unit is equal to the average width of the<br />

characters that is used by the template, and its vertical base unit is equal to the height of the font. The<br />

dialog box is measured by the base units: each horizontal base unit is equal to 4 horizontal dialog units and<br />

each vertical base unit is equal to 8 vertical dialog units. This is a very complex calculation, fortunately in<br />

class CDialog there is a member function CDialog::MapDialogRect(…) that can be used to implement the<br />

dimension conversion so we do not need to calculate the details.<br />

If we want the initial size of a dialog box to be exactly the same with its template size, we need to call<br />

function CDialog::MapDialogRect(…) to convert its template size to screen pixels then call CWnd::<br />

MoveWindow(…) to resize the dialog box before it is displayed.<br />

Tracking Size and Maximized Size<br />

There are two types of tracking sizes: minimum tracking size and maximum tracking size, which<br />

correspond to limit sizes that can be set to a window by dragging one of its resizable border. The<br />

maximized size of a window is the size when it is in the maximized state (when a window is maximized, it<br />

doesn’t have to take up the whole screen). There is no “minimized size” here because when a window is<br />

minimized, it will become an icon.<br />

The size of<br />

dialog template<br />

is shown on the<br />

status bar<br />

Figure 6-1. Dialog box dimension<br />

These sizes can all be customized. To provide user defined sizes, we can override function CWnd::<br />

OnGetMinMaxInfo(…), which will be called when any of the above sizes is needed by the system. We can<br />

provide our own sizes within the overridden function.<br />

Function CWnd::OnGetMinMaxInfo(…) has the following format:<br />

afx_msg void CWnd::OnGetMinMaxInfo(MINMAXINFO *lpMMI);<br />

It is the handler of WM_GETMINMAXINFO message.<br />

Whenever the system needs to know the tracking sizes or maximized size of a window, it sends a<br />

WM_GETMINMAXINFO message to it. In <strong>MFC</strong>, this message is handled by function CWnd::<br />

OnGetMinMaxInfo(…). The input parameter of this function is a MINMAXINFO type pointer, if we want to<br />

customize the default implementation, we can change the members of MINMAXINFO. Structure MINMAXINFO is<br />

defined as follows:<br />

typedef struct tagMINMAXINFO {<br />

POINT ptReserved;<br />

POINT ptMaxSize;<br />

POINT ptMaxPosition;<br />

POINT ptMinTrackSize;<br />

POINT ptMaxTrackSize;<br />

148

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!