[Ttssh2-commit] [8519] ウィンドウの作成時 Unicode APIを使用

scmno****@osdn***** scmno****@osdn*****
2020年 2月 1日 (土) 00:37:23 JST


Revision: 8519
          https://osdn.net/projects/ttssh2/scm/svn/commits/8519
Author:   zmatsuo
Date:     2020-02-01 00:37:22 +0900 (Sat, 01 Feb 2020)
Log Message:
-----------
ウィンドウの作成時 Unicode APIを使用

- pDefWindowProcW() 追加
- TTCFrameWnd::CreateW() 追加
- TTCFrameWnd::Create() -> CreateA()
- vtwin、tekwinで、
  - TTCFrameWnd::Create() から CreateW() に変更
- TTCFrameWnd::OnDestroy() 削除 (特に何も行っていない関数)

Modified Paths:
--------------
    trunk/teraterm/common/compat_win.cpp
    trunk/teraterm/common/compat_win.h
    trunk/teraterm/common/tmfc.cpp
    trunk/teraterm/common/tmfc.h
    trunk/teraterm/common/tmfc_frame.cpp
    trunk/teraterm/teraterm/tekwin.cpp
    trunk/teraterm/teraterm/ttwinman.c
    trunk/teraterm/teraterm/vtwin.cpp

-------------- next part --------------
Modified: trunk/teraterm/common/compat_win.cpp
===================================================================
--- trunk/teraterm/common/compat_win.cpp	2020-01-30 23:42:47 UTC (rev 8518)
+++ trunk/teraterm/common/compat_win.cpp	2020-01-31 15:37:22 UTC (rev 8519)
@@ -36,10 +36,10 @@
 #include "ttlib.h"
 
 ATOM (WINAPI *pRegisterClassW)(const WNDCLASSW *lpWndClass);
-HWND(WINAPI *pCreateWindowExW)
-(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight,
+HWND (WINAPI *pCreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight,
  HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
-HPROPSHEETPAGE (WINAPI * pCreatePropertySheetPageW)(LPCPROPSHEETPAGEW constPropSheetPagePointer);
+LRESULT (WINAPI *pDefWindowProcW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
+HPROPSHEETPAGE (WINAPI *pCreatePropertySheetPageW)(LPCPROPSHEETPAGEW constPropSheetPagePointer);
 INT_PTR (WINAPI *pPropertySheetW)(LPCPROPSHEETHEADERW constPropSheetHeaderPointer);
 LRESULT (WINAPI *pSendDlgItemMessageW)(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam);
 BOOL (WINAPI *pModifyMenuW)(HMENU hMnu, UINT uPosition, UINT uFlags, UINT_PTR uIDNewItem, LPCWSTR lpNewItem);
@@ -119,6 +119,9 @@
 }
 
 static const APIInfo Lists_user32[] = {
+	{ "RegisterClassW", (void **)&pRegisterClassW },
+	{ "CreateWindowExW", (void **)&pCreateWindowExW },
+	{ "DefWindowProcW", (void **)&pDefWindowProcW },
 	{ "SetLayeredWindowAttributes", (void **)&pSetLayeredWindowAttributes },
 	{ "SetThreadDpiAwarenessContext", (void **)&pSetThreadDpiAwarenessContext },
 	{ "IsValidDpiAwarenessContext", (void **)&pIsValidDpiAwarenessContext },
@@ -213,6 +216,7 @@
 		pDialogBoxIndirectParamW = NULL;
 		pCreateWindowExW = NULL;
 		pRegisterClassW = NULL;
+		pDefWindowProcW = NULL;
 	}
 
 	// GetConsoleWindow\x93\xC1\x95ʏ\x88\x97\x9D

Modified: trunk/teraterm/common/compat_win.h
===================================================================
--- trunk/teraterm/common/compat_win.h	2020-01-30 23:42:47 UTC (rev 8518)
+++ trunk/teraterm/common/compat_win.h	2020-01-31 15:37:22 UTC (rev 8519)
@@ -68,9 +68,10 @@
 #endif
 
 extern ATOM (WINAPI *pRegisterClassW)(const WNDCLASSW *lpWndClass);
-extern HWND(WINAPI *pCreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X,
-									  int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance,
-									  LPVOID lpParam);
+extern HWND (WINAPI *pCreateWindowExW)(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, int X,
+									   int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance,
+									   LPVOID lpParam);
+extern LRESULT (WINAPI *pDefWindowProcW)(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam);
 extern HPROPSHEETPAGE (WINAPI * pCreatePropertySheetPageW)(LPCPROPSHEETPAGEW constPropSheetPagePointer);
 extern INT_PTR (WINAPI *pPropertySheetW)(LPCPROPSHEETHEADERW constPropSheetHeaderPointer);
 extern LRESULT (WINAPI *pSendDlgItemMessageW)(HWND hDlg, int nIDDlgItem, UINT Msg, WPARAM wParam, LPARAM lParam);

Modified: trunk/teraterm/common/tmfc.cpp
===================================================================
--- trunk/teraterm/common/tmfc.cpp	2020-01-30 23:42:47 UTC (rev 8518)
+++ trunk/teraterm/common/tmfc.cpp	2020-01-31 15:37:22 UTC (rev 8519)
@@ -35,6 +35,7 @@
 #include <assert.h>
 #include "dlglib.h"
 #include "ttlib.h"
+#include "compat_win.h"
 #include "layer_for_unicode.h"
 
 // \x83e\x83\x93\x83v\x83\x8C\x81[\x83g\x82̏\x91\x82\xAB\x8A\xB7\x82\xA6\x82\xF0\x8Ds\x82\xA4
@@ -51,6 +52,7 @@
 	m_hInst = nullptr;
 	m_hAccel = nullptr;
 	m_hParentWnd = nullptr;
+	m_WindowUnicode = FALSE;
 }
 
 LRESULT TTCWnd::SendMessage(UINT msg, WPARAM wp, LPARAM lp)
@@ -259,7 +261,13 @@
 
 LRESULT TTCWnd::DefWindowProc(UINT msg, WPARAM wParam, LPARAM lParam)
 {
-	return ::DefWindowProc(m_hWnd, msg, wParam, lParam);
+	if (m_WindowUnicode && pDefWindowProcW != NULL) {
+		// Unicode API \x82\xA0\x82\xE8 && Unicode Window
+		return pDefWindowProcW(m_hWnd, msg, wParam, lParam);
+	}
+	else {
+		return ::DefWindowProcA(m_hWnd, msg, wParam, lParam);
+	}
 }
 
 ////////////////////////////////////////

Modified: trunk/teraterm/common/tmfc.h
===================================================================
--- trunk/teraterm/common/tmfc.h	2020-01-30 23:42:47 UTC (rev 8518)
+++ trunk/teraterm/common/tmfc.h	2020-01-31 15:37:22 UTC (rev 8519)
@@ -79,6 +79,8 @@
 	void SetDlgItemInt(int id, UINT val, BOOL bSigned = TRUE);
 	UINT GetDlgItemInt(int id, BOOL* lpTrans = NULL, BOOL bSigned = TRUE) const;
 	void EnableDlgItem(int id, BOOL enable);
+protected:
+	BOOL m_WindowUnicode;
 private:
 	void ModifyStyleCom(int nStyleOffset, DWORD dwRemove, DWORD dwAdd, UINT nFlags = 0);
 };
@@ -90,15 +92,22 @@
 	virtual ~TTCFrameWnd();
 	static TTCFrameWnd *pseudoPtr;
 	static LRESULT CALLBACK ProcStub(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp);
-	virtual BOOL Create(HINSTANCE hInstance,
-						LPCTSTR lpszClassName,
-						LPCTSTR lpszWindowName,
-						DWORD dwStyle = WS_OVERLAPPEDWINDOW,
-						const RECT& rect = rectDefault,
-						HWND pParentWnd = NULL,        // != NULL for popups
-						LPCTSTR lpszMenuName = NULL,
-						DWORD dwExStyle = 0);//,
-						//CCreateContext* pContext = NULL);
+	BOOL CreateA(HINSTANCE hInstance,
+				 LPCSTR lpszClassName,
+				 LPCSTR lpszWindowName,
+				 DWORD dwStyle = WS_OVERLAPPEDWINDOW,
+				 const RECT& rect = rectDefault,
+				 HWND pParentWnd = NULL,
+				 LPCTSTR lpszMenuName = NULL,
+				 DWORD dwExStyle = 0);
+	BOOL CreateW(HINSTANCE hInstance,
+				 LPCWSTR lpszClassName,
+				 LPCWSTR lpszWindowName,
+				 DWORD dwStyle = WS_OVERLAPPEDWINDOW,
+				 const RECT& rect = rectDefault,
+				 HWND pParentWnd = NULL,
+				 LPCTSTR lpszMenuName = NULL,
+				 DWORD dwExStyle = 0);
 	virtual LRESULT Proc(UINT msg, WPARAM wp, LPARAM lp) = 0;
 	static const RECT rectDefault;
 	///
@@ -105,7 +114,6 @@
 	virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
 	///
 	void OnKillFocus(HWND hNewWnd);
-	void OnDestroy();
 	void OnSetFocus(HWND hOldWnd);
 	void OnSysCommand(WPARAM nID, LPARAM lParam);
 	void OnClose();

Modified: trunk/teraterm/common/tmfc_frame.cpp
===================================================================
--- trunk/teraterm/common/tmfc_frame.cpp	2020-01-30 23:42:47 UTC (rev 8518)
+++ trunk/teraterm/common/tmfc_frame.cpp	2020-01-31 15:37:22 UTC (rev 8519)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018 TeraTerm Project
+ * Copyright (C) 2018-2020 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -31,6 +31,8 @@
  */
 #include "tmfc.h"
 #include "ttlib.h"
+#include "compat_win.h"
+#include "layer_for_unicode.h"
 
 #if (defined(_MSC_VER) && (_MSC_VER <= 1500)) || \
 	(__cplusplus <= 199711L)
@@ -52,10 +54,10 @@
 {
 }
 
-BOOL TTCFrameWnd::Create(
+BOOL TTCFrameWnd::CreateA(
 	HINSTANCE hInstance,
-	LPCTSTR lpszClassName,
-	LPCTSTR lpszWindowName,
+	LPCSTR lpszClassName,
+	LPCSTR lpszWindowName,
 	DWORD dwStyle,
 	const RECT& rect,
 	HWND hParentWnd,
@@ -87,6 +89,45 @@
 	}
 }
 
+BOOL TTCFrameWnd::CreateW(
+	HINSTANCE hInstance,
+	LPCWSTR lpszClassName,
+	LPCWSTR lpszWindowName,
+	DWORD dwStyle,
+	const RECT& rect,
+	HWND hParentWnd,
+	LPCTSTR lpszMenuName,
+	DWORD dwExStyle)
+{
+	m_hInst = hInstance;
+	m_hParentWnd = hParentWnd;
+	pseudoPtr = this;
+	HWND hWnd = _CreateWindowExW(
+		WS_EX_OVERLAPPEDWINDOW,
+		lpszClassName,
+		lpszWindowName,
+		dwStyle,
+		rect.left, rect.top,
+		rect.right - rect.left, rect.bottom - rect.top,
+		hParentWnd,
+		nullptr,
+		hInstance,
+		nullptr);
+	pseudoPtr = nullptr;
+	if (hWnd == nullptr) {
+		OutputDebugPrintf("CreateWindow %d\n", GetLastError());
+		return FALSE;
+	} else {
+		m_hWnd = hWnd;
+		if (pCreateWindowExW != NULL) {
+			// Unicode API\x82\xAA\x91\xB6\x8D݂\xB7\x82\xE9
+			m_WindowUnicode = TRUE;
+		}
+		SetWindowLongPtr(GWLP_USERDATA, (LONG_PTR)this);
+		return TRUE;
+	}
+}
+
 TTCFrameWnd *TTCFrameWnd::pseudoPtr;
 
 LRESULT TTCFrameWnd::ProcStub(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
@@ -109,9 +150,6 @@
 void TTCFrameWnd::OnKillFocus(HWND hNewWnd)
 {}
 
-void TTCFrameWnd::OnDestroy()
-{}
-
 void TTCFrameWnd::OnSetFocus(HWND hOldWnd)
 {}
 

Modified: trunk/teraterm/teraterm/tekwin.cpp
===================================================================
--- trunk/teraterm/teraterm/tekwin.cpp	2020-01-30 23:42:47 UTC (rev 8518)
+++ trunk/teraterm/teraterm/tekwin.cpp	2020-01-31 15:37:22 UTC (rev 8519)
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 1994-1998 T. Teranishi
- * (C) 2006-2019 TeraTerm Project
+ * (C) 2006-2020 TeraTerm Project
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -46,8 +46,9 @@
 #include <htmlhelp.h>
 #include "dlglib.h"
 #include <tchar.h>
+#include "layer_for_unicode.h"
 
-#define TEKClassName _T("TEKWin32")
+#define TEKClassName L"TEKWin32"
 
 /////////////////////////////////////////////////////////////////////////////
 // CTEKWindow
@@ -54,7 +55,7 @@
 
 CTEKWindow::CTEKWindow(HINSTANCE hInstance)
 {
-	WNDCLASS wc;
+	WNDCLASSW wc;
 	RECT rect;
 	DWORD Style;
 	int fuLoad = LR_DEFAULTCOLOR;
@@ -84,7 +85,7 @@
 	wc.lpszMenuName = NULL;
 	wc.lpszClassName = TEKClassName;
 
-	RegisterClass(&wc);
+	_RegisterClassW(&wc);
 
 	if (ts.TEKPos.x==CW_USEDEFAULT) {
 		rect = rectDefault;
@@ -95,7 +96,7 @@
 		rect.right = rect.left + 640; //temporary width
 		rect.bottom = rect.top + 400; //temporary height
 	}
-	Create(hInstance, TEKClassName, _T("Tera Term"), Style, rect, ::GetDesktopWindow(), NULL);
+	CreateW(hInstance, TEKClassName, L"Tera Term", Style, rect, ::GetDesktopWindow(), NULL);
 //--------------------------------------------------------
 	HTEKWin = GetSafeHwnd();
 	if (HTEKWin == NULL) {
@@ -277,8 +278,6 @@
 	// remove this window from the window list
 	UnregWin(HTEKWin);
 
-	TTCFrameWnd::OnDestroy();
-
 	TEKEnd(&tk);
 	FreeTTTEK();
 	HTEKWin = NULL;

Modified: trunk/teraterm/teraterm/ttwinman.c
===================================================================
--- trunk/teraterm/teraterm/ttwinman.c	2020-01-30 23:42:47 UTC (rev 8518)
+++ trunk/teraterm/teraterm/ttwinman.c	2020-01-31 15:37:22 UTC (rev 8519)
@@ -246,7 +246,7 @@
 	if ((ts.TitleFormat & 4)!=0) // VT
 		strncat_s(TempTitle,sizeof(TempTitle)," VT",_TRUNCATE);
 
-	SetWindowText(HVTWin,TempTitle);
+	SetWindowTextA(HVTWin,TempTitle);
 
 	if (HTEKWin!=0)
 	{
@@ -254,7 +254,7 @@
 		{
 			strncat_s(TempTitle,sizeof(TempTitle)," TEK",_TRUNCATE);
 		}
-		SetWindowText(HTEKWin,TempTitle);
+		SetWindowTextA(HTEKWin,TempTitle);
 	}
 }
 

Modified: trunk/teraterm/teraterm/vtwin.cpp
===================================================================
--- trunk/teraterm/teraterm/vtwin.cpp	2020-01-30 23:42:47 UTC (rev 8518)
+++ trunk/teraterm/teraterm/vtwin.cpp	2020-01-31 15:37:22 UTC (rev 8519)
@@ -99,7 +99,7 @@
 DEFINE_GUID(GUID_DEVINTERFACE_USB_DEVICE, 0xA5DCBF10L, 0x6530, 0x11D2, 0x90, 0x1F, 0x00, \
              0xC0, 0x4F, 0xB9, 0x51, 0xED);
 
-#define VTClassName _T("VTWin32")
+#define VTClassName L"VTWin32"
 
 // \x83E\x83B\x83\x93\x83h\x83E\x8Dő剻\x83{\x83^\x83\x93\x82\xF0\x97L\x8C\xF8\x82ɂ\xB7\x82\xE9 (2005.1.15 yutaka)
 #define WINDOW_MAXMIMUM_ENABLED 1
@@ -513,7 +513,7 @@
 
 CVTWindow::CVTWindow(HINSTANCE hInstance)
 {
-	WNDCLASS wc;
+	WNDCLASSW wc;
 	RECT rect;
 	DWORD Style;
 	char *Param;
@@ -679,7 +679,7 @@
 	wc.lpszMenuName = NULL;
 	wc.lpszClassName = VTClassName;
 
-	RegisterClass(&wc);
+	_RegisterClassW(&wc);
 	m_hAccel = ::LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACC));
 
 	if (ts.VTPos.x==CW_USEDEFAULT) {
@@ -691,7 +691,7 @@
 		rect.right = rect.left + 100;
 		rect.bottom = rect.top + 100;
 	}
-	Create(hInstance, VTClassName, _T("Tera Term"), Style, rect, NULL, NULL);
+	CreateW(hInstance, VTClassName, L"Tera Term", Style, rect, NULL, NULL);
 
 	/*--------- Init2 -----------------*/
 	HVTWin = GetSafeHwnd();
@@ -1779,7 +1779,6 @@
 
 	FreeBuffer();
 
-	TTCFrameWnd::OnDestroy();
 	TTXEnd(); /* TTPLUG */
 
 	DeleteNotifyIcon(&cv);


Ttssh2-commit メーリングリストの案内