Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cWinProcess.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cWinProcess_H
7 #define _INC_cWinProcess_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayLibBase.h"
13 #include "../System/cOSProcessX.h"
14 
15 #ifdef _WIN32
16 
17 namespace GrayLib
18 {
19  UNITTEST2_PREDEF(cWinProcess);
20 
21  class cWinProcess : public cOSProcessX
22  {
25 
26  public:
27  const GChar_t* const m_pszWindowClass;
28  cTimeSys m_tStarted;
29  protected:
30  HWND m_hWndProc;
31 
32  public:
33  cWinProcess(const GChar_t* pszWindowClass)
34  : m_pszWindowClass(pszWindowClass)
35  , m_tStarted(cTimeSys::k_CLEAR)
36  , m_hWndProc(WINHANDLE_NULL)
37  {
38  }
39 
40  HWND get_ProcWnd() const
41  {
42  return m_hWndProc;
43  }
44  void DisconnectProcWnd()
45  {
46  m_hWndProc = WINHANDLE_NULL;
47  }
48  bool FindProcWnd(bool bUsePid)
49  {
52  if (m_hWndProc != WINHANDLE_NULL && ::IsWindow(m_hWndProc))
53  {
54  return true;
55  }
56  if (m_pszWindowClass == nullptr && (!bUsePid || get_ProcessId() == PROCESSID_BAD))
57  {
58  // Weird that process 0 (idle proc) has a window ? i don't want it.
59  return false;
60  }
61  m_hWndProc = cOSProcess::FindWindowForProcessID(bUsePid ? get_ProcessId() : PROCESSID_BAD, 0, m_pszWindowClass);
62  if (m_hWndProc != WINHANDLE_NULL && ::IsWindow(m_hWndProc))
63  {
64  return true;
65  }
66  m_hWndProc = WINHANDLE_NULL;
67  return false;
68  }
69 
70  UNITTEST2_PREDEF(cWinProcess);
71  };
72 };
73 #endif
74 #endif
#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
Definition: cMesh.h:22
UNITTEST2_PREDEF(cQuadtree)
constexpr PROCESSID_t PROCESSID_BAD
Invalid process id.
Definition: cOSProcess.h:46
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26