Jul 272009
Este es un módulo que nos permitirá poner un formulario MDI en modo FullScreen cuando está maximizado, la ventaja de esto es ganarle un poco más de espacio al monitor, y sobre todo cuando el software tiene un papel protagónico en el PC que lo ejecuta.
Código del módulo bas «MdiFullScreen»
Option Explicit Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal ID As Long, ByVal fsModifiers As Long, ByVal vk As Long) As Long Private Declare Function UnregisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal ID As Long) As Long Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long Private Const HWND_TOPMOST As Long = -1 Private Const HWND_NOTOPMOST As Long = -2 Private Const SWP_NOACTIVATE As Long = &H10 Private Const SWP_NOSIZE As Long = &H1 Private Const SWP_NOMOVE As Long = &H2 Private Const SWP_SHOWWINDOW As Long = &H40 Private Const WS_MAXIMIZEBOX As Long = &H10000 Private Const WS_MINIMIZEBOX As Long = &H20000 Private Const WS_THICKFRAME As Long = &H40000 Private Const WS_SYSMENU As Long = &H80000 Private Const WS_CAPTION As Long = &HC00000 Private Const SC_RESTORE As Long = &HF120& Private Const WM_ACTIVATEAPP As Long = &H1C Private Const WM_HOTKEY As Long = &H312 Private Const WM_SYSCOMMAND As Long = &H112 Private Const GWL_STYLE As Long = (-16) Private Const GWL_WNDPROC As Long = (-4) Const MyHotKey As Long = &H1000 Dim WndStyle As Long Dim bFullScreen As Boolean Dim PrevProc As Long Public Sub ShowFullScreen(hwnd As Long) If Not bFullScreen Then bFullScreen = True Call RegisterHotKey(hwnd, MyHotKey, 0, vbKeyEscape) WndStyle = GetWindowLong(hwnd, GWL_STYLE) SetWindowLong hwnd, GWL_STYLE, WndStyle And Not WS_MAXIMIZEBOX And Not WS_MINIMIZEBOX And Not WS_THICKFRAME And Not WS_CAPTION SetWindowPos hwnd, HWND_TOPMOST, 0, 0, Screen.Width / 15, Screen.Height / 15, SWP_NOACTIVATE PrevProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc) End If End Sub Public Sub EndFullScreen(hwnd) If bFullScreen Then bFullScreen = False SetWindowLong hwnd, GWL_STYLE, WndStyle SendMessage hwnd, WM_SYSCOMMAND, SC_RESTORE, ByVal 0& SetWindowLong hwnd, GWL_WNDPROC, PrevProc Call UnregisterHotKey(hwnd, MyHotKey) End If End Sub Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long WindowProc = CallWindowProc(PrevProc, hwnd, uMsg, wParam, lParam) If uMsg = WM_ACTIVATEAPP Then EndFullScreen hwnd End If If uMsg = WM_HOTKEY Then If wParam = MyHotKey Then EndFullScreen hwnd End If End If End Function
Código en el Formulario MDI»
Option Explicit Private Sub MDIForm_Load() Form1.Show End Sub Private Sub MDIForm_Resize() If Me.WindowState = vbMaximized Then ShowFullScreen Me.hwnd Else EndFullScreen Me.hwnd End If