sprint 1-alpha
|
00001 /****************************************************************************** 00002 * GTL: GUI Template Library 00003 * A Cross Platform C++ Wrapper for Win32 users 00004 * Copyright (C) 2007-2011 Paolo Medici (www.pmx.it) 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public 00008 * License as published by the Free Software Foundation; either 00009 * version 2.1 of the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 * 00020 *******************************************************************************/ 00021 00022 #ifndef _SPRINT_CWINDOW_H 00023 #define _SPRINT_CWINDOW_H 00024 00025 #ifdef WIN32 00026 # include <windows.h> 00027 #endif 00028 00032 #include <string> 00033 #include <sprint/gtl/menu.h> 00034 00035 namespace sprint { 00039 namespace gtl { 00040 00045 class CWindow { 00046 00047 public: 00048 HWND m_hwnd; 00049 00050 static const int Default = CW_USEDEFAULT; 00051 00052 // Default Procedure Handler (???) 00053 // inline bool OnCreate(LPCREATESTRUCT lpCreateStruct) { return true; } 00054 00055 public: 00057 CWindow(HWND hWnd=NULL) : m_hwnd(hWnd) {} 00058 00059 inline void SetHwnd(HWND hwnd) { m_hwnd = hwnd; } 00060 00062 inline operator HWND() const { return m_hwnd; } 00063 00064 inline operator bool() const { return m_hwnd != NULL; } 00065 00067 inline RECT GetClientRect() const 00068 { 00069 RECT rt; 00070 ::GetClientRect(m_hwnd, &rt); 00071 return rt; 00072 } 00073 00075 inline RECT GetWindowRect() const 00076 { 00077 RECT rt; 00078 ::GetWindowRect(m_hwnd, &rt); 00079 return rt; 00080 } 00081 00083 inline LONG SetText(const char *txt) 00084 { 00085 return ::SetWindowTextA(m_hwnd, txt); 00086 } 00087 00088 inline LONG SetText(const std::string & txt) 00089 { 00090 return ::SetWindowTextA(m_hwnd, txt.c_str()); 00091 } 00092 00094 inline LONG GetText(char *buffer, int buf_len) const 00095 { 00096 return ::GetWindowTextA(m_hwnd, buffer, buf_len); 00097 } 00098 00100 inline LONG SetWindowLong(int nIndex, LONG dwNewLong) 00101 { 00102 return ::SetWindowLong(m_hwnd, nIndex, dwNewLong); 00103 } 00104 00106 inline LONG GetWindowLong(int nIndex) 00107 { 00108 return ::GetWindowLong(m_hwnd, nIndex); 00109 } 00110 00112 inline HMODULE GetInstance() { return (HMODULE)::GetWindowLong(m_hwnd, GWL_HINSTANCE); } 00113 00116 inline void Show(int mode = SW_SHOW) { ::ShowWindow (m_hwnd, mode); } 00119 inline void Hide() { ::ShowWindow(m_hwnd, SW_HIDE); } 00120 00121 inline void Enable() {::EnableWindow(m_hwnd, TRUE); } 00122 inline void Disable() {::EnableWindow(m_hwnd, FALSE); } 00123 bool IsEnabled() const {::IsWindowEnabled(m_hwnd); } 00124 00127 inline void Move(int x, int y) const { ::SetWindowPos(m_hwnd, NULL, x,y, 0,0,SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOOWNERZORDER |SWP_NOSIZE); } 00128 00131 inline void Resize(int sx, int sy) const { ::SetWindowPos(m_hwnd, NULL, 0,0,sx,sy,SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOOWNERZORDER |SWP_NOMOVE); } 00132 00135 inline void Redraw(bool RedrawBg=TRUE) const { ::InvalidateRect(m_hwnd, NULL, RedrawBg); } 00136 00138 inline void SetCapture() const { ::SetCapture(m_hwnd); } 00140 inline void ReleaseCapture() const { ::ReleaseCapture(); } 00141 00143 inline void Destroy() const { ::DestroyWindow(m_hwnd); } 00144 00146 inline HWND Parent(void) const { return ::GetParent(m_hwnd); } 00147 00148 inline CMenuHandle Menu(void) const { return ::GetMenu(m_hwnd); } 00149 00150 inline bool SetMenu(HMENU hmenu) { return ::SetMenu(m_hwnd, hmenu) == TRUE; } 00151 00155 inline void SetTimer(UINT uTimeOut, UINT nIDEvent=0) const { ::SetTimer(m_hwnd, nIDEvent, uTimeOut, NULL); } 00156 00158 inline void KillTimer(UINT nIDEvent=0) const { ::KillTimer(m_hwnd, nIDEvent); } 00159 00161 inline CWindow GetDlgItem(int id) 00162 { return CWindow(::GetDlgItem(m_hwnd, id)); } 00163 00165 void MoveWindow(int X, 00166 int Y, 00167 int nWidth, 00168 int nHeight, 00169 BOOL bRepaint = TRUE) 00170 { 00171 ::MoveWindow(m_hwnd, X,Y,nWidth, nHeight, bRepaint); 00172 } 00173 00174 void MoveWindow(const RECT &rc, BOOL bRepaint = TRUE) 00175 { 00176 ::MoveWindow(m_hwnd, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, bRepaint); 00177 } 00178 00179 void Close() 00180 { 00181 ::SendMessage(m_hwnd, WM_CLOSE, 0,0); 00182 } 00183 00184 // forza il ridisegno della barra menu 00185 void DrawMenuBar() 00186 { 00187 ::DrawMenuBar(m_hwnd); 00188 } 00189 }; 00190 00191 } 00192 } 00193 00194 #endif