PostMessage_ to another application window input string

Just starting out? Need help? Post your questions and find answers here.
ehowington
Enthusiast
Enthusiast
Posts: 115
Joined: Sat Sep 12, 2009 3:06 pm

PostMessage_ to another application window input string

Post 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?
User avatar
Kiffi
Addict
Addict
Posts: 1486
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: PostMessage_ to another application window input string

Post 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
Hygge
ehowington
Enthusiast
Enthusiast
Posts: 115
Joined: Sat Sep 12, 2009 3:06 pm

Re: PostMessage_ to another application window input string

Post by ehowington »

is it possible to send this to a editor or string form input etc?
ehowington
Enthusiast
Enthusiast
Posts: 115
Joined: Sat Sep 12, 2009 3:06 pm

Re: PostMessage_ to another application window input string

Post by ehowington »

and any alternatives to spy++ to see detailed information to a applications forms etc?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Re: PostMessage_ to another application window input string

Post 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?
BERESHEIT
ehowington
Enthusiast
Enthusiast
Posts: 115
Joined: Sat Sep 12, 2009 3:06 pm

Re: PostMessage_ to another application window input string

Post 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.
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: PostMessage_ to another application window input string

Post 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
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
PureLeo
Enthusiast
Enthusiast
Posts: 221
Joined: Fri Jan 29, 2010 1:05 pm
Location: Brazil

Re: PostMessage_ to another application window input string

Post by PureLeo »

You can easily do this with AutoIt+Purebasic
ehowington
Enthusiast
Enthusiast
Posts: 115
Joined: Sat Sep 12, 2009 3:06 pm

Re: PostMessage_ to another application window input string

Post by ehowington »

got a link that works for autoit search pulls up a few results but seems link is dead for download etc.
User avatar
PureLeo
Enthusiast
Enthusiast
Posts: 221
Joined: Fri Jan 29, 2010 1:05 pm
Location: Brazil

Re: PostMessage_ to another application window input string

Post 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
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: PostMessage_ to another application window input string

Post by Kwai chang caine »

Great PureLeo ...thanks :shock:
ImageThe happiness is a road...
Not a destination
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: PostMessage_ to another application window input string

Post by ts-soft »

PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
PureLeo
Enthusiast
Enthusiast
Posts: 221
Joined: Fri Jan 29, 2010 1:05 pm
Location: Brazil

Re: PostMessage_ to another application window input string

Post by PureLeo »

True. That's a better solution :)
ehowington
Enthusiast
Enthusiast
Posts: 115
Joined: Sat Sep 12, 2009 3:06 pm

Re: PostMessage_ to another application window input string

Post 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?
ehowington
Enthusiast
Enthusiast
Posts: 115
Joined: Sat Sep 12, 2009 3:06 pm

Re: PostMessage_ to another application window input string

Post by ehowington »

#Include <GuiTreeView.au3>

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