I'm maintaining a classic MDI MFC application, and I'd like to prevent the user from minimizing an MDI document window.
The best solution would be if I just could remove or disable the "Minimze" button
from the MDI Window and remove/disable the "Minimize" command from the menu that shows up when you click on the upper left corner of the MDI window.
Override PreCreateWindow from CChildFrame, and write:
BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.style &= ~WS_MINIMIZEBOX;
if(! CMDIChildWnd::PreCreateWindow(cs))
return FALSE;
return TRUE;
}
Related
When I drag a WinForms window to the top of the screen to perform a Maximize "Aero Snap", if I then hit the "Restore" button after this, the window is restored to the correct size but at the wrong location. It flickers to the correct location for a moment, but then it immediately moves to the top of the screen with its title bar halfway off the screen.
Apparently, the WinForms window restores to its last dragged location before it was maximized, which was at the top of the screen where it was dragged in order to do the Aero Snap.
This behavior is incorrect and annoying. You can see the correct behavior by following those same steps for a Windows Explorer window. After an Aero Snap, the Windows Explorer window correctly restores to the last dropped restore location (wherever it was sitting before it was dragged to do the Aero Snap).
How can I make a WinForms window restore to the correct location after an Aero Snap, like a Windows Explorer window does?
I could try and hook into the form positioning events and save the last-dropped restore location, and restore that after a Restore after an Aero Snap, but I'm hoping there's a simpler way.
You can override the OnResizeBegin, OnResizeEnd and OnSizeChanged methods to:
store a Form's current Location when it's first dragged (when you begin to drag a Form around the OnResizeBegin is called)
clear the stored values if the Form is released (OnResizeEnd is called) while it's WindowState is FormWindowState.Normal
finally restore the Form.Location when OnSizeChanged notifies that the Form.WindowState changes from FormWindowState.Maximized to FormWindowState.Normal.
If you use a Controller or similar, you can subscribe to the corresponding events instead.
Point beginDragLocation = Point.Empty;
FormWindowState beginDragFormState = FormWindowState.Normal;
protected override void OnResizeBegin(EventArgs e)
{
base.OnResizeBegin(e);
beginDragLocation = this.Location;
}
protected override void OnResizeEnd(EventArgs e)
{
base.OnResizeEnd(e);
if (this.WindowState != FormWindowState.Maximized) {
beginDragLocation = Point.Empty;
}
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
if (beginDragFormState == FormWindowState.Maximized && beginDragLocation != Point.Empty) {
BeginInvoke(new Action(() => this.Location = beginDragLocation));
}
beginDragFormState = this.WindowState;
}
MainActivity
ActionBar.SetHomeAsUpIndicator (Resource.Drawable.ic_menu_white_24dp);
ActionBar.SetDisplayHomeAsUpEnabled (true);
drawerLayout = FindViewById<DrawerLayout> (Resource.Id.drawer_layout);
navigationView = FindViewById<NavigationView> (Resource.Id.nav_view);
Event click on navigatonView
CreateFragments();
LoadInditialFragment ();
navigationView.NavigationItemSelected += NavigationView_NavigationItemSelected;
Onefragment
Twofragment
Navigation back from second Fragment to first fragment(navigation back on toolbar).??? MainActivity I have a button menu on toolbar.
I want to replace menu icon into back icon when It is standing at second fragment.
Download back arrow and save as navBack.png
Then in SwitchFragment method where we navigate between fragments
switch (FragmentId) {
case Resource.Id.nav_home:
ActionBar.SetHomeAsUpIndicator (Resource.Drawable.ic_menu_white_24dp);
transaction.Show (homeFragment);
transaction.Commit ();
break;
case Resource.Id.nav_genre:
ActionBar.SetHomeAsUpIndicator (Resource.Drawable.navBack);
transaction.Show (genresFragment);
transaction.Commit ();
break;
}
In Your MainActivity do this in OnCreate:
SupportFragmentManager.BackStackChanged += HandleBackstackChanged;
Implement the HandleBackstackChanged method like this
private void HandleBackstackChanged(object sender, EventArgs e)
{
ActionBar.SetDisplayHomeAsUpEnabled (SupportFragmentManager.BackStackEntryCount > 0);
}
What this will do is toggle between the Menu button and the Back button based on the BackStack count of the FragmentManager.
NOTE:
I am assuming you are using the Support library for backwards compatibility of Fragments. If you aren't using the support library, just use FragmentManger instead of SupportFragmentManager.
I have an application written using Qt5 in Python (PyQt5).
I want to override default behavior of the zoom (green "+" at top left) so it will set appropriate size of the window rather than maximize it to cover all available space.
I tried to override showMaximize, but that method was never called. My window is a subclass of QWidget without any additional window flags set (i.e. defaults are used).
How can I override the event or how can I tell the layout system size I want to be set once user clicks that button?
You cannot override showMaximized because it is not virtual. There is no way to override this action. But you can override changeEvent. It will be called when user maximizes the window. You can reset normal window's position and adjust its size.
void MyWidget::changeEvent(QEvent *e) {
QWidget::changeEvent(e);
if (e->type() == QEvent::WindowStateChange) {
if (isMaximized()) {
showNormal();
resize(200, 200);
move(100, 100);
}
}
}
Question:
Is there a way to always let a click, that brings a form in to focus, through an have effect on the form?
Background:
With my (C# win form) application out of focus I can hover the form and get shades and borders indicating where my mouse is.
Clicking for example a menu entry (File) the form gets focus but the file menu does not get click. This takes an additional click.
For an ordinary button on the form only one click is required.
This can be fixed by setting focus before the click occurs. Se code:
class ToolStripEx : System.Windows.Forms.ToolStrip
{
protected override void WndProc(ref Message m)
{
// WM_MOUSEACTIVATE = 0x21
if (m.Msg == 0x21 && this.CanFocus && !this.Focused)
{
this.Focus();
}
base.WndProc(ref m);
}
}
This approach also works on MenuStrip
I found a few helpful articles – especially this one by Rick Brewster. The solution lies in overriding the WndProc method for the ToolStrip (or MenuStrip):
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (this.clickThrough &&
m.Msg == NativeConstants.WM_MOUSEACTIVATE &&
m.Result == (IntPtr)NativeConstants.MA_ACTIVATEANDEAT)
{
m.Result = (IntPtr)NativeConstants.MA_ACTIVATE;
}
}
I have an MFC dialog containing a dozen or so buttons, radio buttons and readonly edit controls.
I'd like to know when the user hits Ctrl+V in that dialog, regardless of which control has the focus.
If this were C#, I could set the KeyPreview proprety and my form would receive all the keystrokes before the individual controls - but how do I do that in my MFC dialog?
JTeagle is right. You should override PreTranslateMessage().
// Example
BOOL CDlgFoo::PreTranslateMessage( MSG* pMsg )
{
// Add your specialized code here and/or call the base class
if ( pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN )
{
int idCtrl= this->GetFocus()->GetDlgCtrlID();
if ( idCtrl == IDC_MY_EDIT ) {
// do something <--------------------
return TRUE; // eat the message
}
}
return CDialog::PreTranslateMessage( pMsg );
}
Add a handler to override PreTranslateMessage() in the dialog class, and check the details of the MSG struct received there. Be sure to call the base class to get the right return value, unless you want to eat the keystroke to prevent it going further.