Drew Wutka
DWUTKA at Marlow.com
Fri Jul 13 18:29:01 CDT 2007
Ya learn something new every day, don't ya? I've been re-writing an application I built 7 years ago. The new version is already in production, but I'll be adding new features probably for years to come. It's a help desk application, and one issue I'm working on is that there are several things that are 'monitored' events. Some events are lightning fast, some are a bit slower. The slower ones slow down the interface a bit, because it's all running in the same .exe. To fix this I thought about multithreading, but decided on just creating another application to do the monitoring. So how do you have one application talk to another? Before, I have used winsocks to do this. But it involves making socket connections, etc. This time, I dug into Window Messaging. I've done a lot of things with windows (in Windows) before, but I had to share this little tidbit with the List. To bring everyone up to snuff, every window on your machine has an hWnd value. That's the ID of each window. Windows sends all sorts of messages to each window, for every single thing that you do. When you move the mouse over a window, windows is firing window messages to that window with the mouse position. Clicking, typing, resizing, redrawing and more are all sent to the windows through window messages. When you close an application, that too is a window message. The fun part is, we can use that same process for our own purposes. There's a simple API call, called SendMessage, that requires the hWnd of the window you want to send a message too, the message ID (every process has a static ID, but you can use RegisterWindowMessage to create your own messageid (Unique to that particular machine)) and then two parameters (both long integers). Hey, but wait, if all I can send between two applications is two integers, what's the point? Well, you can also create a window on the fly, with a single API, you can then set it's window text to anything you want, and your recipient applications can read that window text and destroy the window. I have this process in place (the communication part, now I'm on to actually doing something with the comms), and it works great. Virtually no overhead in the communication process, runs as smoothly as moving a window across your screen. If there's interest in something like this, I'll post some code for it. Drew The information contained in this transmission is intended only for the person or entity to which it is addressed and may contain II-VI Proprietary and/or II-VI BusinessSensitve material. If you are not the intended recipient, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. You are notified that any review, retransmission, copying, disclosure, dissemination, or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited.