I have been able to create a CButton in a CView derived class, and it is visible.
The problem is, no matter how and where I insert the ON_BN_CLICKED event management map entry, it seems the event is not fired or at least not propagated to the correct message map.
This is my CView derived class Initial update handler:
void CMFC_csv2hstView::OnInitialUpdate()
{
RECT R;
R.bottom = 250;
R.top = 100;
R.left = 100;
R.right = 250;
CB.Create(_T("Hello"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, R, this, 1);
}
and the related message map :
IMPLEMENT_DYNCREATE(CMFC_csv2hstView, CView)
BEGIN_MESSAGE_MAP(CMFC_csv2hstView, CView)
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CMFC_csv2hstView::OnFilePrintPreview)
ON_COMMAND(WM_CREATE, &CMFC_csv2hstView::OnCreateWindow)
ON_BN_CLICKED(1, &CMFC_csv2hstView::OnButton)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
END_MESSAGE_MAP()
As you can see the "OnButton" method is my OnClick handler , where I put a breakpoint, but its never reached.It seems that, however you click the button, the event is not managed.
I have to say I made lots of tries before reaching this point, I tried to put the event handler in every possible message map around the application (even if sometimes it was clearly nonsense).
Some told me , that maybe the ID I was assigning to the CButton (1) was already in use, I tried to look in the application for other objects with the same ID but couldn't find it. Is there a way to assign an ID and be sure it's not already used ?
I looked around a lot of tutorials and online resources, it seems noone takes in consideration the eventuality of managing a Button without the use of Dialog Boxes.
Is this a rule ? is there a limit in MFC framework which makes it not possible to do what I want to do ?
The application is a MDI and I am using VS 2013 Community
What I have tried:
Putting :
ON_BN_CLICKED(1, &CMFC_csv2hstView::OnButton)
in CWinApp, MainFrm