void CShellBrowser::DragStarted(int iFirstItem,POINT *ptCursor) { DraggedFile_t df; int iSelected = -1; if(iFirstItem != -1) { POINT ptOrigin; POINT ptItem; ListView_GetItemPosition(m_hListView,iFirstItem,&ptItem); ListView_GetOrigin(m_hListView,&ptOrigin); m_ptDraggedOffset.x = ptOrigin.x + ptCursor->x - ptItem.x; m_ptDraggedOffset.y = ptOrigin.y + ptCursor->y - ptItem.y; } while((iSelected = ListView_GetNextItem(m_hListView,iSelected,LVNI_SELECTED)) != -1) { QueryDisplayName(iSelected, SIZEOF_ARRAY(df.szFileName), df.szFileName); m_DraggedFilesList.push_back(df); } m_bDragging = TRUE; }
void wxCheckListBox::DoSetFirstItem(int n) { int pos = ListView_GetTopIndex( (HWND)GetHWND() ); if(pos == n) return; POINT ppt; BOOL ret = ListView_GetItemPosition( (HWND)GetHWND(), n, &ppt ); wxCHECK_RET( ret == TRUE, wxT("Broken DoSetFirstItem") ); ListView_Scroll( (HWND)GetHWND(), 0, 0 ); ListView_Scroll( (HWND)GetHWND(), 0, ppt.y ); }
void PaintAlternatingRows (HWND hWnd) // re-draw rows with the appropriate background colour { int i; RECT rectUpd, // rectangle to update rectDestin, // temporary storage rect; // row rectangle POINT pt; int iItems, iTop; COLORREF c; // temporary storage // get the rectangle to be updated GetUpdateRect (hWnd, &rectUpd, FALSE); // allow default processing first CallWindowProc (old_lv_proc, hWnd, WM_PAINT, 0, 0); // set the row horizontal dimensions SetRect (&rect, rectUpd.left, 0, rectUpd.right, 0); // number of displayed rows iItems = ListView_GetCountPerPage (hWnd); // first visible row iTop = ListView_GetTopIndex (hWnd); ListView_GetItemPosition (hWnd, iTop, &pt); for (i=iTop ; i<=iTop+iItems ; i++) { // set row vertical dimensions rect.top = pt.y; ListView_GetItemPosition (hWnd, i+1, &pt); rect.bottom = pt.y; // if row rectangle intersects update rectangle then it requires // re-drawing if (IntersectRect (&rectDestin, &rectUpd, &rect)) { // change text background colour accordingly c = get_row_color(hWnd, i); ListView_SetTextBkColor (hWnd, c); // invalidate the row rectangle then... InvalidateRect (hWnd, &rect, FALSE); // ...force default processing CallWindowProc (old_lv_proc, hWnd, WM_PAINT, 0, 0); } } }
void EraseAlternatingRowBkgnds (HWND hWnd, HDC hDC) // re-draw row backgrounds with the appropriate background colour { int i; RECT rect; // row rectangle POINT pt; int iItems, iTop; HBRUSH brushes[MAX_LV_COLOR_NUM]; // create coloured brushes brushes[0]=CreateSolidBrush(lv_row_color[0]); brushes[1]=CreateSolidBrush(lv_row_color[1]); brushes[2]=CreateSolidBrush(lv_row_color[2]); brushes[3]=CreateSolidBrush(lv_row_color[3]); // get horizontal dimensions of row GetClientRect (hWnd, &rect); // number of displayed rows iItems = ListView_GetCountPerPage (hWnd); // first visible row iTop = ListView_GetTopIndex (hWnd); ListView_GetItemPosition (hWnd, iTop, &pt); for (i=iTop ; i<=iTop+iItems ; i++) { // set row vertical dimensions rect.top = pt.y; ListView_GetItemPosition (hWnd, i+1, &pt); rect.bottom = pt.y; // fill row with appropriate colour FillRect (hDC, &rect, brushes[get_row_color_idx(hWnd, i)]); } // cleanup DeleteObject (brushes[0]); DeleteObject (brushes[1]); DeleteObject (brushes[2]); DeleteObject (brushes[3]); }
static unsigned int GetDesktopIconInfoListW4(std::vector<WindowIconInfo> &vec,CSAORIOutput& out) { OSVERSIONINFO osvi; ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); ::GetVersionEx( &osvi ); bool isNT = (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT); // Windows NT系でしか利用できない関数を、Windows 95系に感知させない形で // 呼び出すための工夫 HMODULE hDLL = GetModuleHandle("kernel32"); PF_VIRTUALALLOCEX pVirtualAllocEx = (PF_VIRTUALALLOCEX)GetProcAddress(hDLL,"VirtualAllocEx"); PF_VIRTUALFREEEX pVirtualFreeEx = (PF_VIRTUALFREEEX)GetProcAddress(hDLL, "VirtualFreeEx"); //デスクトップウインドウ (左上0,0) HWND hWnd = GetDesktopListView(); if ( ! hWnd ) { return 0; } //PIDを取って、内部に領域確保 DWORD pid; ::GetWindowThreadProcessId(hWnd,&pid); HANDLE ph; void *ptr; if ( isNT ) { ph = ::OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, false, pid); if ( ! ph ) { return 0; } ptr = pVirtualAllocEx(ph,NULL,BUFFER_SIZE,MEM_RESERVE|MEM_COMMIT,PAGE_READWRITE); if ( ! ptr ) { ::CloseHandle(ph); return 0; } } else { ph = ::CreateFileMapping((HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0, BUFFER_SIZE,NULL); ptr = ::MapViewOfFile(ph, FILE_MAP_ALL_ACCESS, 0, 0, 0); } //要素取得ループ unsigned int count = ListView_GetItemCount(hWnd); WindowIconInfo info; for ( int i = 0 ; i < count ; ++i ) { //プロセス内メモリにLVITEMを書いて取得、残りの領域に文字列を書いてもらう LVITEM li; ZeroMemory(&li,sizeof(li)); li.mask = LVIF_TEXT; li.iItem = i; li.iSubItem = 0; li.cchTextMax = BUFFER_SIZE-sizeof(LVITEM)-1; li.pszText = reinterpret_cast<char*>(ptr)+sizeof(LVITEM); DWORD numRead; char text_buffer[BUFFER_SIZE-sizeof(LVITEM)]; if ( isNT ) { ::WriteProcessMemory(ph, ptr, &li, sizeof(LVITEM), &numRead ); } else { memcpy(ptr, &li, sizeof(LVITEM) ); } ::SendMessage(hWnd, LVM_GETITEM , 0, (LPARAM)ptr); if ( isNT ) { ::ReadProcessMemory(ph, reinterpret_cast<char*>(ptr)+sizeof(LVITEM), text_buffer, BUFFER_SIZE-sizeof(LVITEM)-1, &numRead ); } else { memcpy(text_buffer, reinterpret_cast<char*>(ptr)+sizeof(LVITEM), BUFFER_SIZE-sizeof(LVITEM)-1); } info.m_name = SAORI_FUNC::MultiByteToUnicode(text_buffer); ListView_GetItemPosition(hWnd,i,ptr); if ( isNT ) { ::ReadProcessMemory(ph, ptr, &info.m_pt, sizeof(POINT), &numRead ); } else { memcpy(&info.m_pt, ptr, sizeof(POINT) ); } info.m_index = i; vec.push_back(info); } if ( isNT ) { pVirtualFreeEx(ph,ptr,0,MEM_RELEASE); ::CloseHandle(ph); } else { ::UnmapViewOfFile(ptr); ::CloseHandle(ph); } return count; }
void inline CShellBrowser::InsertAwaitingItems(BOOL bInsertIntoGroup) { LVITEM lv; ULARGE_INTEGER ulFileSize; unsigned int nPrevItems; int nAdded = 0; int iItemIndex; nPrevItems = ListView_GetItemCount(m_hListView); m_nAwaitingAdd = (int)m_AwaitingAddList.size(); if((nPrevItems + m_nAwaitingAdd) == 0) { if(m_bApplyFilter) SendMessage(m_hOwner,WM_USER_FILTERINGAPPLIED,m_ID,TRUE); else SendMessage(m_hOwner,WM_USER_FOLDEREMPTY,m_ID,TRUE); m_nTotalItems = 0; return; } else if(!m_bApplyFilter) { SendMessage(m_hOwner,WM_USER_FOLDEREMPTY,m_ID,FALSE); } /* Make the listview allocate space (for internal data structures) for all the items at once, rather than individually. Acts as a speed optimization. */ ListView_SetItemCount(m_hListView,m_nAwaitingAdd + nPrevItems); lv.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM; if(bInsertIntoGroup) lv.mask |= LVIF_GROUPID; /* Constant for each item. */ lv.iSubItem = 0; if(m_bAutoArrange) NListView::ListView_SetAutoArrange(m_hListView,FALSE); for(auto itr = m_AwaitingAddList.begin();itr != m_AwaitingAddList.end();itr++) { if(!IsFileFiltered(itr->iItemInternal)) { lv.iItem = itr->iItem; lv.pszText = ProcessItemFileName(itr->iItemInternal); lv.iImage = I_IMAGECALLBACK; lv.lParam = itr->iItemInternal; if(bInsertIntoGroup) { lv.iGroupId = DetermineItemGroup(itr->iItemInternal); } /* Insert the item into the list view control. */ iItemIndex = ListView_InsertItem(m_hListView,&lv); if(itr->bPosition && m_ViewMode != VM_DETAILS) { POINT ptItem; if(itr->iAfter != -1) { ListView_GetItemPosition(m_hListView,itr->iAfter,&ptItem); } else { ptItem.x = 0; ptItem.y = 0; } /* The item will end up in the position AFTER iAfter. */ ListView_SetItemPosition32(m_hListView,iItemIndex,ptItem.x,ptItem.y); } if(m_ViewMode == VM_TILES) { SetTileViewItemInfo(iItemIndex,itr->iItemInternal); } if(m_bNewItemCreated) { LPITEMIDLIST pidlComplete = NULL; pidlComplete = ILCombine(m_pidlDirectory,m_pExtraItemInfo[(int)itr->iItemInternal].pridl); if(CompareIdls(pidlComplete,m_pidlNewItem)) m_bNewItemCreated = FALSE; m_iIndexNewItem = iItemIndex; CoTaskMemFree(pidlComplete); } /* If the file is marked as hidden, ghost it out. */ if(m_pwfdFiles[itr->iItemInternal].dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { ListView_SetItemState(m_hListView,iItemIndex,LVIS_CUT,LVIS_CUT); } /* Add the current file's size to the running size of the current directory. */ /* A folder may or may not have 0 in its high file size member. It should either be zeroed, or never counted. */ ulFileSize.LowPart = m_pwfdFiles[itr->iItemInternal].nFileSizeLow; ulFileSize.HighPart = m_pwfdFiles[itr->iItemInternal].nFileSizeHigh; m_ulTotalDirSize.QuadPart += ulFileSize.QuadPart; nAdded++; } else { m_FilteredItemsList.push_back(itr->iItemInternal); } } if(m_bAutoArrange) NListView::ListView_SetAutoArrange(m_hListView,TRUE); m_nTotalItems = nPrevItems + nAdded; if(m_ViewMode == VM_DETAILS) { TCHAR szDrive[MAX_PATH]; BOOL bNetworkRemovable = FALSE; QueueUserAPC(SetAllColumnDataAPC,m_hThread,(ULONG_PTR)this); StringCchCopy(szDrive,SIZEOF_ARRAY(szDrive),m_CurDir); PathStripToRoot(szDrive); if(GetDriveType(szDrive) == DRIVE_REMOVABLE || GetDriveType(szDrive) == DRIVE_REMOTE) { bNetworkRemovable = TRUE; } /* If the user has selected to disable folder sizes on removable drives or networks, and we are currently on such a drive, do not calculate folder sizes. */ if(m_bShowFolderSizes && !(m_bDisableFolderSizesNetworkRemovable && bNetworkRemovable)) QueueUserAPC(SetAllFolderSizeColumnDataAPC,m_hFolderSizeThread,(ULONG_PTR)this); } PositionDroppedItems(); m_AwaitingAddList.clear(); m_nAwaitingAdd = 0; }