Programming with Microsoft Visual C++.NET 6ed [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Programming with Microsoft Visual C++.NET 6ed [Electronic resources] - نسخه متنی

George Shepherd, David Kruglinski

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید








Using Other Windows Messages


The MFC library directly supports hundreds of Windows message-handling functions. In addition, you can define your own messages. You'll see plenty of message-handling examples in later chapters, including handlers for menu items, child window controls, and so forth. In the meantime, five special Windows messages deserve special attention: WM_CREATE, WM_CLOSE, WM_QUERYENDSESSION, WM_DESTROY, and WM_NCDESTROY.


The WM_CREATE Message


This is the first message that Windows sends to a view. It is sent when the window's Create function is called by the framework. At that time, the window creation is not finished, so the window is not visible. Therefore, your OnCreate handler cannot call Windows functions that depend on the window being completely alive. You can call such functions in an overridden OnInitialUpdate function, but you must be aware that in an SDI application OnInitialUpdate can be called more than once in a view's lifetime.



The WM_CLOSE Message


Windows sends the WM_CLOSE message when the user closes a window from the system menu and when a parent window is closed. If you implement the OnClose message map function in your derived view class, you can control the closing process. If, for example, you need to prompt the user to save changes to a file, you can do it in OnClose. Only after you've determined that it is safe to close the window should you call the base class OnClose function, which will continue the close process. The view object and the corresponding window will both still be active.





Note

When you're using the full application framework, you probably won't use the WM_CLOSE message handler. You can override the CDocument::SaveModified virtual function instead, as part of the application framework's highly structured program exit procedure.




The WM_QUERYENDSESSION Message


Windows sends the WM_QUERYENDSESSION message to all running applications when the user exits Windows. The OnQueryEndSession message map function handles it. If you write a handler for WM_CLOSE, you should write one for WM_QUERYENDSESSION, too.



The WM_DESTROY Message


Windows sends the WM_DESTROY message after the WM_CLOSE message, and the OnDestroy message map function handles it. When your program receives this message, it should assume that the view window is no longer visible on the screen but that it is still active and its child windows are still active. You use this message handler to do cleanup that depends on the existence of the underlying window. Be sure to call the base class OnDestroy function. You cannot "abort" the window destruction process in your view's OnDestroy function. OnClose is the place to do that.



The WM_NCDESTROY Message


This is the last message that Windows sends when the window is being destroyed. All child windows have already been destroyed. You can do final processing in OnNcDestroy that doesn't depend on a window being active. Be sure to call the base class OnNcDestroy function.





Note

Do not try to destroy a dynamically allocated window object in OnNcDestroy. That job is reserved for a special CWnd virtual function, PostNcDestroy, that the base class OnNcDestroy calls. MFC Technical Note #17 in the online documentation offers hints about when it's appropriate to destroy a window object.




/ 319