RECT TaskList::adjustSize() { RECT rc; ListView_GetItemRect(_hSelf, 0, &rc, LVIR_ICON); const int imgWidth = rc.right - rc.left; const int leftMarge = 30; const int xpBottomMarge = 5; const int w7BottomMarge = 15; // Temporary set "selected" font to get the worst case widths ::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFontSelected), 0); int maxwidth = -1; _rc.left = 0; _rc.top = 0; _rc.bottom = 0; for (int i = 0 ; i < _nbItem ; ++i) { TCHAR buf[MAX_PATH]; ListView_GetItemText(_hSelf, i, 0, buf, MAX_PATH); int width = ListView_GetStringWidth(_hSelf, buf); if (width > maxwidth) maxwidth = width; _rc.bottom += rc.bottom - rc.top; } _rc.right = maxwidth + imgWidth + leftMarge; ListView_SetColumnWidth(_hSelf, 0, _rc.right); ::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFont), 0); reSizeTo(_rc); winVer ver = (NppParameters::getInstance())->getWinVersion(); _rc.bottom += (ver <= WV_XP && ver != WV_UNKNOWN)?xpBottomMarge:w7BottomMarge; return _rc; }
RECT TaskList::adjustSize() { RECT rc; ListView_GetItemRect(_hSelf, 0, &rc, LVIR_ICON); const int imgWidth = rc.right - rc.left; const int marge = 30; // Temporary set "selected" font to get the worst case widths ::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFontSelected), 0); int maxwidth = -1; _rc.left = 0; _rc.top = 0; _rc.bottom = 0; for (int i = 0 ; i < _nbItem ; i++) { TCHAR buf[MAX_PATH]; ListView_GetItemText(_hSelf, i, 0, buf, MAX_PATH); int width = ListView_GetStringWidth(_hSelf, buf); if (width > maxwidth) maxwidth = width; _rc.bottom += rc.bottom - rc.top; } _rc.right = maxwidth + imgWidth + marge; ::SendMessage(_hSelf, WM_SETFONT, reinterpret_cast<WPARAM>(_hFont), 0); reSizeTo(_rc); return _rc; }
RECT TaskList::adjustSize() { RECT rc; ListView_GetItemRect(_hSelf, 0, &rc, LVIR_ICON); const int imgWidth = rc.right - rc.left; const int marge = 30; for (int i = 0 ; i < _nbItem ; i++) { char buf[MAX_PATH]; ListView_GetItemText(_hSelf, i, 0, buf, sizeof(buf)); int width = ListView_GetStringWidth(_hSelf, buf); if (width > (_rc.right - _rc.left)) _rc.right = _rc.left + width + imgWidth + marge; _rc.bottom += rc.bottom - rc.top; } // additional space for horizontal scroll-bar _rc.bottom += rc.bottom - rc.top; reSizeTo(_rc); return _rc; }
void MyListView_AddItemWithIcon(HWND hListView, TCHAR *ItemText, int ColumnIndex, int RowIndex, void *pData, int iIcon) { LV_ITEM ListViewItem; int ColumnWidth; int ItemWidth; HWND hHeader; hHeader = ListView_GetHeader(hListView); if (ColumnIndex == (Header_GetItemCount(hHeader)-1)) { RECT itemRect; RECT headerRect; // get rect of last column in header Header_GetItemRect(hHeader, (Header_GetItemCount(hHeader)-1), &itemRect); GetClientRect(hHeader,&headerRect); ItemWidth= headerRect.right - itemRect.left; } else { ItemWidth = ListView_GetStringWidth(hListView, ItemText) + (GetSystemMetrics(SM_CXEDGE)<<1)+(4<<1); } ColumnWidth = ListView_GetColumnWidth(hListView,ColumnIndex); ListViewItem.mask = LVIF_TEXT; if (iIcon!=-1) { ListViewItem.mask |= LVIF_IMAGE; ListViewItem.iImage = iIcon; } ListViewItem.iItem = RowIndex; ListViewItem.iSubItem = ColumnIndex; ListViewItem.pszText = ItemText; if (ColumnIndex == 0) { ListViewItem.mask |= LVIF_PARAM; ListViewItem.lParam = (LPARAM)pData; ListView_InsertItem(hListView, &ListViewItem); } else { ListView_SetItem(hListView, &ListViewItem); } if (ItemWidth>ColumnWidth) ListView_SetColumnWidth(hListView, ColumnIndex, ItemWidth); }
/* add a column to a list view control */ void MyListView_AddColumn(HWND hListView, TCHAR *ColumnTitle, int ColumnIndex) { LV_COLUMN ListViewColumn; int StringWidth = ListView_GetStringWidth(hListView, ColumnTitle); ListViewColumn.mask = LVCF_TEXT | LVCF_WIDTH; ListViewColumn.cx = StringWidth + (GetSystemMetrics(SM_CXEDGE)<<1)+(4<<1); ListViewColumn.pszText = ColumnTitle; ListViewColumn.cchTextMax = 0; ListViewColumn.iSubItem = 0; ListView_InsertColumn(hListView, ColumnIndex, &ListViewColumn); }
void TaskListDlg::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { RECT rect = lpDrawItemStruct->rcItem; HDC hDC = lpDrawItemStruct->hDC; int nItem = lpDrawItemStruct->itemID; const TCHAR *label = _taskListInfo._tlfsLst[nItem]._fn.c_str(); int iImage = _taskListInfo._tlfsLst[nItem]._status; const int aSpaceWidth = ListView_GetStringWidth(_taskList.getHSelf(), TEXT(" ")); COLORREF textColor = darkGrey; int imgStyle = ILD_SELECTED; if (lpDrawItemStruct->itemState & ODS_SELECTED) { imgStyle = ILD_TRANSPARENT; textColor = black; ::SelectObject(hDC, _taskList.GetFontSelected()); } // // DRAW IMAGE // HIMAGELIST hImgLst = _taskList.getImgLst(); IMAGEINFO info; ::ImageList_GetImageInfo(hImgLst, iImage, &info); RECT & imageRect = info.rcImage; // center icon position, prefer bottom orientation imageRect.top = ((rect.bottom - rect.top) - (imageRect.bottom - imageRect.top) + 1) / 2; rect.left += aSpaceWidth; ::ImageList_Draw(hImgLst, iImage, hDC, rect.left, rect.top + imageRect.top, imgStyle); rect.left += imageRect.right - imageRect.left + aSpaceWidth * 2; // // DRAW TEXT // ::SetTextColor(hDC, textColor); ::DrawText(hDC, label, lstrlen(label), &rect, DT_SINGLELINE | DT_VCENTER | DT_LEFT); }
BOOL plMultistageBehComponent::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg) { case WM_COMMAND: if (HIWORD(wParam) == BN_CLICKED) { // Adding a new stage if (LOWORD(wParam) == IDC_ADD) { // Create the new stage and give it a default name. plBaseStage* stage = new plStandardStage; int count = fStages.size(); fStages.push_back(stage); char buf[64]; sprintf(buf, "Stage %d", count); stage->SetName(buf); // Add the new stage to the list and make sure the list is wide enough HWND hList = GetDlgItem(fDlg, IDC_STAGE_LIST); int idx = ListView_AddString(hList, stage->GetName().c_str()); ListView_SetColumnWidth(hList, 0, LVSCW_AUTOSIZE); ListView_SetItemState(hList, idx, LVIS_SELECTED, LVIS_SELECTED); // Put up the new stages dialog IDestroyStageDlg(); fCurStage = idx; ICreateStageDlg(); SetSaveRequiredFlag(); } // Removing the selected stage else if (LOWORD(wParam) == IDC_REMOVE) { HWND hList = GetDlgItem(fDlg, IDC_STAGE_LIST); int sel = ListView_GetNextItem(hList, -1, LVNI_SELECTED); if (sel != -1) { IDestroyStageDlg(); plBaseStage* stage = fStages[sel]; fStages.erase(fStages.begin()+sel); delete stage; ListView_DeleteItem(hList, sel); SetSaveRequiredFlag(); } } else if (LOWORD(wParam) == IDC_FREEZE_PHYS) { fFreezePhys = (Button_GetCheck((HWND)lParam) == BST_CHECKED); SetSaveRequiredFlag(); } else if (LOWORD(wParam) == IDC_SMART_SEEK) { fSmartSeek = (Button_GetCheck((HWND)lParam) == BST_CHECKED); SetSaveRequiredFlag(); } else if (LOWORD(wParam) == IDC_MULTI_REVERSE_CTL) { fReverseFBOnRelease = (Button_GetCheck((HWND)lParam) == BST_CHECKED); SetSaveRequiredFlag(); } return TRUE; } break; case WM_NOTIFY: { NMHDR *nmhdr = (NMHDR*)lParam; if (nmhdr->idFrom == IDC_STAGE_LIST) { switch (nmhdr->code) { // Stop Max from reading keypresses while the list has focus case NM_SETFOCUS: plMaxAccelerators::Disable(); return TRUE; case NM_KILLFOCUS: plMaxAccelerators::Enable(); return TRUE; // The edit box this creates kills the focus on the listbox, // so add an extra disable to ignore it case LVN_BEGINLABELEDIT: plMaxAccelerators::Disable(); return TRUE; // Finishing changing the name of a stage case LVN_ENDLABELEDIT: { NMLVDISPINFO *di = (NMLVDISPINFO*)lParam; const char *name = di->item.pszText; // If the name was changed... if (name && *name != '\0') { plBaseStage* stage = fStages[fCurStage]; stage->SetName(name); // Make sure the column is wide enough int width = ListView_GetStringWidth(nmhdr->hwndFrom, name)+10; if (width > ListView_GetColumnWidth(nmhdr->hwndFrom, 0)) { ListView_SetColumnWidth(nmhdr->hwndFrom, 0, width); } // Return true to keep the changes SetWindowLong(hDlg, DWL_MSGRESULT, TRUE); } plMaxAccelerators::Enable(); } return TRUE; case LVN_ITEMCHANGED: { int sel = ListView_GetNextItem(nmhdr->hwndFrom, -1, LVNI_SELECTED); IDestroyStageDlg(); if (sel != -1 && sel != fCurStage) { fCurStage = sel; ICreateStageDlg(); } } return TRUE; } } } break; } return FALSE; }
inline size_t CListView::StringWidth(const tchar* pszString) const { return ListView_GetStringWidth(m_hWnd, pszString); }