class WinMaker
{
public:
WinMaker (WinClass & winClass);
operator HWND () { return _hwnd; }
void AddCaption (char const * caption)
{
_windowName = caption;
}
void AddSysMenu () { _style |= WS_SYSMENU; }
void AddVScrollBar () { _style |= WS_VSCROLL; }
void AddHScrollBar () { _style |= WS_HSCROLL; }
void Create ();
void Show (int nCmdShow = SW_SHOWNORMAL);
protected:
WinClass & _class;
HWND _hwnd;
DWORD _exstyle; // 扩展窗口风格
char const * _windowName; // 指向窗口名字的指针p
DWORD _style; // 窗口风格
int _x; // 窗口的水平位置
int _y; // 窗口的升起位置
int _width; // 窗口宽
int _height; // 窗口高
HWND _hWndParent; // 父窗口或所有者的句柄
HMENU _hMenu; // 菜单的句柄,或子窗口的标识符
void * _data; // 指向窗口创造数据
};
WinMaker::WinMaker (WinClass & winClass)
: _hwnd (0),
_class (winClass),
_exstyle (0), // 扩展窗口风格
_windowName (0), // 指向窗口的名字
_style (WS_OVERLAPPED), // 窗口风格
_x (CW_USEDEFAULT), // 窗口的水平位置
_y (0), // 窗口的升起位置
_width (CW_USEDEFAULT), // 窗口宽
_height (0), // 窗口高
_hWndParent (0), // 父窗口或所用者的句柄
_hMenu (0), // 指向菜单,或子窗口的标识符
_data (0) // 指向窗口创造数据
{
}
void WinMaker::Create ()
{
_hwnd = ::CreateWindowEx (
_exstyle,
_class.GetName (),
_windowName,
_style,
_x,
_y,
_width,
_height,
_hWndParent,
_hMenu,
_class.GetInstance (),
_data);
if (_hwnd == 0)
throw WinException ("Internal error: Window Creation Failed.");
}
void WinMaker::Show (int nCmdShow)
{
::ShowWindow (_hwnd, nCmdShow);
::UpdateWindow (_hwnd);
}
// 制造顶层重叠带标题的窗口
TopWinMaker::TopWinMaker ((WinClass & winClass, char const * caption)
: WinMaker (winClass)
{
_style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;
_windowName = caption;
}
--------------------------------------------------------------------------------
在我们开始下一步前,这有一个小的类。WinException抛出任何时刻的Windows API的失败。它需取回的Windows错误代码。(顺便,使用formatMessage很容易的转换错误代码到字符串。)
ResString类是对你的应用程序的字符串资源中贮存的字符串的简单的封装。
--------------------------------------------------------------------------------
上一页 [1] [2] [3] [4] [5] [6] 下一页