WxWidgets Show form after first is closed - c++

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.

Related

wxFrame and wxTaskBarIcon taskbar event Mac OSX : callback not being triggered

I have a derived class for wxFrame (MyFrame) (for OSX - Yosemite platform), where it calls:
Bind(wxEVT_TASKBAR_RIGHT_DOWN), &HandleTaskBarEvent, this);
The issue is HandleTaskBarEvent is not being invoked when I right click the icon in the dock.
I see the generic right click menu that Mac has (Open at Login, Keep in Dock, etc) for the main icon in the dock.
Also, I created a wxTaskBarIcon. I am guessing this will be utilized for the minimized icon in the dock after the frame is minimized.
systemIcon = new wxTaskBarIcon(); //declared in header
systemIcon.Bind(wxEVT_TASKBAR_RIGHT_DOWN, &HandleTaskBarEvent, this);
Popup = new wxMenu(); //declared in header
QuitMenu = new wxMenuItem(Popup, wxID_ANY, wxString(wxT("Quit")), wxEmptyString, wxITEM_NORMAL); //declared in header
Popup->Append(QuitMenu)
Popup->Bind(wxEVT_COMMAND_MENU_SELECTED, &CloseFunc, this, QuitMenu->GetId());
This is inside the same derived class(MyFrame).
I call Iconize() inside that MyFrame same function, which works as expected. It minimized the window.
This is the HandleTaskBarEvent function (virtual)
void MyFrame::HandleTaskBarEvent(wxTaskBarIconEvent& event)
{
if(event.GetEventType() == wxEVT_TASKBAR_RIGHT_DOWN)
{
systemIcon->PopupMenu(Popup);
}
}
I saw this post : Mouse Events of WxPython TaskBarIcon on Mac OSX are not triggering
and there seems to be a bug about it. But I am not able to find that bug or its status online. It is mentioned that the issue is with wxPython, but seems related to my problem.
Also I created a derived class for wxTaskBarIcon and overrode CreatePopupMenu and made systemIcon as an instance of MyTaskBarIcon, but that function is not being triggered for any clicks(left,right, etc). Also the main wxFrame 's Bind callback (HandleTaskBarEvent) is not being triggered, hence the systemIcon is not being able to popup the menu.
I am not using mouse for my Mac (using trackpad instead). Not sure if it should make any difference to right click code, but adding the information here anyways.
So I am thinking this could be wxWidget-OSX specific issue, because the code works on Windows as expected.
Does anyone know if this is purely wxWidget-OSX incomplete feature, if there is any open bugs about it, and more importantly if there is any solution to show the popup menu items for the minimized icon in the dock, and to handle the click events for the menu.
Thanks in advance.
This is a limitation of the OS X wxTaskBarIcon implementation. See wxTaskBarIcon on OSX - two-finger click does not send mouse event and related/linked issues.
The only way I know of (on OS X) is overriding wxTaskBarIcon::CreatePopupMenu().
You should be able to have something like:
MyApp::wxApp/
MyTaskBarIcon::wxTaskBarIcon (override CreatePopupMenu(), return a new wxMenu)
This is the model I use in a few applications and it works the same on Windows and OS X (albeit no specific click handlers as mentioned).

Qt how to create a settings/configuration window

I was trying to find an example of creating a settings/configuration windows. The settings window is launched by clicking "Options" action in the menu item. I wanted to figure out how to open up a 2nd window from the main window. As well how the new window return the settings information back to main window. Tried to play around with the QDialog or some inherited dialog classes, but those are for limited uses, not for general setting window. Is there any example/documentation about this?
Have you seen this property browser. Similar to property editor in Qt Designer. qtpropertybrowser Image

extra initialization in new window of a MFC/OpenCV project

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();
}

Title Bar customization

I'm trying to build a c++ program that customizes another window title bar, adding colored text and icons. The window I need to customize is in a closed source program.
Right now I can only change the text with SetWindowText, but was unable no find a way to get that level of customization:
Razor Ultima Online Customized Titlebar
The image is from Ultima Online title bar being customized by Razor, a closed source helper program.
Thanks for reading.
Custom drawing and subclassing of other process windows requires DLL injection and hooking to detect the windows creation with subclassing to handle the non client drawing and click/hittest messages..
You should inject you DLL into client.exe process, then override main window function (WndProc), or create new window and make original client's window to be the child of your window.
Writing colored text on the caption is non-trivial task itself, especially if you want support Win7\Vista (however it's doable with GDI).

Can't display modal QProgressDialog in MFC application

I'm having problems displaying a modal Qt dialog while starting up a Qt application from an MFC application. Specifically, a QProgressDialog instance won't display within the MFC application when I set its parent to a QWinWidget instance. Here's my problem in more detail...
My MFC application needs to transfer a lot of data over to the Qt application, which is a DLL. The Qt application includes a ProgressDlg class in its API that behind the scenes is implemented using a QProgressDialog. This dialog must be created and updated before the Qt application's event loop is initialised so that the MFC application can update its progress (The QApplication::exec() help says this is possible with modal widgets).
Without setting the underlying QProgressDialog's parent, the progress bar gets updated as I would expect and the dialog remains responsive during the transfer, but I can continue to interract with the MFC application.
So I tried installing the Qt/MFC Migration Framework and setting the QProgressDialog's parent to be a QWinWidget:
void ProgressDlg::SetParent(HWND hParentWnd)
{
QWinWidget* w = new QWinWidget(hParentWnd);
m_impl->setParent(w);
}
(where m_impl derives from QProgressDialog.)
And then adding the calling code on the MFC side to create the dialog:
HWND hWnd = FindWindow(NULL, "ABC");
if(hWnd)
{
ProgressDlg dlg;
dlg.SetParent(hWnd);
//...
dlg.SetValue(0);
//...
}
However in setting the parent, the QProgressDialog no longer appears. (I retrieved the handle using ::FindWindow, passing in the Window Name, as to complicate the scenario further, my MFC application is actually a plugin DLL to a 3rd party executable.)
All help appreciated. Thanks.
Gotcha! The problem was caused by the call to SetParent(). I needed to instead create the QWinWidget before the QProgressDialog and pass the QWinWidget instance in to the QProgressDialog's constructor as its parent.
As the help says, QWidget::setParent resets the window flags, so the dialog was no longer being recognised as a dialog.