Home

OFF-SOFT.net

OFF-SOFT.net

This site is support & information site of WEB,and Software. This site might help you that create software or Web Site…perhaps?[:]

From WTL to MFC (2) trap the wizard (dialog Chapter)

Published on| May 5th, 2009 | No Comment.
To add a new button, try to display a message box
Add a new button
ResEdit using the Add button.


Here is an example
Caption: Thanks
ID: IDC_BUTTON1
And.

PIKUCHAKONTORORU and paste controls and a slider (like the message below) may cause compilation errors of the resource. This is, COMMCTRL as often happens, if the header does not load properly.
(There are problems with simple configuration. )

error RC2104: undefined keyword or key name: WC_STATIC

[Tools] - [Option]
[Solutions and Projects (Left) - [include] (Right screen)

In, Microsoft Platform SDK's include directory to the top, I'll have a strong position.
% Platform SDK installation directory% \ include
Example) C: \ Program Files \ Microsoft Platform SDK \ Include

Then, please try to rebuild implementation. I will not be in error.


Add a new button handler
The VC + +, OK after the handler of the button will be added.

[MainDlg.h add]
1
2
3
4
5
6
7
8
9
10
11
12
	BEGIN_MSG_MAP(CMainDlg)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
			:
		COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
		//	add following line.
		COMMAND_ID_HANDLER(IDC_BUTTON1, OnThankYou)
	END_MSG_MAP()
	:
	:
	LRESULT OnCancel(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
		// 以下の1行を追加!!
	LRESULT OnThankYou(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);

[MainDlg.cpp added to the last line]
1
2
3
4
5
LRESULT CMainDlg::OnThankYou(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
	MessageBox("ThankYou");
	return 0;
}
Try to build and run
To build, I could easily see a message box and try to run.


So far, it was very easy. If you use MFC, many small parameter of this handler will be surprised.
COMMAND_ID_HANDLER macro definitions and further? .
1
2
3
4
5
6
7
8
#define COMMAND_ID_HANDLER(id, func) \
        if(uMsg == WM_COMMAND && id == LOWORD(wParam)) \
        { \
                bHandled = TRUE; \
                lResult = func(HIWORD(wParam), LOWORD(wParam), (HWND)lParam, bHandled); \
                if(bHandled) \
                        return TRUE; \
        }
I will certainly work to the same, wParam of a low not seen it.
MFC actually, is to be expanded as follows: To the same, wParam of a high "BN_CLICKED" after you check in, I should call the handler.
However, this is good, but now, here is precisely because we, then, MFC I want to close.
(WTL in the handler are equivalent to define it. )

[dlgtestDlg.h added to the end of]
1
2
3
4
	:
public:
	afx_msg void OnThankYou();
	:

[dlgtestDlg.cpp add]
1
2
3
4
5
6
7
8
9
10
11
12
13
BEGIN_MESSAGE_MAP(CdlgtestDlg, CDialog)
	:
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BUTTON1, OnThankYou)
END_MESSAGE_MAP()
	:
	:
	:
void CdlgtestDlg::OnThankYou()
{
	// TODO : ...
	MessageBox("ThankYou");
}

Comments

Leave a Reply







  • はてなブックマークへ追加する
  • Facebookでシェアする
  • twitter でつぶやく
  • Google Plusでシェアする
  • Pocketでシェアする
ページトップへ