chapter two windows programming and mfc application framework

上传人:第*** 文档编号:49170766 上传时间:2018-07-24 格式:PPT 页数:26 大小:128.50KB
返回 下载 相关 举报
chapter two windows programming and mfc application framework_第1页
第1页 / 共26页
chapter two windows programming and mfc application framework_第2页
第2页 / 共26页
chapter two windows programming and mfc application framework_第3页
第3页 / 共26页
chapter two windows programming and mfc application framework_第4页
第4页 / 共26页
chapter two windows programming and mfc application framework_第5页
第5页 / 共26页
点击查看更多>>
资源描述

《chapter two windows programming and mfc application framework》由会员分享,可在线阅读,更多相关《chapter two windows programming and mfc application framework(26页珍藏版)》请在金锄头文库上搜索。

1、C+ ProgrammingChaper 7 Windows Programming and MFC IntroducingIndexp7.1 The Windows Programming Modeln7.1.1 Message Processingn7.1.2 Handlesn7.1.3 Windows APIs n7.1.4 A Windows Programp7.2 Introducing MFCn7.2.1 The Visual C+ Components n7.2.2 MFC Application Framework 7.1 The Windows Programming Mod

2、elpPrograms written for traditional operating environments use a procedural programming model in which programs execute from top to bottom in an orderly fashion. pThe path taken from start to finish may vary with each invocation of the program depending on the input it receives or the conditions und

3、er which it is run, but the path remains fairly predictable. pIn a C program, execution begins with the first line in the function named main and ends when main returns. In between, main might call other functions and these functions might call even more functions, but ultimately it is the programno

4、t the operating systemthat determines what gets called and when. 7.1 The Windows Programming ModelpWindows programs operate differently. They use the event-driven programming model, in which applications respond to events by processing messages sent by the operating system. pAn event could be a keys

5、troke, a mouse click, or a command for a window to repaint itself, among other things. 7.1 The Windows Programming Model7.1.1 Message ProcessingpWhere do messages come from, and what kinds of information do they convey? Windows defines hundreds of different message types. Most messages have names th

6、at begin with the letters “WM“ and an underscore, as in WM_CREATE and WM_PAINT. pOne way to characterize a Windows program is to think of it as a collection of message handlers. To a large extent, it is a programs unique way of responding to messages that gives it its personality. typedef struct tag

7、MSG HWND hwnd; UINT message;WPARAM wParam;LPARAM lParam;DWORD time;POINT pt; MSG; 7.1.1 Message ProcessingCommon Windows MessagesMessageSent When WM_CHARA character is input from the keyboard.WM_COMMANDThe user selects an item from a menu, or a control sends a notification to its parent. WM_CREATEA

8、window is created.WM_DESTROYA window is destroyed.WM_LBUTTONDOWNThe left mouse button is pressed.WM_LBUTTONUPThe left mouse button is released.WM_MOUSEMOVE The mouse pointer is moved.WM_PAINTA window needs repainting.WM_QUITThe application is about to terminate.WM_SIZEA window is resized.7.1.2 Handl

9、es pHandles are used quite frequently in Windows. Like HICON (a handle to an icon), HCURSOR (a handle to a mouse cursor), and HBRUSH (a handle to a graphics brush). pA handle is simply a number (usually 32 bits in size) that refers to an object. The handles in Windows are similar to file handles use

10、d in conventional C or MS-DOS programming. pA program almost always obtains a handle by calling a Windows function. The program uses the handle in other Windows functions to refer to the object. pThe actual value of the handle is unimportant to your program, but the Windows module that gives your pr

11、ogram the handle knows how to use it to reference the object.7.1.2 HandlesIdentifierMeaning HINSTANC EHandle to an “instance“the program itself HWNDHandle to a windowHDCHandle to a device contextCommon Handles7.1.3 Windows APIspTo a programmer, an operating system is defined by its API. An API encom

12、passes all the function calls that an application program can make of an operating system, as well as definitions of associated data types and structures. pEarly Windows programmers wrote applications in C for the Win16 application programming interface (API). Today, if you want to write 32-bit appl

13、ications, you must use the new Win32 API, either directly or indirectly.7.1.4 A Windows ProgrampThe entry point for a Windows program is a function named WinMain, but most of the action takes place in a function known as the window procedure.The window procedure processes messages sent to the window

14、. pWinMain creates that window and then enters a message loop, alternately retrieving messages and dispatching them to the window procedure. Messages wait in a message queue until they are retrieved. pA typical Windows application performs the bulk of its processing in response to the messages it re

15、ceives, and in between messages, it does little except wait for the next message to arrive. 7.1.4 A Windows ProgramStep 1:pWinMain begins by calling the API function RegisterClass to register a window class. pThe window class defines important characteristics of a window such as its window procedure

16、 address, its default background color, and its icon. These and other properties are defined by filling in the fields of a WNDCLASS structure, which is subsequently passed to RegisterClass. pAn application must specify a window class when it creates a window, and a class must be registered before it can be used. Thats why RegisterClass is called at the outset of the program. 7.1.4 A Windows ProgramStep 2:pOnc

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 职业教育

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号