Simple class wrapper for window handle (HWND) with elegant and intuitive methods.
#pragma once class DeviceContext { private: HWND _hWnd; private: HDC _hDC; public: DeviceContext(HWND hwnd) : _hWnd(hwnd), _hDC(NULL) { _hDC = ::GetDC(_hWnd); } public: HWND Window() const { return _hWnd; } public: HDC Handle() const { return _hDC; } public: ~DeviceContext() { BOOL bRet = ::ReleaseDC(_hWnd, _hDC); _ASSERTE(FALSE != bRet); } public: int GetDeviceCaps(int nIndex) { return ::GetDeviceCaps(_hDC, nIndex); } }; enum BorderStyle { BORDERSTYLE_NONE, BORDERSTYLE_THIN, BORDERSTYLE_CLIENTEDGE }; class Window { private: HWND _hWnd; public: Window(HWND hwnd) : _hWnd(hwnd) { _ASSERTE(NULL != hwnd); } public: virtual ~Window() { } public: HWND Handle() const { return _hWnd; } public: void ShowFullScreen() { // Remove caption and border const int currentStyle = GetWindowLong(_hWnd, GWL_STYLE); const int modifiedStyle = currentStyle & (~(WS_CAPTION | WS_BORDER)); ::SetWindowLong(_hWnd, GWL_STYLE, & modifiedStyle); // Put window on top and expand it to fill screen ::SetWindowPos(_hWnd, HWND_TOPMOST, -(GetSystemMetrics(SM_CXBORDER) + 1), -(GetSystemMetrics(SM_CYBORDER) + 1), cx + 1, cy + 1, SWP_NOZORDER); } public: void Restore() { } public: void Resize(int width, int height) { RECT rect; ::GetWindowRect(_hWnd, &rect); ::SetWindowPos(NULL, rect.left, rect.top, width, height, SWP_NOZORDER|SWP_NOMOVE); } public: void SnapIntoDesktop() const { ::SendMessage(_hWnd, DM_REPOSITION, 0, 0); } public: void asdasd() { ::SetWindowLong(_hWnd, GWL_STYLE, GetWindowLong(_hWnd, GWL_STYLE) | WS_MINIMIZEBOX | WS_MAXIMIZEBOX); } // SetDialogBkColor(RGB(255,0,0),RGB(0,255,0)); public: int ShowBorder(BorderStyle eStyle) { switch (eStyle) { case BORDERSTYLE_NONE: { const BOOL bOK = ModifyStyle(WS_BORDER, 0, SWP_DRAWFRAME | SWP_FRAMECHANGED); const BOOL bOK2 = ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_DRAWFRAME | SWP_FRAMECHANGED); return bOK | bOK2; } case BORDERSTYLE_THIN: { const DWORD dwStyle = static_cast( GetWindowLong(Handle(), GWL_STYLE) ); const BOOL bOK = ModifyStyle(0, dwStyle | WS_BORDER, SWP_DRAWFRAME | SWP_FRAMECHANGED); return bOK; } case BORDERSTYLE_CLIENTEDGE: { const DWORD dwExStyle = static_cast( GetWindowLong(Handle(), GWL_EXSTYLE) ); const BOOL bOK = ModifyStyleEx(0, dwExStyle | WS_EX_CLIENTEDGE, SWP_DRAWFRAME | SWP_FRAMECHANGED); return bOK; } } } };