فهرست منبع

【软件版本】
V
【模块名称】

【问题原因】
添加水平滚动条,需要在rc文件里给COMMBOBOX加入WS_HSCROLL。
【修改描述】

【测试结果】

sat23 3 سال پیش
والد
کامیت
b67634c8f4

+ 1 - 1
TestWizardTool/TestWizardTool/TestWizardTool.ini

@@ -4,6 +4,6 @@ Com=COM27
 ;信号集路径
 xmlpath=D:\SAT\resource\RCU\TW2
 ;使用的信号集;
-useSignal=02_AP_6122A_00BF_BT
+useSignal=DE80
 ;旧的信号集路径;
 oldxmlpath=D:\SAT\resource\RCU\TW

+ 5 - 4
TestWizardTool/TestWizardTool/TestWizardTool.rc

@@ -94,10 +94,11 @@ EXSTYLE WS_EX_APPWINDOW
 CAPTION "TestWizardTool"
 FONT 9, "MS Shell Dlg", 0, 0, 0x1
 BEGIN
-    COMBOBOX        COMBO_COM,7,8,38,85,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
-    PUSHBUTTON      "Open",BTN_OPEN_COM,47,7,29,14
-    COMBOBOX        COMBO_SINGALS,80,8,104,125,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
-    PUSHBUTTON      "ReLoad",BTN_RELOAD_SIGNAL,184,7,29,14
+    COMBOBOX        COMBO_COM,10,12,38,85,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_TABSTOP
+    PUSHBUTTON      "Open",BTN_OPEN_COM,49,11,29,14
+    COMBOBOX        COMBO_SINGALS,81,12,98,125,CBS_DROPDOWNLIST | CBS_SORT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
+    PUSHBUTTON      "ReLoad",BTN_RELOAD_SIGNAL,181,11,29,14
+    GROUPBOX        "",IDC_STATIC_GROUP,7,2,206,29
 END
 
 

+ 2 - 2
TestWizardTool/TestWizardTool/TestWizardTool.vcproj

@@ -101,7 +101,7 @@
 			OutputDirectory="..\..\..\..\bin\$(SolutionName)"
 			IntermediateDirectory="$(OutDir)\$(ProjectName)\$(ConfigurationName)"
 			ConfigurationType="1"
-			UseOfMFC="1"
+			UseOfMFC="2"
 			CharacterSet="2"
 			WholeProgramOptimization="1"
 			>
@@ -130,7 +130,7 @@
 				AdditionalIncludeDirectories="..\tinyxml2;..\..\TCLCommand\TCLCommand;..\..\SATHelper\filehelper"
 				PreprocessorDefinitions="WIN32;_WINDOWS;NDEBUG"
 				MinimalRebuild="false"
-				RuntimeLibrary="0"
+				RuntimeLibrary="2"
 				EnableFunctionLevelLinking="true"
 				UsePrecompiledHeader="2"
 				WarningLevel="3"

+ 50 - 7
TestWizardTool/TestWizardTool/TestWizardToolDlg.cpp

@@ -146,6 +146,7 @@ void CTestWizardToolDlg::DoDataExchange(CDataExchange* pDX)
     DDX_Control(pDX, COMBO_SINGALS, m_cbSignals);
     DDX_Control(pDX, BTN_OPEN_COM, m_btnOpen);
     DDX_Control(pDX, BTN_RELOAD_SIGNAL, m_btnReload);
+    DDX_Control(pDX, IDC_STATIC_GROUP, m_stGroup);
 }
 
 BEGIN_MESSAGE_MAP(CTestWizardToolDlg, CDialog)
@@ -199,6 +200,8 @@ BOOL CTestWizardToolDlg::OnInitDialog()
 
     // TODO: 在此添加额外的初始化代码
     InitBtnStyle();
+    m_stGroup.GetWindowRect(m_rcGroup);
+    ScreenToClient(m_rcGroup);
 
     GetSysSerialPort(m_vtPorts);
     InitSerialCombobox();
@@ -296,14 +299,11 @@ void CTestWizardToolDlg::AdjustLayout()
         return;
     }
 
-    CRect rcCtrl;
     CRect rectClient;
     GetClientRect(rectClient);
     TRACE2(_T("更新后的大小:%d,%d\n"), rectClient.Width(), rectClient.Height());
-    m_cbCOM.GetWindowRect(rcCtrl);
-    ScreenToClient(rcCtrl);
 
-    int sx = 0, sy = rcCtrl.bottom + m_nTopMargin;
+    int sx = 0, sy = m_rcGroup.bottom + m_nTopMargin;
     int i = 0, id = 10000;
     int nWidth = (rectClient.Width() - 25) / m_nCols;
     DWORD dwStyle = WS_CHILD | WS_VISIBLE;
@@ -333,6 +333,8 @@ void CTestWizardToolDlg::LoadSignals()
     {
         m_cbSignals.AddString(fh.getfilename(it->c_str()).c_str());
     }
+
+    AutoSetDroppedWidth(&m_cbSignals);
 }
 
 void CTestWizardToolDlg::LoadKeyInfo(std::vector<KeyInfo> &vtKeyInfo, std::string path)
@@ -420,7 +422,7 @@ void CTestWizardToolDlg::LoadKeyInfo(std::vector<KeyInfo> &vtKeyInfo, std::strin
         }
     }
 
-    int sx = 0, sy = m_nComboHeight * 2 + 15;
+    int sx = 0, sy = m_rcGroup.bottom + m_nTopMargin;
     int i = 0, id = 10000;
     DWORD dwStyle = WS_CHILD | WS_VISIBLE;
     int maxX = 0, maxY = 0;
@@ -463,12 +465,13 @@ void CTestWizardToolDlg::LoadKeyInfo(std::vector<KeyInfo> &vtKeyInfo, std::strin
         i++;
     }
 
-    m_nDefaultHeight = sy + m_nTopMargin;
+    std::vector<KeyInfo>::iterator it = vtKeyInfo.begin();
+    m_nDefaultHeight = m_rcGroup.bottom + 15 + (vtKeyInfo.size()/m_nCols + (vtKeyInfo.size()%m_nCols > 0 ? 1 : 0)) * (it->height + m_nRowSpacing);
     m_nDefaultHeight = m_nDefaultHeight < MINIMUM_WINDOWS_Y ? MINIMUM_WINDOWS_Y : m_nDefaultHeight;
     m_nDefaultWidth = m_nDefaultWidth < MINIMUM_WINDOWS_X ? MINIMUM_WINDOWS_X : m_nDefaultWidth+30;
 
     // 设置窗口大小;
-    SetWindowPos(NULL,0,0, m_nDefaultWidth, m_nDefaultHeight, SWP_NOMOVE);
+    SetWindowPos(NULL, 0, 0, m_nDefaultWidth, m_nDefaultHeight + 23/*标题栏高度*/, SWP_NOMOVE);
 
     AdjustLayout();
 }
@@ -866,3 +869,43 @@ BOOL CTestWizardToolDlg::PreTranslateMessage(MSG* pMsg)
     }
     return CDialog::PreTranslateMessage(pMsg);
 }
+
+void CTestWizardToolDlg::AutoSetDroppedWidth(CComboBox* pCombobox)
+{
+    if (!pCombobox)
+        return;
+    // Find the longest string in the combo box.
+    CString str;
+    CSize sz;
+    int dx = 0;
+
+    TEXTMETRIC tm = { 0 };
+    CDC* pDC = pCombobox->GetDC();
+    CFont* pFont = pCombobox->GetFont();
+
+    // Select the listbox font, save the old font
+    CFont* pOldFont = pDC->SelectObject(pFont);
+
+    // Get the text metrics for avg char width
+    pDC->GetTextMetrics(&tm);
+
+    for (int i = 0; i < pCombobox->GetCount(); i++)
+    {
+        pCombobox->GetLBText(i, str);
+        sz = pDC->GetTextExtent(str);
+
+        // Add the avg width to prevent clipping
+        sz.cx += tm.tmAveCharWidth;
+
+        if (sz.cx > dx)
+            dx = sz.cx;
+    }
+
+    // Select the old font back into the DC
+    pDC->SelectObject(pOldFont);
+    pCombobox->ReleaseDC(pDC);
+
+    // Set the horizontal extent so every character of all strings can
+    // be scrolled to.
+    pCombobox->SetHorizontalExtent(dx);
+}

+ 5 - 0
TestWizardTool/TestWizardTool/TestWizardToolDlg.h

@@ -87,6 +87,7 @@ public:
     std::vector<std::string> m_vtTWSignal;
     std::vector<BTNInfo*> m_vtBTNInfo;
     CBaseSerial m_Serial;
+    CRect m_rcGroup;
 
     void AdjustLayout();
     void InitSerialCombobox();
@@ -111,9 +112,13 @@ public:
     afx_msg void OnDestroy();
 protected:
     virtual void OnOK();
+
+    // 自动根据Combobox选项长度设置宽度;
+    void AutoSetDroppedWidth(CComboBox* pCombobox);
 public:
     CMFCButton m_btnOpen;
     CMFCButton m_btnReload;
     void InitBtnStyle();
     virtual BOOL PreTranslateMessage(MSG* pMsg);
+    CStatic m_stGroup;
 };

+ 2 - 2
TestWizardTool/TestWizardTool/resource.h

@@ -11,8 +11,8 @@
 #define COMBO_COM                       1000
 #define BTN_OPEN_COM                    1001
 #define COMBO_SINGALS                   1002
-#define IDC_BUTTON1                     1003
 #define BTN_RELOAD_SIGNAL               1003
+#define IDC_STATIC_GROUP                1004
 
 // Next default values for new objects
 // 
@@ -20,7 +20,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NEXT_RESOURCE_VALUE        129
 #define _APS_NEXT_COMMAND_VALUE         32771
-#define _APS_NEXT_CONTROL_VALUE         1004
+#define _APS_NEXT_CONTROL_VALUE         1005
 #define _APS_NEXT_SYMED_VALUE           101
 #endif
 #endif