窗口的创建

nWindows程序的入口函数
int WINAPI WinMain(
  HINSTANCE hInstance,  // handle to current instance,当前实例的句柄
  HINSTANCE hPrevInstance,  // handle to previous instance,先前实例的句柄,对于win32为空
  LPSTR lpCmdLine,      // pointer to command line,LP指针,STR字符串。命令行
  int nCmdShow          // show state of window,显示状态
);//操作系统的入口点函数

 
  

  创建一个完整的窗口需要经过下面四个操作步骤:

设计一个窗口类;注册窗口类;创建窗口;显示及更新窗口。
对设计窗口的类进行赋值:
typedef struct _WNDCLASS { 
    UINT    style;	//指定了类的类型,CS--类的类型
    WNDPROC lpfnWndProc;  //指定这类型窗口的过程函数,也叫回调函数。不同类型的窗口都有自己专用的回调函数
    int     cbClsExtra; //类设定额外的字节,初始化为0
    int     cbWndExtra; //窗口类附加内存,通常为0
    HANDLE  hInstance; //当前的实例号
    HICON   hIcon; //图标的句柄,使用LoadIcon()函数装载图标
    HCURSOR hCursor; //光标句柄,使用LoadCursor()函数
    HBRUSH  hbrBackground; //画刷的句柄,使用GetStockObject()函数,
    LPCTSTR lpszMenuName; //常量字符串,设定菜单的名字
    LPCTSTR lpszClassName; //类的名字,常量字符串
} WNDCLASS; //设计窗口类
此时,设计窗口类成功,设定一个对象,对其进行赋值。

对对象进行注册:
RegisterClass(&类对象);

创建句柄:
HWND  hwnd;///利用句柄保存窗口的标示

HWND CreateWindow(
  LPCTSTR lpClassName,  // pointer to registered class name,窗口类名
  LPCTSTR lpWindowName, // pointer to 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,          // handle to menu or child-window identifier
  HANDLE hInstance,     // handle to application instance
  LPVOID lpParam        // pointer to window-creation data
);

你可能感兴趣的:(设计)