计算机程序设计语言与方法-l.ppt
Windows(Win32)API,API(Application Programming Interface)Win32环境下的所有应用程序都直接或间接地调用Windows提供得Win32 API函数.动态链接库组件对象模型(COM).MSDN的使用,Windows API 调用注意事项,动态链接库查找顺序应用程序所在的当前目录Windows目录Windows系统目录系统环境变量指示的目录,Windows编程,WinMain主函数窗体结构体注册窗体构造和显示窗体消息结构体回调函数消息循环消息处理,WinMain函数,int WINAPI WinMain(HINSTANCE hInstance,/handle to current instance HINSTANCE hPrevInstance,/handle to previous instance LPSTR lpCmdLine,/command line int nCmdShow/show state);,窗体结构体,typedef struct _WNDCLASS UINT style;/显示风格WNDPROC lpfnWndProc;/回调函数int cbClsExtra;/类额外内存int cbWndExtra;/窗体额外内存HINSTANCE hInstance;/实例句柄HICON hIcon;/图标类型HCURSOR hCursor;/光标类型HBRUSH hbrBackground;/背景类型LPCTSTR lpszMenuName;/菜单类型LPCTSTR lpszClassName;/类名称 WNDCLASS,*PWNDCLASS;,注册窗体类,ATOM RegisterClass(CONST WNDCLASS*lpWndClass/class data);,窗体构造,HWND CreateWindow(LPCTSTR lpClassName,/registered class name LPCTSTR lpWindowName,/window name DWORD dwStyle,/window style int x,/horizontal position of window int y,/vertical position of window int nWidth,/window width int nHeight,/window height HWND hWndParent,/handle to parent or owner window HMENU hMenu,/menu handle or child identifier HINSTANCE hInstance,/handle to application instance LPVOID lpParam/window-creation data);,窗体显示,BOOL ShowWindow(HWND hWnd,/handle to window int nCmdShow/show state);,窗体更新,BOOL UpdateWindow(HWND hWnd/handle to window);,消息结构体,typedef struct tagMSG HWND hwnd;/消息所属窗体句柄(类似指针)UINT message;/消息本身(宏表示)WPARAM wParam;/消息额外信息(整数)LPARAM lParam;/消息额外信息(整数)DWORD time;/发送时间POINT pt;/消息发送是光标位置 MSG,*PMSG;,回调函数,LRESULT CALLBACK WindowProc(HWND hwnd,/handle to window UINT uMsg,/message identifier WPARAM wParam,/first message parameter LPARAM lParam/second message parameter);,获取消息,BOOL GetMessage(LPMSG lpMsg,/message information HWND hWnd,/handle to window UINT wMsgFilterMin,/first message UINT wMsgFilterMax/last message);,消息转换,BOOL TranslateMessage(CONST MSG*lpMsg/message information);,消息分发,LRESULT DispatchMessage(CONST MSG*lpmsg/message information);,回调函数中消息处理,