Sending a message between two separate applications - c++

Hi,
I'm relatively new to c++ and software development in general, so I hope I can explain clearly my question.
I need two apps, one that listens the keyboard for a combo key press, and one that executes a function when that combo was pressed. I can't make them in a single app, because I'm trying to build something that resembles a kyosk, that when launched, starts a new desktop with limited functionality, and when a combo is detected, the original desktop is switched back. So, what I did, is launch this keyboard hook in the new desktop using CreateProcess, launch a new explorer.exe using the same function and switch to the new desktop.
I was doing some reading about Messages and Message Queues and I found out that this is a way to communicate between threads. So I was wondering if I could create my own Queue, put a message there at the combo key press, and periodically interogate this queue from another process, to make the necessary changes. If possible, could you post a link, or a code sample.
Thanks

Related

Multiple consoles for a single application C++

Is it possible to create two console windows (one being the main) and the secondary being a pop-up like a message box in Windows Forms?
I only want the secondary console window to hold IDs (that will be hard coded into the application) So the user does not have to keep returning to the main menu to check available IDs
If so how would you go about it?
Many Thanks
Yes, you can do it.
The solution is actually very simple - our process can start a new helper child-process, so the helper process will display whatever our process sends it. We can easily implement such a solution with pipes: for each new console (that I'll call logger), we'll open a pipe, and execute a Console-Helper application - the role of this application is very simple, it will print everything sent through the pipe. Check out this article Multiple consoles for a single application for details (contains the source code).
In the code, it implement a console class CConsoleLogger, then you can create multiple console windows like:
CConsoleLogger another_console;
another_console.Create("This is the first console");
another_console.printf("WOW !!! COOLL !!! another console ???");
And you will get something like:
Take a look at http://msdn.microsoft.com/en-us/library/windows/desktop/ms682528(v=vs.85).aspx for instructions for creating a console window.
Nop
A process can be associated with only one console.
AllocConsole

c++ event loop in sub application in a dll

Good day,
I have the following issue:
I have one exe application that writes text files to the disk, and that exe source is unavailable.
Customer has asked that, when users press numpad 5, a new window pops up, and does some operations with some files.
Problem is, numpad 5 + new application popup MUST only work when the application is running and has focus (they use numpad 5 for other operations).
I thought about this
create a dll with a form and buttons that do the required actions
inject the dll in the process
But I'm struggling to understand if there is a way to create a "keypress loop" in the dll.
Please note that I'm a beginner in c++ and forms, but I just need a feasibility check and a direction.
Is it possible to create a window application that waits for a keypress in an injected dll?
Is it there any simple example of this? Using google like a madman I was unable to find references to this so I think I have a problem with the proper terms.
My main issue is that the dllmain is obviously a one shot routine, and I don't understand how to create an "event loop".
Thanks for any information provided.
If you have successfully managed to inject your DLL in the traget process, use the _beginthread API in DllMain to start a new thread, and in that thread you can create a Dialog Box and have a message loop in the usal way.

Add console to existing MFC application

I'm working with 2 friends in a class project to make a D&D game. so far for the assignments I've been doing character creation stuff and strutting on the command line.
Now we're bringing or part together and I need to output ny dice rolls on a console and a few things on another one that will have to become the main view or tab or whatever it's called when it requires input/attention.
Problem is I never learned MFC yet because I didn't need it. How hard would it be to make a sample MFC console all that I can give to the teammate in charge of the GUI?
Could anyone point me to some instruction on making a console for an MFC app and how to give it output and receive output?
First, you can't. for both Unix/Linux and Windows, there is a one console/process limit. If you want another console, you have to create another process, that writes and reads the other console, while you send and receive the data.
You can use a NamedPipe http://msdn.microsoft.com/en-us/library/windows/desktop/aa365590%28v=vs.85%29.aspx to send data between processes, and the CreateProcess() function lets you create a process with a separate Console window.
Alternatively you can just write a Console-Look-a-Like window in some GUI.

Is it possible to trap the Windows Start Menu popup via Windows key(possibly without a hook)?

I've been working on an input event system.
I mapped all the keys on my own keyboard, the scancodes and so on, including both windows keys.
When I press them, the program successfully receives the distinct keydown events for them without any trouble.
When I release the keys, however, the Start Menu pops up, obscuring the program in windows mode, or even minimizing it in fullscreen.
So my problem lies in suppressing that.
Arma 2, a Military Simulator/Game allows commands to be mapped on those keys without any trouble.
Where do I have to catch that event?
Can I do it for my own window as long as it has focus?
Am I going to be stuck with a disabled win-key as long as it is running?
Or something else?
Googling it was mainly fruitless due to Windows key also referring to the product key, and when I did find something, it usually flat out disabled the whole button.
I just want to suppress the popup.
Edit:
I tried
case WM_SYSCOMMAND:
switch(wParam)
{
case SC_TASKLIST:
return 0;
default:
break;
}
But that gave me very odd results.
If I spammed the winkeys and only the winkeys, it seemed to work, as soon as I moved the mouse while doing so, it didn't, the start menu would pop up again.
Edit:
I also tried hooks, but on win7 they get removed if the callback takes too much time, which can happen when large data is loaded, so they suggest a dedicated thread for it, but I think that's overkill for just one key that needs handled.
I just want to know where the Start Menu gets called. My own program? The system?
This is so friggin annoying, I am contemplating trying to reach the people from Bohemia Interactive and ask them how they did it.
Just this one key, sheesh Microsoft...even with "Super key/superkey" search terms, I usually only get flat out disabling methods, from registry changes to third party background programs.
Bah!
This artcile was relating to C# but may point you in the right direction;
From MSDN:
A global hook monitors messages for all threads in the same desktop as
the calling thread. A thread-specific hook monitors messages for only
an individual thread. A global hook procedure can be called in the
context of any application in the same desktop as the calling thread,
so the procedure must be in a separate DLL module. A thread-specific
hook procedure is called only in the context of the associated thread.
This was the most helpful link in order to answer the question in the above article
The Raw Input API should solve your problem.
http://msdn.microsoft.com/en-us/library/ms645543.aspx

How to send mouse click event to a game application?

I try to send a mouse click event to a game application. First, i use Spy++ to find what message the application receive. I see something like : WM_MOUSEACTIVATE, WM_WINDOWPOSCHANGING, WM_ACTIVATEAPP, WM_ACTIVATE, WM_SETFOCUS, ...
i try to send the same as i see on Spy++ but it doesn't work. How to send mouse click to a game application without give it focus? . it's run in window mode. Thanks in advance.
You want WM_LMOUSEDOWN. You can always check MSDN for the documentation on which messages mean what.
The best way to automate applications and games is via SendInput. While in theory it should be possible to drive an application via WM_LUBTTONDOWN etc, many applications read the key state directly via lower level APIs (such as GetAsyncKeyState) which don't change their state to reflect the messages processed from the message queue.
Using SendInput requires actually setting the game to the foreground as the input events are synthesized at a low level and are thus delivered to the active/focused window.