Click here to Skip to main content
15,920,896 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: HELP! Anyone know MFC here? Pin
David Crow12-May-03 6:54
David Crow12-May-03 6:54 
GeneralRe: HELP! Anyone know MFC here? Pin
Bigsteiny12-May-03 16:20
Bigsteiny12-May-03 16:20 
GeneralRe: HELP! Anyone know MFC here? Pin
David Crow13-May-03 2:12
David Crow13-May-03 2:12 
AnswerRe: HELP! Anyone know MFC here? Pin
Toni7812-May-03 7:21
Toni7812-May-03 7:21 
GeneralRe: HELP! Anyone know MFC here? Pin
Bigsteiny12-May-03 16:18
Bigsteiny12-May-03 16:18 
AnswerRe: HELP! Anyone know MFC here? Pin
Roger Allen13-May-03 1:04
Roger Allen13-May-03 1:04 
Generalsigh. still not working. Pin
Bigsteiny13-May-03 16:48
Bigsteiny13-May-03 16:48 
GeneralRe: sigh. still not working. Pin
MAAK13-May-03 22:02
MAAK13-May-03 22:02 
You dont need to inherit from CButton to handle the click event of your button
All you have to do is to add a button notification handler in the view class for the id of your button, and ensure that the button's id is unique in order not to conflict with other controls. This code should explain it:

//in the class declaration
class CTstButtonView : public CView
{
	.
	.
	CButton m_btn;
	afx_msg void MyButtonHandler();
	.
	.
};

//this code is in the message map
BEGIN_MESSAGE_MAP(CTstButtonView , CView)
	.
	.
	ON_BN_CLICKED(ID_MYBUTTON, MyButtonHandler)
	.
	.
END_MESSAGE_MAP()

//implementation of the OnInitialUpdate
void CTstButtonView::OnInitialUpdate() 
{
	CView::OnInitialUpdate();
	//if the button is not already created
	if(!m_btn.GetSafeHwnd())
		//create the button, WS_VISIBLE can be ised instead of using
		//ShowWindow
		m_btn.Create("TEST", WS_CHILD|WS_VISIBLE, CRect(0,0, 200, 100), this, ID_MYBUTTON);
}
//implementation of the button's handler funciton
void MyButtonHandler()
{
	AfxMessageBox("My Function!");
}

note that in your code you made the parent window of the button is the main window which is the CMainFrame class, if you want it this way you may need to move the handler function and handler message map to the CMainFrame instead of the CView
GeneralRe: sigh. still not working. Pin
MAAK13-May-03 22:07
MAAK13-May-03 22:07 
GeneralGot it! Pin
Bigsteiny14-May-03 16:18
Bigsteiny14-May-03 16:18 
GeneralAdding to dialogue design palette Pin
Trollslayer12-May-03 5:31
mentorTrollslayer12-May-03 5:31 
GeneralRe: Adding to dialogue design palette Pin
G. Steudtel12-May-03 6:05
G. Steudtel12-May-03 6:05 
QuestionTLB's need to be registered ?? Pin
Braulio Dez12-May-03 5:28
Braulio Dez12-May-03 5:28 
AnswerRe: TLB's need to be registered ?? Pin
Anonymous13-May-03 16:13
Anonymous13-May-03 16:13 
GeneralWinINet Via Proxy Pin
thowra12-May-03 5:09
thowra12-May-03 5:09 
GeneralErrors Pin
flora_k12-May-03 4:50
flora_k12-May-03 4:50 
GeneralRe: Errors Pin
flora_k12-May-03 4:53
flora_k12-May-03 4:53 
GeneralRe: Errors Pin
G. Steudtel12-May-03 5:11
G. Steudtel12-May-03 5:11 
GeneralRe: Errors Pin
David Crow12-May-03 5:11
David Crow12-May-03 5:11 
GeneralRe: Errors Pin
Iain Clarke, Warrior Programmer12-May-03 5:13
Iain Clarke, Warrior Programmer12-May-03 5:13 
GeneralSpinControl Help Pin
VanHlebar12-May-03 4:45
VanHlebar12-May-03 4:45 
GeneralRe: SpinControl Help Pin
Iain Clarke, Warrior Programmer12-May-03 5:05
Iain Clarke, Warrior Programmer12-May-03 5:05 
GeneralRe: SpinControl Help Pin
VanHlebar12-May-03 16:25
VanHlebar12-May-03 16:25 
GeneralRe: SpinControl Help Pin
VanHlebar12-May-03 16:26
VanHlebar12-May-03 16:26 
GeneralDynamic loading of buttons Pin
JensB12-May-03 4:33
JensB12-May-03 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.