PostMsg - Post a message to any window on the desktop

Environment: Windows NT/2000, Visual C++ 6.0

Purpose:

One day while running an optimization utility against a VC++ project, I had the need for a tool that would allow me to cleanly shut down an out-of-process COM server. Without modifying the original source code, the best way that came to mind would be to simply post a quit message to the server's main application window. I then opened up the handy little SPY++ tool and found my window in the list, but to my disappointment I was not able to do anything interactively, so I decided to write PostMsg.

Functionality:

PostMsg is a simple dialog application that mimics part of the functionality of SPY++, in that it gets a list of all windows on the current desktop and displays them in a child-parent manner via a standard tree control, exactly like SPY++ does. The next thing the user will need is a list of common windows messages to select from. PostMsg uses a msg.dat file that was basically grep'd from winuser.h, so it should be fairly complete, and includes both the messages defined in hex and decimal values. PostMsg will look for msg.dat in it's startup directory. New messages can be used by adding them to msg.dat and restarting the application. PostMsg also provides a case-insensitive way to do a substring search for a particular window title.

Technology:

PostMsg uses a single call to the ::EnumChildWindows() API function on the current desktop window to build it's list of windows. Given how ::EnumChildWindows() iterates through the window list, I used a reverse-dependency loop via CTreeCtrl::GetParentItem() to determine the correct insertion point in the tree for each window. The search routine I wrote ended up being a recursive function because they are easy to read, small in size, and...I guess I just like recursive solutions.

Author's Notes:

I added a couple buttons Hide and Show that would allow a quick way to manipulate windows. I find them useful for those annoying applications that don't have a taskbar icon, or prevent you from repositioning or minimizing the window on the desktop. Those free ISP application banner windows come to mind as ideal candidates for this.

I should also note that PostMsg is a "Use at Your Own Risk" tool, as it allows message posting to virtually any window on the system, and this could cause problems if you aren't careful.

Downloads

Download source - 31 Kb


Comments

  • jksdkjk

    Posted by nike free 5.0 dam nike free run 2 dam on 07/13/2013 12:21am

    nike free 5.0 dam Before the summer, pushing adidas ClimaCool running shoes freshride series. Excellent smooth uppers and breathable ClimaCool mesh material properties of cliamcool freshride to have more excellent breathable thermal effects. As for the summer of 2012 ClimaCool shoes ClimaCool freshride inherited the most successful, still using the classic texture of the leaves. Upper layer network structure combined with flexible gas-tight end, will undoubtedly make more cool and comfortable. As one of the world's most famous current, from United States the UNDEFEATED West Coast always maintained a good cooperative relationship with Nike, the two sides jointly footwear nike free run 2 damis the market hot. Following the cooperation between the two sides before the white "double DUNK" after the great success, UNDFTD again show a preference for basketball shoes, launched the military wind sheer as both sides jointly the "Joe 4", which make the Army Green shoes around and hit the red. These HYPERDUNK is doing, using approximate color scheme proposal, and uses a leather lining and "plastic shoes" congenitally deficient sense, just don't know how much people will be willing to hang in these "fence sign" HYPERDUNK to conquer the field?

    Reply
  • buy cheap generic discount viagra

    Posted by Sildenafil on 03/31/2013 02:04am

    cheap viagara in order to cheapest viagra cheap viagra rx true an important saved authentic do the job, consequently high cheap viagra buy without prescription on real a higher amount cheap deal discount price viagra connected with peculiarly cheapest viagra online cheap viaga cheaper vigra viagra for sale cheap cheap viagra in us many factor many people in terms of iron cheap deal discount viagra

    Reply
  • Comment to Keyboard Message

    Posted by Legacy on 10/13/2002 12:00am

    Originally posted by: P.Kolodziej

    Hi!
    You must replace message from WM_KEYDOWN to WM_SYSKEYDOWN for each messages in yours example.

    Reply
  • How to retrive properties like Row data, Column data of MSflexGrid at runtime

    Posted by Legacy on 01/28/2002 12:00am

    Originally posted by: James

    Could anybody tell me How to retrive properties like Row data, Column data of MSflexGrid at runtime .By any means

    Reply
  • About Keybord Message

    Posted by Legacy on 10/16/2001 12:00am

    Originally posted by: Xuqing Bai

    Hi Mr. Matt,
    

    I am glad to read your code and commets about the "Post a message to any window on the desktop ",
    and i tested the WN_F3 message, it works well. But i want to post message "Alt + H + A"
    to the Notepad to show the Notepad's vision information DialogBox, How can i do it.

    I do it as following, but it does not work.


    // Alt = WM_MENU ?
    PostMessage(Notepad's Handle,WM_KEYDOWN,WM_MENU, 0L);
    // 0x48 = H
    PostMessage(Notepad's Handle,WM_KEYDOWN,0x48,0L);
    // 0x41 = A
    PostMessage(Notepad's Handle, WM_KEYDOWN, 0x41, 0L);

    What is wrong with me?

    And you said that there are other programs out there to do this much more efficiently, could
    you give me some information?

    Thanks.

    Bai.


    -------------------------------------------------------------
    1) Open up an instance of Notepad
    2) Start PostMsg or refresh the window list if already open
    3) Search for or find Notepad in the window list, highlight it
    4) Select WM_KEYDOWN as your message
    5) Select VK_F3 as your WPARAM
    6) Leave NULL as your LPARAM
    7) Push the Post Message button

    Notepad should pop up a find dialog as expected. Every key on the standard keyboard may not be included in the list of messages, but PostMsg was never intended to be used as a typewriter, there are other programs out there to do this much more efficiently.

    Reply
  • Not working except for WM_QUIT

    Posted by Legacy on 08/24/2001 12:00am

    Originally posted by: Krishnakumar

    Hi,
    Seems the program is working well, but can u tell me how shall I send a WM_KEYDOWN or WM_RBUTTONDOWM message to the same? I tried but its not working.. I mean the even though the PostMessage API returns true, nothing happens on the target window. Any help will be highly appreciated.
    NB:My aim is to post a WM_KEYDOWN or WM_RBUTTONDOWM message to another window.

    Regards,

    krishnakumar

    Reply
  • Great Value.

    Posted by Legacy on 08/23/2001 12:00am

    Originally posted by: Sangyon

    Could you recomand other VC++ site ?

    Reply
  • neat program!

    Posted by Legacy on 08/23/2001 12:00am

    Originally posted by: soichi

    That is a very neat little program. I have discovered tons of hidden applications that win2000 automaticly runs and I simply didn't know.

    I have a question for this ap. When you call ::EnumChildWindows(::GetDesktopWindow(), EnumWindowsProc, (LPARAM)this); what is the reason that you pass 'this' pointer to the EnumWindowProc? Since the proc is in the same dialog class, I just don't see why EnumWindowProc couldn't do this->m_hLastItem instead of (CPostMsgDlg*)lParam->m_hLastItem.


    Reply
  • Very Useful as tool ... and just what I needed for timely controlling some applications ...

    Posted by Legacy on 08/23/2001 12:00am

    Originally posted by: Christiaan

    Thanks, don't hesitate to mail me if you need something yourself as reward.


    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today make data protection a must-have, as we live in a data driven society. The digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join eVault Chief Technology …

  • "Security" is the number one issue holding business leaders back from the cloud. But does the reality match the perception? Keeping data close to home, on premises, makes business and IT leaders feel inherently more secure. But the truth is, cloud solutions can offer companies real, tangible security advantages. Before you assume that on-site is the only way to keep data safe, it's worth taking a comprehensive approach to evaluating risks. Doing so can lead to big benefits.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds