If you ever tried to make irregular windows in wpf and used setting windowstyle=none,You might have used some code like this to enable minimising,maximising properties for the window:
private void Minimize_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void Maximize_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Maximized;
}
But on maximizing ,the window hides the taskbar.i.e it goes fullscreen.
To avoid that issue,You can use this code and yes,it works like a charm.
http://blogs.msdn.com/llobo/archive/2006/08/01/Maximizing-window-_2800_with-WindowStyle_3D00_None_2900_-considering-Taskbar.aspx
public override void OnApplyTemplate()
{
System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
}
private static System.IntPtr WindowProc(
System.IntPtr hwnd,
int msg,
System.IntPtr wParam,
System.IntPtr lParam,
ref bool handled)
{
switch (msg)
{
case 0x0024:/* WM_GETMINMAXINFO */
WmGetMinMaxInfo(hwnd, lParam);
handled = true;
break;
}
return (System.IntPtr)0;
}
private static void WmGetMinMaxInfo(System.IntPtr hwnd, System.IntPtr lParam)
{
MINMAXINFO mmi = (MINMAXINFO)Marshal.PtrToStructure(lParam, typeof(MINMAXINFO));
// Adjust the maximized size and position to fit the work area of the correct monitor
int MONITOR_DEFAULTTONEAREST =0x00000002;
System.IntPtr monitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
if (monitor != System.IntPtr.Zero)
{
MONITORINFO monitorInfo = new MONITORINFO();
GetMonitorInfo(monitor, monitorInfo);
RECT rcWorkArea = monitorInfo.rcWork;
RECT rcMonitorArea = monitorInfo.rcMonitor;
mmi.ptMaxPosition.x = Math.Abs(rcWorkArea.left - rcMonitorArea.left);
mmi.ptMaxPosition.y = Math.Abs(rcWorkArea.top - rcMonitorArea.top);
mmi.ptMaxSize.x = Math.Abs(rcWorkArea.right - rcWorkArea.left);
mmi.ptMaxSize.y = Math.Abs(rcWorkArea.bottom - rcWorkArea.top);
}
Marshal.StructureToPtr(mmi, lParam, true);
}
As seen above the code basically handles the WM_GETMINMAXINFO message. The sample project code is also included. Have Fun. :)
Update: A better way to get the handle to the window is to use the SourceInitialized event. This would also avoid calling ApplyTemplate everytime the window template is changedon the fly. Thanks to Hamid for pointing out the better solution. The attached project is now updated.
win.SourceInitialized += new EventHandler(win_SourceInitialized);
void win_SourceInitialized(object sender, EventArgs e)
{
System.IntPtr handle = (new WinInterop.WindowInteropHelper(this)).Handle;
WinInterop.HwndSource.FromHwnd(handle).AddHook(new WinInterop.HwndSourceHook(WindowProc));
}
College is opening tommorow and I am thinking what i have done in past 1 and half months of vacations.
The only thing i can remember is bluz,my open source project.
Where is that p2p thing i decided earlier?
All the research papers about skype,overlay networks ,guntella etc are lying there on disk as it is.i have read them only once.I have read not understood..
The positive side of vacations is:
1)I learned a lot about WPF,Blend etc.
2) I am participating in win7 contest based on above experience.
3)I met shaun,my new co-developer of bluz..
4)I have got some books of ASP.Net by bill ,scott and WPF book by Mathew macdonald..
And now i have some web 2.0 ideas that i hope to implement as a way of parcticing this ASP.net stuff.Thats a business idea,So you might see something interesting on web soon.
So,If i look back that way,I think it was more rewarding than any of internship i could get.
Now ,its my last year of graduation,My targets include:
1)Enjoy it fully.I know thats hard but i'll have to make this year remeberable .
2)Implement business ideas.(I love making money in humanatic way).
3)Make final year Project.
The 3rd one is where i'll cut my efforts ,Becoz i don't think that really matters as compared to my learning.Also,I don't see potential partners for a cool. .Net team to make a cool project at the college.
cya guys,
cheers