Skip to content
⌘ NSIS Forum Archive

Copy to clipboard and paste from that

7 posts

r2du-soft#

Copy to clipboard and paste from that

hi
i copy a text to clipbord with this code:

Section
Push "hello"
Call CopyToClipboard
SectionEnd


Function CopyToClipboard
Exch $0 ;input string
Push $1
Push $2
System::Call 'user32::OpenClipboard(i 0)'
System::Call 'user32::EmptyClipboard()'
StrLen $1 $0
IntOp $1 $1 + 1
System::Call 'kernel32::GlobalAlloc(i 2, i r1) i.r1'
System::Call 'kernel32::GlobalLock(i r1) i.r2'
System::Call 'kernel32::lstrcpyA(i r2, t r0)'
System::Call 'kernel32::GlobalUnlock(i r1)'
System::Call 'user32::SetClipboardData(i 1, i r1)'
System::Call 'user32::CloseClipboard()'
Pop $2
Pop $1
Pop $0
FunctionEnd
now "hello" word is in windows clipboard,i can paste that with mouse in a notepad or in a application textbox....

but i need to a code for write clipboard history "hello" to a text box sample Function CopyToClipboard....
i search in web but cant find any code to do it..
now i focus to a text box and want after open my app,windows clipboard text write to that textbot.
Thanks
r2du-soft#
Originally Posted by Anders View Post
Have you tried sending the WM_PASTE message to the text control?
Yes,m try but any codes not works 🙁
i focus to another application textbox and i want paste clipboard to that textbox,not in my application textbox
Anders#
Originally Posted by r2du-soft View Post
Yes,m try but any codes not works 🙁
i focus to another application textbox and i want paste clipboard to that textbox,not in my application textbox
Post the code where you do FindWindow + SendMessage and maybe we can help you fix it...
jr2k5#
!include StrFunc.nsh
!include nsDialogs.nsh
!include LogicLib.nsh

Name "CopyToClipboard"
OutFile CopyToClipboard.exe
RequestExecutionLevel user

Section
Push "Help"
Call CopyToClipboard
SectionEnd

Function CopyToClipboard
Exch $0 ;input string
Push $1
Push $2
System::Call 'user32::OpenClipboard(i 0)'
System::Call 'user32::EmptyClipboard()'
StrLen $1 $0
IntOp $1 $1 + 1
System::Call 'kernel32::GlobalAlloc(i 2, i r1) i.r1'
System::Call 'kernel32::GlobalLock(i r1) i.r2'
System::Call 'kernel32::lstrcpyA(i r2, t r0)'
System::Call 'kernel32::GlobalUnlock(i r1)'
System::Call 'user32::SetClipboardData(i 1, i r1)'
System::Call 'user32::CloseClipboard()'
Pop $2
Pop $1
Pop $0
FunctionEnd
I did the same script above, but when I run the script, copy only the first digit .... Example: "Help" .... saved to the clipboard just the "H"
Can someone help me please!... What is wrong?
Anders#
Originally Posted by jr2k5 View Post
I did the same script above, but when I run the script, copy only the first digit .... Example: "Help" .... saved to the clipboard just the "H"
Can someone help me please!... What is wrong?
It fails because you took some code you found somewhere and it was not designed for Unicode installers but you are creating a Unicode installer. Next time you post example code make sure the example code actually has the problem in the first place! The only exception to this would be is if you are using the unofficial Unicode fork but then you should be asking them for help or at least mention that you are using it!

Try this:
Function CopyToClipboard
Exch $0 ;input string
Push $1
Push $2
System::Call 'user32::OpenClipboard(i 0)'
System::Call 'user32::EmptyClipboard()'
StrLen $1 $0
IntOp $1 $1 + 1
!if "${NSIS_CHAR_SIZE}" > 1
IntOp $1 $1 * ${NSIS_CHAR_SIZE}
!endif
System::Call 'kernel32::GlobalAlloc(i 2, i r1) i.r1'
System::Call 'kernel32::GlobalLock(i r1) i.r2'
!if "${NSIS_CHAR_SIZE}" < 2
System::Call 'kernel32::lstrcpy(i r2, t r0)'
System::Call 'kernel32::GlobalUnlock(i r1)'
System::Call 'user32::SetClipboardData(i 1, i r1)'
!else
System::Call 'kernel32::lstrcpyW(i r2, w r0)'
System::Call 'kernel32::GlobalUnlock(i r1)'
System::Call 'user32::SetClipboardData(i 13, i r1)'
!endif
System::Call 'user32::CloseClipboard()'
Pop $2
Pop $1
Pop $0
FunctionEnd 
jr2k5#
Originally Posted by Anders View Post
It fails because you took some code you found somewhere and it was not designed for Unicode installers but you are creating a Unicode installer. Next time you post example code make sure the example code actually has the problem in the first place! The only exception to this would be is if you are using the unofficial Unicode fork but then you should be asking them for help or at least mention that you are using it!
Now is working!

Thanks Anders 🙂