Question about WM_GETMINMAXINFO in hook

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi everybody:
I want to use hook to change windows size when it was MAXIMIZE. Here is my code:
<pre class="prettyprint SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, hInstHookDll, 0) // ... LRESULT CALLBACK CallWndProc(
__in int nCode,
__in WPARAM wParam,
__in LPARAM lParam
)
{
if(nCode == HC_ACTION)
{
CWPSTRUCT *TempCWPSTRUCT = (CWPSTRUCT*)lParam;
switch(TempCWPSTRUCT->message)
{
case WM_SYSCOMMAND:
{
switch(TempCWPSTRUCT->wParam)
{
case SC_MAXIMIZE:
{
HANDLE HH = TempCWPSTRUCT->hwnd;

break;
}
default:
{
break;
}
}

break;
}
case WM_GETMINMAXINFO:
{
MINMAXINFO* mmi = (MINMAXINFO*)TempCWPSTRUCT->lParam;
mmi->ptMaxTrackSize.x /= 2;
mmi->ptMaxTrackSize.y /= 2;
mmi->ptMaxSize.x /= 2;
mmi->ptMaxSize.y /= 2;

break;
}
default:
{
break;
}
}
return 0;
}
else
{
return CallNextHookEx(hkKey, nCode, wParam, lParam);
}
[/code]
In this code, I can get the WM_GETMINMAXINFO message, but after i modify the MINMAXINFOs value,
<span>the <span class="x_hps window<span>s<span class="x_hps size<span class="x_hps dose not changed, its no effect...

But i found i can change the windows size when it was MAXIMIZE in WndProc:

<pre class="prettyprint protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_GETMINMAXINFO:
{
MINMAXINFO MINMAXINFO = (MINMAXINFO)Marshal.PtrToStructure(m.LParam, typeof(MINMAXINFO));
MINMAXINFO.ptMaxTrackSize.x /= 2;
MINMAXINFO.ptMaxTrackSize.y /= 2;
MINMAXINFO.ptMaxSize.x /= 2;
MINMAXINFO.ptMaxSize.y /= 2;
MINMAXINFO.ptMinTrackSize.x /= 2;
MINMAXINFO.ptMinTrackSize.y /= 2;
Marshal.StructureToPtr(MINMAXINFO, m.LParam, false);

break;
}
}
base.WndProc(ref m);
}
[/code]
Why?
Thanks!

View the full article
 
Back
Top