7 #ifndef _INC_cWndHandle_H
8 #define _INC_cWndHandle_H
12 #include "../WinAPI/WinTypes.h"
13 #include "../WinAPI/cClipboard.h"
14 #include "../WinAPI/cWinResource.h"
15 #include "../Geometry/cRectI.h"
44 : m_hWnd(pWnd->GetSafeHwnd())
49 : m_hWnd(pWndParent->GetDlgItem(id))
51 ASSERT(pWndParent !=
nullptr);
55 cWndHandle(
CWnd* pWnd)
56 : m_hWnd(pWnd->GetSafeHwnd())
69 return ::IsWindow(m_hWnd);
78 if (!SUPER_t::isValidCheck())
88 operator HWND() const noexcept
109 return isValidHwnd();
119 bool CreateWindowX(DWORD dwExStyle,
const GChar_t* pszClassName,
const GChar_t* pszText,
120 DWORD dwStyle,
int x,
int y,
int iSizeX,
int iSizeY,
126 return AttachHwnd(
_GTN(::CreateWindowEx)(dwExStyle, pszClassName, pszText,
127 dwStyle, x, y, iSizeX, iSizeY,
132 virtual BOOL OnCreate(HWND hwnd,
_GTN(CREATESTRUCT)* lpCreateStruct =
nullptr)
138 if (!this->AttachHwnd(hwnd))
140 this->put_WindowLongPtr(GWLP_USERDATA, (LONG_PTR)
this);
143 virtual void OnDestroy()
151 BOOL IsWindow(
void)
const
159 return ::IsWindow(m_hWnd);
161 HWND GetParent()
const
165 return ::GetParent(m_hWnd);
167 BOOL IsChild(HWND hWndChild)
const
172 return ::IsChild(m_hWnd, hWndChild);
175 LRESULT SendMessageX(
WINMSG_t uMsg, WPARAM wParam = 0, LPARAM lParam = 0)
const
181 return _GTN(::SendMessage)(m_hWnd, uMsg, wParam, lParam);
183 BOOL PostMessageX(
WINMSG_t uMsg, WPARAM wParam = 0, LPARAM lParam = 0)
const
189 return _GTN(::PostMessage)(m_hWnd, uMsg, wParam, lParam);
193 void DestroyWindow(
void)
197 ::DestroyWindow(m_hWnd);
203 ::DestroyWindow(m_hWnd);
205 ::CloseWindow(m_hWnd);
210 bool GetClientRect(RECT& rcClient)
const
216 return ::GetClientRect(m_hWnd, &rcClient);
218 bool GetWindowRect(RECT& rcWnd)
const
226 return ::GetWindowRect(m_hWnd, &rcWnd);
228 cRectI get_ClientRect()
const
236 cRectI get_WindowRect()
const
247 BOOL GetWindowPlacement(::WINDOWPLACEMENT* lpwndpl)
const
250 return ::GetWindowPlacement(m_hWnd, lpwndpl);
253 BOOL SetWindowPlacement(const ::WINDOWPLACEMENT* lpwndpl)
256 return ::SetWindowPlacement(m_hWnd, lpwndpl);
259 BOOL MoveWindow(
int X,
int Y,
int nWidth,
int nHeight,
bool bRepaint =
true)
262 return(::MoveWindow(m_hWnd, X, Y, nWidth, nHeight, bRepaint));
264 BOOL SetWindowPos(HWND hWndAfter,
int x,
int y,
int cx,
int cy, UINT nFlags)
269 return(::SetWindowPos(m_hWnd, hWndAfter, x, y, cx, cy, nFlags));
272 THREADID_t get_WindowThread()
const
276 return ::GetWindowThreadProcessId(m_hWnd,
nullptr);
279 BOOL SetForegroundWindow()
286 return(::SetForegroundWindow(m_hWnd));
288 HWND SetActiveWindow()
295 return(::SetActiveWindow(m_hWnd));
305 return(::SetFocus(m_hWnd));
307 void ClientToScreen(POINT* pPoint)
const
311 ::ClientToScreen(m_hWnd, (POINT*)pPoint);
313 void ClientToScreen(RECT* pRect)
const
316 ClientToScreen((POINT*)&(pRect->left));
317 ClientToScreen((POINT*)&(pRect->right));
319 void ScreenToClient(POINT* pPoint)
const
323 ::ScreenToClient(m_hWnd, (POINT*)pPoint);
325 void ScreenToClient(RECT* pRect)
const
328 ScreenToClient((POINT*)&(pRect->left));
329 ScreenToClient((POINT*)&(pRect->right));
331 bool IsWindowVisible(
void)
const
333 return ::IsWindowVisible(m_hWnd);
335 bool IsZoomed(
void)
const
339 return IsWindowVisible();
341 return ::IsZoomed(m_hWnd);
344 bool IsIconic(
void)
const
350 return ::IsIconic(m_hWnd);
353 bool ShowWindow(SHOWWINDOW_t nCmdShow)
358 return ::ShowWindow(m_hWnd, nCmdShow);
360 bool ShowWindow(
bool bCmdShow)
363 return ShowWindow(bCmdShow ? SW_SHOWNORMAL : SW_HIDE);
366 bool IsWindowEnabled()
const
370 return ::IsWindowEnabled(m_hWnd);
372 bool EnableWindow(
bool bState =
true)
376 return ::EnableWindow(m_hWnd, bState);
380 void SetRedraw(
bool bRedraw)
383 SendMessageX(WM_SETREDRAW, bRedraw);
385 HDC GetDC(
void)
const
388 return(::GetDC(m_hWnd));
390 void ReleaseDC(HDC hDC)
const
393 ::ReleaseDC(m_hWnd, hDC);
395 void ValidateRect(RECT* pRect =
nullptr)
const
400 ::ValidateRect(m_hWnd, pRect);
402 void InvalidateRect(RECT* pRect =
nullptr,
bool bErase =
false)
const
407 ::InvalidateRect(m_hWnd, pRect, bErase);
409 void InvalidateRect(
int sx,
int sy,
int iWidth,
int iHeight)
const
411 cRectI
rect(sx, sy, sx + iWidth, sy + iHeight);
412 InvalidateRect(
rect);
417 return(::UpdateWindow(m_hWnd));
419 bool RedrawWindow(
const RECT* pRectUpdate =
nullptr, HRGN hRgn =
WINHANDLE_NULL, UINT flags = RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE)
423 return(::RedrawWindow(m_hWnd, pRectUpdate, hRgn, flags));
427 StrLen_t GetWindowTextLengthX()
const
432 return(
_GTN(::GetWindowTextLength)(m_hWnd));
439 return(
_GTN(::GetWindowText)(m_hWnd, lpszText, iLen));
441 cString GetWindowTextX()
const;
442 BOOL SetWindowTextX(
const GChar_t* lpszText)
447 return(
_GTN(::SetWindowText)(m_hWnd, lpszText));
451 HMENU GetMenu(
void)
const
454 return(::GetMenu(m_hWnd));
456 HMENU GetSystemMenu(
bool bReset =
false)
const
459 return(::GetSystemMenu(m_hWnd, bReset));
463 HFONT GetFont()
const
465 return((HFONT)(UINT_PTR)SendMessageX(WM_GETFONT));
467 void SetFont(HFONT hFont,
bool bRedraw =
false)
469 SendMessageX(WM_SETFONT, (WPARAM)hFont, MAKELPARAM(bRedraw, 0));
472 HICON GetIcon(
int fType = ICON_SMALL)
const
475 return((HICON)(UINT_PTR)SendMessageX(WM_GETICON, (WPARAM)fType));
477 HICON SetIcon(HICON hIcon,
int fType = ICON_SMALL)
480 return((HICON)(UINT_PTR)SendMessageX(WM_SETICON, (WPARAM)fType, (LPARAM)hIcon));
487 return(::SetTimer(m_hWnd, uTimerID, uWaitmSec,
nullptr));
489 BOOL KillTimer(
DLGID_t uTimerID)
493 return(::KillTimer(m_hWnd, uTimerID));
495 int ShowMessageBox(
const GChar_t* pszText,
const GChar_t* pszTitle, UINT fuStyle = MB_OK)
const
499 return(
_GTN(::MessageBox)(m_hWnd, pszText, pszTitle, fuStyle));
501 LONG SetLongValue(
int nIndex, LONG dwNewLong)
506 return(
_GTN(::SetWindowLong)(m_hWnd, nIndex, dwNewLong));
508 LONG GetLongValue(
int nIndex)
const
513 return(
_GTN(::GetWindowLong)(m_hWnd, nIndex));
516 static inline LONG_PTR SetLongPtr(HWND hWnd,
int nIndex, LONG_PTR dwNewLong)
520 #ifndef GWLP_USERDATA
521 #define GWLP_USERDATA GWL_USERDATA
522 #define GWLP_WNDPROC GWL_WNDPROC
524 #if defined(USE_64BIT) && ! defined(UNDER_CE)
525 return(
_GTN(::SetWindowLongPtr)(hWnd, nIndex, dwNewLong));
527 return(
_GTN(::SetWindowLong)(hWnd, nIndex, (LONG)dwNewLong));
531 static inline LONG_PTR GetLongPtr(HWND hWnd,
int nIndex)
534 #if defined(USE_64BIT) && ! defined(UNDER_CE)
535 return(
_GTN(::GetWindowLongPtr)(hWnd, nIndex));
537 return(
_GTN(::GetWindowLong)(hWnd, nIndex));
541 LONG_PTR put_WindowLongPtr(
int nIndex, LONG_PTR dwNewLong)
545 return SetLongPtr(m_hWnd, nIndex, dwNewLong);
548 LONG_PTR get_WindowLongPtr(
int nIndex)
552 return GetLongPtr(m_hWnd, nIndex);
554 LONG_PTR GetClassLongPtrX(
int nIndex)
const
559 #if defined(USE_64BIT)
560 return(
_GTN(::GetClassLongPtr)(m_hWnd, nIndex));
562 return(
_GTN(::GetClassLong)(m_hWnd, nIndex));
566 DWORD GetStyle()
const
569 return((DWORD)GetLongValue(GWL_STYLE));
571 DWORD SetStyle(DWORD dwStyle)
573 return((DWORD)SetLongValue(GWL_STYLE, dwStyle));
575 DWORD GetExStyle()
const
578 return((DWORD)GetLongValue(GWL_EXSTYLE));
582 virtual DLGID_t GetDlgCtrlID()
const
589 return ::GetDlgCtrlID(m_hWnd);
592 cWndHandle GetDlgItem(
DLGID_t id)
const
595 return ::GetDlgItem(m_hWnd,
id);
597 LRESULT SendDlgItemMessageX(
DLGID_t nIDDlgItem,
WINMSG_t Msg, WPARAM wParam = 0, LPARAM lParam = 0)
const
601 return(
_GTN(::SendDlgItemMessage)(m_hWnd, nIDDlgItem, Msg, wParam, lParam));
607 return(
_GTN(::GetDlgItemText)(m_hWnd, nIDDlgItem, lpString, nMaxCount));
611 BOOL SetDlgItemTextX(
DLGID_t nIDDlgItem,
const GChar_t* lpszText)
const
615 return(
_GTN(::SetDlgItemText)(m_hWnd, nIDDlgItem, lpszText));
618 void SetDlgItemInt(
DLGID_t nIDDlgItem,
int iVal)
const;
619 int GetDlgItemInt(
DLGID_t nIDDlgItem)
const;
621 UINT IsDlgButtonChecked(
DLGID_t nIDDlgItem)
const
626 return(::IsDlgButtonChecked(m_hWnd, nIDDlgItem));
628 bool CheckDlgButton(
DLGID_t nIDButton, UINT uCheck)
632 return(::CheckDlgButton(m_hWnd, nIDButton, uCheck));
637 return(::CheckRadioButton(m_hWnd, nIDFirstButton, nIDLastButton, nIDCheckButton));
642 return(::SetCapture(m_hWnd));
647 static HWND
GRAYCALL FindWindowAtPoint(HWND hWndParent,
const POINT& ptScreen);
649 void CenterWindow(HWND hWndOrder = HWND_NOTOPMOST);
650 void EnableWindowItem(
DLGID_t id,
bool bState);
651 void EnableWindowRange(
DLGID_t idChildStart,
DLGID_t idChildEnd,
bool bState);
652 void ShowWindowItem(
DLGID_t id,
bool bState);
653 void ShowWindowRange(
DLGID_t idChildStart,
DLGID_t idChildEnd,
bool bState);
658 return cClipboard::GetClipboardText(get_Hwnd(), iSizeMax);
660 bool SetClipboardText(
cString sText)
662 return cClipboard::SetClipboardText(get_Hwnd(), sText);
670 #define HANDLE_DLGMSG HANDLE_MSG
#define GRAYCALL
declare calling convention for static functions so everyone knows the arg passing scheme....
Definition: GrayCore.h:36
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
#define IS_TYPE_OF(t, p)
Definition: PtrCast.h:23
#define _GTN(c)
_WIN32 name has a A or W for UTF8 or UNICODE (like _FNF)
Definition: StrConst.h:28
#define UNREFERENCED_PARAMETER(P)
< _WIN32 type thing. get rid of stupid warning.
Definition: SysTypes.h:299
UINT WINMSG_t
Supplement _WIN32 "windows.h".
Definition: WinTypes.h:111
#define ASSERT(exp)
Definition: cDebugAssert.h:87
#define DEBUG_CHECK(exp)
Definition: cDebugAssert.h:90
#define WINHANDLE_NULL
HWND, HPEN, etc are NOT OS Handles. like HWND_DESKTOP. like HANDLEPTR_NULL. This is a WINAPI void* ha...
Definition: cOSHandle.h:23
#define ASSERT_VALID(p)
Definition: cObject.h:61
Definition: cWndHandle.h:26
cWndHandle(HWND hWnd=WINHANDLE_NULL) noexcept
Definition: cWndHandle.h:39
bool AttachHwnd(HWND hWnd)
Definition: cWndHandle.h:105
HWND get_Hwnd() const noexcept
Definition: cWndHandle.h:93
void DetachHwnd()
Definition: cWndHandle.h:111
bool isValidHwnd() const noexcept
Definition: cWndHandle.h:65
cWndHandle(cWndHandle *pWnd) noexcept
Definition: cWndHandle.h:43
HWND GetSafeHwnd() const noexcept
Definition: cWndHandle.h:98
virtual bool isValidCheck() const noexcept
< memory allocation and structure definitions are valid.
Definition: cWndHandle.h:74
virtual ~cWndHandle()
Definition: cWndHandle.h:60
HWND m_hWnd
Handle to window (i may or may not have to destroy this)
Definition: cWndHandle.h:36
static HMODULE __stdcall get_HModule()
Definition: cAppState.cpp:782
cWndHandle CWnd
Definition: cWndHandle.h:669
UINT DLGID_t
old window format this was a WORD, EX format this is UINT32.
Definition: cResDialog.h:68
interface const RECTQ_t & rect
Definition: cQuadtree.h:44
int StrLen_t
the length of a string in chars (bytes for UTF8, wchar_t for UNICODE). or offset in characters....
Definition: StrConst.h:32
INT32 TIMESYSD_t
Time delta. signed milli-Seconds Span. cTimeSys::k_DMAX, cTimeSys::k_INF = MAILSLOT_WAIT_FOREVER.
Definition: cTimeSys.h:28
int ITERATE_t
like size_t but signed
Definition: Index.h:28
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26
cArrayString< char > cArrayStringA
Definition: cArrayString.h:174
cStringT< GChar_t > cString
Definition: cString.h:636
static const StrLen_t k_LEN_MAX
arbitrary max size for Format() etc. NOTE: _MSC_VER says stack frame should be at least 16384
Definition: StrT.h:75
static bool IsValidApp(const void *pData) noexcept
Definition: cMem.h:42