// Resizes all columns in a listview (report style) // to make all text visible void ResizeColumns(HWND hwndLV) { int nCol = 0; LVCOLUMN lvCol; lvCol.mask = LVCF_WIDTH; while (ListView_GetColumn(hwndLV, nCol++, &lvCol)) ListView_SetColumnWidth(hwndLV, nCol-1, LVSCW_AUTOSIZE); }
unsigned ListView_GetColumnCount(HWND hwnd) { unsigned count = 0; LVCOLUMN column; column.mask = LVCF_WIDTH; while(ListView_GetColumn(hwnd, count++, &column)); return --count; }
PPH_STRING PhSaveListViewColumnSettings( _In_ HWND ListViewHandle ) { PH_STRING_BUILDER stringBuilder; ULONG i = 0; LVCOLUMN lvColumn; PhInitializeStringBuilder(&stringBuilder, 20); PhAppendFormatStringBuilder(&stringBuilder, L"@%u|", PhGlobalDpi); lvColumn.mask = LVCF_WIDTH | LVCF_ORDER; while (ListView_GetColumn(ListViewHandle, i, &lvColumn)) { PhAppendFormatStringBuilder( &stringBuilder, L"%u,%u|", lvColumn.iOrder, lvColumn.cx ); i++; } if (stringBuilder.String->Length != 0) PhRemoveEndStringBuilder(&stringBuilder, 1); return PhFinalStringBuilderString(&stringBuilder); }
uint ListView::ColumnsProxy::GetIndex(const uint index) const { LVCOLUMN lvColumn; lvColumn.mask = LVCF_ORDER; ListView_GetColumn( control, index, &lvColumn ); return NST_MAX(lvColumn.iOrder,0); }
int lv_get_col_text(HWND hlistview,int index,char *str,int size) { LV_COLUMN col; if(hlistview!=0 && str!=0 && size>0){ col.mask = LVCF_TEXT; col.pszText = str; col.cchTextMax = size; return ListView_GetColumn(hlistview,index,&col); } return FALSE; }
int CCListBox::GetColumnCount() { int r = 0; LVCOLUMNW col; col.mask = LVCF_WIDTH; while(ListView_GetColumn(m_hWnd, r, &col) != FALSE) { r++; } return r; }
void TcodecsPage::moveCBX(bool isscroll) { if (isscroll && !IsWindowVisible(hcbx)) { return; } LVCOLUMN lvc0,lvc1; lvc0.mask=lvc1.mask=LVCF_WIDTH; ListView_GetColumn(hlv,0,&lvc0); ListView_GetColumn(hlv,1,&lvc1); RECT lvr; GetWindowRect(hlv,&lvr); RECT pr; GetWindowRect(GetParent(hlv),&pr); OffsetRect(&lvr,-pr.left,-pr.top); RECT ir; int iItem=lvGetSelItem(IDC_LV_INCODECS); ListView_GetItemRect(hlv,iItem,&ir,LVIR_BOUNDS); MoveWindow(hcbx,lvr.left+lvc0.cx+3,lvr.top+ir.top-1,lvc1.cx,12,TRUE); show(true,IDC_CBX_INCODECS); SetWindowPos(hcbx,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_SHOWWINDOW); SetFocus(hcbx); }
HRESULT CCListBox::GetColumnText(int iCol, CCString* pOut) { LVCOLUMNW col; col.mask = LVCF_TEXT; col.pszText = pOut->GetBuffer(MAX_PATH); col.cchTextMax = MAX_PATH; if(ListView_GetColumn(this->hWnd, iCol, &col) == FALSE) { return E_FAIL; } return S_OK; }
void saveListSettings(HWND hwnd, ColumnsSettings *cs) { char tmp[FLD_SIZE]; LVCOLUMN sLC = { 0 }; sLC.mask = LVCF_WIDTH; int i = 0; while (cs[i].name) { if (ListView_GetColumn(hwnd, cs[i].index, &sLC)) { mir_snprintf(tmp, cs[i].dbname, i); db_set_w(NULL, modname, tmp, (WORD)sLC.cx); } i++; } }
/* ================ rvRegistryOptions::SetColumnWidths Set a group of column widths in the options ================ */ void rvRegistryOptions::SetColumnWidths(const char *name, HWND list) { LVCOLUMN col; int index; idStr widths; col.mask = LVCF_WIDTH; for (index = 0; ListView_GetColumn(list, index, &col); index ++) { widths += va("%d ", col.cx); } mValues.Set(name, widths); }
void CServices::OnHdnItemclickServicesList(NMHDR *pNMHDR, LRESULT *pResult) { LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR); LVCOLUMN col; col.mask = LVCF_SUBITEM; /*Get the colum Info*/ ListView_GetColumn(hServicePageListCtrl,phdr->iItem,&col); serviceColumn = col.iSubItem; ListView_SortItems(hServicePageListCtrl,ServiceCompareFunc,NULL); serviceIsASC = !serviceIsASC; *pResult = 0; }
void CProcesses::OnHdnItemclickProcessList(NMHDR *pNMHDR, LRESULT *pResult) { LPNMHEADER phdr = reinterpret_cast<LPNMHEADER>(pNMHDR); LVCOLUMN col; col.mask = LVCF_SUBITEM; /*Get the colum Info*/ ListView_GetColumn(hProcPageListCtrl,phdr->iItem,&col); sortColum = col.iSubItem; isASC = !isASC; ListView_SortItems(hProcPageListCtrl,ProcessPageCompareFunc,NULL); *pResult = 0; }
HRESULT CCListBox::GetColumnText(int iCol, CCString* pOut) { LVCOLUMN col; TCHAR tsz[MAX_PATH]; col.mask = LVCF_TEXT; col.pszText = tsz; col.cchTextMax = MAX_PATH; if(ListView_GetColumn(m_hWnd, iCol, &col) == FALSE) { return E_FAIL; } *pOut = tsz; return S_OK; }
int wbGetListViewColumnWidths(PWBOBJ pwbo, int *pwidths) { LV_COLUMN lvct; int i; if(!pwbo || !pwbo->hwnd || !IsWindow(pwbo->hwnd)) return FALSE; for(i = 0; i < MAX_LISTVIEWCOLS; i++) { lvct.iSubItem = i - 0; lvct.mask = LVCF_SUBITEM; if(pwidths) { *(pwidths + i) = ListView_GetColumnWidth(pwbo->hwnd, i); } if(!ListView_GetColumn(pwbo->hwnd, i, &lvct)) break; } return i; }
ColumnProperties TableViewImpl::column(int c) const { ColumnProperties result; result.header.wstr.resize(MAX_TABLEVIEW_ITEM_CHARS); LVCOLUMNW lvc; lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; lvc.pszText = &result.header.wstr[0]; lvc.cchTextMax = MAX_TABLEVIEW_ITEM_CHARS; if( ListView_GetColumn(hWnd,c,&lvc) == FALSE ) { log::error("ListView_GetColumn returned FALSE for hWnd ",hWnd); } else { result .setAlignment(win32ToAlign(lvc.fmt)) .setImageIndex(lvc.iImage) .setWidth(lvc.cx); } return result; }
BOOL wbSetListViewColumnWidths(PWBOBJ pwbo, int *pwidths) { LV_COLUMN lvct; int i; if(!pwbo || !pwbo->hwnd || !IsWindow(pwbo->hwnd)) return FALSE; if(!pwidths) return FALSE; for(i = 0; i < MAX_LISTVIEWCOLS; i++) { lvct.iSubItem = i; lvct.mask = LVCF_SUBITEM; if(!ListView_GetColumn(pwbo->hwnd, i, &lvct)) break; if(!wbSetListViewColumnWidth(pwbo, i, pwidths[i])) return FALSE; } return TRUE; }
BOOL CXTPHeaderCtrl::SetAlingment(int nFlag) { int iIndex = HitTest(m_pt); if (iIndex != -1) { CWnd* pParentWnd = GetParent(); if (pParentWnd && ( pParentWnd->IsKindOf(RUNTIME_CLASS(CListCtrl)) || pParentWnd->IsKindOf(RUNTIME_CLASS(CListView)))) { LVCOLUMN lvc; lvc.mask = LVCF_FMT; ListView_GetColumn(pParentWnd->m_hWnd, iIndex, &lvc); lvc.fmt &= ~LVCFMT_JUSTIFYMASK; lvc.fmt |= nFlag; ListView_SetColumn(pParentWnd->m_hWnd, iIndex, &lvc); ListView_SetWorkAreas(pParentWnd->m_hWnd, 0, NULL); } } return FALSE; }
void Picker_HandleDrawItem(HWND hWnd, LPDRAWITEMSTRUCT lpDrawItemStruct) { struct PickerInfo *pPickerInfo; HDC hDC = lpDrawItemStruct->hDC; RECT rcItem = lpDrawItemStruct->rcItem; UINT uiFlags = ILD_TRANSPARENT; HIMAGELIST hImageList; int nItem = lpDrawItemStruct->itemID; COLORREF clrTextSave = 0; COLORREF clrBkSave = 0; COLORREF clrImage = GetSysColor(COLOR_WINDOW); static TCHAR szBuff[MAX_PATH]; BOOL bFocus = (GetFocus() == hWnd); LPCTSTR pszText; UINT nStateImageMask = 0; BOOL bSelected = 0; LV_COLUMN lvc; LV_ITEM lvi; RECT rcAllLabels; RECT rcLabel; RECT rcIcon; int offset = 0; SIZE size; int i = 0, j = 0; int nColumn = 0; int nColumnMax = 0; int *order; BOOL bDrawAsChild = 0; int indent_space = 0; BOOL bColorChild = FALSE; BOOL bParentFound = FALSE; int nParent = 0; HBITMAP hBackground = GetBackgroundBitmap(); MYBITMAPINFO *pbmDesc = GetBackgroundInfo(); BOOL res = 0; pPickerInfo = GetPickerInfo(hWnd); order = (int*)malloc(pPickerInfo->nColumnCount * sizeof(*order)); if (!order) return; nColumnMax = Picker_GetNumColumns(hWnd); if (GetUseOldControl()) { pPickerInfo->pCallbacks->pfnGetColumnOrder(order); } else { /* Get the Column Order and save it */ res = ListView_GetColumnOrderArray(hWnd, nColumnMax, order); /* Disallow moving column 0 */ if (order[0] != 0) { for (i = 0; i < nColumnMax; i++) { if (order[i] == 0) { order[i] = order[0]; order[0] = 0; } } res = ListView_SetColumnOrderArray(hWnd, nColumnMax, order); } } /* Labels are offset by a certain amount */ /* This offset is related to the width of a space character */ GetTextExtentPoint32(hDC, TEXT(" "), 1, &size); offset = size.cx; lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE | LVIF_PARAM; lvi.iItem = nItem; lvi.iSubItem = order[0]; lvi.pszText = szBuff; lvi.cchTextMax = sizeof(szBuff) / sizeof(szBuff[0]); lvi.stateMask = 0xFFFF; /* get all state flags */ res = ListView_GetItem(hWnd, &lvi); bSelected = ((lvi.state & LVIS_DROPHILITED) || ( (lvi.state & LVIS_SELECTED) && ((bFocus) || (GetWindowLong(hWnd, GWL_STYLE) & LVS_SHOWSELALWAYS)))); /* figure out if we indent and draw grayed */ if (pPickerInfo->pCallbacks->pfnFindItemParent) nParent = pPickerInfo->pCallbacks->pfnFindItemParent(hWnd, lvi.lParam); else nParent = -1; bDrawAsChild = (pPickerInfo->pCallbacks->pfnGetViewMode() == VIEW_GROUPED && (nParent >= 0)); /* only indent if parent is also in this view */ if ((nParent >= 0) && bDrawAsChild) { for (i = 0; i < ListView_GetItemCount(hWnd); i++) { lvi.mask = LVIF_PARAM; lvi.iItem = i; res = ListView_GetItem(hWnd, &lvi); if (lvi.lParam == nParent) { bParentFound = TRUE; break; } } } if (pPickerInfo->pCallbacks->pfnGetOffsetChildren && pPickerInfo->pCallbacks->pfnGetOffsetChildren()) { if (!bParentFound && bDrawAsChild) { /*Reset it, as no Parent is there*/ bDrawAsChild = FALSE; bColorChild = TRUE; } else { nParent = -1; bParentFound = FALSE; } } res = ListView_GetItemRect_Modified(hWnd, nItem, &rcAllLabels, LVIR_BOUNDS); res = ListView_GetItemRect_Modified(hWnd, nItem, &rcLabel, LVIR_LABEL); rcAllLabels.left = rcLabel.left; if (hBackground != NULL) { RECT rcClient; HRGN rgnBitmap; RECT rcTmpBmp = rcItem; RECT rcFirstItem; HPALETTE hPAL; HDC htempDC; HBITMAP oldBitmap; htempDC = CreateCompatibleDC(hDC); oldBitmap = (HBITMAP)SelectObject(htempDC, hBackground); GetClientRect(hWnd, &rcClient); rcTmpBmp.right = rcClient.right; /* We also need to check whether it is the last item The update region has to be extended to the bottom if it is */ if (nItem == ListView_GetItemCount(hWnd) - 1) rcTmpBmp.bottom = rcClient.bottom; rgnBitmap = CreateRectRgnIndirect(&rcTmpBmp); SelectClipRgn(hDC, rgnBitmap); DeleteBitmap(rgnBitmap); hPAL = GetBackgroundPalette(); if (hPAL == NULL) hPAL = CreateHalftonePalette(hDC); if (GetDeviceCaps(htempDC, RASTERCAPS) & RC_PALETTE && hPAL != NULL) { SelectPalette(htempDC, hPAL, FALSE); RealizePalette(htempDC); } res = ListView_GetItemRect_Modified(hWnd, 0, &rcFirstItem, LVIR_BOUNDS); for (i = rcFirstItem.left; i < rcClient.right; i += pbmDesc->bmWidth) for (j = rcFirstItem.top; j < rcClient.bottom; j += pbmDesc->bmHeight) BitBlt(hDC, i, j, pbmDesc->bmWidth, pbmDesc->bmHeight, htempDC, 0, 0, SRCCOPY); SelectObject(htempDC, oldBitmap); DeleteDC(htempDC); if (GetBackgroundPalette() == NULL) { DeletePalette(hPAL); hPAL = NULL; } } indent_space = 0; if (bDrawAsChild) { RECT rect; res = ListView_GetItemRect_Modified(hWnd, nItem, &rect, LVIR_ICON); /* indent width of icon + the space between the icon and text * so left of clone icon starts at text of parent */ indent_space = rect.right - rect.left + offset; } rcAllLabels.left += indent_space; if (bSelected) { HBRUSH hBrush; HBRUSH hOldBrush; if (bFocus) { clrTextSave = SetTextColor(hDC, GetSysColor(COLOR_HIGHLIGHTTEXT)); clrBkSave = SetBkColor(hDC, GetSysColor(COLOR_HIGHLIGHT)); hBrush = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT)); } else { clrTextSave = SetTextColor(hDC, GetSysColor(COLOR_BTNTEXT)); clrBkSave = SetBkColor(hDC, GetSysColor(COLOR_BTNFACE)); hBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); } hOldBrush = (HBRUSH)SelectObject(hDC, hBrush); FillRect(hDC, &rcAllLabels, hBrush); SelectObject(hDC, hOldBrush); DeleteBrush(hBrush); } else { if (hBackground == NULL) { HBRUSH hBrush; hBrush = CreateSolidBrush(GetSysColor(COLOR_WINDOW)); FillRect(hDC, &rcAllLabels, hBrush); DeleteBrush(hBrush); } if (pPickerInfo->pCallbacks->pfnGetOffsetChildren && pPickerInfo->pCallbacks->pfnGetOffsetChildren()) { if (bDrawAsChild || bColorChild) clrTextSave = SetTextColor(hDC, GetListCloneColor()); else clrTextSave = SetTextColor(hDC, GetListFontColor()); } else { if (bDrawAsChild) clrTextSave = SetTextColor(hDC, GetListCloneColor()); else clrTextSave = SetTextColor(hDC, GetListFontColor()); } clrBkSave = SetBkColor(hDC, GetSysColor(COLOR_WINDOW)); } if (lvi.state & LVIS_CUT) { clrImage = GetSysColor(COLOR_WINDOW); uiFlags |= ILD_BLEND50; } else if (bSelected) { if (bFocus) clrImage = GetSysColor(COLOR_HIGHLIGHT); else clrImage = GetSysColor(COLOR_BTNFACE); uiFlags |= ILD_BLEND50; } nStateImageMask = lvi.state & LVIS_STATEIMAGEMASK; if (nStateImageMask) { int nImage = (nStateImageMask >> 12) - 1; hImageList = ListView_GetImageList(hWnd, LVSIL_STATE); if (hImageList) ImageList_Draw(hImageList, nImage, hDC, rcItem.left, rcItem.top, ILD_TRANSPARENT); } res = ListView_GetItemRect_Modified(hWnd, nItem, &rcIcon, LVIR_ICON); rcIcon.left += indent_space; res = ListView_GetItemRect_Modified(hWnd, nItem, &rcItem, LVIR_LABEL); hImageList = ListView_GetImageList(hWnd, LVSIL_SMALL); if (hImageList) { UINT nOvlImageMask = lvi.state & LVIS_OVERLAYMASK; if (rcIcon.left + 16 + indent_space < rcItem.right) { ImageList_DrawEx(hImageList, lvi.iImage, hDC, rcIcon.left, rcIcon.top, 16, 16, GetSysColor(COLOR_WINDOW), clrImage, uiFlags | nOvlImageMask); } } res = ListView_GetItemRect_Modified(hWnd, nItem, &rcItem, LVIR_LABEL); pszText = MakeShortString(hDC, szBuff, rcItem.right - rcItem.left, 2*offset + indent_space); rcLabel = rcItem; rcLabel.left += offset + indent_space; rcLabel.right -= offset; DrawText(hDC, pszText, -1, &rcLabel, DT_LEFT | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER); for (nColumn = 1; nColumn < nColumnMax; nColumn++) { int nRetLen; UINT nJustify; LV_ITEM lvItem; lvc.mask = LVCF_FMT | LVCF_WIDTH; res = ListView_GetColumn(hWnd, order[nColumn], &lvc); lvItem.mask = LVIF_TEXT; lvItem.iItem = nItem; lvItem.iSubItem = order[nColumn]; lvItem.pszText = szBuff; lvItem.cchTextMax = sizeof(szBuff) / sizeof(szBuff[0]); if (ListView_GetItem(hWnd, &lvItem) == FALSE) continue; rcItem.left = rcItem.right; rcItem.right += lvc.cx; nRetLen = _tcslen(szBuff); if (nRetLen == 0) continue; pszText = MakeShortString(hDC, szBuff, rcItem.right - rcItem.left, 2 * offset); nJustify = DT_LEFT; if (pszText == szBuff) { switch (lvc.fmt & LVCFMT_JUSTIFYMASK) { case LVCFMT_RIGHT: nJustify = DT_RIGHT; break; case LVCFMT_CENTER: nJustify = DT_CENTER; break; default: break; } } rcLabel = rcItem; rcLabel.left += offset; rcLabel.right -= offset; DrawText(hDC, pszText, -1, &rcLabel, nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER); } if (lvi.state & LVIS_FOCUSED && bFocus) DrawFocusRect(hDC, &rcAllLabels); SetTextColor(hDC, clrTextSave); SetBkColor(hDC, clrBkSave); free(order); res++; }
void CProcesses::OnLvnGetdispinfoProcessList(NMHDR *pNMHDR, LRESULT *pResult) { NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR); LVCOLUMN col; col.mask = LVCF_SUBITEM; /*Get the colum Info*/ ListView_GetColumn(hProcPageListCtrl,pDispInfo->item.iSubItem,&col); if(columns[col.iSubItem].isShow) { PERFDATA *pPerfData = (PERFDATA *)pDispInfo->item.lParam; /*Set the Column Data*/ switch(columns[col.iSubItem].nId) { case COLUMN_IMAGENAME: break; case COLUMN_PID: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->ProcessId); break; case COLUMN_USERNAME: pDispInfo->item.pszText = pPerfData->UserName; break; case COLUMN_SESSIONID: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->SessionId); break; case COLUMN_CPUUSAGE: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%02d"),pPerfData->CPUUsage); break; case COLUMN_CPUTIME: DWORD dwHours; DWORD dwMinutes; DWORD dwSeconds; GetHMSFromLargeInt(pPerfData->CPUTime, &dwHours, &dwMinutes, &dwSeconds); swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%02d:%02d:%02d"),dwHours,dwMinutes,dwSeconds); break; case COLUMN_MEMORYUSAGE: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->WorkingSetSizeBytes / 1024); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); wcscat(pDispInfo->item.pszText,_T(" K")); break; case COLUMN_PEAKMEMORYUSAGE: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d") ,pPerfData->PeakWorkingSetSizeBytes / 1024); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); wcscat(pDispInfo->item.pszText,_T(" K")); break; case COLUMN_MEMORYUSAGEDELTA: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->WorkingSetSizeDelta / 1024); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); wcscat(pDispInfo->item.pszText,_T(" K")); break; case COLUMN_PAGEFAULTS: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->PageFaultCount); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; case COLUMN_PAGEFAULTSDELTA: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->PageFaultCountDelta); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; case COLUMN_VIRTUALMEMORYSIZE: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->VirtualMemorySizeBytes / 1024); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); wcscat(pDispInfo->item.pszText,_T(" K")); break; case COLUMN_PAGEDPOOL: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->PagedPoolUsagePages / 1024); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); wcscat(pDispInfo->item.pszText,_T(" K")); break; case COLUMN_NONPAGEDPOOL: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->NonPagedPoolUsagePages / 1024); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); wcscat(pDispInfo->item.pszText,_T(" K")); break; case COLUMN_BASEPRIORITY: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->BasePriority); break; case COLUMN_HANDLECOUNT: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->HandleCount); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; case COLUMN_THREADCOUNT: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->ThreadCount); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; case COLUMN_USEROBJECTS: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->USERObjectCount); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; case COLUMN_GDIOBJECTS: swprintf_s(pDispInfo->item.pszText,pDispInfo->item.cchTextMax,_T("%d"),pPerfData->GDIObjectCount); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; case COLUMN_IOREADS: _ui64tow(pPerfData->IOCounters.ReadOperationCount,pDispInfo->item.pszText,10); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; case COLUMN_IOWRITES: _ui64tow(pPerfData->IOCounters.WriteOperationCount,pDispInfo->item.pszText,10); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; case COLUMN_IOOTHER: _ui64tow(pPerfData->IOCounters.OtherOperationCount,pDispInfo->item.pszText,10); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; case COLUMN_IOREADBYTES: _ui64tow(pPerfData->IOCounters.ReadTransferCount,pDispInfo->item.pszText,10); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; case COLUMN_IOWRITEBYTES: _ui64tow(pPerfData->IOCounters.WriteTransferCount,pDispInfo->item.pszText,10); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; case COLUMN_IOOTHERBYTES: _ui64tow(pPerfData->IOCounters.OtherTransferCount,pDispInfo->item.pszText,10); SeparateNumber(pDispInfo->item.pszText,pDispInfo->item.cchTextMax); break; } } *pResult = 0; }
void _draw_listview( LPDRAWITEMSTRUCT itst ) { DRAWTEXTPARAMS dtp = { sizeof(dtp) }; LVCOLUMN lvc = { sizeof(lvc) }; wchar_t s_text[200] = { 0 }; int cx, cy, k = 0; int offset = 0; int icon; BOOL is_root; int col_cnt = Header_GetItemCount( ListView_GetHeader( itst->hwndItem ) ); LVITEM lvitem = { LVIF_TEXT | LVIF_PARAM, itst->itemID, 0, 0, 0, s_text, countof(s_text) }; COLORREF bgcolor = ListView_GetBkColor( itst->hwndItem ); ListView_GetItem( itst->hwndItem, &lvitem ); is_root = _is_root_item( lvitem.lParam ); { void *user_data = wnd_get_long( __lists[HMAIN_DRIVES], GWL_USERDATA ); if (user_data != NULL) { MessageBox( __dlg, s_text, NULL, 0 ); } } if ( ( itst->itemState & ODS_SELECTED ) && IsWindowEnabled( itst->hwndItem ) /*&& ( lvitem.lParam != NULL )*/ ) { if ( GetFocus( ) == itst->hwndItem ) { bgcolor = CL_WHITE; } else { bgcolor = _cl( COLOR_BTNFACE, 80 ); } } if ( is_root ) { bgcolor = _cl( COLOR_BTNSHADOW, 60 ); } if ( _is_marked_item(lvitem.lParam) ) { bgcolor = _cl( COLOR_BTNSHADOW, 35 ); } _fill( itst->hDC, &itst->rcItem, bgcolor ); for ( ; k < col_cnt; k++ ) { lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_IMAGE; ListView_GetColumn( itst->hwndItem, k, &lvc ); itst->rcItem.left = k ? itst->rcItem.right : 0; itst->rcItem.right = itst->rcItem.left + lvc.cx; lvitem.iItem = itst->itemID; lvitem.iSubItem = k; ListView_GetItem( itst->hwndItem, &lvitem ); dtp.iLeftMargin = dtp.iRightMargin = 5; if ( (!itst->rcItem.left) && _is_icon_show( itst->hwndItem, k ) ) { ImageList_GetIconSize( __dsk_img, &cx, &cy ); offset = lvitem.lParam && !is_root ? 25 : 3; itst->rcItem.left += offset + cy + ( lvitem.lParam && !is_root ? 8 : 4 ); icon = 0; if (! is_root ) { if ( _is_splited_item(lvitem.lParam) ) icon = 1; if ( _is_cdrom_item(lvitem.lParam) ) icon = 2; } ImageList_Draw( __dsk_img, icon, itst->hDC, offset, itst->rcItem.top + 3, ILD_TRANSPARENT ); } else { offset = 0; } if ( offset && is_root ) { DrawState( itst->hDC, 0, NULL, (LPARAM)s_text, 0, itst->rcItem.left+5, itst->rcItem.top, 0, 0, DST_PREFIXTEXT | DSS_MONO ); } else { if ( wcslen(s_text) != 0 ) { COLORREF text_color = GetSysColor( COLOR_WINDOWTEXT ); if ( !_is_active_item(lvitem.lParam) ) { text_color = GetSysColor( COLOR_GRAYTEXT ); } SetTextColor( itst->hDC, text_color ); if ( k >= 4 ) { SelectObject( itst->hDC, __font_bold ); } if ( !IsWindowEnabled( itst->hwndItem ) ) { SetTextColor( itst->hDC, GetSysColor(COLOR_GRAYTEXT) ); DrawTextEx( itst->hDC, s_text, -1, &itst->rcItem, DT_END_ELLIPSIS | ((lvc.fmt & LVCFMT_RIGHT) ? DT_RIGHT : FALSE), &dtp ); } else { DrawTextEx( itst->hDC, s_text, -1, &itst->rcItem, DT_END_ELLIPSIS | ((lvc.fmt & LVCFMT_RIGHT) ? DT_RIGHT : FALSE), &dtp ); /* if ( GetFocus( ) == itst->hwndItem ) { DrawFocusRect( itst->hDC, &itst->rcItem ); } */ } } } } }
void CXTPHeaderCtrl::OnRButtonDown(UINT nFlags, CPoint point) { CPoint pt = m_pt = point; ClientToScreen(&pt); // If no sort headers are defined for the parent control or popup menus // has been disabled, call the base class and return. CWnd* pParentWnd = GetParent(); if (pParentWnd->GetStyle() & LVS_NOSORTHEADER || m_bEnableMenus == FALSE) { CHeaderCtrl::OnRButtonDown(nFlags, point); return; } // No menu was defined use default if (!m_popupMenuID) { // Get the index to the header item under the cursor. int iIndex = HitTest(m_pt); if (iIndex != -1) { CMenu menu; CXTPResourceManager::AssertValid(XTPResourceManager()->LoadMenu(&menu, XTP_IDM_POPUP)); CMenu* pPopup = menu.GetSubMenu(2); ASSERT(pPopup != NULL); if (!pPopup) return; if (m_nSortedCol == iIndex && m_bAscending == TRUE) pPopup->CheckMenuItem(XTP_IDC_SORTASC, MF_CHECKED | MF_BYCOMMAND); else if (m_nSortedCol == iIndex && m_bAscending == FALSE) pPopup->CheckMenuItem(XTP_IDC_SORTDSC, MF_CHECKED | MF_BYCOMMAND); if (pParentWnd && ( pParentWnd->IsKindOf(RUNTIME_CLASS(CListCtrl)) || pParentWnd->IsKindOf(RUNTIME_CLASS(CListView)))) { LVCOLUMN lvc; lvc.mask = LVCF_FMT; ListView_GetColumn(pParentWnd->m_hWnd, iIndex, &lvc); switch (lvc.fmt & LVCFMT_JUSTIFYMASK) { case LVCFMT_LEFT: pPopup->CheckMenuItem(XTP_IDC_ALIGNLEFT, MF_CHECKED | MF_BYCOMMAND); break; case LVCFMT_CENTER: pPopup->CheckMenuItem(XTP_IDC_ALIGNCENTER, MF_CHECKED | MF_BYCOMMAND); break; case LVCFMT_RIGHT: pPopup->CheckMenuItem(XTP_IDC_ALIGNRIGHT, MF_CHECKED | MF_BYCOMMAND); break; } } XTPContextMenu(pPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, this, XTP_IDR_TBAR_HDR); } } else { CMenu menu; VERIFY(menu.LoadMenu(m_popupMenuID)); CMenu* pPopup = menu.GetSubMenu(m_nPos); ASSERT(pPopup != NULL); if (!pPopup) return; pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, GetOwner()); } }
INT_PTR Dlg_MemBookmark::MemBookmarkDialogProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { PMEASUREITEMSTRUCT pmis; PDRAWITEMSTRUCT pdis; int nSelect; HWND hList; int offset = 2; RECT rcBounds, rcLabel; switch ( uMsg ) { case WM_INITDIALOG: { GenerateResizes( hwnd ); m_hMemBookmarkDialog = hwnd; hList = GetDlgItem( m_hMemBookmarkDialog, IDC_RA_LBX_ADDRESSES ); SetupColumns( hList ); // Auto-import bookmark file when opening dialog if ( g_pCurrentGameData->GetGameID() != 0 ) { std::string file = RA_DIR_BOOKMARKS + std::to_string( g_pCurrentGameData->GetGameID() ) + "-Bookmarks.txt"; ImportFromFile( file ); } RestoreWindowPosition( hwnd, "Memory Bookmarks", true, false ); return TRUE; } case WM_GETMINMAXINFO: { LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam; lpmmi->ptMinTrackSize = pDlgMemBookmarkMin; } break; case WM_SIZE: { RARect winRect; GetWindowRect( hwnd, &winRect ); for ( ResizeContent content : vDlgMemBookmarkResize ) content.Resize( winRect.Width(), winRect.Height() ); //InvalidateRect( hwnd, NULL, TRUE ); RememberWindowSize(hwnd, "Memory Bookmarks"); } break; case WM_MOVE: RememberWindowPosition(hwnd, "Memory Bookmarks"); break; case WM_MEASUREITEM: pmis = (PMEASUREITEMSTRUCT)lParam; pmis->itemHeight = 16; return TRUE; case WM_DRAWITEM: { pdis = (PDRAWITEMSTRUCT)lParam; // If there are no list items, skip this message. if ( pdis->itemID == -1 ) break; switch ( pdis->itemAction ) { case ODA_SELECT: case ODA_DRAWENTIRE: hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES ); ListView_GetItemRect( hList, pdis->itemID, &rcBounds, LVIR_BOUNDS ); ListView_GetItemRect( hList, pdis->itemID, &rcLabel, LVIR_LABEL ); RECT rcCol ( rcBounds ); rcCol.right = rcCol.left + ListView_GetColumnWidth( hList, 0 ); // Draw Item Label - Column 0 wchar_t buffer[ 512 ]; if ( m_vBookmarks[ pdis->itemID ]->Decimal() ) swprintf_s ( buffer, 512, L"(D)%s", m_vBookmarks[ pdis->itemID ]->Description().c_str() ); else swprintf_s ( buffer, 512, L"%s", m_vBookmarks[ pdis->itemID ]->Description().c_str() ); if ( pdis->itemState & ODS_SELECTED ) { SetTextColor( pdis->hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) ); SetBkColor( pdis->hDC, GetSysColor( COLOR_HIGHLIGHT ) ); FillRect( pdis->hDC, &rcBounds, GetSysColorBrush( COLOR_HIGHLIGHT ) ); } else { SetTextColor( pdis->hDC, GetSysColor( COLOR_WINDOWTEXT ) ); COLORREF color; if ( m_vBookmarks[ pdis->itemID ]->Frozen() ) color = RGB( 255, 255, 160 ); else color = GetSysColor( COLOR_WINDOW ); HBRUSH hBrush = CreateSolidBrush( color ); SetBkColor( pdis->hDC, color ); FillRect( pdis->hDC, &rcBounds, hBrush ); DeleteObject( hBrush ); } if ( wcslen( buffer ) > 0 ) { rcLabel.left += ( offset / 2 ); rcLabel.right -= offset; DrawTextW( pdis->hDC, buffer, wcslen( buffer ), &rcLabel, DT_SINGLELINE | DT_LEFT | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS ); } // Draw Item Label for remaining columns LV_COLUMN lvc; lvc.mask = LVCF_FMT | LVCF_WIDTH; for ( size_t i = 1; ListView_GetColumn( hList, i, &lvc ); ++i ) { rcCol.left = rcCol.right; rcCol.right += lvc.cx; switch ( i ) { case CSI_ADDRESS: swprintf_s ( buffer, 512, L"%06x", m_vBookmarks[ pdis->itemID ]->Address() ); break; case CSI_VALUE: if ( m_vBookmarks[ pdis->itemID ]->Decimal() ) swprintf_s ( buffer, 512, L"%u", m_vBookmarks[ pdis->itemID ]->Value() ); else { switch ( m_vBookmarks[ pdis->itemID ]->Type() ) { case 1: swprintf_s ( buffer, 512, L"%02x", m_vBookmarks[ pdis->itemID ]->Value() ); break; case 2: swprintf_s ( buffer, 512, L"%04x", m_vBookmarks[ pdis->itemID ]->Value() ); break; case 3: swprintf_s ( buffer, 512, L"%08x", m_vBookmarks[ pdis->itemID ]->Value() ); break; } } break; case CSI_PREVIOUS: if ( m_vBookmarks[ pdis->itemID ]->Decimal() ) swprintf_s ( buffer, 512, L"%u", m_vBookmarks[ pdis->itemID ]->Previous() ); else { switch ( m_vBookmarks[ pdis->itemID ]->Type() ) { case 1: swprintf_s ( buffer, 512, L"%02x", m_vBookmarks[ pdis->itemID ]->Previous() ); break; case 2: swprintf_s ( buffer, 512, L"%04x", m_vBookmarks[ pdis->itemID ]->Previous() ); break; case 3: swprintf_s ( buffer, 512, L"%08x", m_vBookmarks[ pdis->itemID ]->Previous() ); break; } } break; case CSI_CHANGES: swprintf_s ( buffer, 512, L"%d", m_vBookmarks[ pdis->itemID ]->Count() ); break; default: swprintf_s ( buffer, 512, L"" ); break; } if ( wcslen( buffer ) == 0 ) continue; UINT nJustify = DT_LEFT; switch ( lvc.fmt & LVCFMT_JUSTIFYMASK ) { case LVCFMT_RIGHT: nJustify = DT_RIGHT; break; case LVCFMT_CENTER: nJustify = DT_CENTER; break; default: break; } rcLabel = rcCol; rcLabel.left += offset; rcLabel.right -= offset; DrawTextW( pdis->hDC, buffer, wcslen( buffer ), &rcLabel, nJustify | DT_SINGLELINE | DT_NOPREFIX | DT_VCENTER | DT_END_ELLIPSIS ); } //if (pdis->itemState & ODS_SELECTED) //&& (GetFocus() == this) // DrawFocusRect(pdis->hDC, &rcBounds); break; case ODA_FOCUS: break; } return TRUE; } case WM_NOTIFY: { switch ( LOWORD( wParam ) ) { case IDC_RA_LBX_ADDRESSES: if ( ( (LPNMHDR)lParam )->code == NM_CLICK ) { hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES ); nSelect = ListView_GetNextItem( hList, -1, LVNI_FOCUSED ); if ( nSelect == -1 ) break; } else if ( ( (LPNMHDR)lParam )->code == NM_DBLCLK ) { hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES ); LPNMITEMACTIVATE pOnClick = (LPNMITEMACTIVATE)lParam; if ( pOnClick->iItem != -1 && pOnClick->iSubItem == CSI_DESC ) { nSelItemBM = pOnClick->iItem; nSelSubItemBM = pOnClick->iSubItem; EditLabel ( pOnClick->iItem, pOnClick->iSubItem ); } else if ( pOnClick->iItem != -1 && pOnClick->iSubItem == CSI_ADDRESS ) { g_MemoryDialog.SetWatchingAddress( m_vBookmarks[ pOnClick->iItem ]->Address() ); MemoryViewerControl::setAddress( ( m_vBookmarks[ pOnClick->iItem ]->Address() & ~( 0xf ) ) - ( (int)( MemoryViewerControl::m_nDisplayedLines / 2 ) << 4 ) + ( 0x50 ) ); } } } return TRUE; } case WM_COMMAND: { switch ( LOWORD( wParam ) ) { case IDOK: case IDCLOSE: case IDCANCEL: EndDialog( hwnd, true ); return TRUE; case IDC_RA_ADD_BOOKMARK: { if ( g_MemoryDialog.GetHWND() != nullptr ) AddAddress(); return TRUE; } case IDC_RA_DEL_BOOKMARK: { HWND hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES ); int nSel = ListView_GetNextItem( hList, -1, LVNI_SELECTED ); if ( nSel != -1 ) { while ( nSel >= 0 ) { MemBookmark* pBookmark = m_vBookmarks[ nSel ]; // Remove from vector m_vBookmarks.erase( m_vBookmarks.begin() + nSel ); // Remove from map std::vector<const MemBookmark*> *pVector; pVector = &m_BookmarkMap.find( pBookmark->Address() )->second; pVector->erase( std::find( pVector->begin(), pVector->end(), pBookmark ) ); if ( pVector->size() == 0 ) m_BookmarkMap.erase( pBookmark->Address() ); delete pBookmark; ListView_DeleteItem( hList, nSel ); nSel = ListView_GetNextItem( hList, -1, LVNI_SELECTED ); } InvalidateRect( hList, NULL, FALSE ); } return TRUE; } case IDC_RA_FREEZE: { if ( m_vBookmarks.size() > 0 ) { hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES ); unsigned int uSelectedCount = ListView_GetSelectedCount( hList ); if ( uSelectedCount > 0 ) { for ( int i = ListView_GetNextItem( hList, -1, LVNI_SELECTED ); i >= 0; i = ListView_GetNextItem( hList, i, LVNI_SELECTED ) ) m_vBookmarks[ i ]->SetFrozen( !m_vBookmarks[ i ]->Frozen() ); } ListView_SetItemState( hList, -1, LVIF_STATE, LVIS_SELECTED ); } return TRUE; } case IDC_RA_CLEAR_CHANGE: { if ( m_vBookmarks.size() > 0 ) { hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES ); int idx = -1; for ( MemBookmark* bookmark : m_vBookmarks ) { idx++; bookmark->ResetCount(); } InvalidateRect( hList, NULL, FALSE ); } return TRUE; } case IDC_RA_DECIMALBOOKMARK: { if ( m_vBookmarks.size() > 0 ) { hList = GetDlgItem( hwnd, IDC_RA_LBX_ADDRESSES ); unsigned int uSelectedCount = ListView_GetSelectedCount( hList ); if ( uSelectedCount > 0 ) { for ( int i = ListView_GetNextItem( hList, -1, LVNI_SELECTED ); i >= 0; i = ListView_GetNextItem( hList, i, LVNI_SELECTED ) ) m_vBookmarks[ i ]->SetDecimal( !m_vBookmarks[ i ]->Decimal() ); } ListView_SetItemState( hList, -1, LVIF_STATE, LVIS_SELECTED ); } return TRUE; } case IDC_RA_SAVEBOOKMARK: { ExportJSON(); return TRUE; } case IDC_RA_LOADBOOKMARK: { std::string file = ImportDialog(); if (file.length() > 0 ) ImportFromFile( file ); return TRUE; } default: return FALSE; } } default: break; } return FALSE; }
void SortListView( HWND hListview, int iSubItem, LISTVIEW_COLUMN * ColumnList, bool Reverse ) { bool SortReversed = false; int PrevColumn = 0; // If column is negative then repeat the last sort if ( iSubItem < 0 ) { iSubItem = GetListViewSortColumn( ColumnList ); if ( iSubItem >= 0 ) SortListView( hListview, iSubItem, ColumnList, false ); return; } HCURSOR hSaveCursor = SetCursor( LoadCursor( NULL, IDC_WAIT ) ); // if sorting the same column twice in a row then reverse the sort order if ( ColumnList[ iSubItem ].SortDir == SORTDIR_UNDEF ) { // clicked on a new column for ( PrevColumn = 0; ColumnList[PrevColumn].Title; ++PrevColumn ) if ( ColumnList[PrevColumn].SortDir != SORTDIR_UNDEF ) break; ColumnList[PrevColumn].SortDir = SORTDIR_UNDEF; SortReversed = false; } else { // reverse sort direction if requested if ( Reverse ) SortReversed = ColumnList[ iSubItem ].SortDir == SORTDIR_UP; else SortReversed = ColumnList[ iSubItem ].SortDir != SORTDIR_UP; } ColumnList[ iSubItem ].SortDir = SortReversed ? SORTDIR_DOWN : SORTDIR_UP; // remove arrow from previously sorted column LVCOLUMN lvc; lvc.mask = LVCF_FMT; ListView_GetColumn( hListview, PrevColumn, &lvc ); lvc.fmt &= ~(LVCFMT_IMAGE | LVCFMT_COL_HAS_IMAGES | LVCFMT_BITMAP_ON_RIGHT); ListView_SetColumn( hListview, PrevColumn, &lvc ); // add arrow to sorted column lvc.mask = LVCF_FMT | LVCF_IMAGE; ListView_GetColumn( hListview, iSubItem, &lvc ); lvc.fmt |= LVCFMT_IMAGE | LVCFMT_COL_HAS_IMAGES | LVCFMT_BITMAP_ON_RIGHT; lvc.iImage = SortReversed ? LISTVIEW_IMG_DESCENDING : LISTVIEW_IMG_ASCENDING; ListView_SetColumn( hListview, iSubItem, &lvc ); // Perform sort LISTVIEW_SORT ctx; ctx.Column = iSubItem; ctx.ColumnList = ColumnList; ctx.hList = hListview; ctx.UsingEx = true; // Version 5.80 and later of Comctl32.dll BOOL ok = ListView_SortItemsEx( hListview, CompareListViewColumn, (LPARAM)&ctx ); if ( !ok ) { // Use old, slow way of sorting. ctx.UsingEx = false; ListView_SortItems( hListview, CompareListViewColumn, (LPARAM)&ctx ); } SetCursor( hSaveCursor ); }
void CSetPgDebug::OnSaveActivityLogFile() { HWND hListView = GetDlgItem(mh_Dlg, lbActivityLog); wchar_t szLogFile[MAX_PATH]; OPENFILENAME ofn; memset(&ofn,0,sizeof(ofn)); ofn.lStructSize=sizeof(ofn); ofn.hwndOwner = ghOpWnd; ofn.lpstrFilter = _T("Log files (*.csv)\0*.csv\0\0"); ofn.nFilterIndex = 1; ofn.lpstrFile = szLogFile; szLogFile[0] = 0; ofn.nMaxFile = countof(szLogFile); ofn.lpstrTitle = L"Save shell and processes log..."; ofn.lpstrDefExt = L"csv"; ofn.Flags = OFN_ENABLESIZING|OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST|OFN_EXPLORER|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT; if (!GetSaveFileName(&ofn)) return; HANDLE hFile = CreateFile(szLogFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL); if (!hFile || hFile == INVALID_HANDLE_VALUE) { DisplayLastError(L"Create log file failed!"); return; } int nMaxText = 262144; wchar_t* pszText = (wchar_t*)malloc(nMaxText*sizeof(wchar_t)); LVCOLUMN lvc = {LVCF_TEXT}; //LVITEM lvi = {0}; int nColumnCount = 0; DWORD nWritten = 0, nLen; for (;;nColumnCount++) { if (nColumnCount) WriteFile(hFile, L";", 2, &nWritten, NULL); lvc.pszText = pszText; lvc.cchTextMax = nMaxText; if (!ListView_GetColumn(hListView, nColumnCount, &lvc)) break; nLen = _tcslen(pszText)*2; if (nLen) WriteFile(hFile, pszText, nLen, &nWritten, NULL); } WriteFile(hFile, L"\r\n", 2*sizeof(wchar_t), &nWritten, NULL); //-V112 if (nColumnCount > 0) { INT_PTR nItems = ListView_GetItemCount(hListView); //-V220 for (INT_PTR i = 0; i < nItems; i++) { for (int c = 0; c < nColumnCount; c++) { if (c) WriteFile(hFile, L";", 2, &nWritten, NULL); pszText[0] = 0; ListView_GetItemText(hListView, i, c, pszText, nMaxText); nLen = _tcslen(pszText)*2; if (nLen) WriteFile(hFile, pszText, nLen, &nWritten, NULL); } WriteFile(hFile, L"\r\n", 2*sizeof(wchar_t), &nWritten, NULL); //-V112 } } free(pszText); CloseHandle(hFile); }
/*--------------------------------*/ void refresh() //odswiezanie widoku ListView { LVCOLUMN col; //struktura kolumny w kontrolce ListView HIMAGELIST hImgList; //lista obrazków, wykorzystana potem w ListView //RECT rect; DWORD pid; TBBUTTON tbb, *ptbb, tmp; char txt[256], *ptxt, path[512]; HWND hOkno; HICON hIcon = NULL; HANDLE hproc; SetCursor(LoadCursor(NULL, IDC_WAIT)); //zmiana kursora na klepsydrê, by u¿ytkownik //wiedzia³, ¿e coœ siê dzieje if (!hPasek) //je¿eli nie znany jest jeszcze uchwyt paska zadañ { hPasek = FindWindowEx(NULL, NULL, "Shell_TrayWnd", NULL); EnumChildWindows(hPasek, EnumChildProc, (LPARAM)txt); col.pszText = txt; col.cchTextMax = strlen(txt); GetWindowThreadProcessId(hPasek, &pid); //pobieranie ID procesu explorera proces = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ, false, pid); //otwieranie procesu explorera } else //je¿eli mamy ju¿ uchwyt paska zadañ { col.mask = LVCF_TEXT; col.pszText = txt; //tytu³ kolumny col.cchTextMax = 256; //maksymalny rozmiar tytu³u kolumny ListView_GetColumn(hList, 0, &col); ListView_DeleteAllItems(hList); ListView_DeleteColumn(hList, 0); ListView_DeleteColumn(hList, 0); } /*---alokowanie pamiêci dla przycisku i jego nazwy---*/ ptbb = (TBBUTTON*)VirtualAllocEx(proces, NULL, sizeof(TBBUTTON), MEM_COMMIT, PAGE_READWRITE); ptxt = (char*)VirtualAllocEx(proces, NULL, 256, MEM_COMMIT, PAGE_READWRITE); ile = SendMessage(hPasek, TB_BUTTONCOUNT, 0, 0); hImgList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, ile-1, 0); ListView_SetImageList(hList, hImgList, LVSIL_SMALL); item.mask = LVIF_STATE | LVIF_IMAGE | LVIF_INDENT | LVIF_PARAM | LVIF_TEXT; item.iItem = 0; item.iSubItem = 0; col.cx = 400; col.mask = LVCF_TEXT | LVCF_WIDTH; col.iSubItem = 0; ListView_InsertColumn(hList, 0, &col); strcpy(txt, "Stan"); col.iSubItem = 1; col.cx = 70; ListView_InsertColumn(hList, 1, &col); for (int i = 0; i < ile; i++) { SendMessage(hPasek, TB_GETBUTTON, (WPARAM)i, (LPARAM)ptbb); ReadProcessMemory(proces, (void*)ptbb, (void*)&tbb, sizeof(TBBUTTON), NULL); SendMessage(hPasek, TB_GETBUTTONTEXT, (WPARAM)tbb.idCommand, (LPARAM)ptxt); ReadProcessMemory(proces, (void*)ptxt, (void*)txt, 256, NULL); item.pszText = txt; item.cchTextMax = 256; item.iItem = i; item.iSubItem = 0; hIcon = NULL; if (tbb.fsStyle & BTNS_WHOLEDROPDOWN) //je¿eli przycisk jest przyciskiem grupowym { SendMessage(hPasek, TB_GETBUTTON, (WPARAM)(i+1), (LPARAM)ptbb); //i+1, by pobraæ ikonê przycisku tej grupy ReadProcessMemory(proces, (void*)ptbb, (void*)&tmp, sizeof(TBBUTTON), NULL); ReadProcessMemory(proces, (void*)tmp.dwData, (void*)&hOkno, sizeof(HWND), NULL); if (!hIcon) { GetWindowThreadProcessId(hOkno, &pid); hproc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pid); GetModuleFileNameEx(hproc, NULL, path, 512); ExtractIconEx(path, 0, NULL, &hIcon, 1); CloseHandle(hproc); } if (!hIcon) hIcon = LoadIcon(NULL, IDI_APPLICATION); item.iImage = ImageList_AddIcon(hImgList, hIcon); item.iIndent = 0; } else { //w tbb.dwData umieszczony jest uchwyt do okna skojarzonego z przyciskiem ReadProcessMemory(proces, (void*)tbb.dwData, (void*)&hOkno, sizeof(HWND), NULL); if (!hIcon) hIcon = (HICON)SendMessage(hOkno, WM_GETICON, ICON_SMALL, 0); if (!hIcon) hIcon = (HICON)SendMessage(hOkno, WM_GETICON, ICON_BIG, 0); if (!hIcon) hIcon = (HICON)GetClassLong(hOkno, GCL_HICONSM); if (!hIcon) hIcon = (HICON)GetClassLong(hOkno, GCL_HICON); if (!hIcon) hIcon = (HICON)GetClassLongPtr(hOkno, GCLP_HICONSM); if (!hIcon) hIcon = (HICON)GetClassLongPtr(hOkno, GCLP_HICON); if (!hIcon) { GetWindowThreadProcessId(hOkno, &pid); hproc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, pid); GetModuleFileNameEx(hproc, NULL, path, 512); ExtractIconEx(path, 0, NULL, &hIcon, 1); CloseHandle(hproc); } if (!hIcon) hIcon = LoadIcon(NULL, IDI_APPLICATION); item.iImage = ImageList_AddIcon(hImgList, hIcon); item.iIndent = 1; item.lParam = (LPARAM)hOkno; } ListView_InsertItem(hList,&item); if (tbb.fsState & TBSTATE_HIDDEN) strcpy(txt, "[ukryty]"); else strcpy(txt, "[widoczny]"); ListView_SetItemText(hList, i, 1, txt); } VirtualFreeEx(proces, ptbb, 0, MEM_RELEASE); VirtualFreeEx(proces, ptxt, 0, MEM_RELEASE); }
static bool ProbeColumn(HWND view, int index) { LVCOLUMN col = {LVCF_ORDER}; return !! ListView_GetColumn(view, index, &col); }
// Re/initialize the ListControl Columns static void Picker_InternalResetColumnDisplay(HWND hWnd, BOOL bFirstTime) { LV_COLUMN lvc; int i = 0; int nColumn = 0; int *widths; int *order; int *shown; //int shown_columns; LVCOLUMN col; struct PickerInfo *pPickerInfo; HRESULT res = 0; BOOL b_res = 0; pPickerInfo = GetPickerInfo(hWnd); widths = (int*)malloc(pPickerInfo->nColumnCount * sizeof(*widths)); order = (int*)malloc(pPickerInfo->nColumnCount * sizeof(*order)); shown = (int*)malloc(pPickerInfo->nColumnCount * sizeof(*shown)); if (!widths || !order || !shown) goto done; memset(widths, 0, pPickerInfo->nColumnCount * sizeof(*widths)); memset(order, 0, pPickerInfo->nColumnCount * sizeof(*order)); memset(shown, 0, pPickerInfo->nColumnCount * sizeof(*shown)); pPickerInfo->pCallbacks->pfnGetColumnWidths(widths); pPickerInfo->pCallbacks->pfnGetColumnOrder(order); pPickerInfo->pCallbacks->pfnGetColumnShown(shown); if (!bFirstTime) { DWORD style = GetWindowLong(hWnd, GWL_STYLE); // switch the list view to LVS_REPORT style so column widths reported correctly SetWindowLong(hWnd, GWL_STYLE, (GetWindowLong(hWnd, GWL_STYLE) & ~LVS_TYPEMASK) | LVS_REPORT); // Retrieve each of the column widths i = 0; memset(&col, 0, sizeof(col)); col.mask = LVCF_WIDTH; while(ListView_GetColumn(hWnd, 0, &col)) { nColumn = Picker_GetRealColumnFromViewColumn(hWnd, i++); widths[nColumn] = col.cx; b_res = ListView_DeleteColumn(hWnd, 0); } pPickerInfo->pCallbacks->pfnSetColumnWidths(widths); // restore old style SetWindowLong(hWnd, GWL_STYLE, style); } nColumn = 0; for (i = 0; i < pPickerInfo->nColumnCount; i++) { if (shown[order[i]]) { lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_SUBITEM | LVCF_TEXT; lvc.pszText = (LPTSTR) pPickerInfo->ppszColumnNames[order[i]]; lvc.iSubItem = nColumn; lvc.cx = widths[order[i]]; lvc.fmt = LVCFMT_LEFT; if (lvc.pszText[0] > 0) // column name cannot be blank { res = ListView_InsertColumn(hWnd, nColumn, &lvc); pPickerInfo->pnColumnsOrder[nColumn] = order[i]; //dprintf("Visible column %d: Logical column %d; Width=%d\n", nColumn, order[i], widths[order[i]]); nColumn++; } } } //shown_columns = nColumn; /* Fill this in so we can still sort on columns NOT shown */ for (i = 0; i < pPickerInfo->nColumnCount && nColumn < pPickerInfo->nColumnCount; i++) { if (!shown[order[i]]) { pPickerInfo->pnColumnsOrder[nColumn] = order[i]; nColumn++; } } if (GetListFontColor() == RGB(255, 255, 255)) b_res = ListView_SetTextColor(hWnd, RGB(240, 240, 240)); else b_res = ListView_SetTextColor(hWnd, GetListFontColor()); done: if (widths) free(widths); if (order) free(order); if (shown) free(shown); res++; b_res++; }