Question on Windows Messages

This topic is 2627 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

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 as described here. Also doesn't seem to work.

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

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()

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 on other sites
Are you trying to manipulate a window in a different program?

There are limitations on what can be done across process boundaries in Windows.

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 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.

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• Forum Statistics

• Total Topics
633756
• Total Posts
3013707
×