Get the path of selected item in ListView - Win32 API - winapi

I find a way to get ListView's selected item full path. I do it in treeview by using this:
temp = (HTREEITEM)SendDlgItemMessage(hWnd,ID_TREE,TVM_GETNEXTITEM,TVGN_PARENT,(LPARAM)temp);
But I don't find familiar method in listview controls.
THanks for reading this and I w8 for your answers :)

Use the LVM_GETNEXTITEM message, specifying LVNI_SELECTED as lParam, and then the LVM_GETITEMTEXT message.

Related

Get item that caused context menu to open?

Is there a way to get the element the user right clicked on to open a context menu?
( The only method i see is looking for an item with .k-state-focused.. hopefully, there is a better way )
edit: in my code context menus are created using a filter and not a target.
You can find it in target field of the event object received by you Event Handler.
Example:
$("#container").on("contextmenu", function(e) {
console.log("target", e.target);
});
See an example here: http://jsfiddle.net/OnaBai/crobgjyf/

MS Header Control - how to update (repaint) only 1 item?

We are using the standard Header control from the OS common controls lib. We need to force the control to refresh the area related to only one column header (item). Is there a special WinAPI message for that, or a trick we could use?
Use the HDM_GETITEMRECT message to get the rectangle for the item in question, then refresh it using the InvalidateRect function.
We've used the following trick as the column header texts aren't stored directly in the header (VB6 code):
Dim tHI As HD_ITEM
tHI.mask = HDI_TEXT
SendMessage m_hWnd, HDM_SETITEM, lCol, tHI
In fact, we do not change the item, but the header "thinks" it happened so actually we force the header to redraw the item.
Caution: HDN_ITEMCHANGING is sent in this case, so ignore it when using this trick.

How to implement sorting in namespace extension using shell folder defview

I have a working namespace extension using ATL/MFC. To make it look like explorer I used the default shell folder view (defview) using SHCreateShellFolderView. So far everything works pretty well. Only big question mark I have is how I can implement sorting in the defview when a column is clicked? When I click on a column CompareIDs of the IShellFolder is called but I have to set focus into the view and hit F5 to see some changes. I tried searching the internet but information on this subject is pretty rare...
Kind regards,
Michael
Maybe response to the SFVM_COLUMNCLICK message helps you.
Example:
HRESULT ExampleFolderView_OnColumnClick(HWND hwnd, UINT uiColumn)
{
SHShellFolderView_Message(hwnd, SFVM_REARRANGE, uiColumn)
return S_OK;
}

How to Get Submenu in MFC?

I'm trying to get a submenu so that I can make changes to it before it is displayed.
So I created an OnInitMenu() handler for my window. And I had planned to use pMenu->GetMenuItemInfo() to get the submenu.
However, it doesn't appear this will work. In order to locate the menu I want, I must supply the menu command ID (I do not consider it satisfactory to hard code item positions). But menu items that open submenus do not have command IDs. I can get a menu command that exists inside that submenu, but then I still don't have the menu itself.
How can I locate a submenu nested in my main menu, without relying on MF_BYPOSITION?
My solution to this same problem was to create a helper function to search through the menu and return the position based on the name of the menu.
int CEnviroView::FindMenuItem(CMenu* Menu, LPCTSTR MenuName) {
int count = Menu->GetMenuItemCount();
for (int i = 0; i < count; i++) {
CString str;
if (Menu->GetMenuString(i, str, MF_BYPOSITION) &&
str.Compare(MenuName) == 0)
return i;
}
return -1;
}
It appears the answer is that you can't. Using command IDs to locate a menu command makes great sense because such code will continue to work as you rearrange menu items. However, menu items that are sub menus simply do not have a command ID.
One approach is to have a known menu command, which you can search for by ID, and then insert new items next to that command. However, you still need the containing menu.
The approach I ended up using resulted from studying the code MFC uses to populate the most recently used file list in the File menu. The general technique is described in the somewhat dated Paul DiLascia's Q & A column from Microsoft Systems Journal.
It would be much simpler to use MFC Command routing that allows you to update menu items?
If this is MDI/SDI application you have it for free if not you will have to implement update mechanism.
Do not handle WM_INITMENU. You should handle WM_INITMENUPOPUP. WM_INITMENUPOPUP delivers pointer to the menu that is just about to popup.
In the handler you can write a code that will allow dialog updating specific menu items using UI update mechanism fo all menus, or you can handle only a change to the specific menu item you have to alter in the handler.
You can use the method GetSubMenu from the class CMenu.
http://msdn.microsoft.com/en-us/library/dtfc356x(v=vs.80).aspx

Get the value of a selected ComboBoxItem WP7

How can i get the value of a selected comboBox Item on WP7?I tried this code:
string val = MonthBox.SelectedItem.ToString();
textBlock1.Text = val;
but it didn't work!
Don't use ComboBox on Windows Phone. Instead use the ListPicker from the Silverlight Toolkit.
In fact I had to choose "SelectionBoxItem" instead of "SelectedItem" , i finally found it !Thanks everybody for the help ;-)

Resources