SendMessage

Discussion in 'Software' started by IAmLerxt, Feb 15, 2006.

  1. IAmLerxt

    IAmLerxt Private E-2

    I have built MDI app that is a code editor for a client of mine. Here's what I want to happen.....

    If the app is already open, and somebody runs it again (i.e. by dragging a file onto the apps desktop icon) I want to open the file in the app that is already running.

    I am currently doing this by checking for previous instance, and if one is found, write the command line (file name) to a registry key and exit. I am using a timer control to poll that registry key every second, so the existing app immediately finds it, opens the file, and then deletes the key.

    This works okay, but it seems cheesy to me. I've read that SendMessage can be used, but I don't really know how to use it. Or, I could just leave the solution I have in place, unless somebody tells me that's a bad idea.

    Any help/input would be appreciated.
    Thanks.
     
  2. zethon

    zethon Private E-2

    I don't know about SendMessage.

    Try sending a WM_COPYDATA message to the already open window. You can do something like copy the command line from the second instance into the first instance. Then just parse it in a OnCopyData() handler. It's been a while since I've used MFC much less wrote an MDI app, but I think you should be able to handle OnCopyData in your frame class (assuming you're using MFC).
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds