Chapter 3: Windows Resources Visual C++ and MFC Fundamentals
When calling one of these methods, you can simply pass its identifier as argument. You
can also specify the resource identifier as a constant string. To do this, pass the name of
the icon to the MAKEINTRESOURCE macro that would convert its identifier to a
string.
Practical Learning: Using Custom Resources
- To use a custom cursor and a custom icon, change the Exercise.cpp file as follows:
#include <afxwin.h>
#include "resource.h"
class CResFrame : public CFrameWnd
{
public:
CResFrame()
{
HCURSOR hCursor;
HICON hIcon;
hCursor = AfxGetApp()->LoadCursor(IDC_APP_CURS);
hIcon = AfxGetApp()->LoadIcon(IDI_APP_ICO);
const char *RWC = AfxRegisterWndClass(CS_VREDRAW | CS_HREDRAW,
hCursor,
(HBRUSH)GetStockObject(BLACK_BRUSH),
hIcon);
Create(RWC, "Custom Resources", WS_OVERLAPPEDWINDOW,
CRect(200, 120, 640, 400), NULL);
}
};
class CResApp: public CWinApp
{
public:
BOOL InitInstance()
{
m_pMainWnd = new CResFrame;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
CResApp theApp;
- Test the application: