Sign in to follow this  
Telcontar

Question on Windows Messages

Recommended Posts

I'm dabbling in some windows programming lately, and am confused on a point about window Handles and Messages.

For one, I can't seem to get a window by it's title as I supposedly should be able to. I know for sure what the title is, and am using the following command:

theTracker = FindWindowEx(NULL, NULL, NULL, "OpenMPT");

to try and grab the handle. However, it always returns NULL. My understanding is that this command should search every active window (including children), using the desktop as the parent, for a window with the title of "OpenMPT". However, it never finds anything.

Turning instead to the PostMessage() function, I tried to post to the 'current thread' by replacing the handle parameter with NULL [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms644944%28v=vs.85%29.aspx"]as described here.[/url] Also doesn't seem to work.

The messages I'm trying to send are found in a message map, which I reproduce here:

[code]BEGIN_MESSAGE_MAP(CTrackApp, CWinApp)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
ON_COMMAND(ID_FILE_NEWMOD, OnFileNewMOD)
ON_COMMAND(ID_FILE_NEWS3M, OnFileNewS3M)
ON_COMMAND(ID_FILE_NEWXM, OnFileNewXM)
ON_COMMAND(ID_FILE_NEWIT, OnFileNewIT)
ON_COMMAND(ID_NEW_ITPROJECT,OnFileNewITProject)
ON_COMMAND(ID_NEW_MPT, OnFileNewMPT)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_HELP_INDEX, CWinApp::OnHelpIndex)
ON_COMMAND(ID_HELP_FINDER, CWinApp::OnHelpFinder)
ON_COMMAND(ID_HELP_USING, CWinApp::OnHelpUsing)
ON_COMMAND(ID_HELP_SEARCH, OnHelpSearch)
END_MESSAGE_MAP()[/code]

I am trying to Post or SendMessage() with the ID_FILE_NEW message. Can't get it to work.

One final question: is ID_FILE_NEW the actual message name? It seems it should be, but I thought maybe Windows might append some other prefix to it?

Any help, even a pointer to some nice reading on this stuff, would be great.

Share this post


Link to post
Share on other sites
FindWindowEx should work unless the process is running with elevated permissions compared to your own process. I would use a tool like Spy++ (or whatever is available recently) to find out what the window class is, instead of the caption. Lots of apps change their caption when they are playing/viewing a different file, for example.

The ID_* constants aren't windows messages, they're parameters for a message. The message you want (I believe) is WM_COMMAND. Pass the ID_* value as the wParam. You'll have to figure out what their actual integer value is, though, since they're custom defined in that app itself, not in the Win32 API.

Share this post


Link to post
Share on other sites
Not in a different program, I'm adding this code directly into the already-existing program.

Thank Nypyren, that's helped a good deal. Still ain't working, sadly, but you led me to the Resource.h file where all the constants are defined - and it doesn't seem like ID_FILE_NEW actually is, only the ID_FILE_NEWIT and such. Which is weird, cuz then how can ID_FILE_NEW have it's own command in the message map? Aie.

I've got ProcessExplorer, but none of the info it gives me is much help.

EDIT: I'm beginning to think there's something wonky going on with the code I'm modifying, as even GetActiveWindow returns null when there is a very definite active window. In other words, I think I need to abandon the windows handle thing and try something else. Thanks for the help, guys. I'll have to return to this stuff with my own projects so I know more about what's going on.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this