Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 3: Windows Resources


HCURSOR hCursor;
HICON hIcon;

hCursor = AfxGetApp()->LoadStandardCursor(IDC_SIZEALL);
hIcon = AfxGetApp()->LoadStandardIcon(IDI_EXCLAMATION);

const char *RWC = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW,
hCursor,
(HBRUSH)GetStockObject(BLACK_BRUSH),
hIcon);
Create(RWC, "Resources Fundamentals", WS_OVERLAPPEDWINDOW,
CRect(200, 120, 640, 400), NULL);
}


  1. Test the application

  2. After viewing the window, close it and return to MSVC


3.9.2 Window Registration and Custom Resources....................................


If the standard cursors and/or icons are not enough, you can create your own. To create
your own cursor, display and select Cursor from the Add Resource dialog box. A starting
but empty cursor would be displayed. Design the cursor to your liking.

To use a custom cursor, you can retrieve its identifier and pass it to the
CWinApp::LoadCursor() method. It is overloaded as follows:

HCURSOR LoadCursor(LPCTSTR lpszResourceName) const;
HCURSOR LoadCursor(UINT nIDResource) const;

To use a custom icon, you can pass its identifier to the CWinApp::LoadIcon() method
overloaded as follows:

HICON LoadIcon(LPCTSTR lpszResourceName) const;
HICON LoadIcon(UINT nIDResource) const;
Free download pdf