gpt4 book ai didi

c++ winapi listview项目已选中但未突出显示

转载 作者:可可西里 更新时间:2023-11-01 09:34:09 25 4
gpt4 key购买 nike

这是包含 ListView 的对话框的 dialogProc该对话框是通过我的应用程序主窗口中的一个简单按钮创建的。问题是 ListView_SetItemState 成功但项目未突出显示。同样,当我手动单击一个项目(图标)时,仅选择了该图标(突出显示)不是项目的整个 RECT。感谢您的帮助。

   BOOL CALLBACK DialogProc(HWND ihDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
TCHAR pszfile[MAX_PATH];
SIZE size;
int selected_icon,wn_v;
char buffer[MAX_PATH];
LVTILEVIEWINFO tileViewInfo;
LVCOLUMN LvCol;
size_t i;
switch(uMsg)
{
case WM_INITDIALOG:

EnableWindow(GetParent(ihDlg),false);

hDLGedit = CreateWindowEx(WS_EX_CLIENTEDGE,L"edit",L"",WS_HSCROLL|ES_AUTOHSCROLL|
WS_CHILD|WS_VISIBLE,5,25,250,25,ihDlg,(HMENU) DLG_edit_BX,0,0);
hDLGb_browse = CreateWindowEx(WS_EX_CLIENTEDGE,L"BUTTON",L"Browse",
WS_CHILD|WS_VISIBLE,257,25,60,25,ihDlg,(HMENU) DLG_bt_BROWS,0,0);
hDLGlistv = CreateWindow(WC_LISTVIEW,L"",WS_HSCROLL|LVS_AUTOARRANGE|LVS_ICON|LVS_SINGLESEL|
WS_VISIBLE|WS_CHILD | LVS_REPORT | LVS_EDITLABELS,10,80,425,150,ihDlg,(HMENU) DLG_LIST_icons,0,0);
size.cx=45;
size.cy=45;
tileViewInfo.cbSize = sizeof(tileViewInfo);
tileViewInfo.dwFlags = LVTVIF_FIXEDSIZE;
tileViewInfo.dwMask = LVTVIM_COLUMNS | LVTVIM_TILESIZE;
tileViewInfo.cLines = 2;
tileViewInfo.sizeTile = size;
ListView_SetTileViewInfo(hDLGlistv, &tileViewInfo);
LvCol.mask=LVCF_IMAGE;
LvCol.fmt=LVCFMT_IMAGE;
LvCol.pszText=L"Item";
ListView_InsertColumn(hDLGlistv,0,&LvCol);

ShowScrollBar(hDLGedit,SB_HORZ,0);
GetWindowsDirectory(pszfile,MAX_PATH);
wcscat_s(pszfile,50,TEXT("\\system32\\SHELL32.dll"));
SendMessage(hDLGedit,WM_SETTEXT,0,reinterpret_cast<LPARAM>(pszfile) );
iload_Icons(hDLGlistv,pszfile);//just a function that loads icons and fill up the listview
ListView_SetView(hDLGlistv,LV_VIEW_TILE);
ListView_SetItemState(hDLGlistv,0,LVIS_FOCUSED | LVIS_SELECTED,LVIS_FOCUSED | LVIS_SELECTED);
break;
case WM_PAINT:
// some painting
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case DLG_edit_BX:
return TRUE;
case DLG_bt_BROWS:
Do_icon_open(ihDlg);// just filling the listview
ListView_SetItemState(hDLGlistv,0,LVIS_FOCUSED | LVIS_SELECTED,LVIS_FOCUSED | LVIS_SELECTED );
return TRUE;
case IDOK:
SendMessage(hDLGedit, WM_GETTEXT, 260, (LPARAM) pszfile);
selected_icon= ListView_GetNextItem(hDLGlistv, -1, LVNI_SELECTED);
// some code related to the selection of an icon
EndDialog(ihDlg, wParam);
hDlg=NULL;
break;
case IDCANCEL:
EndDialog(ihDlg, wParam);
hDlg=NULL; //golobal varialble (the dialog itself
break;
}
case WM_CLOSE:
EndDialog(ihDlg, wParam);
hDlg=NULL;
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return 0;

最佳答案

如果您希望即使 Listview 没有焦点也能显示选择,请使用 LVS_SHOWSELALWAYS 窗口样式。

如果您希望项目和子项目在选中时突出显示,请使用 LVS_EX_FULLROWSELECT 窗口扩展样式。

使用 CreateWindowExSetWindowLongGWL_EXSTYLE,可以指定扩展样式。

关于c++ winapi listview项目已选中但未突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20729150/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com