Что нового

Создаём MDI окна на WinAPI

Viktor1703

AutoIT Гуру
Сообщения
1 535
Репутация
408
В целом пример был взят от сюда я его чуть изменил и зделал не простое окно, а MDI.

Код:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPIEx.au3>

Global Const $IDC_ARROW = 32512
Global Const $CS_HREDRAW = 0x0002
Global Const $CS_VREDRAW = 0x0001
Global Const $CS_BYTEALIGNWINDOW = 0x2000
Global Const $tmWNDCLASSEX = "uint Size;uint Style;ptr hWndProc;int ClsExtra;int WndExtra;ptr hInstance;ptr hIcon;ptr hCursor;ptr hBackground;ptr MenuName;ptr ClassName;ptr hIconSm"
Global Const $sClass = 'MDIClient'
Global Const $sName = 'Example'
Global $tCLIENTCREATESTRUCT = DllStructCreate("hwnd hWindowMenu;uint idFirstChild")

$tWndClassEx = DllStructCreate($tmWNDCLASSEX)
$hWndProc = DllCallbackRegister("MDIClientProc", "lresult", "hwnd;uint;wparam;lparam")
$hInstance = _WinAPI_GetModuleHandle(0)
$hCursor = _WinAPI_LoadCursor(0, $IDC_ARROW)
$tIcon = DllStructCreate('ptr;ptr')
_WinAPI_ExtractIconEx('shell32.dll', 210, DllStructGetPtr($tIcon, 1), DllStructGetPtr($tIcon, 2), 1)
$hBrush = _WinAPI_CreateSolidBrush(_WinAPI_GetSysColor($COLOR_3DFACE))
$tClass = DllStructCreate('wchar[' & StringLen($sClass) + 1 & ']')
DllStructSetData($tClass, 1, $sClass)

DllStructSetData($tWndClassEx, "Size", DllStructGetSize($tWndClassEx))
DllStructSetData($tWndClassEx, "Style", BitOR($CS_HREDRAW, $CS_VREDRAW, $CS_BYTEALIGNWINDOW))
DllStructSetData($tWndClassEx, "hWndProc", DllCallbackGetPtr($hWndProc))
DllStructSetData($tWndClassEx, "ClsExtra", 0)
DllStructSetData($tWndClassEx, "WndExtra", 0)
DllStructSetData($tWndClassEx, "hInstance", $hInstance)
DllStructSetData($tWndClassEx, "hIcon", DllStructGetData($tIcon, 1))
DllStructSetData($tWndClassEx, "hCursor", $hCursor)
DllStructSetData($tWndClassEx, "hBackground", $hBrush)
DllStructSetData($tWndClassEx, "MenuName", 0)
DllStructSetData($tWndClassEx, "ClassName", DllStructGetPtr($tClass))
DllStructSetData($tWndClassEx, "hIconSm", DllStructGetData($tIcon, 2))

_WinAPI_RegisterClassEx($tWndClassEx)

$hForm = GUICreate("", 800, 500)
GUISetState()

$MDIClient = DllCall('user32.dll', 'hwnd', 'CreateWindowExW', 'dword', 0, 'wstr', $sClass, 'str', $sName, 'dword', BitOR($WS_CHILD, $WS_VISIBLE, $WS_OVERLAPPEDWINDOW), 'int', 50, 'int', 50, 'int', 400, 'int', 200, 'hwnd', $hForm, 'hwnd', 0, 'hwnd', $hInstance, 'ptr', DllStructGetPtr($tCLIENTCREATESTRUCT))
$MDIClient = $MDIClient[0]

While 1
	Switch GUIGetMsg()
           Case $GUI_EVENT_CLOSE
               GUIDelete()
               Exit
	EndSwitch
WEnd

_WinAPI_UnregisterClass($sClass, $hInstance)
DllCallbackFree($hWndProc)

_WinAPI_DestroyCursor($hCursor)
For $i = 1 To 2
    _WinAPI_DestroyIcon(DllStructGetData($tIcon, $i))
Next

Func MDIClientProc($hWnd, $iMsg, $wParam, $lParam)
	Switch $iMsg
	    Case $WM_CREATE
		Case $WM_PAINT
			$tPAINTSTRUCT = DllStructCreate("hwnd hDC;int fErase;dword rPaint[4];int fRestore;int fIncUpdate;byte rgbReserved[32];")
			$hDC = _WinAPI_BeginPaint($hWnd, $tPAINTSTRUCT)
			_WinAPI_EndPaint($hWnd, $tPAINTSTRUCT)
			Return 0 		
		Case $WM_SIZE 
        Case $WM_DESTROY 
			MsgBox(64, "MDIClient", "Закрыли MDI окно")
	EndSwitch	
	Return _WinAPI_DefMDIChildProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc	

Func _WinAPI_DefMDIChildProc($hWnd, $iMsg, $wParam, $lParam)
    Local $aResult = DllCall("user32.dll", "lresult", "DefMDIChildProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)
	If @error Then Return SetError(@error, @extended, 0)
	Return $aResult[0]
EndFunc
 

gregaz

AutoIT Гуру
Сообщения
1 166
Репутация
298
После закрытия главного окна остается 50% загрузка процессора.
Надо бы добавить перед закрытием скрипта :
Код:
Case $GUI_EVENT_CLOSE
     GUIDelete()
     Exit
 
Автор
Viktor1703

Viktor1703

AutoIT Гуру
Сообщения
1 535
Репутация
408
Спасибо, исправил. :smile:
 
Верх