[Ttssh2-commit] [8168] TipWinの作成・削除の処理を明確にして整理した

Back to archive index
scmno****@osdn***** scmno****@osdn*****
2019年 9月 16日 (月) 04:45:17 JST


Revision: 8168
          https://osdn.net/projects/ttssh2/scm/svn/commits/8168
Author:   yasuhide
Date:     2019-09-16 04:45:17 +0900 (Mon, 16 Sep 2019)
Log Message:
-----------
TipWinの作成・削除の処理を明確にして整理した

CTipWinクラス生成時(new CTipWin())
  - メモリ確保
  - ウィンドウ作成(Create)
CTipWinクラス削除時(delete TipWin)
  - ウィンドウ破棄(Destroy)
  - メモリ解放
CTipWin::Create(TipWin->Create(...))
  - ウィンドウの作成
CTipWin::Destroy(TipWin->Destroy())
  - ウィンドウとウィンドウハンドルの破棄
  - WndProcに伝えるUSERDATAをNULL

Modified Paths:
--------------
    branches/tootip_classify/teraterm/common/tipwin.cpp
    branches/tootip_classify/teraterm/common/tipwin.h
    branches/tootip_classify/teraterm/teraterm/addsetting.cpp
    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-15 19:45:15 UTC (rev 8167)
+++ branches/tootip_classify/teraterm/common/tipwin.cpp	2019-09-15 19:45:17 UTC (rev 8168)
@@ -114,7 +114,7 @@
 			return TRUE;
 
 		case WM_PAINT:
-			{
+			if(self) {
 				HBRUSH hbr;
 				HGDIOBJ holdbr;
 				RECT cr;
@@ -154,7 +154,7 @@
 		case WM_NCHITTEST:
 			return HTTRANSPARENT;
 		case WM_SETTEXT:
-			{
+			if(self) {
 				LPCTSTR str = (LPCTSTR) lParam;
 				const int str_width = self->tWin->str_rect.right - self->tWin->str_rect.left;
 				const int str_height = self->tWin->str_rect.bottom - self->tWin->str_rect.top;
@@ -169,7 +169,6 @@
 							 str_width + TIP_WIN_FRAME_WIDTH * 2, str_height + TIP_WIN_FRAME_WIDTH * 2,
 				             SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
 				InvalidateRect(hWnd, NULL, FALSE);
-
 			}
 			break;
 		case WM_NCDESTROY:
@@ -182,9 +181,11 @@
 				 */
 			break;
 		case WM_TIMER:
-			KillTimer(hWnd, self->timerid);
-			self->timerid = NULL;
-			self->SetVisible(FALSE);
+			if(self) {
+				KillTimer(hWnd, self->timerid);
+				self->timerid = NULL;
+				self->SetVisible(FALSE);
+			}
 			break;
 		default:
 			break;
@@ -193,26 +194,21 @@
 	return DefWindowProc(hWnd, nMsg, wParam, lParam);
 }
 
-CTipWin::CTipWin(HWND src)
-{
-	Create(src, 0, 0, "");
-	SetVisible(FALSE);
-}
-
 CTipWin::CTipWin(HWND src, int cx, int cy, const TCHAR *str)
 {
+	tWin = (TipWin *)malloc(sizeof(TipWin));
 	Create(src, cx, cy, str);
-	SetVisible(TRUE);
 }
 
 CTipWin::~CTipWin()
 {
 	if(IsExists()) {
-		DestroyWindow(tWin->tip_wnd);
-		DeleteObject(tWin->tip_font);
-		tWin->tip_font = NULL;
+		if(tWin->tip_wnd)
+			Destroy();
 		free((void*)tWin->str);
+		tWin->str = NULL;
 		free(tWin);
+		tWin = NULL;
 	}
 }
 
@@ -240,7 +236,6 @@
 		tip_class = RegisterClass(&wc);
 	}
 
-	tWin = (TipWin *)malloc(sizeof(TipWin));
 	if (tWin == NULL) return;
 	tWin->str_len = _tcslen(str);
 	tWin->str = _tcsdup(str);
@@ -277,6 +272,19 @@
 	timerid = NULL;
 }
 
+VOID CTipWin::Destroy()
+{
+	if(IsExists()) {
+		// \x83t\x83H\x83\x93\x83g\x82̔j\x8A\xFC
+		DeleteObject(tWin->tip_font);
+		tWin->tip_font = NULL;
+		// \x83E\x83B\x83\x93\x83h\x83E\x82̔j\x8A\xFC
+		DestroyWindow(tWin->tip_wnd);
+		SetWindowLongPtr(tWin->tip_wnd, GWLP_USERDATA, NULL);
+		tWin->tip_wnd = NULL;
+	}
+}
+
 VOID CTipWin::GetTextWidthHeight(HWND src, const TCHAR *str, int *width, int *height)
 {
 	TipWinGetTextWidthHeight(src, str, width, height);
@@ -293,7 +301,6 @@
 		pts.x = x;
 		pts.y = y;
 		SetWindowPos(tWin->tip_wnd, 0, x, y, 0, 0, SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
-
 	}
 }
 
@@ -342,6 +349,7 @@
 TipWin* TipWinCreate(HWND src, int cx, int cy, const TCHAR *str)
 {
 	CTipWin* tipwin = new CTipWin(src, cx, cy, str);
+	tipwin->SetVisible(TRUE);
 	return (TipWin*)tipwin;
 }
 

Modified: branches/tootip_classify/teraterm/common/tipwin.h
===================================================================
--- branches/tootip_classify/teraterm/common/tipwin.h	2019-09-15 19:45:15 UTC (rev 8167)
+++ branches/tootip_classify/teraterm/common/tipwin.h	2019-09-15 19:45:17 UTC (rev 8168)
@@ -58,8 +58,7 @@
 class CTipWin
 {
 public:
-	CTipWin(HWND hWnd, int x, int y, const TCHAR *str);
-	CTipWin(HWND hWnd);
+	CTipWin(HWND src, int x, int y, const TCHAR *str);
 	~CTipWin(VOID);
 	VOID SetText(TCHAR *str);
 	VOID GetTextWidthHeight(HWND src, const TCHAR *str, int *width, int *height);

Modified: branches/tootip_classify/teraterm/teraterm/addsetting.cpp
===================================================================
--- branches/tootip_classify/teraterm/teraterm/addsetting.cpp	2019-09-15 19:45:15 UTC (rev 8167)
+++ branches/tootip_classify/teraterm/teraterm/addsetting.cpp	2019-09-15 19:45:17 UTC (rev 8168)
@@ -634,7 +634,7 @@
 	             _T("Visual"), ts.UILanguageFile);
 	m_psp.pszTitle = _tcsdup(UIMsg);
 	m_psp.dwFlags |= (PSP_USETITLE | PSP_HASHELP);
-	TipWin = new CTipWin(m_hWnd);
+	TipWin = new CTipWin(m_hWnd, 0, 0, "VisualPropPageDlg");
 }
 
 CVisualPropPageDlg::~CVisualPropPageDlg()

Modified: branches/tootip_classify/teraterm/teraterm/vtwin.cpp
===================================================================
--- branches/tootip_classify/teraterm/teraterm/vtwin.cpp	2019-09-15 19:45:15 UTC (rev 8167)
+++ branches/tootip_classify/teraterm/teraterm/vtwin.cpp	2019-09-15 19:45:17 UTC (rev 8168)
@@ -805,7 +805,7 @@
 	DropListCount = 0;
 
 	// TipWin
-	TipWin = new CTipWin(HVTWin);
+	TipWin = new CTipWin(HVTWin, 0, 0, "VTWindow");
 }
 
 /////////////////////////////////////////////////////////////////////////////


Ttssh2-commit メーリングリストの案内
Back to archive index