Capturing every minimize and restore
-
I'm working on an application where I need to capture minimize and restore (all of them) and I ran into a problem with my current method... At the moment I have an override in winproc to look for "size_minimize" and then it'll prompt me. I also look for the system command "SC_RESTORE" to reset it, but I have an issue, if you open the application minimize and then use tasksmanager's "switch to" it doesn't send the "SC_RESTORE" and this will cause a horrible problem! The app will stop working till they minimize and restore it normally... I HAVE to shutdown my background workers when the app is minimized, and restore them when the user restores the app... Here is my current winproc
protected override void WndProc(ref System.Windows.Forms.Message m) { bool bwincmd = false; switch (m.Msg) { case 0x112: //WM\_SYSCOMMAND switch (m.WParam.ToInt32() & 0xFFF0) { //redundant but prevents Maximize command (CreateParams has it grayed out) case 0xF030: //SC\_MAXIMIZE bwincmd = true; //allow do nothing else break; case 0xF010: //SC\_MOVE setprogramedmove(); //move and click the mouse to move the application bwincmd = true; //allow do nothing break; case 0xF120: //SC\_RESTORE (this is the only way to restore? doesn't look like it) bMinimized = false; //flag workers to start again break; } break; case 0x0005: //WM\_SIZE switch (m.WParam.ToInt32()) { case 0x1: //SIZE\_MINIMIZED if (this.OnMinimize != null) { //call captured minimize event this.OnMinimize(this, EventArgs.Empty); } break; } break; } if (bwincmd) { //do nothing and stop real WndProc from seeing message. return; } else { // send control to base message handler (real WndProc
-
I'm working on an application where I need to capture minimize and restore (all of them) and I ran into a problem with my current method... At the moment I have an override in winproc to look for "size_minimize" and then it'll prompt me. I also look for the system command "SC_RESTORE" to reset it, but I have an issue, if you open the application minimize and then use tasksmanager's "switch to" it doesn't send the "SC_RESTORE" and this will cause a horrible problem! The app will stop working till they minimize and restore it normally... I HAVE to shutdown my background workers when the app is minimized, and restore them when the user restores the app... Here is my current winproc
protected override void WndProc(ref System.Windows.Forms.Message m) { bool bwincmd = false; switch (m.Msg) { case 0x112: //WM\_SYSCOMMAND switch (m.WParam.ToInt32() & 0xFFF0) { //redundant but prevents Maximize command (CreateParams has it grayed out) case 0xF030: //SC\_MAXIMIZE bwincmd = true; //allow do nothing else break; case 0xF010: //SC\_MOVE setprogramedmove(); //move and click the mouse to move the application bwincmd = true; //allow do nothing break; case 0xF120: //SC\_RESTORE (this is the only way to restore? doesn't look like it) bMinimized = false; //flag workers to start again break; } break; case 0x0005: //WM\_SIZE switch (m.WParam.ToInt32()) { case 0x1: //SIZE\_MINIMIZED if (this.OnMinimize != null) { //call captured minimize event this.OnMinimize(this, EventArgs.Empty); } break; } break; } if (bwincmd) { //do nothing and stop real WndProc from seeing message. return; } else { // send control to base message handler (real WndProc
You can set up event handler for form's resize event and check for the window state there. Also, have a look at http://www.codeproject.com/csharp/windowstatemonitor.asp I don't know if it solves the problem with task manager but I hope you find it useful
#region signature my articles #endregion
-
You can set up event handler for form's resize event and check for the window state there. Also, have a look at http://www.codeproject.com/csharp/windowstatemonitor.asp I don't know if it solves the problem with task manager but I hope you find it useful
#region signature my articles #endregion
Ahh crap, it has the same exact issue... Thanks for the input though The hook methood used is seems like more overhead... I guess it is easier people who havn't written in Win32 C; IE those who don't handle winproc their self and just want the events to fire. Even like my application if thie 'bug' occurs and you unfocus the form (goto another window) then click back on the taskbar(or Alt-Tab as both send SC_RESTORE) the state is restored because the command is sent (cool!) but now I need to figure out what command is being sent from taskmanager... Taskmanager is a weird application! maybe because it loads KM independent from the shell? This looks like a job for Microsoft ;) :( (I'll get back to everyone in 5 to 6 months :laugh::laugh:) Just so you know I am capturing the resize event as you said, look at my code I posted the winproc has a case "0x0005" aka WM_SIZE where I trigger my minimize event...
-Spacix All your skynet questions[^] belong to solved -- modified at 14:47 Tuesday 4th September, 2007
-
Ahh crap, it has the same exact issue... Thanks for the input though The hook methood used is seems like more overhead... I guess it is easier people who havn't written in Win32 C; IE those who don't handle winproc their self and just want the events to fire. Even like my application if thie 'bug' occurs and you unfocus the form (goto another window) then click back on the taskbar(or Alt-Tab as both send SC_RESTORE) the state is restored because the command is sent (cool!) but now I need to figure out what command is being sent from taskmanager... Taskmanager is a weird application! maybe because it loads KM independent from the shell? This looks like a job for Microsoft ;) :( (I'll get back to everyone in 5 to 6 months :laugh::laugh:) Just so you know I am capturing the resize event as you said, look at my code I posted the winproc has a case "0x0005" aka WM_SIZE where I trigger my minimize event...
-Spacix All your skynet questions[^] belong to solved -- modified at 14:47 Tuesday 4th September, 2007
-
You could also use the tool "Spy++" that comes with visual studio .net to watch what messages are passed between windows and your app.
Yea I did that, which is how I knew it doesn't send SC_RESTORE (other than it doesn't work, but was my reason "why" it didn't work...) Here is my screen cap from gVIM of the commands: http://img72.imageshack.us/my.php?image=commandsvimzs0.gif for some reason imageshack added transparency to my image (so it looks funny on their background...)
-Spacix All your skynet questions[^] belong to solved
-
You can set up event handler for form's resize event and check for the window state there. Also, have a look at http://www.codeproject.com/csharp/windowstatemonitor.asp I don't know if it solves the problem with task manager but I hope you find it useful
#region signature my articles #endregion
Giorgi Dalakishvili wrote:
You can set up event handler for form's resize event and check for the window state there.
nobugz from the MSDN forums pointed this out and it doesn't have the same issue; I think this must have been what this post was pointing out and I just missed it after looking at the link on the bottom...
nobugz wrote:
Use the Resize event. For example:
public partial class Form1 : Form {
private FormWindowState mState;
public Form1() {
InitializeComponent();
this.Resize += Form1_Resize;
mState = this.WindowState;
}
private void Form1_Resize(object sender, EventArgs e) {
if (mState != this.WindowState) {
mState = this.WindowState;
switch (mState) {
case FormWindowState.Normal: Console.WriteLine("Restored"); break;
case FormWindowState.Maximized: Console.WriteLine("Maximized"); break;
case FormWindowState.Minimized: Console.WriteLine("Minimized"); break;
}
}
}
}
-Spacix All your skynet questions[^] belong to solved
-
Giorgi Dalakishvili wrote:
You can set up event handler for form's resize event and check for the window state there.
nobugz from the MSDN forums pointed this out and it doesn't have the same issue; I think this must have been what this post was pointing out and I just missed it after looking at the link on the bottom...
nobugz wrote:
Use the Resize event. For example:
public partial class Form1 : Form {
private FormWindowState mState;
public Form1() {
InitializeComponent();
this.Resize += Form1_Resize;
mState = this.WindowState;
}
private void Form1_Resize(object sender, EventArgs e) {
if (mState != this.WindowState) {
mState = this.WindowState;
switch (mState) {
case FormWindowState.Normal: Console.WriteLine("Restored"); break;
case FormWindowState.Maximized: Console.WriteLine("Maximized"); break;
case FormWindowState.Minimized: Console.WriteLine("Minimized"); break;
}
}
}
}
-Spacix All your skynet questions[^] belong to solved
Yes, this is what I meant :)
#region signature my articles #endregion
-
Yes, this is what I meant :)
#region signature my articles #endregion
There is a bug with this though, pointed out by Peter Ritchie after that was posted, if the form is at point (0,0) and it is maximized then the resize event doesn't trigger, but since I don't care/even have the ability for a user to maximize my form not a problem with me. The main form in my application is a static sized "panel" or "meter" which doesn't need to be resized.
-Spacix All your skynet questions[^] belong to solved