问题描述
- 控制CRollupCtrl类创建的标题栏
-
想通过OnSize变化来动态改变CRollupCtrl的标题:代码如下,麻烦大家帮我看看怎么不对了。CString str1 = "ZERO DATA(mv)",str2 = "10 KHz", str3 = "30 KHz", str4 = "50 KHz", str5 = "70 KHz", str6 = "90 KHz", str7 = "110 KHz", str8 = "130 KHz", str9 = "150 KHz"; CString str = ""; CRect m_rollRect; float m_rollTilte = 0; float m_Width = 0; m_wndRollupCtrl.GetClientRect(m_rollRect); m_rollTilte = m_rollRect.Width(); m_rollTilte = m_rollTilte/9.0f; CClientDC dc(this); CSize size1 = dc.GetTextExtent(str1.GetBuffer(str1.GetLength()), strlen(str1.GetBuffer(str1.GetLength())));
// GetTextExtentPoint32(dc,str1.GetBuffer(str1.GetLength()),strlen(str1.GetBuffer(str1.GetLength())),&size1);
m_Width = size1.cx;if ((m_rollTilte - m_Width) > 0) { CString strNULL = ""; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNULL += " "; } str += str1; str += strNULL; } else { CString strNULL = ""; str1 = "ZER"; size1 = dc.GetTextExtent(str1.GetBuffer(str1.GetLength()), strlen(str1.GetBuffer(str1.GetLength()))); m_Width = size1.cx; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNULL += " "; } str += str1; str += strNULL; } CSize size2 = dc.GetTextExtent(str2.GetBuffer(str2.GetLength()), strlen(str2.GetBuffer(str2.GetLength()))); m_Width = size2.cx; if ((m_rollTilte - m_Width) > 0) { CString strNUll = ""; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNUll += " "; } str += str2; str += strNUll; } else { CString strNULL = ""; str2 = "10"; size2 = dc.GetTextExtent(str2.GetBuffer(str2.GetLength()), strlen(str2.GetBuffer(str2.GetLength()))); m_Width = size2.cx; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNULL += " "; } str += str2; str += strNULL; } CSize size3 = dc.GetTextExtent(str3.GetBuffer(str3.GetLength()), strlen(str3.GetBuffer(str3.GetLength()))); m_Width = size3.cx; if ((m_rollTilte - m_Width) > 0) { CString strNUll = ""; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNUll += " "; } str += str3; str += strNUll; } else { CString strNULL = ""; str3 = "30"; size3 = dc.GetTextExtent(str3.GetBuffer(str3.GetLength()), strlen(str3.GetBuffer(str3.GetLength()))); m_Width = size3.cx; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNULL += " "; } str += str3; str += strNULL; } CSize size4 = dc.GetTextExtent(str4.GetBuffer(str4.GetLength()), strlen(str4.GetBuffer(str4.GetLength()))); m_Width = size4.cx; if ((m_rollTilte - m_Width) > 0) { CString strNUll = ""; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNUll += " "; } str += str4; str += strNUll; } else { CString strNULL = ""; str4 = "50"; size4 = dc.GetTextExtent(str4.GetBuffer(str4.GetLength()), strlen(str4.GetBuffer(str4.GetLength()))); m_Width = size4.cx; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNULL += " "; } str += str4; str += strNULL; } CSize size5 = dc.GetTextExtent(str5.GetBuffer(str5.GetLength()), strlen(str5.GetBuffer(str5.GetLength()))); m_Width = size5.cx; if ((m_rollTilte - m_Width) > 0) { CString strNUll = ""; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNUll += " "; } str += str5; str += strNUll; } else { CString strNULL = ""; str5 = "70"; size5 = dc.GetTextExtent(str5.GetBuffer(str5.GetLength()), strlen(str5.GetBuffer(str5.GetLength()))); m_Width = size5.cx; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNULL += " "; } str += str5; str += strNULL; } CSize size6 = dc.GetTextExtent(str6.GetBuffer(str6.GetLength()), strlen(str6.GetBuffer(str6.GetLength()))); m_Width = size6.cx; if ((m_rollTilte - m_Width) > 0) { CString strNUll = ""; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNUll += " "; } str += str6; str += strNUll; } else { CString strNULL = ""; str6 = "90"; size6 = dc.GetTextExtent(str6.GetBuffer(str6.GetLength()), strlen(str6.GetBuffer(str6.GetLength()))); m_Width = size6.cx; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNULL += " "; } str += str6; str += strNULL; } CSize size7 = dc.GetTextExtent(str7.GetBuffer(str7.GetLength()), strlen(str7.GetBuffer(str7.GetLength()))); m_Width = size7.cx; if ((m_rollTilte - m_Width) > 0) { CString strNUll = ""; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNUll += " "; } str += str7; str += strNUll; } else { CString strNULL = ""; str7 = "110"; size7 = dc.GetTextExtent(str7.GetBuffer(str7.GetLength()), strlen(str7.GetBuffer(str7.GetLength()))); m_Width = size7.cx; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNULL += " "; } str += str7; str += strNULL; } CSize size8 = dc.GetTextExtent(str8.GetBuffer(str8.GetLength()), strlen(str8.GetBuffer(str8.GetLength()))); m_Width = size8.cx; if ((m_rollTilte - m_Width) > 0) { CString strNUll = ""; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNUll += " "; } str += str8; str += strNUll; } else { CString strNULL = ""; str8 = "130"; size8 = dc.GetTextExtent(str8.GetBuffer(str8.GetLength()), strlen(str8.GetBuffer(str8.GetLength()))); m_Width = size8.cx; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNULL += " "; } str += str8; str += strNULL; } CSize size9 = dc.GetTextExtent(str9.GetBuffer(str9.GetLength()), strlen(str9.GetBuffer(str9.GetLength()))); m_Width = size9.cx; if ((m_rollTilte - m_Width) > 0) { CString strNUll = ""; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNUll += " "; } str += str9; str += strNUll; } else { CString strNULL = ""; str9 = "150"; size9 = dc.GetTextExtent(str9.GetBuffer(str9.GetLength()), strlen(str9.GetBuffer(str9.GetLength()))); m_Width = size9.cx; int a = (m_rollTilte - m_Width)/4; for (int i = 0; i < a; i ++) { strNULL += " "; } str += str9; str += strNULL; } CSize size11 = dc.GetTextExtent(str.GetBuffer(str.GetLength()), strlen(str.GetBuffer(str.GetLength()))); /* CSize size1 ;*/ m_Width = size11.cx; m_wndRollupCtrl.SetPageCaption(0,str);
时间: 2024-10-26 09:26:13