I send Message to alien window (not mine) with PostMessage is it possible to know this Message execute already or how many Message's in queue?
SendMessageCallBack don't work - the difference
Places (posts) a message in the message queue associated with the thread
calls the window procedure for the specified window
QuoteThere is a limit of 10,000 posted messages per message queue. This limit should be sufficiently large. If your application exceeds the limit, it should be redesigned to avoid consuming so many system resources. To adjust this limit, modify the following registry key.
HKEY_LOCAL_MACHINE
SOFTWARE
Microsoft
Windows NT
CurrentVersion
Windows
USERPostMessageLimit
The minimum acceptable value is 4000.
Using return value of POSTMESSAGE don't give result some messages lose
REATTEMPT:
invoke PostMessage, esi, WM_CHAR,edx,0
.if eax==0
add ATTEMPT, 1
.if ATTEMPT<=10
push edx
invoke Sleep, 1000
pop edx
jmp REATTEMPT
.else
mov ebx,1
.endif
.endif
this work but Sleep is not standby method
add MessCount,1
.if MessCount>=1024
invoke Sleep, 1024
mov MessCount, 0
.endif
if you use SendMessage, you will know because the function does not return until the message has been processed
if you want to continue execution while the message is being processed, put the SendMessage in a seperate thread
Thrd PROTO
;
;
xor eax,eax
INVOKE CreateThread,eax,eax,Thrd,eax,eax,eax
;
;
Thrd PROC
INVOKE SendMessage,hRecWin,WM_SOMEMESSAGE,wParam,lParam
INVOKE ExitThread,0
Thrd ENDP
you can use GetExitCodeThread to see if the thread has terminated
or you can set a semaphore flag after the SendMessage call
also, you can pass a parameter to the thread
it could be a pointer to a structure that contains the handle, message, wParam, and lParam
this method is also useful when sending messages that contain pointers as wParam or lParam
PostMessage does not work in these cases :bg
sendmessage WM_CHAR don't work with WORD only postmessage. It's belong to SendMessageCallBack too
Places (posts) a message in the message queue associated with the thread
calls the window procedure for the specified window
in that case, the only thing i can think of is using PeekMessage to see if the message you posted is still in the queue
that does not tell you that the message has been handled
it will tell you if it has been removed, though
PeekMessage work only with messages for YOURS window
QuoteA handle to the window whose messages are to be retrieved. The window must belong to the current thread.
May be try to send WM_CHAR post message for mine window too and wait it
oh well :P
QuoteMay be try to send WM_CHAR post message for mine window too and wait it
:dazzled:
No all windows have it's own queue (http://smiles.kolobok.us/light_skin/mda.gif)
queue overload may destroy system. my 8 year old computer lose about 60 message from 1 000 000. it's may be WM_CHAR but may be some system messages
what are you trying to do? WM_CHAR won't work in all situations -you may need to change the method for simulation user input...
Sending messages to other applications in other threads is at best a risky business and there is no garrantee that it is supported by the operating system. If you want communication betqween two different applications, you need to write both of them yourself and use documented inter-process communication techniques.
WM_CHAR work so - as application it execute.
supported. all work OK with different edit windows. accept cases when CHAR text bigger 5 000-6 000 symbols
it sounds like you might be better off to put the data in the clipboard
and let the user paste it into the Word document
with some windows this work but with some no.
(http://xmages.net/storage/10/1/0/d/4/upload/bf967125.png)
http://xmages.net/storage/10/1/0/2/c/upload/c5995af6.gif
WM_CHAR is an internal message - there are several reason why you should not send it explicit. One is the fact, that all application assumes that they only will receive text, if they have the focus - this can cause unexpected behaviour of the target application.
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
you do not use WM_PASTE to place data into the clipboard :bg
use SetClipboardData :U
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
;--------------------------------------------------------------------
???? leave paste clipboard in edit control some of them don't execute WM_PASTE
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
WORD need SendKey CTRL+V it's work if it foreground of course. But there is very many edit windows ICQ....
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
standart mechanizm open document, select text, press RBMouse, copy, make WORD active, press RBMouse, paste
(http://xmages.net/storage/10/1/0/7/3/upload/8e257f7c.gif)
CTRL+V block with UVCRScreenCamera
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
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
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 (http://blogs.msdn.com/b/oldnewthing/archive/2006/02/21/536055.aspx)
When the Normal Window Destruction Messages are Thrown For a Loop (http://blogs.msdn.com/b/oldnewthing/archive/2005/07/27/443824.aspx)
The Dangers of Mixing Synchronous and Asynchronous State (http://blogs.msdn.com/b/oldnewthing/archive/2009/06/18/9771135.aspx)
Thread Messages are Eaten By Modal Loops (http://blogs.msdn.com/b/oldnewthing/archive/2005/04/26/412116.aspx)
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.
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
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.
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
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
Quote from: bomz on July 02, 2011, 07:32:17 PM
for most but not for all. and send key may conflict with some programs and may send to another window if you lose focus
1. you set the focus immediately before emulating the input.
2. CTRL+c/v is well known key combination on Windows OSs - please show me a program that use this combination for other purpose!
3. I'm also sure: there is no solution for all programs - just thought of the case programs using GetAsyncKeyState for determining the status of CTRL or ALT.
I find only one situation when CTRL+V block's with uvcrscreen camera. but Google say that this method is not universal. there is many such programs from Delphi programmers but any don't work fully correct
(http://xmages.net/storage/10/1/0/a/2/upload/e7b418ce.gif)
(http://xmages.net/storage/10/1/0/f/c/upload/6b0a9bd6.gif)
even 128 millisec OK with 75% processor use with video. WORD made orthography search it need bigger pause
in the attachment an example using SendInput() for both, console and GUI applications. Simply drag a line in listview and release the mouse over the target window/console (there is no dragging icon/image).
???? (http://smiles.kolobok.us/light_skin/unknw.gif)
http://xmages.net/storage/10/1/0/2/c/upload/a9adc793.gif
I make "method" WM_CHAR+sendkey VK_RETURN for Alkepad. Lose focus VK_RETURN was send for another application which open 300 windows. CTRL+V is safe key's, others may be dangerous and need attention
copy some text into the clipboard - this contend is shown in the list view. Then you can drag this entries back to other applications.
ypu have windows 7?
http://xmages.net/storage/10/1/0/9/c/upload/6805a420.gif
it's good idea to drop text in window - this decide the problem's with windows without autofocus
yes, win7-x86-64 ... works perfect here, also when running it using OllyDbg ... :(
for universal program need do using XP and than try w7. from down to up
mhh, can't see the problem. However, you can see the code for conole input: first Set the console as forground window an the pass the text using SendInput()(). The trick is, to replace LFCR with VK_RETURN.
text was big - 1 mb, I see film forgot about pasting, and move other window.
I haven't read this whole thread so forgive me if I'm off the mark here. However, from the first few posts I gather that you are having problems sending certain messages to a window in another thread using SendMessage but mysteriously PostMessage seems to work. That is becuase the input states of the two message queues are independant of each other, use AttachThreadInput to syncronize them then SendMessage should work fine.
Quote from: donkey on July 03, 2011, 03:34:41 PM
I haven't read this whole thread so forgive me if I'm off the mark here. However, from the first few posts I gather that you are having problems sending certain messages to a window in another thread using SendMessage but mysteriously PostMessage seems to work. That is becuase the input states of the two message queues are independant of each other, use AttachThreadInput to syncronize them then SendMessage should work fine.
LOCAL chWnd:DWORD
LOCAL dhWnd:DWORD
----------------------------------------
invoke GetCurrentThreadId
mov chWnd, eax
invoke GetWindowThreadProcessId, EDITOR.hwndFocus , addr dhWnd
mov dhWnd, eax
invoke AttachThreadInput,chWnd,dhWnd,TRUE
--------------------------------------
invoke SendMessage,EDITOR.hwndFocus, WM_CHAR,edx,0
--------------------------------------
invoke AttachThreadInput,chWnd,dhWnd,FALSE
invoke ExitThread, 0
(http://smiles.kolobok.us/standart/not_i.gif)
the problem is - that Windows don't provide that somebody would print quicker than 5000 sing in sec, and provide only 10 000 places in postmessage queue (http://smiles.kolobok.us/madhouse/gamer1.gif)
Quote from: dedndave on July 02, 2011, 02:04:22 PM
push 0
CALL OpenClipboard
push hWnd
CALL OpenClipboard
(http://xmages.net/storage/10/1/0/0/3/upload/9100e17a.gif)
and some other artefact too happens like that
Quote
A handle to the window to be associated with the open clipboard. If this parameter is NULL, the open clipboard is associated with the current task.
If an application calls OpenClipboard with hwnd set to NULL, EmptyClipboard sets the clipboard owner to NULL; this causes SetClipboardData to fail.
well, the method Donkey describe is also used in my example. Just to say, AttachThreadInput() fails on console windows (protected). Fortunately it work if you set the console as the forground window.
WM_CHAR, WM_KEYDOWN ,... are messages that are send by the OS - they are not not designed for explicit sending. SendInput() is the way to go!
WM_CHAR rather than SendKey of SendInput because it have target. you may move window hide it print to another editor. only one problem with speed of print
http://xmages.net/storage/10/1/0/a/b/upload/05df53f1.gif
Quote from: bomz on July 03, 2011, 05:30:45 PM
WM_CHAR rather than SendKey of SendInput because it have target. you may move window hide it print to another editor
:dazzled:
good luck!
program needs several methods - sendkey one of them
i a not sure i understand the MSDN document...
QuoteIf an application calls OpenClipboard with hwnd set to NULL, EmptyClipboard
sets the clipboard owner to NULL; this causes SetClipboardData to fail.
that makes no sense to me :P
in their own example, they set it to NULL...
http://msdn.microsoft.com/en-us/library/ms649016%28v=VS.85%29.aspx
here is a little test program
it places the text "test string" into the clipboard...
data set, but some may crashes. findtext for ex. and some times data not set or set even odd time. I think this may updates with windows update
invoke CreateThread,NULL,NULL,eax,0,0,addr ThreadID
mov ThreadID, eax
invoke SetWindowLong,hList,GWL_WNDPROC,ThreadID
mov OldWndProc,eax
this code would work?
nahhhhhhhhhh :P
ThreadID is not physical address in memory?
whether it is or not, a thread function does not have 4 parms :bg
even so, i don't think it's a valid plan
if you want to do something like that, you create the window in a thread
then, the message loop can be in that thread :U
parameters is not a problem
WndProc proc hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
ListViewWndProc proc hWnd:DWORD
pop uMsg
pop wParam
pop lParam
Thread and proc diff things
I must post-send message CHAR with address in lParam.This addres in lParam to old wnd proc and count of message
http://msdn.microsoft.com/en-us/library/ms644944%28v=vs.85%29.aspx
QuoteIf you send a message in the range below WM_USER to the asynchronous message functions
(PostMessage, SendNotifyMessage, and SendMessageCallback), its message parameters cannot
include pointers. Otherwise, the operation will fail. The functions will return before the receiving
thread has had a chance to process the message and the sender will free the memory before it is used.
if the pointer points to global data, i suppose you can get away with it,
as long as the data isn't modified before it's processed
(http://s43.radikal.ru/i102/1107/b9/3e0e1b591d78.gif)
Is it possible to THREAD have it is own PROC inside?
Quote from: bomz on July 10, 2011, 08:16:06 PM
Is it possible to THREAD have it is own PROC inside?
You mean the window procedure with PROC? If so:
Windows are associated with the thread they are created from. The WndProc is allways executed in the same thread as CreateWindowsEx().
invoke SetWindowLong,hWnd,GWL_WNDPROC,add MyProc
mov OldWndProc,eax
I mean - MyProc inside Thread proc
MyThread proc lParametre:DWORD
........................
invoke ExitThread,0
MyWnd proc hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
.....................
MyWnd endp
MyThread endp
OR
MyThread proc lParametre:DWORD
......................
invoke ExitThread,0
MyWnd:
pop hWnd
pop uMsg
pop wParam
pop lParam
......................
ret
MyThread endp
You can't change the thread - the code is still executed in cotext of the thread that creates the window.
if you call a function from the thread procedure, it executes under that thread
in other words, you can have functions that are shared between threads
if you write the function carefully, you can call it from more than one thread at a time
mainly, the data items that are modified by the function should be seperated
this is often done by using local variables
each thread that calls the function will have a different stack frame
Quoteif you write the function carefully
in this concrete situation it's impossible to use the same function
because Wnd function execute not only my message which I know to that window was send, it must resend other's native messages and the same function can't know where send this messages
:bg
.XCREF
.NOLIST
INCLUDE \masm32\include\masm32rt.inc
.LIST
;****************************************************************
Thrd PROTO
Func PROTO :DWORD
;****************************************************************
.CODE
_main PROC
xor edi,edi
INVOKE CreateThread,edi,edi,Thrd,500,edi,edi
INVOKE CreateThread,edi,edi,Thrd,400,edi,edi
INVOKE CreateThread,edi,edi,Thrd,600,edi,edi
INVOKE CreateThread,edi,edi,Thrd,100,edi,edi
INVOKE CreateThread,edi,edi,Thrd,300,edi,edi
INVOKE CreateThread,edi,edi,Thrd,200,edi,edi
inkey " "
exit
_main ENDP
;****************************************************************
Thrd PROC
INVOKE Func,[esp+4]
INVOKE ExitThread,0
Thrd ENDP
;****************************************************************
Func PROC uses ebx Val:DWORD
mov ebx,Val
INVOKE Sleep,ebx
print ustr$(ebx),32
ret
Func ENDP
;****************************************************************
END _main
(http://smiles.kolobok.us/light_skin/girl_impossible.gif)
restrict mount of thread's with some number?
you can have something like 1,000 threads, but that isn't very efficient
it depends on the OS, amount of memory, etc
use the number of threads that you need
that program was just a demo
I think about this algorithm it's so complicate and tangled
that is usually a sign that you are doing it wrong :bg
if it isn't simple - make it simple
i wish i could better understand what you are trying to do
maybe if you write it in Russian, i can use google translate to try and understand