Translate/Dispatch Message Api usage

Hi everyone, I'm new in this forum and would really like some help in a project i'm starting.
My project requires me to sendmessage to a certain window using this apis:
TranslateMessage
DispatchMessage

Let's use TranslateMessage for example:

Private Type POINTAPI
x As Long
y As Long
End Type

Private Type MSG
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type

Private Declare Function TranslateMessage Lib "user32" Alias "TranslateMessage" (lpMsg As MSG) As Long

That's the definition, I want to understand, how I can make it send a key to a window (Let's say, notepad or something) when something happens,
For example:

Private Sub Command1_Click()
TranslateMessage (h)
End Sub

^^That's incorrect, I want to find a way to send the letter h to a window, or anything that can help my project, thanks everyone, Mor.
[1031 byte] By [Morhsn] at [2007-11-20 11:35:56]
# 1 Re: Translate/Dispatch Message Api usage
Shouldn't be asking how to cheat any system on a public forum. It's against the AUP. I'll ignore that part, if you edit it out.

Here's a link:

http://www.answers.com/topic/classical-win-api-example?cat=technology
dglienna at 2007-11-9 19:32:58 >
# 2 Re: Translate/Dispatch Message Api usage
Im confused,
I don't understand how that sends a key like H to a window, I know its possible to use the api like that, because in C++ you can do:

void __declspec(dllexport)__stdcall Send(UINT Message, WPARAM Wp, LPARAM Lp)
{
HWND hWND = FindWindow("MapleStoryClass", "MapleStory");
MSG Msg;

Msg.hwnd = hWND;
Msg.lParam = Lp;
Msg.message = Message;
Msg.wParam = Wp;

TranslateMessage(&Msg);
DispatchMessage(&Msg);
}

and later on the form:
Send(WM_KEYDOWN, 0x4e, 1);

How can I do that in Vb :-(
Thanks for your help, this is badly needed!
Morhsn at 2007-11-9 19:33:58 >
# 3 Re: Translate/Dispatch Message Api usage
You can use the same API's in VB. But, you said they don't allow sendmessage, and getting around something like that isn't allowed.
dglienna at 2007-11-9 19:34:55 >
# 4 Re: Translate/Dispatch Message Api usage
http://www.winprog.org/tutorial/message_loop.html

This will help you understand.
sotoasty at 2007-11-9 19:36:00 >
# 5 Re: Translate/Dispatch Message Api usage
You can use the same API's in VB. But, you said they don't allow sendmessage, and getting around something like that isn't allowed.
Not getting around,
its like, school project, You must show your knowledge with those apis, nothing else...
Morhsn at 2007-11-9 19:36:54 >
# 6 Re: Translate/Dispatch Message Api usage
Ever hear of Google? :)

http://allapi.mentalis.org/apilist/apilist.php
dglienna at 2007-11-9 19:37:53 >
# 7 Re: Translate/Dispatch Message Api usage
Ok, I think my problem isn't 100% understandable.

Ok, so this is the definition of translate message:
Declare Function TranslateMessage Lib "user32" Alias "TranslateMessage" (lpMsg As MSG) As Long

How can I use that, to send the letter "H" to another window, that's all I need to know, I tried every possible option, the site you gave me shows a messy not understandable example, without even using the call of translate message!
If anyone can show me how I can acctuly make it work, All I want is "H" to another window...

I got a feeling its not as simple as:
TranslateMessage ("H")
:(
thanks for the help so far!
Morhsn at 2007-11-9 19:39:03 >
# 8 Re: Translate/Dispatch Message Api usage
that doesn't send text, it sends 'messages' to windows, if you know the handle. I don't know if it's even possible to send a message without useing user32's sendmessage.
dglienna at 2007-11-9 19:40:01 >
# 9 Re: Translate/Dispatch Message Api usage
DispatchMessage & TranslateMessage are used within an app's message pump to process a message that is sent (sendmessage) or posted (postmessage). Those APIs are not intended to sendmessages externally, they are used to process recieved messages and forward them on thru their pump as needed or discarded (i.e., when DispatchMessage is not called). However, MSDN doesn't say it can't be used for that purpose. I spent a whopping 2 minutes trying to send a message to my own textbox hWnd with no success.

There is a way, within an application's message pump to determine if the message is was sent from outside of the app's thread (InSendMessage API). If that game is checking, then nothing you send it will work, because you are sending it from outside of the app's thread. If this is the case, forget about it... Short of injecting a DLL into the process and that DLL sending the message, there may be no other way. FYI: VB Active-X DLLs are not injectable.

P.S. VB's SendKeys simply posts a set of WM_KeyDown, WM_Char, & WM_KeyUp messages.

Edited: Other APIs you might try before giving up: SendInput, & keybd_event, mouse_event, PostThreadMessage. Otherwise, you will have to get more familiar with how the target window accepts & processes it messages -- who knows, maybe it adds its own flags to messages so it knows whether or not to process it (kind of like an anti-cheating flag).
LaVolpe at 2007-11-9 19:40:58 >
# 10 Re: Translate/Dispatch Message Api usage
Ok, thanks everyone,
Sending message using translatemessage and dispatchmessage is possible in C++, but I guess its totally diffrent in VB.
Morhsn at 2007-11-9 19:42:02 >