在一个对话框中放有ListBox组件,已经设置Horizontal srcoll!
在程序中有以下语句hlist = GetDlgItem( hDlg, IDC_SELECTFILELIST);
for( i = 0 ; i < nyes ; i++)
{
SendMessage(hlist, LB_ADDSTRING, 0,
(LPARAM) szSelect[i]);
}
当列表时为什么超出部份看不见,也就是水平滑杆不出现!
请问是什么原因?该如果解决?
请各位帮忙,谢谢!
在程序中有以下语句hlist = GetDlgItem( hDlg, IDC_SELECTFILELIST);
for( i = 0 ; i < nyes ; i++)
{
SendMessage(hlist, LB_ADDSTRING, 0,
(LPARAM) szSelect[i]);
}
当列表时为什么超出部份看不见,也就是水平滑杆不出现!
请问是什么原因?该如果解决?
请各位帮忙,谢谢!
设置"Border"、"Notify"、"Vertical scoll"、"No integral height"即可。
调用SetHorizontalExtent()时,可参考以下过程。
//===============================================
CListBox m_clbTest;
CString str;
CSize sz;
int nMaxLen=0;
CDC* pDC = m_clbTest.GetDC(); for (int i=0;i < m_clbTest.GetCount();i++)
{
m_clbTest.GetText( i, str );
sz = pDC->GetTextExtent(str);
if (sz.cx > nMaxLen)
nMaxLen = sz.cx;
}
m_clbTest.ReleaseDC(pDC);
m_clbTest.SetHorizontalExtent(nMaxLen);
//===============================================
但在SDK中应如果做呢?
for( i = 0 ; i < nyes ; i++)
{
SendMessage(hlist, LB_ADDSTRING, 0, (LPARAM) szSelect[i]);
nlength = strlen(szSelect[i]);
if(nmax < nlength)
nmax = nlength;}
SendMessage( hlist,CB_SETHORIZONTALEXTENT, nmax,0);
我查了msdn,加了上面的代码,但还是没有效果!
请问是什么回事呢?谁能帮下我??
hlist = GetDlgItem( hDlg, IDC_SELECTFILELIST);
取得listbox句柄来操作!
style = GetWindowLong(hlist,GWL_STYLE );
style |= WS_HSCROLL;
SetWindowLong(hlist,GWL_STYLE , style );
出现水平滚动条,但只是出现,超出部份内容还是被遮住,也就是滚动条不起作用!是什么原因呢?
int FAR PASCAL
complist_dodlg_copyselectfile(HWND hDlg, UINT message, UINT wParam, long lParam)
{
int i = 0 ;
static char buffer[256];
int nmax;
int nlength;
LONG style;
HWND hlist; switch(message) {
case WM_INITDIALOG:
/*
* set checkboxes and directory field to defaults
*/
SetDlgItemText(hDlg, IDC_COPYTODIR, dlg_root); /*
* set 'copy from' buttons to have the full pathname
*/
hlist = GetDlgItem( hDlg, IDC_SELECTFILELIST);
for( i = 0 ; i < nyes ; i++)
{
nlength = strlen(szSelect[i]);
if(nmax < nlength)
nmax = nlength; }
style = GetWindowLong(hlist,GWL_STYLE );
style |= WS_HSCROLL;
SetWindowLong(hlist,GWL_STYLE , style );
SendMessage( hlist,CB_SETHORIZONTALEXTENT, nmax,0);
SendMessage( hlist, WM_HSCROLL, SB_RIGHT,0);
for( i = 0 ; i < nyes ; i++)
{
SendMessage(hlist, LB_ADDSTRING, 0, (LPARAM) szSelect[i]);
}
return(TRUE); case WM_COMMAND:
switch (GET_WM_COMMAND_ID(wParam, lParam)) { case IDOK:
GetDlgItemText(hDlg, IDC_COPYTODIR, dlg_root, sizeof(dlg_root));
EndDialog(hDlg, TRUE);
break; case IDCANCEL:
EndDialog(hDlg, FALSE);
break;
}
}
return(FALSE);
} /* complist_dodlg_copyselectfile */