I have a computer vision project using OpenCV and MFC for the GUI.
I want to do the following: when i click Button1, i get a new window that displays a video then captures images by clicking on the buttons of that new window.
First, i had an MFC project with only the window that displays the video and it worked fine. Then i created a new project where i made that window comes after clicking on a button. Here is the code that i used to call that window.
void ClassTestDlg::OnBnClickedButton1()
{
CDialog ClassTestDlg(IDD_DIALOG_WindowDisplay);
ClassTestDlg.DoModal();
}
After clicking on button1, i can see the new window but the video doesn't display.
The class of the new dialog doesn't contain an "OnInitDialog()" method and i don't know how to write extra initialization in this new class.
I am new to MFC so Help please.
Thank you
You cannot instantiate a CDialog, only a class derived from CDialog.
Your button handler is in class ClassTestDlg, so why are you trying to create another ClassTestDlg? You need something like this:
void ClassFirstDlg::OnBnClickedButton1()
{
ClassSecondDlg dlg2;
dlg2.DoModal();
}
Related
I created a C++ MFC Program with the Visual Studio Wizard. There I set the application type to "Dialog Based".
I have a button on the first dialog, which opens another dialog. I created this second dialog by right clicking on the project -> Add -> Resource -> Dialog -> New.
Then I added a MFC class to the new dialog by double clicking it in resource view.
On the second Dialog I also created a button. I double clicked the button and added some code which should be executed.
When I run the program and click the button on the second dialog, nothing happens and the code is not executed. I did everything like with the button on the first dialog. That one works fine. Why is the second button not working and what do I need to do?
First Dialog
void CMFCApplication1Dlg::OnBnClickedButton1()
{
CDialogEx secondDialog(IDD_DIALOG1);
secondDialog.DoModal();
}
Second Dialog
void SettingsDlg::OnBnClickedButton1()
{
MessageBox(L"Button clicked", L"Button clicked", MB_OK);
}
#andrew-truckle, your side node was the answer! I changed it to:
void CMFCApplication1Dlg::OnBnClickedButton1()
{
SettingsDlg settingsDialog;
settingsDialog.DoModal();
}
Now the button works just as expected. Thank you very much!
Further Info (from #andrew-truckle)
For the benefit of others the issue here was that the original code declared the dialog like this:
CDialogEx secondDialog(IDD_DIALOG1);
That was wrong because the dialog was actually associated with the class SettingsDlg. This is the class that had the message map and event handlers etc. CDialogEx was the base class.
I added this update to the answer to save the reader from locating my comment to the question.
I am having a proglem with the MFC application and the DialogBox. I am quiet sure I've done everything well with this tutorial: https://msdn.microsoft.com/en-us/library/6wb9s9ah.aspx
but still it doesn't work...
1. I've created new project with simple menu commands.
2. I've created new menu item (+ID) and new resource DialogBox (+ID).
3. Then I've added a new class named CParameters with the Class Wizard. For the BaseClass I've typed in CDialog.
4. I've created new handler on the menu item and added the code
CParameters dlg;
dlg.DoModal();
I think this is it, and this should work... But it doesnt... What is missing??
Here is my project, you can access it freely:
https://www.dropbox.com/sh/e6ajoxqk76hkuvn/AACRMY8bgcuyXguFwP240QB9a?dl=0
Additionally I want to insert TextEditors and to change parameters in my program from the dialog box.
A scan of your source code reveals that you are trying to handle the menu item event within the class that is going to display the dialog.
void CParameters::OnParam()
{
// TODO: Add your command handler code here
CParameters dlg;
dlg.DoModal();
}
I don't see anywhere else that you actually instantiate the dialog class (I may have missed it). What you are trying is incorrect. You cannot handle the menu item event within the same class that displays the dialog because that class (CParameters) has not been instantiated, so, it cannot respond to the menu event. Typically, the menu event would be handled in the mainframe class.
If you are doing this by adding a new menu item from a simple SDI application, then trying adding that part of code in
CMainFrame::OnEdit
OnEdit method used here is obtained from the Event Handler for the new menu item and Message type being COMMAND.
i'm currently working on a project that involves OGRE for the 3D part and WXWidgets for the user interface. I have followed the hello world tutorial and i'm able to create an application, a window and the message map. The goal is to display at startup a window where you can choose some specific settings like fullscreen, texture quality and some other application specific settings. After you have chosen the settings, the window needs to close and then start the OGRE part with the settings from window.
I have tried to put the code to start the new Window for ogre in the init function:
bool MyApp::OnInit() {
MyFrame *frame = new MyFrame( "Settings", wxPoint(50, 50), wxSize(640, 480) );
frame->Show( true );
start_ogre();
return true;
}
The problem is that both forms are showed at the same time. The Application, Frame and window are in my code split in seperate classes.
i also tried to put the code in the main.cpp after the wxwidget code:
wxIMPLEMENT_APP(MyApp);
start_ogre();
This gives the same problem. I tried also in the close event, but that does nothing.
Is there an easy way to make the OGRE form show only when the settings form is closed without shutting down my application or starting both at the same time?
You could use a dialog instead of a frame and show it using ShowModal(). This will block until the user dismisses or closes the dialog. You need to derive your dialog from wxDialog and you need to add some buttons with the appropriate IDs to close or dismiss the dialog. For this you can use the CreateStdDialogButtonSizer(long) method which your dialog inherits from wxDialog.
I am practice on splitter window, I reference to this web site,
Creating a Splitter Window in a Dialog Box in Three Easy Steps
when I build it, some thing error I cant solve it, like follow code...
Out of memory creating a splitter pane.
Error: Trying to create object which is not DECLARE_DYNCREATE
or DECLARE_SERIAL: CDialogEx.
Out of memory creating a splitter pane.
Error: Trying to create object which is not DECLARE_DYNCREATE
or DECLARE_SERIAL: CDialogEx.
the link for download this example, please rewrite the example,
splitter dialog example
the other feature, I want to create a two panel with button and static
and listcontrol item.
thanks guy.
Don't use a dialog base application. Just use the wizard. Create a SDI sample with a CFormView... integrate the splitter window later.
It doesn't make sense to me to create a dialog and to integrate all the CFrameWnd features into a CDialog...
I replaced the CDialog1 with CWnd then solved this problem.
ccc.m_pNewViewClass = RUNTIME_CLASS(CWnd);
m_cSplitter.CreateView(0,0, RUNTIME_CLASS(CWnd),
CSize(100,100), &ccc);
m_cSplitter.CreateView(0,1, RUNTIME_CLASS(CWnd),
CSize(100,100), &ccc);
I am trying to create a wizard like structure using dialog boxes...So I replaced the code in CDialog1App as below
CDialog1Dlg* dlg = new CDialog1Dlg;
m_pMainWnd = dlg;
dlg->Create(IDD_DIALOG1);
dlg->ShowWindow(SW_SHOW);
the above worked fine...its displying the dialog box.but I have added another dialog box...
So in the first dialog box if the user clicks Next it has to hide the first dialog box and display the second dialog..
//CDialog1 class
void CDialog1Dlg::OnBnClickedNext()
{
// TODO: Add your control notification handler code here
CDialog2* dialog2 = new CDialog2();
dialog2->Create(IDD_DIALOG2);
dialog2->ShowWindow(SW_SHOW);
this->ShowWindow(SW_HIDE);
}
in the above code am creating an object for the Dialog2 class and trying to show that....
Now the problem is,when I click next its hiding both the windows..What can I do..I tried several types but its still its not workin..Please dont suggest me to do with PropertySheet..It will work with that, i know ...but I want this using Dialog Box for some reason
You're creating the dialog2 with the default parent window (NULL):
dialog2->Create(IDD_DIALOG2);
But the default parent seems to be dialog1 in your case. And since you hide dialog1 which is the parent of dialog2, dialog2 is also hidden.
Find the window (CWnd) of either your main app dialog (if you have one visible apart from your wizard), or use the desktop window as the parent.
For example:
dialog2->Create(IDD_DIALOG2, GetDesktopWindow());