window编程脉络

windows应用程序编程是一种基于消息的编程。

一般创建一个窗口应用程序, 按以下步骤:

1. winmain函数是windows程序的入口函数。

int WINAPI WinMain(
  HINSTANCE hInstance,      // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,          // command line
  int nCmdShow              // show state
);

2. 创建窗口对象, 并初始化其成员函数。

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; 
3. 注册窗口对象。
ATOM RegisterClass(
  CONST WNDCLASS *lpWndClass  // class data
);
4. 创建窗口。
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
);
5. 显示更新窗口。
BOOL ShowWindow(
  HWND hWnd,     // handle to window
  int nCmdShow   // show state
);
BOOL UpdateWindow(
  HWND hWnd   // handle to window
);
6.消息循环。
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
);
如下一个win32的简单窗口应用程序:
 
MFC-----Microsoft Foundation Classes
MFC编写win32应用程序基本脉络和上面是一样的。
但是我们用Wizard新建程序时, Wizard都替我们把这些事情都做好了。
我们只要基于它的框架进行修改和消息循环操作即可。
MFC更能体现出面向对象的编程思维。
如我们进行窗口应用程序编程时, 主要就是对窗口类的设计和操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值