| 1 | #include <WinAPIRes.au3>
|
|---|
| 2 | #include <WinAPISys.au3>
|
|---|
| 3 | #include <WindowsConstants.au3>
|
|---|
| 4 |
|
|---|
| 5 | Opt( "MustDeclareVars", 1 )
|
|---|
| 6 |
|
|---|
| 7 | Global $bExit = False
|
|---|
| 8 |
|
|---|
| 9 | Example()
|
|---|
| 10 |
|
|---|
| 11 | Func Example()
|
|---|
| 12 | Local Const $sClass = "MyWindowClass"
|
|---|
| 13 | Local Const $sName = "_WinAPI_RegisterClassEx"
|
|---|
| 14 |
|
|---|
| 15 | ; Get module handle for the current process
|
|---|
| 16 | Local $hInstance = _WinAPI_GetModuleHandle( 0 )
|
|---|
| 17 |
|
|---|
| 18 | ; Create a class cursor
|
|---|
| 19 | Local $hCursor = _WinAPI_LoadCursor( 0, 32512 ) ; IDC_ARROW
|
|---|
| 20 |
|
|---|
| 21 | ; Create a class icons (large and small)
|
|---|
| 22 | Local $tIcons = DllStructCreate( "ptr;ptr" )
|
|---|
| 23 | _WinAPI_ExtractIconEx( @SystemDir & "\shell32.dll", 130, DllStructGetPtr( $tIcons, 1 ), DllStructGetPtr( $tIcons, 2 ), 1 )
|
|---|
| 24 | Local $hIcon = DllStructGetData( $tIcons, 1 )
|
|---|
| 25 | Local $hIconSm = DllStructGetData( $tIcons, 2 )
|
|---|
| 26 |
|
|---|
| 27 | ; Create DLL callback function (window procedure)
|
|---|
| 28 | Local $pWinProc = DllCallbackGetPtr( DllCallbackRegister( "WinProc", "lresult", "hwnd;uint;wparam;lparam" ) )
|
|---|
| 29 |
|
|---|
| 30 | ; Create and fill $tagWNDCLASSEX structure
|
|---|
| 31 | Local $tWCEX = DllStructCreate( $tagWNDCLASSEX & ";wchar szClassName[" & ( StringLen( $sClass ) + 1 ) & "]" )
|
|---|
| 32 | DllStructSetData( $tWCEX, "Size", DllStructGetPtr( $tWCEX, "szClassName" ) - DllStructGetPtr( $tWCEX ) )
|
|---|
| 33 | DllStructSetData( $tWCEX, "Style", 0 )
|
|---|
| 34 | DllStructSetData( $tWCEX, "hWndProc", $pWinProc )
|
|---|
| 35 | DllStructSetData( $tWCEX, "ClsExtra", 0 )
|
|---|
| 36 | DllStructSetData( $tWCEX, "WndExtra", 0 )
|
|---|
| 37 | DllStructSetData( $tWCEX, "hInstance", $hInstance )
|
|---|
| 38 | DllStructSetData( $tWCEX, "hIcon", $hIcon )
|
|---|
| 39 | DllStructSetData( $tWCEX, "hCursor", $hCursor )
|
|---|
| 40 | DllStructSetData( $tWCEX, "hBackground", _WinAPI_CreateSolidBrush( _WinAPI_GetSysColor( $COLOR_3DFACE ) ) )
|
|---|
| 41 | DllStructSetData( $tWCEX, "MenuName", 0 )
|
|---|
| 42 | DllStructSetData( $tWCEX, "ClassName", DllStructGetPtr( $tWCEX, "szClassName" ) )
|
|---|
| 43 | DllStructSetData( $tWCEX, "hIconSm", $hIconSm )
|
|---|
| 44 | DllStructSetData( $tWCEX, "szClassName", $sClass )
|
|---|
| 45 |
|
|---|
| 46 | ; Register a window class
|
|---|
| 47 | _WinAPI_RegisterClassEx( $tWCEX )
|
|---|
| 48 |
|
|---|
| 49 | ; Create a window
|
|---|
| 50 | Local $hWnd = _WinAPI_CreateWindowEx( 0, $sClass, $sName, BitOR( $WS_CAPTION, $WS_POPUPWINDOW, $WS_VISIBLE ), ( @DesktopWidth - 826 ) / 2, ( @DesktopHeight - 584 ) / 2, 826, 584, 0 )
|
|---|
| 51 | MsgBox ($MB_SYSTEMMODAL, "", WinGetTitle($hWnd))
|
|---|
| 52 |
|
|---|
| 53 | ; Main msg loop
|
|---|
| 54 | While Sleep(10)
|
|---|
| 55 | If $bExit Then ExitLoop
|
|---|
| 56 | WEnd
|
|---|
| 57 |
|
|---|
| 58 | ; Unregister window class and release resources
|
|---|
| 59 | _WinAPI_UnregisterClass( $sClass, $hInstance )
|
|---|
| 60 | _WinAPI_DestroyCursor( $hCursor )
|
|---|
| 61 | _WinAPI_DestroyIcon( $hIcon )
|
|---|
| 62 | _WinAPI_DestroyIcon( $hIconSm )
|
|---|
| 63 | EndFunc
|
|---|
| 64 |
|
|---|
| 65 | ; Window procedure
|
|---|
| 66 | Func WinProc( $hWnd, $iMsg, $wParam, $lParam )
|
|---|
| 67 | Switch $iMsg
|
|---|
| 68 | Case $WM_CLOSE
|
|---|
| 69 | $bExit = True
|
|---|
| 70 | EndSwitch
|
|---|
| 71 | Return _WinAPI_DefWindowProcW( $hWnd, $iMsg, $wParam, $lParam )
|
|---|
| 72 | EndFunc
|
|---|