Page 1 of 2

PostMessage_ to another application window input string

Posted: Thu Jun 09, 2011 9:48 am
by ehowington
Was wondering if there a way to send string of text to another applications string input like PostMessage_(hWnd, #MyMessage, 0, 0)
how to do that exactly?

Re: PostMessage_ to another application window input string

Posted: Thu Jun 09, 2011 12:32 pm
by Kiffi
something like this?

Code: Select all

hwnd = FindWindow_(#Null, "Unbenannt - Editor") ; on english systems: "Untitled - Notepad"
If hwnd
  SendMessage_(hWnd, #WM_SETTEXT, 0, @"Hello World")
Else
  Debug "Notepad not found!"
EndIf
Greetings ... Kiffi

Re: PostMessage_ to another application window input string

Posted: Thu Jun 09, 2011 6:48 pm
by ehowington
is it possible to send this to a editor or string form input etc?

Re: PostMessage_ to another application window input string

Posted: Thu Jun 09, 2011 7:10 pm
by ehowington
and any alternatives to spy++ to see detailed information to a applications forms etc?

Re: PostMessage_ to another application window input string

Posted: Fri Jun 10, 2011 1:58 am
by netmaestro
So the receiving program isn't something you wrote (meaning you have no control over what gets done with the sent string) Is that right?

Re: PostMessage_ to another application window input string

Posted: Fri Jun 10, 2011 5:06 am
by ehowington
correct just need to send text to a sting input on a application not written by me or in purebasic however im not seeing a easy way to do this. this are just commands for this application.

Re: PostMessage_ to another application window input string

Posted: Fri Jun 10, 2011 7:16 am
by MachineCode
Kiffi's code changes Notepad's title bar. To send a string to the Notepad text area:

Code: Select all

hwnd = FindWindow_(#Null, "Untitled - Notepad")
If hwnd
  SendMessage_(GetWindow_(hwnd,#GW_CHILD), #WM_SETTEXT, 0, @"Hello World")
Else
  Debug "Notepad not found!"
EndIf

Re: PostMessage_ to another application window input string

Posted: Fri Jun 10, 2011 2:01 pm
by PureLeo
You can easily do this with AutoIt+Purebasic

Re: PostMessage_ to another application window input string

Posted: Sat Jun 11, 2011 2:56 am
by ehowington
got a link that works for autoit search pulls up a few results but seems link is dead for download etc.

Re: PostMessage_ to another application window input string

Posted: Sat Jun 11, 2011 3:46 am
by PureLeo
Did you try the official website?
http://www.autoitscript.com

It comes with a dll you can use with Purebasic, I have the header...

AutoIt3.pbi

Code: Select all

;///////////////////////////////////////////////////////////////////////////////
;//
;// AutoItX v3
;//
;// Copyright (C)1999-2008:
;//		- Jonathan Bennett <jon at autoitscript dot com>
;//		- See "AUTHORS.txt" For contributors.
;//
;// This file is part of AutoItX.  Use of This file And the AutoItX DLL is subject
;// To the terms of the AutoItX license details of which can be found in the helpfile.
;//
;// When using the AutoItX3.dll As a standard DLL This file contains the definitions,
;// And function declarations required To use the DLL And AutoItX3.lib file.
;//
;///////////////////////////////////////////////////////////////////////////////

;// Definitions
#AU3_INTDEFAULT = -2147483647	;// "Default" value For _some_ int parameters (largest negative number)

;//
;// NOTE: This DLL is now using Unicode strings.  Only a few functions also have an
;// ANSI version. If you require ANSI strings then please use an older version of AutoItX
;// Or ask about the subject on the forums at http://www.autoitscript.com/forum
;//

;//
;// nBufSize
;// When used For specifying the size of a resulting string buffer This is the number of CHARACTERS 
;// in that buffer, including the null terminator.  For example:
;//
;// WCHAR szBuffer[10];
;// AU3_ClipGetW(szBuffer, 10);
;//
;// The resulting string will be truncated at 9 characters With the the terminating null in the 10th.
;//


;///////////////////////////////////////////////////////////////////////////////
;// Exported functions
;///////////////////////////////////////////////////////////////////////////////
Define.l

Import "AutoItX3.lib"
	
AU3_Init();
AU3_error();

AU3_AutoItSetOption(szOption.s, nValue);

AU3_BlockInput(nFlag);

AU3_CDTray(szDrive.s, szAction.s);
AU3_ClipGet(*szClip, nBufSizex2);
AU3_ClipPut(szClip.s);
AU3_ControlClick(szTitle.s, szText.s, szControl.s, szButton.s, nNumClicks, nX=#AU3_INTDEFAULT, nY=#AU3_INTDEFAULT);
AU3_ControlCommand(szTitle.s, szText.s, szControl.s, szCommand.s, szExtra.s, *szResult, nBufSizex2);
AU3_ControlListView(szTitle.s, szText.s, szControl.s, szCommand.s, szExtra1.s, szExtra2.s, *szResult, nBufSizex2);
AU3_ControlDisable(szTitle.s, szText.s, szControl.s);
AU3_ControlEnable(szTitle.s, szText.s, szControl.s);
AU3_ControlFocus(szTitle.s, szText.s, szControl.s);
AU3_ControlGetFocus(szTitle.s, szText.s, *szControlWithFocus, nBufSizex2);
AU3_ControlGetHandle(szTitle.s, szText.s, szControl.s, *szRetText, nBufSizex2);
AU3_ControlGetPosX(szTitle.s, szText.s, szControl.s);
AU3_ControlGetPosY(szTitle.s, szText.s, szControl.s);
AU3_ControlGetPosHeight(szTitle.s, szText.s, szControl.s);
AU3_ControlGetPosWidth(szTitle.s, szText.s, szControl.s);
AU3_ControlGetText(szTitle.s, szText.s, szControl.s, *szControlText, nBufSizex2);
AU3_ControlHide(szTitle.s, szText.s, szControl.s);
AU3_ControlMove(szTitle.s, szText.s, szControl.s, nX, nY, nWidth=-1, nHeight=-1);
AU3_ControlSend(szTitle.s, szText.s, szControl.s, szSendText.s, nMode=0);
AU3_ControlSetText(szTitle.s, szText.s, szControl.s, szControlText.s);
AU3_ControlShow(szTitle.s, szText.s, szControl.s);
AU3_ControlTreeView(szTitle.s, szText.s, szControl.s, szCommand.s, szExtra1.s, szExtra2.s, *szResult, nBufSizex2);

AU3_DriveMapAdd(szDevice.s, szShare.s, nFlags, szUser.s, szPwd.s, *szResult, nBufSizex2);
AU3_DriveMapDel(szDevice.s);
AU3_DriveMapGet(szDevice.s, *szMapping, nBufSizex2);

AU3_IniDelete(szFilename.s, szSection.s, szKey.s);
AU3_IniRead(szFilename.s, szSection.s, szKey.s, szDefault.s, *szValue, nBufSizex2);
AU3_IniWrite(szFilename.s, szSection.s, szKey.s, szValue.s);
AU3_IsAdmin();

AU3_MouseClick(szButton.s="LEFT", nX=#AU3_INTDEFAULT, nY=#AU3_INTDEFAULT, nClicks=1, nSpeed=-1);
AU3_MouseClickDrag(szButton.s, nX1, nY1, nX2, nY2, nSpeed=-1);
AU3_MouseDown(szButton.s="LEFT");
AU3_MouseGetCursor();
AU3_MouseGetPosX();
AU3_MouseGetPosY();
AU3_MouseMove(nX, nY, nSpeed=-1);
AU3_MouseUp(szButton.s="LEFT");
AU3_MouseWheel(szDirection.s, nClicks);

AU3_Opt(szOption.s, nValue);

AU3_PixelChecksum(nLeft, nTop, nRight, nBottom, nStep=1);
AU3_PixelGetColor(nX, nY);
AU3_PixelSearch(nLeft, nTop, nRight, nBottom, nCol, nVar, nStep, *pPointResult.POINTS);
AU3_ProcessClose(szProcess.s);
AU3_ProcessExists(szProcess.s);
AU3_ProcessSetPriority(szProcess.s, nPriority);
AU3_ProcessWait(szProcess.s, nTimeout=0);
AU3_ProcessWaitClose(szProcess.s, nTimeout=0);
AU3_RegDeleteKey(szKeyname.s);
AU3_RegDeleteVal(szKeyname.s, szValuename.s);
AU3_RegEnumKey(szKeyname.s, nInstance, *szResult, nBufSizex2);
AU3_RegEnumVal(szKeyname.s, nInstance, *szResult, nBufSizex2);
AU3_RegRead(szKeyname.s, szValuename.s, *szRetText, nBufSizex2);
AU3_RegWrite(szKeyname.s, szValuename.s, szType.s, szValue.s);
AU3_Run(szRun.s, szDir.s="", nShowFlags=1);
AU3_RunAsSet(szUser.s, szDomain.s, szPassword.s, nOptions);
AU3_RunWait(szRun.s, szDir.s="", nShowFlags=1);

AU3_Send(szSendText.s, nMode=0);
AU3_SendA(szSendText.s, nMode=0);
AU3_Shutdown(nFlags);
AU3_Sleep(nMilliseconds);
AU3_StatusbarGetText(szTitle.s, szText.s, nPart, *szStatusText, nBufSizex2);

AU3_ToolTip(szTip.s, nX=#AU3_INTDEFAULT, nY=#AU3_INTDEFAULT);

AU3_WinActivate(szTitle.s, szText.s="");
AU3_WinActive(szTitle.s, szText.s="");
AU3_WinClose(szTitle, szText.s="");
AU3_WinExists(szTitle.s, szText.s="");
AU3_WinGetCaretPosX();
AU3_WinGetCaretPosY();
AU3_WinGetClassList(szTitle.s, szText.s, *szRetText, nBufSizex2);
AU3_WinGetClientSizeHeight(szTitle.s, szText.s="");
AU3_WinGetClientSizeWidth(szTitle.s, szText.s="");
AU3_WinGetHandle(szTitle.s, szText.s, *szRetText, nBufSizex2);
AU3_WinGetPosX(szTitle, szText.s="");
AU3_WinGetPosY(szTitle, szText.s="");
AU3_WinGetPosHeight(szTitle, szText.s="");
AU3_WinGetPosWidth(szTitle.s, szText.s="");
AU3_WinGetProcess(szTitle.s, szText.s, *szRetText, nBufSizex2);
AU3_WinGetState(szTitle.s, szText.s="");
AU3_WinGetText(szTitle, szText.s, *szRetText, nBufSizex2);
AU3_WinGetTitle(szTitle.s, szText.s, *szRetText, nBufSizex2);
AU3_WinKill(szTitle.s, szText.s="");
AU3_WinMenuSelectItem(szTitle.s, szText.s, szItem1.s, szItem2.s, szItem3.s, szItem4.s, szItem5.s, szItem6.s, szItem7.s, szItem8.s);
AU3_WinMinimizeAll();
AU3_WinMinimizeAllUndo();
AU3_WinMove(szTitle.s, szText.s, nX, nY, nWidth=-1, nHeight=-1);
AU3_WinSetOnTop(szTitle.s, szText.s, nFlag);
AU3_WinSetState(szTitle.s, szText.s, nFlags);
AU3_WinSetTitle(szTitle.s,szText.s, szNewTitle.s);
AU3_WinSetTrans(szTitle.s, szText.s, nTrans);

AU3_WinWait(szTitle.s, szText.s="", nTimeout=0);
AU3_WinWaitA(szTitle.s, szText.s="", nTimeout=0);
AU3_WinWaitActive(szTitle.s, szText.s="", nTimeout=0);
AU3_WinWaitActiveA(szTitle.s, szText.s="", nTimeout=0);
AU3_WinWaitClose(szTitle.s, szText.s="", nTimeout=0);
AU3_WinWaitCloseA(szTitle.s, szText.s="", nTimeout=0);
AU3_WinWaitNotActive(szTitle.s, szText.s="", nTimeout=0);
AU3_WinWaitNotActiveA(szTitle.s, szText.s="", nTimeout=0);

EndImport
Little example:

Code: Select all

CompilerIf #PB_Compiler_Unicode
CompilerElse
	MessageRequester("AutoIt","AutoIt needs Unicode mode.")
	End
CompilerEndIf

IncludeFile "AutoIt3.pbi"

AU3_Run("notepad.exe", "", 1);
AU3_WinWaitActive("Untitled -", "", 0);
AU3_Opt("sendkeydelay",100)
AU3_Send("Hello{!}");

*hwnd = AllocateMemory(100)
AU3_WinGetHandle("Untitled -","",*hwnd,50)

*szText = AllocateMemory(100)
AU3_StatusbarGetText("Untitled -", "", 2, *szText , 50);
MessageBox_(Val("$"+PeekS(*hwnd)), PeekS(*szText), "Text:", #MB_OK);
Don't remember if it comes with Autoit3.lib or if you need to make it yourself using polib

Re: PostMessage_ to another application window input string

Posted: Sun Jun 12, 2011 9:01 pm
by Kwai chang caine
Great PureLeo ...thanks :shock:

Re: PostMessage_ to another application window input string

Posted: Sun Jun 12, 2011 9:09 pm
by ts-soft

Re: PostMessage_ to another application window input string

Posted: Mon Jun 13, 2011 1:15 am
by PureLeo
True. That's a better solution :)

Re: PostMessage_ to another application window input string

Posted: Thu Jul 14, 2011 8:10 am
by ehowington
ts-soft have a example to target a string input if you know the proc id or some other method using that library?

Re: PostMessage_ to another application window input string

Posted: Mon Oct 31, 2011 7:04 pm
by ehowington
#Include <GuiTreeView.au3>

can you include the other .au3 ??????????