Windows XP将通过Windows XP将Windows消息发送到我的MFC应用程序,以及如何在应用程序中捕获它 [英] Windows message will be sent by windows XP to my MFC application to start with and how can I catch it in my application

查看:134
本文介绍了Windows XP将通过Windows XP将Windows消息发送到我的MFC应用程序,以及如何在应用程序中捕获它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我可以在资源管理器中选择一个文件,然后选择打开方式",然后在列表中选择我的MFC应用程序以打开.
我的问题是Windows XP将从哪个Windows消息开始向我的MFC应用程序发送消息,以及如何在我的应用程序中捕获它?

对于当我选择大" [X]或关闭(Alt + F4)的系统菜单(在图标中)时通过"ON_WM_SYSCOMMAND"进入句子,并在我的处理过程中寻找"SC_CLOSE"的句子.

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

void Myapplication::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == SC_CLOSE)
        {
        }
}


在此先感谢
MH


Thanks in advance
M.H

推荐答案

报价:

我的问题是哪个Windows消息将通过以下方式发送Windows XP从我的MFC应用程序开始,如何在应用程序中捕获它?

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?

嗯,Windows启动时会向您的应用程序发送许多消息.不幸的是,它们都与告诉您为以...打开"而选择的文件的名称无关.

文件名将作为命令行参数传递给您.在MFC应用程序启动InitInstance()中,检查m_lpCmdLine是否存在文件名.它是"char *",是CWinApp基类的一部分.

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.


使用Spy ++查看将发送到应用程序的Windows消息.

或挂接到PreTranslate消息中以在代码中查看它们.

许多消息传递到您的应用程序.您收到的消息可能因操作系统,Service Pack和修补程序而异.唯一知道的方法就是查看.
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.


就您的应用程序而言,打开方式"与双击资源管理器中的文档并直接进行操作一样.到您的应用程序.

除非您正在做一些花哨的事情,否则您不必担心这一点-MFC将为您完成繁重的工作.

如果您确实出于某种原因在乎...资源管理器将在注册表中查找并找到如何调用您的应用程序.这将是"myapp.exe somefile.file",或使用DDE告诉"您的应用程序要加载的文档.

在这两种情况下,MFC都只会创建您的程序的新实例,该实例将在CxxxDocTempplates中创建一个新的视图/文档,然后使用文档OnOpenDocument方法加载该文档,或者如果您不理会打开/保存操作,则进行序列化.

将应用程序限制为单个实例(MFC方式)的文章提供了对此加以考虑的原因示例. a> [^ ]

简而言之:MFC意味着您不必关心,除非您做的事情不正常.

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


这篇关于Windows XP将通过Windows XP将Windows消息发送到我的MFC应用程序,以及如何在应用程序中捕获它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆