• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

Communicating between programs

I have written a program in Visual c++.  I wanted the program to only be able to run once.(if the desktop icon was clicked while it was running it was just restored)  I did this by:

...::OnInitInstance
{
     HWND AlreadyThere = FindWindow(NULL,"My Main Windows Name")
     If(AlreadyThere != 0)
     {
          ShowWindow(AlreadyThere, SW_RESTORE);
          return 0;
     }          

But now I want to take it a step further.  Instead of calling a ShowWindow(AlreadyThere, SW_RESTORE); I want to send a Message to AlreadyThere so I can Have my Program do some extra stuff when it was restored by way of double clicking the desktop icon

Any help
0
MightyK
Asked:
MightyK
1 Solution
 
NosfedraCommented:
You can send a custom message to your function.
define your own message with

#define WM_DO_COOL_TRICKS WM_USER + 100

And when you find there is an instance of your program already running (by the way, you might want to take a look at MSDN - WinMain; look at hPrevInstance paramete, you'll find there how you find out if an instance of your program is already running) you just do a
SendMessage(your_Wnd_handle,WM_DO_COOL_TRICKS,0,0), if you won't pass any params in WParam and LPARAM and then, in the window receiving the message, treat the message in the big case structure of your window callback function.
0
 
CleanupPingCommented:
MightyK:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now