I have a borderless window that I want to be able to show and hide from the main app window. When I show it (it's called from a menu item) the focus shifts to the borderless window. To close it, I have to click to get focus on the main window, then click again to open the menu so I can select the hide item. The borderless window is set to stay on top of the main app window.
How do I keep focus on the main app window even while the borderless window is open?
The code for showing/hiding the borderless window:
private: System::Void previewMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { if (!previewWnd->open) { previewWnd->open = true; previewWnd->Visible = true; previewMenuItem->Enabled = false; stopPreviewMenuItem->Enabled = true; } } private: System::Void stopPreviewMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { if (previewWnd->open) { previewWnd->open = false; previewWnd->Visible = false; previewMenuItem->Enabled = true; stopPreviewMenuItem->Enabled = false; } } |
|
The code for adding the borderless window to the main app:
public ref class Form1 : public System::Windows::Forms::Form { private: Preview ^previewWnd;
public: Form1(void) { InitializeComponent(); previewWnd = gcnew Preview; // //TODO: Add the constructor code here // }
I'm not sure what to put in the destructor, since Preview.h has a destructor in it already:
protected: /// /// Clean up any resources being used. /// ~Form1() { if (components) { delete components; } } . . . } |
|