1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <tengine/guiwindow.hpp>
using namespace TEngine;
/// ------------------------------
/// @class GUIWindow
/// @brief Represents GUI window.
/// ------------------------------
/// Anonymous namespace:
namespace{
#ifdef _WIN32
::LRESULT CALLBACK __TEngine_GUIWindow_WndProc(::HWND h, ::UINT message, ::WPARAM w, ::LPARAM l){
switch(message){
case WM_CLOSE:
::DestroyWindow(h);
return 0;
case WM_DESTROY:
::PostQuitMessage(0);
return 0;
default:
return ::DefWindowProc(h, message, w, l);
}
}
#endif // _WIN32
}
/// Constructors & destructors:
#ifndef _WIN32
GUIWindow::GUIWindow(char const* name, unsigned width, unsigned height) : _m_bOpen(true), _m_cpName(name), _m_uiSizeHeight(height), _m_uiSizeWidth(width){
}
#endif // !_WIN32
GUIWindow::~GUIWindow(void){
if(_m_bOpen)
this->close();
}
/// Constructors & destructors (Windows only):
#ifdef _WIN32
GUIWindow::GUIWindow(char const* name, unsigned width, unsigned height, ::HINSTANCE h, int const& cmd_show) : _m_bOpen(true), _m_cpName(name), _m_uiSizeHeight(height), _m_uiSizeWidth(width), _m_opHandleInstance(h), _m_iCmdShow(cmd_show){
}
#endif // _WIN32
/// Member functions:
void GUIWindow::close(void){
_m_bOpen = false;
::exit(0);
}
void GUIWindow::create(void){
#ifdef _WIN32
{
// Create the window class:
::WNDCLASSEX __wcx;{
__wcx.cbClsExtra = 0;
__wcx.cbWndExtra = 0;
__wcx.hbrBackground = (::HBRUSH)::GetStockObject(BLACK_BRUSH);
__wcx.hCursor = ::LoadCursor (NULL, IDC_ARROW);
__wcx.hIcon = ::LoadIcon(_m_opHandleInstance, IDI_APPLICATION);
__wcx.hInstance = _m_opHandleInstance;
__wcx.lpfnWndProc = __TEngine_GUIWindow_WndProc;
__wcx.lpszClassName = _m_cpName;
__wcx.lpszMenuName = NULL;
__wcx.style = (CS_HREDRAW | CS_VREDRAW);
}
::RegisterClassEx(&__wcx);
// Create the window:
_m_opWindow = ::CreateWindowEx(
WS_EX_APPWINDOW,
_m_cpName, _m_cpName,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, _m_opHandleInstance, NULL
);
// Set the window visible:
::ShowWindow(_m_opWindow, _m_iCmdShow);
::UpdateWindow(_m_opWindow);
}
#endif // _WIN32
}
void GUIWindow::display(void) const{
while(::GetMessage(_m_opMessage, NULL, 0, 0)){
::TranslateMessage(_m_opMessage);
::DispatchMessage(_m_opMessage);
}
}
|