News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

PostMessage Control

Started by bomz, July 02, 2011, 12:53:56 PM

Previous topic - Next topic

bomz

Notepad understand all methods. Alkepad need SENDKEY VK_RETURN instead of WM_CHAR VK_RETURN. Notepad2 need corret back
WORD need SENDKEY CTRL+V or POSTMESSAGE

only notepad full correct all other programs do as it's authors do

dedndave

you do not use WM_PASTE to place data into the clipboard   :bg
use SetClipboardData   :U

dedndave

SetClpBdTxt PROTO :DWORD,:DWORD

;--------------------------------------------------------------------

        OPTION  PROLOGUE:None
        OPTION  EPILOGUE:None

SetClpBdTxt PROC lpString:DWORD,dwLength:DWORD

;Set Clipboard Text
;DednDave, 12-2010

;EAX returns:
;  0 success
;  1 SetClipboardData failed
;  2 GlobalAlloc failed
;  3 OpenClipboard failed

        push    0
        CALL    OpenClipboard
        or      eax,eax
        push    3                            ;return status = 3
        jz      exit_2

        mov     eax,[esp+12]                 ;dwLength
        pop     edx
        add     eax,16
        INVOKE  GlobalAlloc,GMEM_MOVEABLE or GMEM_DDESHARE,eax
        or      eax,eax
        push    2                            ;return status = 2
        jz      exit_1

        pop     edx
        push    eax
        CALL    EmptyClipboard
        INVOKE  GlobalLock,[esp]
        push    esi
        xchg    eax,edi
        mov     esi,[esp+12]                 ;lpString
        mov     ecx,[esp+16]                 ;dwLength
        rep     movsb
        mov byte ptr [edi],0
        pop     esi
        xchg    eax,edi
        INVOKE  GlobalUnlock,[esp]
        INVOKE  SetClipboardData,CF_TEXT,[esp]
        or      eax,eax
        pop     edx
        jz      exit_3

        push    0                            ;return status = 0

exit_1: CALL    CloseClipboard

exit_2: pop     eax
        ret     8

exit_3: INVOKE  GlobalFree,edx
        push    1                            ;return status = 1
        jmp     exit_1

SetClpBdTxt ENDP

        OPTION  PROLOGUE:PrologueDef
        OPTION  EPILOGUE:EpilogueDef

;--------------------------------------------------------------------

bomz

???? leave paste clipboard in edit control some of them don't execute WM_PASTE

dedndave

if you use the code above, Word will paste it   :U
Word - Edit menu - Paste
or use the Paste icon

the only drawback is that the string must not contain any nulls

bomz

WORD need SendKey CTRL+V it's work if it foreground of course. But there is very many edit windows ICQ....

dedndave

by trying to control Word through the use of messages, you are asking for trouble
much better if you can use the standard mechanisms that were designed to perform the desired task

bomz

standart mechanizm open document,  select text, press RBMouse, copy, make WORD active, press RBMouse, paste



CTRL+V block with UVCRScreenCamera

jj2007

Quote from: dedndave on July 02, 2011, 02:14:03 PM
much better if you can use the standard mechanisms that were designed to perform the desired task

That is asking for trouble, Dave. It's called DDE :green2

dedndave

the problem i am having, here, is understanding exactly what he is trying to accomplish
it is a language barrier problem more than a programming problem

in some cases, it may help if he wrote it in Russian, then used google translate to create the post
google translate is not perfect, but it is usually "decodable"   :P

baltoro

BOMZ,
There are a number of reasons that PostMessage may not work as you have envisioned that it would.
Here are a couple of informative blog posts from Raymond Chen:   
In Pursuit of the Message Queue
When the Normal Window Destruction Messages are Thrown For a Loop
The Dangers of Mixing Synchronous and Asynchronous State
Thread Messages are Eaten By Modal Loops

The most obvious reason that this may not work, is that your alien window may not even have a message loop, or, if it does have a message loop, it may not be executing.
Also, you don't know what the alien message loop is doing,...it may not even handle your message, or, it may treat your message as if it some trivial data and discard it. There are a number of other reasons this may not work.
I would go with Hutch's advice and use another mechanism.
Baltoro

bomz

It's FACT - that some edit control's for AUTOPASTE from 'wide clipboard' need PostMessage. We may guess: what inside Word?

Of course for all cases (include different text's*) it's necessary have some PasteMethods. One of them PostMessage - and that PostMessage needs queue overload problem. and I can't find api allow that.

*for ex I have a book in txt format which have 29h sign. WM_CHAR can't send it.
QuoteVK_SELECT
0x29
SELECT key

qWord

my suggestion: Set the focus to the control an then use AttachThreadInput() + SendInput() to emulate CTRL+c/v (do not forget to detach). This should work for most programs.
FPU in a trice: SmplMath
It's that simple!

bomz

for most but not for all. and send key may conflict with some programs and may send to another window if you lose focus

GetQueueStatus - any function can't say anything about alien message

bomz

add MessCount,1
.if MessCount>=1024
invoke Sleep, 256
mov MessCount, 0
.endif


my computer good work with 256 milisec pause. so it's need handly pause in settings