flat assembler
Message board for the users of flat assembler.
Index
> Windows > Clipboard: copy text from window |
Author |
|
bitRAKE 07 Jan 2019, 18:07
https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-openclipboard
Quote: If an application calls OpenClipboard with hwnd set to NULL, EmptyClipboard sets the clipboard owner to NULL; this causes SetClipboardData to fail. Code: hWndTextW_To_ClipBoard: virtual at rbp-.FRAME rq 4 ; shadow forward rb (16-(($-$$) AND 15)) AND 15 ; only if padding needed .FRAME := $-$$ rq 1 ; saved RBP rq 1 ; return address .hWnd rq 1 ; our shadow .hMem rq 1 ; our shadow .pBuffer rq 1 ; our shadow .cchBuffer rq 1 ; our shadow end virtual enter .FRAME,0 mov [.hWnd],rcx call [GetWindowTextLengthW] ; note: can be greater than number of characters xchg ecx,eax jrcxz .return ; include null lea rdx,[rcx+1] mov [.cchBuffer],rdx push 2 ; GMEM_MOVEABLE pop rcx shl edx,1 ; widechar bytes call [GlobalAlloc] ; handle to memory object xchg rcx,rax jrcxz .return mov [.hMem],rcx call [GlobalLock] mov [.pBuffer],rax xchg r9,rax mov r8,[.cchBuffer] push 13 ; WM_GETTEXT pop rdx mov rcx,[.hWnd] call [SendMessageW] ; pass control to clipboard mov rcx,[.hMem] call [GlobalUnlock] xor ecx,ecx ; current task call [OpenClipboard] call [EmptyClipboard] mov rdx,[.hMem] push 13 ; CF_UNICODETEXT pop rcx call [SetClipboardData] call [CloseClipboard] .return: leave retn If your window handles clipboard messages then the code is simply: Code: mov rcx,[.hWnd] call [OpenClipboard] call [EmptyClipboard] xor edx,edx push 1 ; CF_TEXT pop rcx call [SetClipboardData] call [CloseClipboard] _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
07 Jan 2019, 18:07 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.