MFC(Microsoft Foundation Class)ã«ã¤ãã¦ã®ç¥è¦ãã¾ã¨ã¾ã£ã¦ããã®ã§ãã¡ã¢ãæ®ãã¦ãã. 主観ãééããå¤åã«å«ã¾ãã¦ããã¨æãã®ã§ã話ååã«è¦ã¦ãã ãã.
- MFCã¨ã¯
- MFCã¨ã¤ãã³ãããªãã³
- MFCã®å½åè¦å
- MSGæ§é ä½ã¨ã¡ãã»ã¼ã¸
- MFCã§éè¦ãªã¯ã©ã¹
- ãã¤ã¢ãã°ã¨ãã£ã¿ã¼ã®ä½¿ãæ¹
- ã¾ã¨ã
MFCã¨ã¯
MFC(Microsoft Foundation Class)ã¨ã¯ãWindowsAPIãC++ã®ã¯ã©ã¹ã®å½¢ã§æä¾ããããã®ãã¬ã¼ã ã¯ã¼ã¯ã§ãã. MFCã®å 輩ã§ããWindows SDKã§ã¯WindowsAPIã¯Cè¨èªã®é¢æ°ã¨ãã¦æä¾ããã¦ãã.*1 Windows SDKã§ã¯WindowsAPIãCè¨èªã®é¢æ°ã¨ãã¦ç´æ¥*2å¼ã³åºãã¦ããããVC++ã§æ±ããããããã«ã¯ã©ã¹åãããã®ãMFCã§ãã.
ã¶ã£ã¡ãããªãã¸ã§ã¯ãæåã§ããã°ã©ãã³ã°ã§ããããWindows SDKããæ±ããããã¨ããã®ã¯å¹»æ³ã ã¨æãããMFCã®æããå©ç¹ã¯Visual Studioã¨ã®è¦ªåæ§ã«ããã¨æã. å®éã1ã¤ã®ã¦ã£ã³ãã¦ããã 表示ããã ããªãWindows SDKã使ã£ãæ¹ãã½ã¼ã¹ã³ã¼ãã¯å°ãªãã¦æ¸ã. ããããã©ã¤ãã©ãªã®å¼ã³åºããã¦ã£ã³ãã¦ãçæããããã®åå¼ã¯åé·ã§ãé¢æ°ã®å¼æ°ã«ã¨ããããNULLãæå®ããã¨ãããã¨ããã°ãã°.
ããã§MFCããã¨ãVisual Studioã®åºçªã¨ããããã§ãã. Visual Studioã®ã¦ã£ã¶ã¼ããéãã¦ããã¸ã§ã¯ããçæããã°ã¹ã±ã«ãã³ããã°ã©ã ãç¨æãã¦ããããã®ã§ãã³ã¼ããä¸ããçµã¿ç«ã¦ãã¨ãããããã³ã¼ãã追å ãã¦ããã°ãããªãã®GUIã¢ããªã±ã¼ã·ã§ã³ãä½æãããã¨ãåºæ¥ã.ã§ã¯Windows APIãå ¨ãç¥ããªãã¦ãMFCãæ±ãããã¨ããã¨ãããéã§ããããMFCã®æ¹ãOSç¹æã®ç½ ã«é¥ããããã®ã§ã¯ãªããã¨ãæã.
ä¾ãã°CClientã¯ã©ã¹ã¯ã³ã³ã¹ãã©ã¯ã¿å ã§GetDCé¢æ°ãå®è¡ãããã¹ãã©ã¯ã¿å ã§ReleaseDCé¢æ°ãå®è¡ãã. ãã®2ã¤ã®é¢æ°ã®åºèªã¯ãã¡ããWindows APIã§ãã. CClientã¯ã©ã¹ã®çæã¨ç ´æ£æã«ã©ã®ãããªãã¨ãè¡ããã¦ãããã¯ç§å¿åããããªãã¡ã¬ã³ã¹ãèªããããã°ã©ã ã®å®è¡ä¸ã«åé¡ãçããªãéãã¯æ°ã«ãçããªãã ãã. MFCããã°ã©ã ã®å®è¡ä¸ã«åé¡ãçããã¨ããããã解決ããããã«ã¯çµå±ã®ã¨ããWindows APIã®ç¥èãå¿ è¦ã«ãªã. çµå±ã®ã¨ããMFCã¯Windows API(SDK) ã®èãã©ããã¼ã¯ã©ã¹ã©ã¤ãã©ãªã«éããªãã®ã§ãã.
ããã«MFCãããããããã¦ããã®ã¯ãã¯ã©ã¹ã©ã¤ãã©ãªã謳ã£ã¦ãããªããçµæ§ãªã°ãã¼ãã«é¢æ°ãã°ãã¼ãã«å¤æ°ãå«ãã§ãããã¨ã§ãã. MFCã¢ããªã±ã¼ã·ã§ã³ã®printfãã¨AfxMessageBoxé¢æ°ãªã©ãè¯ãä¾ã ã¨æã. ã¾ãããã¯MFCã¨ããããC++/VC++ã®ç¹å¾´ãªã®ãããããªã.
ãªã©ã¨MFCããã£ã¹ã£ã¦ãã¾ã£ããããªãããããè¯ããã¬ã¼ã ã¯ã¼ã¯ã ã¨æã. ä¾ãã°å ã»ã©æ³¥ããã¶ã£ã¦ããã£ãAfxMessageBoxé¢æ°ã ããããã©ã«ãå¼æ°ãæã£ã¦ããã®ã§å¿ é ã®å¼æ°ã¯1åã ãã§ãã. ããããã£ã±ãMFCã¨ããããC++/VC++ã®ä»æ§ããã.
åè
MFCã¨ã¤ãã³ãããªãã³
MFCãå¾æã¨ããã®ã¯ããããã¤ãã³ãé§åããã°ã©ã ã§ãã. æ°å¤è¨ç®ã®ãããªããã°ã©ã ã¯ã½ã¼ã¹ã³ã¼ãã®æ¸ããã¦ããé çªããã®ã¾ã¾ããã°ã©ã ã®å®è¡é ã«ãªã. ã¤ã¾ããä¸ããé ã«å®è¡ãããä¸çªä¸ã¾ã§æ¥ãã¨ããã°ã©ã ãçµäºãã¦ãã¾ã. ããããé»åã®ãããªGUIã¢ããªã±ã¼ã·ã§ã³ããã®ãããªä»æ§ã ã¨ãé»åã®ã¤ã³ã¼ã«ãæ¼ãã¦è¨ç®ãçµããã¨ã¢ããªã±ã¼ã·ã§ã³ãçµäºãã¦ãã¾ããçµæã確èªãããã¨ãã»ã¼ä¸å¯è½ã«ãªã£ã¦ãã¾ã.ããã§ã¤ãã³ãé§åããã°ã©ã ã®åºçªã§ãã. ã¤ãã³ãé§åããã°ã©ã ã§ã¯åæåãçµããã¨ã¡ãã»ã¼ã¸ã«ã¼ãã«å ¥ããã¡ãã»ã¼ã¸ãåä¿¡ããã¨ãã«ã¡ãã»ã¼ã¸ã®ç¨®é¡ã«å¿ããé¢æ°ï¼ã¤ãã³ããã³ãã©ï¼ãå®è¡ãããã®å¦çãçµãããåã³ã¡ãã»ã¼ã¸ã«ã¼ãã«å ¥ãã¨ããåä½ããã.
ã¡ãã»ã¼ã¸ã¨ããã®ã¯å ·ä½çã«ã¯MSGæ§é ä½(winuser.h)ã®ã¤ã³ã¹ã¿ã³ã¹ã®ãã¨ã§ãã¦ã¼ã¶ã¼ããã¦ã¹ãåãããããã¼ãã¼ãå ¥åããããã³ã«ããããã®ããã¤ã¹ã¯å ¥åãMSGæ§é ä½ã®ã¤ã³ã¹ã¿ã³ã¹ã«å¤æããã·ã¹ãã ã¡ãã»ã¼ã¸ãã¥ã¼ã«ããã·ã¥ãã¦ãã. ãã¥ã¼ããã¡ãã»ã¼ã¸ããããããå¾ãMSGæ§é ä½ã«å«ã¾ããå®å ã¦ã£ã³ãã¦ã調ã¹ãé©åãªã¦ã£ã³ãã¦ã«ã¡ãã»ã¼ã¸ãéã. ããã¾ã§ã¯Windowsãèªåçã«è¡ã£ã¦ãããã®ã§ãã¢ããªã±ã¼ã·ã§ã³ãä½ãããã°ã©ãã¼ã¯ã¡ãã»ã¼ã¸ãåä¿¡ããã¨ãã®ã¡ãã»ã¼ã¸ãã¨ã®ãã³ãã©ãããã°ã©ã ããã°ãã.
ã¡ãã»ã¼ã¸ã¯ã·ã¹ãã å´ã§ç¨æããã¦ãããã®ã¨ãã¦ã¼ã¶ã¼ãå®ç¾©ã§ãããã®ããããããããå®æ ã¯UINTåã®æ°å¤ã§ãã. åè ãã·ã¹ãã ã¡ãã»ã¼ã¸ã¨ã§ãå¼ã¶ã¨ãã·ã¹ãã ã¡ãã»ã¼ã¸ã®ãã¡WM_ã¨ããæ¥é è¾ã§å§ã¾ãã¡ãã»ã¼ã¸ã«å¯¾ãããã³ãã©ã¯ãã§ã«ååã決ã¾ã£ã¦ãã(CWndã¯ã©ã¹å ã§å®ç¾©ããã¦ãã). æåã©ããã ã¨æ¬¡ã®ãããªã·ã¹ãã ã¡ãã»ã¼ã¸ã¨ãã³ãã©ã®çµããã.
ã¡ãã»ã¼ã¸å | HEX | æå³ | ãã³ãã©å |
---|---|---|---|
WM_SIZE | 0x0005 | ã¦ã£ã³ãã¦ãµã¤ãºãå¤æ´ãããã¨ã | OnSize |
WM_PAINT | 0x000F | ã¦ã£ã³ãã¦ã«ç¡å¹é åãçºçããã¨ãï¼åæç»ãå¿ è¦ãªæï¼ | OnPaint |
WM_CHAR | 0x0102 | ãã¼ãã¼ãå ¥åããã¨ã | OnChar |
ã·ã¹ãã ã¡ãã»ã¼ã¸ã¯åºæ¬çã«ã¯åä¿¡ãããã¨ã ãèãã¦ããã°ããããä»»æã®ã¿ã¤ãã³ã°ã§ä»»æã®ã¦ã£ã³ãã¦ã«éä¿¡ãããã¨ãã§ãã. ä¾ãã°ãã¦ã£ã³ãã¦ã®å³ä¸ã®Ããã¿ã³ãæ¼ãã¨ã¢ããªã±ã¼ã·ã§ã³ã¯èªåèªèº«ã«WM_CLOSEã¡ãã»ã¼ã¸ãçºä¿¡ãã.
ã¾ããä»ããã»ã¹ã®ããã»ã¹ãã³ãã«ãåå¾ããã°ãèªããã»ã¹ä»¥å¤ã®ã¦ã£ã³ãã¦ã«ã¡ãã»ã¼ã¸ãéããã¨ãå¯è½ã§ãã.
åè
MFCã®å½åè¦å
ãã³ã¬ãªã¢ã³è¨æ³ãªã®ã§å¤æ°åããåãæ¨å®ã§ãã.
æ¥é è¾ | å |
---|---|
b | ãã¼ãªã¢ã³ |
h | ãã³ãã« |
p, lp | ãã¤ã³ã¿ |
n | DWORD |
åã®æ¥é è¾ã§LãWãã¤ãã¦ããã¨ãããããã16-bit ã®MS-DOSã®æã®åæ®ãããç¾å¨ã¯LãWã32bitã表ãã¦ããã®ã§ãã¾ãæ°ã«ããªãã¦ãã.
ã¡ã½ããã¯ãã¹ã«ã«ã±ã¼ã¹ã§ãã¯ã©ã¹ã®ã¡ã³ãã¼ã«ã¯m_ã¨ããæ¥é è¾ãã¤ãã¦ãã
å¤æ° | å | æå³ |
---|---|---|
CWnd::m_hWnd | HWND | CWndã¤ã³ã¹ã¿ã³ã¹ã«ã¢ã¿ããããã¦ããã¦ã£ã³ãã¦ã®ãã³ãã« |
CWinThread::m_hThread | HANDLE | ç¾å¨ã®ã¹ã¬ããã¸ã®ãã³ãã« |
CWinThread::m_pMainWnd | CWnd* | ã¢ããªã±ã¼ã·ã§ã³ã®ã¡ã¤ã³ã¦ã£ã³ãã¦ã¸ã®ãã¤ã³ã¿ã¼ |
CWinApp::m_hInstance | HINSTANCE | ã¢ããªã±ã¼ã·ã§ã³ã®ç¾å¨ã®ã¤ã³ã¹ã¿ã³ã¹ |
HWND(ã¦ã£ã³ãã¦ãã³ãã«)ãHINSTANCE(ã¤ã³ã¹ã¿ã³ã¹ãã³ãã«)ã¯çµå±ã®ã¨ãããã¹ã¦HANDLEåã®typedefã¨ãã¦å®ç¾©ããã¦ãã¦ãHANDLEåèªä½ã¯voidåã¸ã®ãã¤ã³ã¿ã¨ãã¦å®ç¾©ããã¦ããããã. MFCã®å½åè¦åã¨ã¯é¢ä¿ãªããã©çµæ§éè¦.
å | 説æ |
---|---|
HWND | ã¦ã£ã³ãã¦ãã³ãã«ï¼ã¡ãã»ã¼ã¸ã®éãå ãªã©ã§å©ç¨ï¼ |
HHOOK | ããã¯ãã³ãã«ï¼ã¤ãã³ããã¢ããªã±ã¼ã·ã§ã³ãã¤ã³ã¿ã¼ã»ããã§ããï¼ |
HEVENT | ã¤ãã³ããã³ãã«ï¼WaitForSingleObjectçã§å©ç¨ï¼ |
HDC | ããã¤ã¹ã³ã³ããã¹ãï¼æç»çã§å©ç¨ï¼ |
HGLRC | OpenGLã¬ã³ããªã³ã°ã³ã³ããã¹ãï¼ããã¤ã¹ã³ã³ããã¹ãã¨ã¯ã¾ãå¥ç©ï¼ |
HINSTANCE | ã¤ã³ã¹ã¿ã³ã¹ãã³ãã«ï¼ã¢ããªã±ã¼ã·ã§ã³ãDLLã®æå®ã«å©ç¨ï¼ |
åè
MSGæ§é ä½ã¨ã¡ãã»ã¼ã¸
ã¤ãã³ãããªãã³åã¢ããªã±ã¼ã·ã§ã³ã®ããã°ã©ã ã¯ãã¡ãã»ã¼ã¸ã®éç¥ã¨ãã³ãã©ã追å ãã¦ããã®ã主ãªä½æ¥ã¨ãªã. ã¡ãã»ã¼ã¸ã®å®ä½ã§ããMSGæ§é ä½ã¯ãªãã¡ã¬ã³ã¹ã«ããã¨ä»¥ä¸ã®ããã«å®ç¾©ããã¦ãã.
typedef struct tagMSG { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; DWORD lPrivate; } MSG, *PMSG, *NPMSG, *LPMSG;
ã ããwinuser.hãè¦ã¦ã¿ãã¨ä»¥ä¸ã®ããã«å®ç¾©ããã¦ãã.
/* * Message structure */ typedef struct tagMSG { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; #ifdef _MAC DWORD lPrivate; #endif } MSG, *PMSG, NEAR *NPMSG, FAR *LPMSG;
ã¡ã³ãå | å | 説æ |
---|---|---|
hwnd | HWND | ã¡ãã»ã¼ã¸ãåä¿¡ããã¦ã£ã³ãã¦ã¸ã®ãã³ãã«. ã¡ãã»ã¼ã¸ãã¹ã¬ããã¡ãã»ã¼ã¸ã®å ´åNULL |
message | UINT | WM_XXãªã©ã®ã¡ãã»ã¼ã¸ |
wParam | WPARAM | ã¡ãã»ã¼ã¸ã«ã¤ãã¦ã®è¿½å æ å ±. |
lParam | LPARAM | ã¡ãã»ã¼ã¸ã«ã¤ãã¦ã®è¿½å æ å ± |
time | DWORD | ã¡ãã»ã¼ã¸ãæ稿ãããæå» |
pt | POINT | ã¡ãã»ã¼ã¸ãæ稿ãããæã®ã«ã¼ã½ã«ä½ç½® |
lPrivate | DWORD | ãªãã¡ã¬ã³ã¹ã«è¨è¿°ç¡ã |
調ã¹ãã¨ããã«ããã¨_MACã¯mac製åã®ããã®defineããããWindowsã§ã¯æå¹ã«ãªã£ã¦ãªã模æ§. å®éVisual Studioä¸ã§ã¯lPrivateã¡ã³ãã«ã¢ã¯ã»ã¹ã§ããªãã£ã. å ¬å¼ãªãã¡ã¬ã³ã¹ã«ãlPrivateã®è©³ãããã¨ã¯æ¸ãã¦ãªãã®ã§ãWindowsç°å¢ã§ã¯ãªããã®ã¨èãã¦ãã.
Windowsä¸ã§ãã¦ã¹ãåãããããã¼ãã¼ããæã£ããã¦ã£ã³ãã¦ã移åããã縮å°ããã....ãã¨ãããããªã¿ã¤ãã³ã°ã§ãã®MSGæ§é ä½ãããåãããã¦ãã.
ãããã®ã¡ãã»ã¼ã¸ã¯ã·ã¹ãã ã®ã¿ãªãããã¢ããªã±ã¼ã·ã§ã³ããéããã¨ãã§ãã.ãã®ããã«ã¯SendMessage()ã¾ãã¯PostMessageé¢æ°ãå©ç¨ãã. 両è ã®éãã¯ã¡ãã»ã¼ã¸éä¿¡å ã«ã³ã³ããã¼ã«ãæ»ãã¿ã¤ãã³ã°ãéãã ããªã®ã§ãSendMessageé¢æ°ã®ä½¿ãæ¹ãè¦ã¦ãã. ãªãã¡ã¬ã³ã¹ã«ã¯æ¬¡ã®ããã«æ¸ããã¦ãã.
LRESULT SendMessage( HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam );
MSGæ§é ä½ã®ä¸é¨ãå¼æ°ã«ã¨ããã¨ãåãã. hWndãHWND_BROADCAST((HWND)0xffff)ã«ããã¨ã·ã¹ãã å ã®ãã¹ã¦ã®ã¡ã¤ã³ã¦ã£ã³ãã¦ã«éä¿¡ããã(ããã¼ããã£ã¹ã). wParamã¨lParamã®ä½¿ãæ¹ã¯Msgã«ãã£ã¦ç°ãªãã®ã§ããã®é½åº¦èª¿ã¹ãã®ãè¯ãã¨æã.
åä¿¡å´ã¯Wndprocé¢æ°ã使ã. ãªãã¡ã¬ã³ã¹ã«ããå®ç¾©ã¯ãã¡ã.
LRESULT Wndproc( HWND unnamedParam1, UINT unnamedParam2, WPARAM unnamedParam3, LPARAM unnamedParam4 )
åå¼æ°ã®æå³ã¯SendMessageé¢æ°ã¨åããããªã®ã§çç¥. Wndprocé¢æ°å ã§switch~caseæãç¨ãã¦å±ããã¡ãã»ã¼ã¸ãã¨ã®å¦çãå®è£ ãã.
åè
MFCã§éè¦ãªã¯ã©ã¹
MFCã§ç¹ã«éè¦ãªCWndã¯ã©ã¹ãCDialogã¯ã©ã¹ãCWinAppã¯ã©ã¹ãã¯æ¼ããã¦ãããã.
CWndã¯ã©ã¹
CWndã¯ã©ã¹ã¯ååã®éãã¦ã£ã³ãã¦ãªãã¸ã§ã¯ãã表ãããã®ãªãã¸ã§ã¯ãã¯ã©ã¹ã§ãã. ãã¤ã¢ãã°ããã¿ã³ããã¯ãã£ã¼ã³ã³ããã¼ã«ãªã©ç®ã«è¦ãããã®ã¯ãã¹ã¦ãã®ã¯ã©ã¹ããæ´¾çãã¦ãã. ããã§çåãªã®ããï¼Windowsã§ã¯ï¼ç®ã«è¦ãããã®=ã¦ã£ã³ãã¦ãªãã¸ã§ã¯ãã¨ããã¨ããã. ã¦ã£ã³ãã¦ãªãã¸ã§ã¯ãã¨ããããã¦ã£ã³ãã¦ã¨ã¯ã¾ãå°ãéãæ¦å¿µã®ããã§ãããããã¦ã£ã³ãã¦ã®ãã¨ã¯ãã¬ã¼ã ã¦ã£ã³ãã¦ã¨ããããã. CClientDCã¯ã©ã¹ã®ã³ã³ã¹ãã©ã¯ã¿ã«CWndåã¸ã®ãã¤ã³ã¿ã渡ããããCWndã¯ã©ã¹ã§OnPainté¢æ°ãå®ç¾©ããã¦ãããã¨ããããCWndå=ç®ã«è¦ãããã®ã¨ããèãã§ããã®ã ã¨æã.
CWndã¯ã©ã¹ã«ã¯å¤ãã®ã¡ãã»ã¼ã¸ãã³ãã©ãå®è£ ããã¦ããããã¡ãã»ã¼ã¸ãã³ãã©ã®ããã«ç¹å®ã®ã¿ã¤ãã³ã°ã§å¼ã³åºãããé¢æ°ãå®ç¾©ããã¦ãã. 両è ã®éãã¯ãããã¿ã¤ã宣è¨ã§afx_msgã¨ãããã¼ã¯ã¼ããã¤ãã¦ãããã§åºå¥ãããã¨ãåºæ¥ã. afx_msgãã¼ã¯ã¼ããã¤ãã¦ããé¢æ°ã¯ã¡ãã»ã¼ã¸ãããã«å¯¾å¿ããã¡ãã»ã¼ã¸ãç»é²ããªããã°ãªããªã. ãªãã¡ã¬ã³ã¹ã«ããã°afx_msgãã¼ã¯ã¼ãã¯virtualãã¼ã¯ã¼ãã®å¹æã示åãã¦ãããå®éã«ã¯ä»®æ³é¢æ°ã§ã¯ãªãããã. ãããã«ãããªã¼ãã¼ã©ã¤ãã®ãããªãã¨ãåºæ¥ã.
ãããã¿ã¤ãå®£è¨ | å¼ã°ããã¿ã¤ãã³ã° | ã¡ãã»ã¼ã¸ãããã¸ã®ç»é² |
---|---|---|
afx_msg void OnPaint() | ã¦ã£ã³ãã¦ã®ä¸é¨ãåæç»ããè¦æ±ãæ稿ãããã¨ã | å¿ è¦ |
virtual void PreSubclassWindow() | ã¦ã£ã³ãã¦ããµãã¯ã©ã¹åãããå | ä¸è¦ |
CDialogã¯ã©ã¹
CWndã¯ã©ã¹ãç¶æ¿ãããã¤ã¢ãã°ããã¯ã¹ã表ãã¯ã©ã¹. CWndã¯ã¦ã£ã³ãã¦ãªãã¸ã§ã¯ãå ¨è¬ã表ãããã ããCDialogã¯ã©ã¹ã¯ãã¤ã¢ãã°ãããããæ®éã®ã¦ã£ã³ãã¦ã表ãããã«ä½¿ç¨ããã. ãã¤ã¢ãã°ã«ã¢ã¼ãã«ã¨ã¢ã¼ãã¬ã¹ã®2種é¡ããã. ã¢ã¼ãã«ã¯ãã¤ã¢ãã°ããã¯ã¹ãéããã¾ã§ã¢ããªã±ã¼ã·ã§ã³ãåæ¢ããããã¢ã¼ãã¬ã¹ãã¤ã¢ãã°ã¯ãã¤ã¢ãã°ããã¯ã¹ãéãã¦ãã¢ããªã±ã¼ã·ã§ã³ãåæ¢ãããã¨ããªã.
ã¢ã¼ãã«ãã¤ã¢ãã°ãéãã¨ãã¯æ¬¡ã®ããã«ãã.
CDialog dlg; INT_PTR nResponse = dlg.DoModal(); // ããããä¸ã«ã¯ã¢ã¼ãã«ãåé¤ããªãã¨é²ã¾ãªã
ã¢ã¼ãã¬ã¹ãã¤ã¢ãã°ãéãã¨ãã¯æ¬¡ã®ããã«ãã
CDialog dlg; // CWnd* pParentWndã¯çç¥å¯ dlg.Create(IDD_XX, pParentWnd); dlg.ShowWindow(SW_SHOW);
åºæ¬çã«ã¯è¦ªåé¢ä¿ãæãããããã«è¦ªã¨ãªãä½æå ã®CWndåã¸ã®ãã¤ã³ã¿ã渡ãã¦ãã¤ã¢ãã°ãä½æããããå¿ é ã§ã¯ãªã模æ§. ç¶æ¿ã®æ¦å¿µãåãã£ã¦ãããè¨ãã¾ã§ããªãããCWndåã¸ã®ãã¤ã³ã¿ã渡ããªããã°ãªããªãå ´åãCWndåãç¶æ¿ããåã¸ã®ãã¤ã³ã¿ã渡ãã¦ãåé¡ãªã.
CWinApp
ã¢ããªã±ã¼ã·ã§ã³ãã®ãã®ã表ãã¯ã©ã¹. ããããä¸ã¤ã®ããã¸ã§ã¯ãã«ä¸ã¤ãããªã. mfcã©ã¤ãã©ãªã«ãã£ã¦ã¤ã³ã¹ã¿ã³ã¹åããã. èªå¼ãæããã«è¨ãã¨ãMFCã¢ããªã±ã¼ã·ã§ã³ã«ã¯ã¨ã³ããªãã¤ã³ããåå¨ããªã. æ£ç¢ºã«è¨ãã°ãMFCã¢ããªã±ã¼ã·ã§ã³ã¨ã¯mfcvxx.dll (or .lib)ããªã³ã¯ããã¢ããªã±ã¼ã·ã§ã³ã§ããã®ã©ã¤ãã©ãªã®ä¸ã«ã¨ã³ããªãã¤ã³ããå«ã¾ãã¦ããããã.ã¾ãã§ãCè¨èªã®ã¢ããªã±ã¼ã·ã§ã³ãã©ã¤ãã©ãªã«ããã¹ã¿ã¼ãã¢ããã«ã¼ãã³ããªã³ã¯ãã¦ãã«ããã¦ããã®ã§ãMFCã®å ´åã¹ã¿ã¼ãã¢ããã«ã¼ãã³ã®ä¸ã«t_mainãªããmainé¢æ°ã¾ã§å®ç¾©ããã¦ããã¨èãã¦ããã°ååãªæ°ããã. mfcã©ã¤ãã©ãªå ã®ã¡ã¤ã³é¢æ°ã«ã¯CWinAppãã¤ã³ã¹ã¿ã³ã¹åããInitInstanceé¢æ°ãå¼ã³åºãã¨ããå¦çããã§ã«å®è£ ããã¦ãã. ãããã£ã¦MFCã¢ããªã±ã¼ã·ã§ã³ã®å®è³ªçãªã¨ã³ããªãã¤ã³ãã¯CWinApp::InitInstanceé¢æ°ã§ãã.
åè
ãã¤ã¢ãã°ã¨ãã£ã¿ã¼ã®ä½¿ãæ¹
ãã¤ã¢ãã°ã®ç·¨éã¯ãã¤ã¢ãã°ã¨ãã£ã¿ã¼ãå©ç¨ãã¦ã°ã©ãã£ã«ã«ã«è¡ã*3.
ã³ã³ããã¼ã«ã«ã¯å¿ ãä¸æã®IDãã¤ããªããã°ãªããªã. ãã®IDã¯ãªã½ã¼ã¹ã¨ãã£ã¿ã ãã§ãªãã½ã¼ã¹ãã¡ã¤ã«ãå«ããããã¸ã§ã¯ãå ¨ä½ã§å ±æããã. ã³ã³ããã¼ã«ã追å ããã¨Resource.hã«ãã®ã³ã³ããã¼ã«ã®IDã«å¯¾å¿ããæ°å¤ãèªåã§defineãã¦ããã. ãã¤ã¢ãã°ã¨ãã£ã¿ã¼ãã追å ããã³ã³ããã¼ã«ã¯1000ããé ã«æ°å¤ãå²ãæ¯ãããæ§å.
// Resource.h // ããã¸ã§ã¯ãçææããå®ç¾©ããã¦ãã #define IDR_MAINFRAME 128 #define IDM_ABOUTBOX 0x0010 #define IDD_ABOUTBOX 100 #define IDS_ABOUTBOX 101 #define IDD_HATENATEST_DIALOG 102 // ãã¤ã¢ãã°ã¨ãã£ã¿ããèªå追å #define IDC_BUTTON1 1000 // ããã¸ã§ã¯ãçææããå®ç¾©ããã¦ãã #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 129 #define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_COMMAND_VALUE 32771 #endif #endif
ä¸æè°ãªãã¨ã«IDOK(1ã¨ãã¦#defineããã¦ãã)ã¨IDCANCEL(2ã¨ãã¦#defineããã¦ãã)ã®defineã®å®ç¾©ãResource.hã«ããã¦ããªãããã©ããã§å¥éå®ç¾©ããã¦ããããã.
åã³ãã¤ã¢ãã°ã¨ãã£ã¿ã«æ»ãããã¤ã¢ãã°ä¸ãå³ã¯ãªãã¯ããã¨ããã¤ãã®é ç®ã表示ããã¦ãã. ãã®ä¸ã§ããã使ã3ã¤ãåãä¸ãã. ãã®3ã¤ã®é ç®ã¨ã¯ããªãã¡æ¬¡ã§ãã.
- ã¤ãã³ããã³ãã©ã¼ã®è¿½å
- ã¯ã©ã¹ã®è¿½å
- å¤æ°ã®è¿½å
ã¤ãã³ããã³ãã©ã¼ã®è¿½å ã¯ã³ã³ããã¼ã«ãå³ã¯ãªãã¯ããªãã¨è¡¨ç¤ºãããªãã®ã§æ³¨æ. ã¦ã£ã¶ã¼ãã§ã¯ã¤ãã³ããã³ãã©ãç´ã¥ãããã¤ã¢ãã°ã®ã¯ã©ã¹ãã³ã³ããã¼ã«ããã¤ã¢ãã°ã«çºä¿¡ããã¡ãã»ã¼ã¸ã®ç¨®é¡ãã¤ãã³ããã³ãã©åã決ãããã¨ãåºæ¥ã. ã¤ãã³ããã³ãã©ã追å ããã¨ã以ä¸ã®3ç¹ãèªåçã«è¿½å ããã.
- ã½ã¼ã¹ãã¡ã¤ã«å ã®ã¡ãã»ã¼ã¸ããã
- ã½ã¼ã¹ãã¡ã¤ã«ä¸ã®ã¤ãã³ããã³ãã©ã®å®ç¾©
- ãããã¼ãã¡ã¤ã«ä¸ã®ã¤ãã³ããã³ãã©ã®ãããã¿ã¤ã宣è¨
éã«è¨ãã¨ãã¤ãã³ããã³ãã©ãæ¶å»ãããå ´åã¯ä¸è¨ã®3ç¹ãåé¤ããã°ãã.
ã¯ã©ã¹ã®è¿½å ã ãããªããã³ã³ããã¼ã«ã§ã¯ãªããã¤ã¢ãã°ã®ã¯ã©ã¹ã®è¿½å ããã§ããªã. ã³ã³ããã¼ã«ç¬èªã®ã¯ã©ã¹ãå®è£ ãããå ´åã¯ããªã½ã¼ã¹ã¨ãã£ã¿ããã§ã¯ãªãã½ãªã¥ã¼ã·ã§ã³ã¨ã¯ã¹ããã¼ã©ã¼->å³ã¯ãªãã¯->追å ->ã¯ã©ã¹ ããã¦ã£ã¶ã¼ãã使ã£ã¦ã½ã¼ã¹ãã¡ã¤ã«ãçæããã®ã¡ã«å¤æ°ã®è¿½å ãè¡ãã¨ãã.
å¤æ°ã®è¿½å ãé常ã³ã³ããã¼ã«ä¸ã§å³ã¯ãªãã¯ããã°è¡¨ç¤ºããã. ã¦ã£ã¶ã¼ãã§ã¯å¤æ°ã¨ãã¦è¿½å ããã³ã³ããã¼ã«ã®IDãå¤æ°ã®åãå¤æ°åãæå®ãããã¨ãåºæ¥ã. å¤æ°ã®åã¯é常ããããªãã¦ãããããèªä½ããã¯ã©ã¹ã®åã¨ãã¦å®ç¾©ãããå ´åã¯èªåã§é¸æããå¿ è¦ããã.
ã¾ããWMããå§ã¾ãã¡ãã»ã¼ã¸ã®ãã³ãã©ããã¤ã¢ãã°ã«è¿½å ãããå ´åã¯ããã¤ã¢ãã°ã®ããããã£->ã¡ãã»ã¼ã¸ãç·¨éããã°ãã.
ãããããªã®ã ãããªã½ã¼ã¹ã¨ãã£ã¿ã§ã³ã³ããã¼ã«ã追å ããã®ã«IDãå®ç¾©ããã¦ããªãã¨ãããããã¨ããã. ãã®æã¯ã ãããResource.hãincludeãå¿ãã¦ãã.
åè
ã¾ã¨ã
ãã¿ããã¾ã£ãããã詳細ãªMFCã«é¢ããè¨äºãæ¸ãã¦ãããã
MFCãæã£ã¦ãããã奥ãæ·±ã. ã§ããã£ã±ãèã¨ãªãã®ã¯WindowsAPIã ãªã¨æãã.
*1:ããã§ããWindows SDK ã¯Visual Studio 6.0 ãªã©ã«å梱ããã¦ããããããå¤ãSDKãæã. æèã«ãã£ã¦ã¯.NETã¨çµ±åãããæ°ããSDKã®ãã¨ãæããããããªã..
*2:å®ä½ã¯kernel.dll(or .lib)ãuser.dll(or .lib)ãªã©ã®ã©ã¤ãã©ãª
*3:.rc ã¨ãããã¡ã¤ã«ã«ã¯ã³ã³ããã¼ã«ã®ä½ç½®ãªã©ã®æ å ±ãããã¹ãå½¢å¼ã§æ¸ããã¦ããã®ã§ãä½ç½®ãªã©ã微調æ´ãããã¨ãã¯ãã®ãã¡ã¤ã«ãç´æ¥ãããã®ãããï¼