Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clipboard Paste

Status
Not open for further replies.

BJZeak

Programmer
May 3, 2008
230
CA
Not sure what I am doing wrong:

Attempting to force a PASTE into another application

If I have the HWND of the application and force that application to focus using API calls should I not be able to use either sendkeys and or sendmessage to force a PASTE?

I am certain I have the correct HWND because the application does come into focus and is sitting on a textbox as the default control ... I can manually paste from the keyboard using ctrl-v but neither of the code attempts appear to work


Public Declare Function SetFocus Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function BringWindowToTop Lib "user32" (ByVal hWnd As Long) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

dim AppHwnd as Long
dim apiRTN AS Long

AppHwnd = AppObj.HWND

apiRTN = BringWindowToTop( AppHwnd )
apiRTN = SetFocus ( AppHwnd )

Const WM_PASTE = &H302

apiRTN = SendMessage ( AppHwnd, WM_PASTE, 0 , BYVAL 0& )

OR

SendKeys "^V",0





 
What is AppObj ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
This is an object to the application being automated ... as stated the applications HWND is correct as calls to bringtofront and setfocus brings the app window forward and in focus. As that part of the code worked I expected it wasn't needed for the question.

I downloaded an evaluation copy of Macro Express 3 which works ... I just expected that it should be simple to also do this in code. The application has only one textbox and it is in focus ... it manually accepts a Ctrl-V to paste the contents of the clipboard ... Macro Express has a Clipboard Paste command which does this.

my code declares a window obj, opens the application, gets the HWND of the application window, brings it forward, sets focus then does the paste which fails to work.


 
Again, WHICH APPLICATION ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Sorry for opening this topic before doing more research.

Reading through many threads on this topic it seems that there is an issue with "Automation" being used for unscrupulous ends which I can accept would be why no one in the know wants to make it easier to get answers.

Although considering there are plenty of applications available that can provide "Automation Tools" anyone can currently purchase and create a potential automation solution with little or no programming knowledge ... the 2 demo apps I tried quickly provided everything I needed to do ... lets just say my curiousity kicked in along with my passion for "Home Made Solutions".

Bottom line where software is involved almost anything is possible.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top