Sign in to follow this  
Followers 0
zeffy

Question about CreateWindowEx

8 posts in this topic

So basically, I need to use _WinAPI_CreateWindowEx() to make a window with a specific class name, to receive WM_COPYDATA messages from another program, and process the information with my autoit script. I have no idea where to even start with this, could someone point me in the right direction?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

what's so hard about searching the forum for CreateWindowEx (3 pages of results) and WM_COPYDATA (6 pages of results)?

Hint: look on first page of results for CreateWindowEx

Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

hur dur use the seach function

I have already read dozens of topics on this subject, none of them had the specific information that I asked about. Thanks for not being helpful in the slightest, next time consider contributing to a thread before you post.

Edited by zeffy

Share this post


Link to post
Share on other sites

I love how helpful everyone is on this forum!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Anyone feeling helpful?

Edited by zeffy

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

#Include <WinAPIEx.au3>
#Include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Global Const $CW_USEDEFAULT = 0x80000000

Global Const $sClass = 'MyWindowClass'
Global Const $sName = 'MyProg'

Global $tWCEX, $tClass, $hWnd, $hProc, $hInstance, $Text = False

OnAutoItExitRegister('AutoItExit')

$hInstance = _WinAPI_GetModuleHandle(0)
$hProc = DllCallbackRegister('_WndProc', 'lresult', 'hwnd;uint;wparam;lparam')
$tClass = DllStructCreate('wchar[' & StringLen($sClass) + 1 & ']')
DllStructSetData($tClass, 1, $sClass)
$tWCEX = DllStructCreate($tagWNDCLASSEX)
DllStructSetData($tWCEX, 'Size', DllStructGetSize($tWCEX))
DllStructSetData($tWCEX, 'Style', 0)
DllStructSetData($tWCEX, 'hWndProc', DllCallbackGetPtr($hProc))
DllStructSetData($tWCEX, 'ClsExtra', 0)
DllStructSetData($tWCEX, 'WndExtra', 0)
DllStructSetData($tWCEX, 'hInstance', $hInstance)
DllStructSetData($tWCEX, 'hIcon', 0)
DllStructSetData($tWCEX, 'hCursor', 0)
DllStructSetData($tWCEX, 'hBackground', 0)
DllStructSetData($tWCEX, 'MenuName', 0)
DllStructSetData($tWCEX, 'ClassName', DllStructGetPtr($tClass))
DllStructSetData($tWCEX, 'hIconSm', 0)
_WinAPI_RegisterClassEx($tWCEX)

$hWnd = _WinAPI_CreateWindowEx(0, $sClass, $sName, 0, $CW_USEDEFAULT, $CW_USEDEFAULT, $CW_USEDEFAULT, $CW_USEDEFAULT, 0)

While 1
    Sleep(100)
    If $Text Then
        MsgBox(262144, '', $Text)
        $Text = 0
    EndIf
WEnd

Func _WinAPI_DefWindowProcW($hWnd, $iMsg, $wParam, $lParam)

    Local $Ret = DllCall('user32.dll', 'lresult', 'DefWindowProcW', 'hwnd', $hWnd, 'uint', $iMsg, 'wparam', $wParam, 'lparam', $lParam)

    If @error Then
        Return SetError(1, 0, 0)
    EndIf
    Return $Ret[0]
EndFunc   ;==>_WinAPI_DefWindowProcW

Func _WndProc($hWnd, $iMsg, $wParam, $lParam)
    Switch $iMsg
        Case $WM_COPYDATA

            Local $tCOPYDATA = DllStructCreate('ulong_ptr;dword;ptr', $lParam)
            Local $tData = DllStructCreate('wchar[' & DllStructGetData($tCOPYDATA, 2) & ']', DllStructGetData($tCOPYDATA, 3))

            $Text = DllStructGetData($tData, 1)
            Return 1
    EndSwitch
    Return _WinAPI_DefWindowProcW($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_WndProc

Func AutoItExit()
    _WinAPI_DestroyWindow($hWnd)
    _WinAPI_UnregisterClass($sClass, $hInstance)
    DllCallbackFree($hProc)
EndFunc   ;==>AutoItExit

Send a messages with the following code:

#Include <WindowsConstants.au3>

While 1
    $Text = InputBox('', 'String to send', '', '', 300, 130, 200, 200)
    If Not $Text Then
        Exit
    EndIf
    $hWnd = WinGetHandle('[CLASS:MyWindowClass;TITLE:MyProg]')
    $tCOPYDATA = DllStructCreate('ulong_ptr;dword;ptr')
    $tData = DllStructCreate('wchar[' & StringLen($Text) + 1 & ']')
    DllStructSetData($tData, 1, $Text)
    DllStructSetData($tCOPYDATA, 2, DllStructGetSize($tData))
    DllStructSetData($tCOPYDATA, 3, DllStructGetPtr($tData))
    DllCall('user32.dll', 'lresult', 'SendMessage', 'hwnd', $hWnd, 'uint', $WM_COPYDATA, 'ptr', 0, 'ptr', DllStructGetPtr($tCOPYDATA))
WEnd
Edited by Yashied

Share this post


Link to post
Share on other sites

Wow, incredible! Something new to study about WM_COPYDATA! Thanks


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Very nice job Yashied. I was curious about implementing a windows procedure before, its nice to see a working example.

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