Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I can select a file in the explorer and chose “Open with” and then select my MFC application in the list to open.
My question is which windows message will be sent by windows XP to my MFC application to start with and how can I catch it in my application?

For sentence when I select the Big [X] or system menu (in the icon) of Close (Alt+F4) comes in through "ON_WM_SYSCOMMAND" and In my processing looking for "SC_CLOSE".
C++
void Myapplication::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == SC_CLOSE)
        {
        }
}

Thanks in advance
M.H
Posted
Updated 11-Nov-11 3:23am
v3
Comments
Chuck O'Toole 11-Nov-11 10:59am    
What does the processing of ON_WM_SYSCOMMAND have to do with this question? And hey, I recognize that, didn't I post that to some other question you asked over here (http://www.codeproject.com/Questions/281654/MFC-Press-X-or-Close-it-should-be-sent-a-WM_close)
merh 11-Nov-11 17:18pm    
Hi, yes. It was from me. I try to point to that Im searching for something like that but in this case for starting of application.

Quote:
My question is which windows message will be sent by windows XP to my MFC application to start with and how can I catch it in my application?
Well, there are many messages sent by Windows to your application when it starts up. Unfortunately none of them have anything to do with telling you the name of the file that was chosen for you to "open with..."

The file name is passed to you as command line arguments. In your MFC application startup, InitInstance(), check m_lpCmdLine for the file name being present. It's a "char *" and part of the CWinApp base class.
 
Share this answer
 
Use Spy++ to view windows messages that are going to your application.

Or hook into PreTranslate message to view them in your code.

Many messages are passed to your application. The messages you get can vary by the OS, service packs and hotfixes. the only way to know is to look.
 
Share this answer
 
As far as your application is concerned, "open with" will be the same as if you double clicked on a document in explorer and it went straight to your application.

Unless you are doing something fancy, then you don't need to worry about this - MFC will do the heavy lifting for you.

If you do care for some reason... Explorer will look in the registry, and find out how to call your application. It will either be "myapp.exe somefile.file", or use DDE to "tell" your application which document to load.

In both cases, MFC will just create a new instance of yoour program, which creates a new view / document as speficied in the CxxxDocTempplates then load the document using the documents OnOpenDocument method, or serialisation if you've left the open / saving alone.

An example of reasons to care about this is given by the article Limiting an application to a single Instance - the MFC way[^]

In short: MFC means you don't have to care, unless you are doing something out of the normal.

Iain.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900