Вход/Регистрация
Применение Windows API
вернуться

Легалов А. И.

Шрифт:

Верхнее окно создано с использованием класса TopWinMaker, который обеспечивает соответствующий стиль и заголовок.

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; // extended window style

 char const* _windowName; // pointer to window name

 DWORD _style; // window style

 int _x; // horizontal position of window

 int _y; // vertical position of window

 int _width; // window width

 int _height; // window height

 HWND _hWndParent; // handle to parent or owner window

 HMENU _hMenu; // handle to menu, or child-window id

 void * _data; // pointer to window-creation data

};

WinMaker::WinMaker(WinClass& winclass) : _hwnd(0), _class(winClass), _exStyle(0), // extended window style

 _windowName (0), // pointer to window name

 _style(WS_OVERLAPPED), // window style

 _x(CW_USEDEFAULT), // horizontal position of window

 _y(0), // vertical position of window

 _width(CW_USEDEFAULT), // window width

 _height(0), // window height

 _hWndParent(0), // handle to parent or owner window

 _hMenu(0), // handle to menu, or child-window id

 _data(0) // pointer to window-creation data

{ }

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);

}

// Makes top overlapped window with caption

TopWinMaker::TopWinMaker((WinClass& winclass, char const* caption) : WinMaker(winClass) {

 _style = WS_OVERLAPPEDWINDOW | WS_VISIBLE;

 _windowName = caption;

}

Классы общего назначения

Прежде, чем идти дальше, рассмотрим некоторые простые классы общего назначения. WinException — нечто, что мы хотим использовать для исключений во время сбоев Windows API. Он заботится о восстановлении кода ошибки Windows. (Между прочим, имеется простой способ преобразовать код ошибки в строку функцией API FormatMessage.)

Класс ResString просто инкапсулирует строку, хранимую в строковых ресурсах вашего приложения.

// The exception class: stores the message and the error code class

WinException {

public:

 WinException(char* msg) : _err(::GetLastError), _msg(msg) {}

 DWORD GetError const { return _err; }

 char const* GetMessage const { return _msg; }

private:

 DWORD _err;

 char * _msg;

};

// The out-of-memory handler: throws exception

  • Читать дальше
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • ...

Ебукер (ebooker) – онлайн-библиотека на русском языке. Книги доступны онлайн, без утомительной регистрации. Огромный выбор и удобный дизайн, позволяющий читать без проблем. Добавляйте сайт в закладки! Все произведения загружаются пользователями: если считаете, что ваши авторские права нарушены – используйте форму обратной связи.

Полезные ссылки

  • Моя полка

Контакты

  • chitat.ebooker@gmail.com

Подпишитесь на рассылку: