Revision: 8201 https://osdn.net/projects/ttssh2/scm/svn/commits/8201 Author: yasuhide Date: 2019-09-20 20:09:09 +0900 (Fri, 20 Sep 2019) Log Message: ----------- [Tooltip] ウィンドウクラスを登録するときのチェックを強化した - RegisterClass, UnregisterClassをインスタンスメソッドにした Modified Paths: -------------- branches/tootip_classify/teraterm/common/tipwin.cpp branches/tootip_classify/teraterm/common/tipwin.h branches/tootip_classify/teraterm/teraterm/vtwin.cpp -------------- next part -------------- Modified: branches/tootip_classify/teraterm/common/tipwin.cpp =================================================================== --- branches/tootip_classify/teraterm/common/tipwin.cpp 2019-09-20 08:33:01 UTC (rev 8200) +++ branches/tootip_classify/teraterm/common/tipwin.cpp 2019-09-20 11:09:09 UTC (rev 8201) @@ -210,26 +210,35 @@ } } -VOID CTipWin::SetWndClass(HINSTANCE hInstance) +BOOL CTipWin::IsClassRegistered(HINSTANCE hInstance) { - memset(&wc, 0, sizeof(WNDPROC)); - wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS; - wc.lpfnWndProc = WndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInstance; - wc.hIcon = NULL; - wc.hCursor = NULL; - wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = (LPCSTR)TipWinClassName; + WNDCLASS twc = { 0 }; + return (BOOL)GetClassInfo(hInstance, (LPCSTR)TipWinClassName, &twc); } -WNDCLASS CTipWin::GetWndClass() +ATOM CTipWin::RegisterClass(HINSTANCE hInstance) { - return (WNDCLASS) wc; + if (! IsClassRegistered(hInstance)) { + memset(&wc, 0, sizeof(WNDCLASS)); + wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS; + wc.lpfnWndProc = WndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInstance; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = (LPCSTR)TipWinClassName; + } + return ::RegisterClass(&wc); } +BOOL CTipWin::UnregisterClass() +{ + return ::UnregisterClass((LPCSTR)TipWinClassName, wc.hInstance); +} + VOID CTipWin::Create(HWND src, int cx, int cy, const TCHAR *str) { const HINSTANCE hInst = (HINSTANCE)GetWindowLongPtr(src, GWLP_HINSTANCE); @@ -236,7 +245,10 @@ LOGFONTA logfont; const UINT uDpi = GetMonitorDpiFromWindow(src); - if (tWin == NULL) return; + if (! IsClassRegistered(hInst)) + return; + if (tWin == NULL) + return; tWin->str_len = _tcslen(str); tWin->str = _tcsdup(str); tWin->px = cx; Modified: branches/tootip_classify/teraterm/common/tipwin.h =================================================================== --- branches/tootip_classify/teraterm/common/tipwin.h 2019-09-20 08:33:01 UTC (rev 8200) +++ branches/tootip_classify/teraterm/common/tipwin.h 2019-09-20 11:09:09 UTC (rev 8201) @@ -62,8 +62,9 @@ public: CTipWin(); ~CTipWin(); - VOID SetWndClass(HINSTANCE hInstance); - WNDCLASS GetWndClass(); + ATOM RegisterClass(HINSTANCE hInstance); + BOOL UnregisterClass(); + BOOL IsClassRegistered(HINSTANCE hInstance); VOID Create(HWND src, int x, int y, const TCHAR *str); VOID Destroy(); VOID SetText(TCHAR *str); Modified: branches/tootip_classify/teraterm/teraterm/vtwin.cpp =================================================================== --- branches/tootip_classify/teraterm/teraterm/vtwin.cpp 2019-09-20 08:33:01 UTC (rev 8200) +++ branches/tootip_classify/teraterm/teraterm/vtwin.cpp 2019-09-20 11:09:09 UTC (rev 8201) @@ -806,11 +806,8 @@ // TipWin TipWin = new CTipWin(); - { - // TipWin\x82\xCCWindow\x83N\x83\x89\x83X\x82̓o\x98^\x82\xCDTera Term\x91S\x91̂\xC51\x93x\x82\xBE\x82\xAF\x8Ds\x82\xA4 - TipWin->SetWndClass(hInstance); - ::RegisterClass(&TipWin->GetWndClass()); - } + // TipWin\x82\xCCWindow\x83N\x83\x89\x83X\x82̓o\x98^\x82\xCDTera Term\x91S\x91̂\xC51\x93x\x82\xBE\x82\xAF\x8Ds\x82\xA4 + TipWin->RegisterClass(hInstance); TipWin->Create(HVTWin, 0, 0, VTClassName); } @@ -820,10 +817,7 @@ CVTWindow::~CVTWindow() { TipWin->Destroy(); - { - WNDCLASS wc = TipWin->GetWndClass(); - ::UnregisterClass(wc.lpszClassName, wc.hInstance); - } + TipWin->UnregisterClass(); delete TipWin; TipWin = NULL; }