Sign in to follow this  
Followers 0
Greenhorn

CreateWindow() Function

5 posts in this topic

#1 ·  Posted (edited)

Moin Moin,

I took a deeper look into the _WinAPI_CreateWindowEx and so I tried the same just with CreateWindow().

But it doesn't work, I get always NULL returned ...

Please, could anybody say me why the function fails ?

#include-once
#include <GuiConstants.au3>
#Include <WinAPI.au3>


$hWndMain    = GUICreate("My Own Created Button", 300, 200)
GUISetBkColor(0x000000)

; this here doesn't work, why ?
$hWndButton = CreateWindow('BUTTON', 'CheckBox', _
                        BitOr($WS_CHILD, $WS_VISIBLE, $BS_AUTOCHECKBOX), _
                        90, 50, 120, 30, _
                        $hWndMain, 6, _
                        GetWindowLong($hWndMain, $GWL_HINSTANCE))

#cs
; this works, so why doesn't CreateWindow work ?
$hWndButton = _WinAPI_CreateWindowEx($WS_EX_DLGMODALFRAME , 'BUTTON', 'CheckBox', _
                                    BitOr($WS_CHILD, $WS_VISIBLE, $BS_AUTOCHECKBOX), _
                                    90, 50, 120, 30, _
                                    $hWndMain, 5, _
                                    GetWindowLong($hWndMain, $GWL_HINSTANCE))
#ce

GUISetState()

While True

    Switch GUIGetMsg()
        Case -3
            Exit
        Case 5
            MsgBox(4096, '', 'This function works fine ...')
        Case 6
            MsgBox(4096, '', "Why can't I be visible ...")
    EndSwitch

WEnd

;========================================================================================
;========================================================================================
Func CreateWindow($sClassName, $sWindowName, $iStyle, $iX, $iY, $iWidth, $iHeight, $hWndParent = 0, $hMenu = 0, $hInstance = 0, $pParam = 0)   
    Local $aResult
    
    If $hInstance = 0 Then $hInstance = _WinAPI_GetModuleHandle("")
    $aResult = DllCall("User32.dll", "hwnd", "CreateWindow", "str",  $sClassName, _
                                                             "str",  $sWindowName, _
                                                             "int",  $iStyle, _
                                                             "int",  $iX, _
                                                             "int",  $iY, _
                                                             "int",  $iWidth, _
                                                             "int",  $iHeight, _
                                                             "hwnd", $hWndParent, _
                                                             "hwnd", $hMenu, _
                                                             "hwnd", $hInstance, _
                                                             "ptr",  $pParam)
    _WinAPI_Check("CreateWindow", ($aResult[0] = 0), 0, True)
    Return $aResult[0]
EndFunc
;========================================================================================
;========================================================================================
Func GetWindowLong($hWnd, $iIndex)

    Local $aResult
    $aResult = DllCall('user32.dll', 'int', 'GetWindowLong', 'hwnd', $hWnd, 'int', $iIndex)
;    _ArrayDisplay($aResult)
    GetLastError()

    Return $aResult[0]

EndFunc
Func GetLastError()

    Local $aResult
    $aResult = DllCall('Kernel32.dll', 'int', 'GetLastError')
;    _ArrayDisplay($aResult)
    Return $aResult[0]

EndFunc

Thanx for pay attention to this topic.

Greetz

Greenhorn

Edited by Greenhorn

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

There is no "CreateWindow" in user32.dll. Get yourself a dump of the exports of user32.dll and you'll see only CreateWindowExA and CreateWindowExW (unicode and non unicode). CreateWindow is actually a macro for CreateWindowEx with the extended styles parameter set to 0. Maybe someone can correct me though, as I'm not 100% sure.

Edited by covaks

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You could try this:

Global $hMYGUI = _CreateWindowEx("My Window Name")
_GUISetState($hMYGUI)
Sleep(30000)


Func _GUISetState($hWnd, $iState = @SW_SHOW)
    Return WinSetState($hWnd, "", $iState)
EndFunc

Func _CreateWindowEx($sWinName, $sClass = "AutoIt v3 GUI", $sText = "", $iXPos = -1, $iYPos = -1, _
        $iWidth = -1, $iHeight = -1, $iStyle = -1, $iExStyle = -1, $hParent = 0, $hMenu = 0, $hInstance = 0, $pParam = 0)
    
    If $iXPos = -1 Or $iXPos = Default Then $iXPos = (@DesktopWidth - 400) / 2
    If $iYPos = -1 Or $iYPos = Default Then $iYPos = (@DesktopHeight - 300) / 2
    If $iWidth = -1 Or $iWidth = Default Then $iWidth = 400
    If $iHeight = -1 Or $iHeight = 0 Then $iHeight = 300
    If $iExStyle = -1 Or $iExStyle = Default Then $iExStyle = 0
    If $iStyle = -1 Or $iStyle = Default Then $iStyle = BitOr(0x00020000, 0x00010000, 0x00C00000, 0x00040000, 0x80000000, 0x0080000)
    If $hParent <> 0 And IsHWnd($hParent) = 0 Then $hParent = WinGetHandle($hParent)
    
    If $hParent And $hInstance = 0 Then
        $hInstance = DllCall("USER32.DLL", "long", "GetWindowLong", "hwnd", $hParent, "int", -6)
        If @error Then Return SetError(1, @error, 0)
        $hInstance = $hInstance[0]
    EndIf
    
    Local $aCWEX = DllCall("USER32.DLL", "hwnd", "CreateWindowEx", "long", $iExStyle, "str", $sClass, "str", $sText, _
                        "long", $iStyle, "int", $iXPos, "int", $iYPos, "int", $iWidth, "int", $iHeight, _
                        "hwnd", $hParent, "hwnd", $hMenu, "long", $hInstance, "ptr", $pParam)

    If @error Then Return SetError(2, @error, 0)
    Return $aCWEX[0]
EndFunc

Edit:

Just a quick note... You'll need to use the CallWindowProc/RegisterClassEx to do different Class names than what have already been registered... I didn't have enough time to even play with those and their pointers.... So Next??... lol

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

There is no "CreateWindow" in user32.dll. Get yourself a dump of the exports of user32.dll and you'll see only CreateWindowExA and CreateWindowExW (unicode and non unicode). CreateWindow is actually a macro for CreateWindowEx with the extended styles parameter set to 0. Maybe someone can correct me though, as I'm not 100% sure.

http://msdn2.microsoft.com/en-us/library/m...679(VS.85).aspx

Greetz

Greenhorn

Share this post


Link to post
Share on other sites

Regardless of what MSDN says, I get @error=3 ("function" not found in the DLL file) returned from that DllCall in your example. There is no such function exported from user32.dll.

And even if it were, consider that in WinAPI, if there are two versions of some function - one "simple" and one "Ex", the "simple" one is just a wrapper for Ex function, which ends up being called anyway, the only difference is that system fills in some parameters for you. So why bother... stick to CreateWindowEx.


"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0