Revision: 8762 https://osdn.net/projects/ttssh2/scm/svn/commits/8762 Author: zmatsuo Date: 2020-05-02 22:25:04 +0900 (Sat, 02 May 2020) Log Message: ----------- ExpandCBWidth() を dlglib に移動 Modified Paths: -------------- trunk/teraterm/common/dlglib.h trunk/teraterm/common/dlglib_cpp.cpp trunk/ttssh2/ttxssh/ttxssh.c -------------- next part -------------- Modified: trunk/teraterm/common/dlglib.h =================================================================== --- trunk/teraterm/common/dlglib.h 2020-05-02 13:24:54 UTC (rev 8761) +++ trunk/teraterm/common/dlglib.h 2020-05-02 13:25:04 UTC (rev 8762) @@ -100,6 +100,7 @@ int GetFontPixelFromPoint(HWND hWnd, int point); wchar_t *AllocControlTextW(HWND hWnd); char *AllocControlTextA(HWND hWnd); +void ExpandCBWidth(HWND dlg, int ID); #ifdef __cplusplus } Modified: trunk/teraterm/common/dlglib_cpp.cpp =================================================================== --- trunk/teraterm/common/dlglib_cpp.cpp 2020-05-02 13:24:54 UTC (rev 8761) +++ trunk/teraterm/common/dlglib_cpp.cpp 2020-05-02 13:25:04 UTC (rev 8762) @@ -183,3 +183,32 @@ ReleaseDC(hWnd, DC); return pixel; } + +/** + * \x83\x8A\x83X\x83g\x82̉\xA1\x95\x9D\x82\xF0\x8Ag\x92\xA3\x82\xB7\x82\xE9(\x8C\xB3\x82̕\x9D\x82\xE6\x82苷\x82\xAD\x82Ȃ邱\x82Ƃ͂Ȃ\xA2) + * @param[in] dlg \x83_\x83C\x83A\x83\x8D\x83O\x82̃n\x83\x93\x83h\x83\x8B + * @param[in] ID \x83R\x83\x93\x83{\x83{\x83b\x83N\x83X\x82\xCCID + */ +void ExpandCBWidth(HWND dlg, int ID) +{ + HWND hCtrlWnd = GetDlgItem(dlg, ID); + int count = (int)SendMessage(hCtrlWnd, CB_GETCOUNT, 0, 0); + HFONT hFont = (HFONT)SendMessage(hCtrlWnd, WM_GETFONT, 0, 0); + int i, max_width = 0; + HDC TmpDC = GetDC(hCtrlWnd); + hFont = (HFONT)SelectObject(TmpDC, hFont); + for (i=0; i<count; i++) { + SIZE s; + int len = (int)SendMessage(hCtrlWnd, CB_GETLBTEXTLEN, i, 0); + char *lbl = (char *)calloc(len+1, sizeof(char)); + SendMessage(hCtrlWnd, CB_GETLBTEXT, i, (LPARAM)lbl); + GetTextExtentPoint32(TmpDC, lbl, len, &s); + if (s.cx > max_width) + max_width = s.cx; + free(lbl); + } + max_width += GetSystemMetrics(SM_CXVSCROLL); // \x83X\x83N\x83\x8D\x81[\x83\x8B\x83o\x81[\x82̕\x9D\x82\xE0\x91\xAB\x82\xB5\x8D\x9E\x82\xF1\x82ł\xA8\x82\xAD + SendMessage(hCtrlWnd, CB_SETDROPPEDWIDTH, max_width, 0); + SelectObject(TmpDC, hFont); + ReleaseDC(hCtrlWnd, TmpDC); +} Modified: trunk/ttssh2/ttxssh/ttxssh.c =================================================================== --- trunk/ttssh2/ttxssh/ttxssh.c 2020-05-02 13:24:54 UTC (rev 8761) +++ trunk/ttssh2/ttxssh/ttxssh.c 2020-05-02 13:25:04 UTC (rev 8762) @@ -1290,35 +1290,6 @@ return CallWindowProc(OrigHostnameEditProc, dlg, msg, wParam, lParam); } -/** - * \x83\x8A\x83X\x83g\x82̉\xA1\x95\x9D\x82\xF0\x8Ag\x92\xA3\x82\xB7\x82\xE9(\x8C\xB3\x82̕\x9D\x82\xE6\x82苷\x82\xAD\x82Ȃ邱\x82Ƃ͂Ȃ\xA2) - * @param[in] dlg \x83_\x83C\x83A\x83\x8D\x83O\x82̃n\x83\x93\x83h\x83\x8B - * @param[in] ID \x83R\x83\x93\x83{\x83{\x83b\x83N\x83X\x82\xCCID - */ -static void ExpandCBWidth(HWND dlg, int ID) -{ - HWND hCtrlWnd = GetDlgItem(dlg, ID); - int count = (int)SendMessage(hCtrlWnd, CB_GETCOUNT, 0, 0); - HFONT hFont = (HFONT)SendMessage(hCtrlWnd, WM_GETFONT, 0, 0); - int i, max_width = 0; - HDC TmpDC = GetDC(hCtrlWnd); - hFont = (HFONT)SelectObject(TmpDC, hFont); - for (i=0; i<count; i++) { - SIZE s; - int len = (int)SendMessage(hCtrlWnd, CB_GETLBTEXTLEN, i, 0); - char *lbl = (char *)calloc(len+1, sizeof(char)); - SendMessage(hCtrlWnd, CB_GETLBTEXT, i, (LPARAM)lbl); - GetTextExtentPoint32(TmpDC, lbl, len, &s); - if (s.cx > max_width) - max_width = s.cx; - free(lbl); - } - max_width += GetSystemMetrics(SM_CXVSCROLL); // \x83X\x83N\x83\x8D\x81[\x83\x8B\x83o\x81[\x82̕\x9D\x82\xE0\x91\xAB\x82\xB5\x8D\x9E\x82\xF1\x82ł\xA8\x82\xAD - SendMessage(hCtrlWnd, CB_SETDROPPEDWIDTH, max_width, 0); - SelectObject(TmpDC, hFont); - ReleaseDC(hCtrlWnd, TmpDC); -} - static INT_PTR CALLBACK TTXHostDlg(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam) {