SendMessage WM_LBUTTONDOWN to another window

i want to send a message to another window(program - which i know only it's name - i don't have it's hwnd)

this is the code i wrote:

like u see - i want to send after few seconds another message -(simulates a left button down for 3 sec on another window-application)?

help please?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You have to find out window and send it directly to destination. Use Spy to figureout the window class and FindWindow() api to get the handle.
also you must determine which SendMessage version you're using:

LRESULT SendMessage(
HWND hWnd,
WPARAM wParam,

LRESULT SendMessage(
UINT message,
WPARAM wParam = 0,
LPARAM lParam = 0

The first one is a function (::SendMessage) which takes four parameters. The second one is a method of CWnd which takes 1-3 parameters) and works solely on the object window.
I think that windows hooks are usually used for mouse & keyboard events simulation (JournalRecordProc, JournalPlaybackProc, etc.)
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

No MichaelS and mjswart,
   A direct sendmessage from one application to another won't work unless you send WM_COPYDATA or send to HWND_BROADCAST which will be recieved by all windows. In this case, the programmer wants to send LBUTTONDOWN and LBUTTONUP. These are windows messages and not user messages. So when send to HWND_BROADCAST it will create undesirable effects in other windows present in the system.
   Tell me nirkr, are you working under windows NT? If so, you could create a remote thread in the target app and try sending messages from that thread. The whole idea is that you need to be in the same address space to send windows messages direct. Or you have to send IPC messages and take appropriate action in the target application. If you are the owner of the target application, you can try with WM_COPYDATA.
In the following code, a window is found by specifying the window title text and then the relevant button is pressed:

      //------------ 1st - find the window ------------//

      HWND hDlg = ::FindWindowEx(NULL, NULL, m_lpszClass, (LPCTSTR)m_strWindowText);

      //------------ 2nd - find and click the control ------------//

      if (hDlg)      
            HWND hControl = 0;
            hControl = ::GetDlgItem(hDlg, m_nControlID);

            if ( ::PostMessage(hDlg, WM_COMMAND, (WPARAM)((BN_CLICKED*0x10000)+m_nControlID), (LPARAM)hControl) )
                  if ( ! m_bLurk)      
                        return true;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
To Priyesh. Are you sure that SendMessage() won't work? It sounds at least new for me.
Yes michael,
   You cannot send general windows messages between applications. You are thinking abt writing to the message queue of another application and it can be done by special ipc messages only (like the ones i mentioned in the last comment). You can try by finding another window in your system and sending a WM_LBUTTONDOWN to it.
Didn't try it. Just used WM_HOTKEY and it works.
I've written to other app's message queues before.
I found out the command ID of a certain function (using spy and the app's own menu) and posted a message to the app. The app responded as if I had used the menu.
WM_COMMAND works aswel.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.