11.04.2014 Views

Advanced MFC Programming

Advanced MFC Programming

Advanced MFC Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 12. Screen Capturing & Printing<br />

select a window. The new dialog template is IDD_DIALOG_SELECT, and the class associated with it is<br />

CSelDlg. To make the interface user friendly, mouse cursor will be changed when the user is selecting a<br />

window (With left button held down). In the sample, a cursor resource IDC_CURSOR_SELECT is added for<br />

this purpose. The cursor is loaded in the constructor of CSelDlg and its handle is stored in variable<br />

CSelDlg::m_curSelect. In the dialog box template, an icon that contains the cursor is displayed. If the user<br />

click on this icon, it will be changed to a blank icon and at the same time, the cursor will be customized to<br />

IDC_CURSOR_SELECT. If the user releases the mouse button, everything will be resumed. This will give the<br />

user a feeling that the mouse clicking actually picks up the cursor (Figure 12-3).<br />

The icons displayed in the dialog box are also stored as resources. Their IDs are IDI_ICON_CURSOR and<br />

IDI_ICON_BLANK. Also, they are loaded in the class constructor and are displayed in the dialog box by<br />

calling function CStatic::SetIcon(…). The control used to display the icon is a static control (Actually it<br />

is added as a “Picture” control). In the property sheet “Picture Properties”, we can choose the type of<br />

images that will be displayed, such as bitmap or icon (Figure 12-4).<br />

Messages WM_LBUTTONDOWN, WM_LBUTTONUP and WM_MOUSEMOVE are handled to let the user select a<br />

window. When the left button is pressed down, we check if it hits the icon contained in the dialog box. If<br />

so, we set window capture for the dialog box, change the mouse cursor, and change icon IDI_ICON_CURSOR<br />

to IDI_ICON_BLANK:<br />

void CSelDlg::OnLButtonDown(UINT nFlags, CPoint point)<br />

{<br />

CRect rect;<br />

}<br />

CDialog::OnLButtonDown(nFlags, point);<br />

GetDlgItem(IDC_STATIC_CURSOR)->GetWindowRect(rect);<br />

ScreenToClient(rect);<br />

if(rect.PtInRect(point))<br />

{<br />

SetCapture();<br />

((CStatic *)GetDlgItem(IDC_STATIC_CURSOR))->SetIcon(m_iconBlank);<br />

GetDlgItem(IDC_STATIC_CURSOR)->Invalidate();<br />

m_curSave=::SetCursor(m_curSelect);<br />

m_bCaptureOn=TRUE;<br />

m_rectSelect=CRect(0, 0, 0, 0);<br />

m_hWnd=NULL;<br />

}<br />

If the user clicks on this icon, it will<br />

disappear. At the same time, the<br />

mouse cursor will be changed to this<br />

shape. This will give the user an<br />

impression that the mouse clicking<br />

picks up the cursor.<br />

Figure 12-3. Dialog box used for selecting window<br />

376

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

Saved successfully!

Ooh no, something went wrong!