diff --git a/ReadMe.md b/ReadMe.md index 2705b8b..607e7b6 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -133,5 +133,5 @@ ``` (pop-select/popup-shell-menu PATH X Y) ``` -PATH即路径,目录/文件都可以,X、Y即屏幕座标,如何都是0,那么会在当前鼠标指针位置弹出。 -我是拿来配合dired使用 +PATH即路径,目录/文件都可以,X、Y即屏幕座标,如何都是0,那么会在当前鼠标指针位置弹出。额外添加第1项为路径的文件名。 +TODO: 点击空白处目前不会消失。 diff --git a/src/ShellMenu.cpp b/src/ShellMenu.cpp index d16b5ae..a5209ec 100644 --- a/src/ShellMenu.cpp +++ b/src/ShellMenu.cpp @@ -24,6 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include "shellmenu.h" +#include //----------------------------------------------------------------------------- // Name: CShellMenu @@ -70,6 +71,10 @@ CShellMenu::CShellMenu(HWND hWndDialog,int SpecialFolderCSIDL,BOOL bFolderBackgr //----------------------------------------------------------------------------- CShellMenu::CShellMenu(HWND hWndDialog,TCHAR* FileOrDirectoryPath) { + name_ = FileOrDirectoryPath; + std::wstring temp = PathFindFileNameW(name_.c_str()); + name_.swap(temp); + this->CommonConstructor(hWndDialog); this->bFillMenuSuccess=this->FillMenu(FileOrDirectoryPath); } @@ -471,6 +476,9 @@ BOOL CShellMenu::Show(int x,int y) // add window subclassing this->SubClassWindowProc(); + InsertMenu(this->hPopUpMenu, 0, 0x0400|0x800, 2, 0); + InsertMenu(this->hPopUpMenu, 0, 0x0400|0x002, 1, name_.c_str()); + // show popupmenu CmdId=(UINT)::TrackPopupMenuEx(this->hPopUpMenu,TPM_LEFTALIGN|TPM_RETURNCMD,x,y,this->hWndDialog,NULL); diff --git a/src/ShellMenu.h b/src/ShellMenu.h index fed80a3..ab57132 100644 --- a/src/ShellMenu.h +++ b/src/ShellMenu.h @@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #pragma warning (pop) #include #include +#include // atlstr.hУrustҲ #pragma comment (lib,"comctl32.lib") #define CShellMenu_idCmdFirst 0xF000// Cmd must be on WORD see CMINVOKECOMMANDINFO.lpVerb @@ -48,6 +49,7 @@ class CShellMenu IContextMenu* pContextMenu; IContextMenu2* pContextMenu2; IContextMenu3* pContextMenu3; + std::wstring name_; void CommonConstructor(HWND hWndDialog); BOOL SubClassWindowProc(); diff --git a/src/lib.rs b/src/lib.rs index 797ec30..2789ee3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -80,7 +80,7 @@ fn ensure_all_window_dark_mode() -> Result { } #[defun] -fn popup_shell_menu(path: String, x: usize, y: usize) -> Result { +fn popup_shell_menu(path: String, x: i32, y: i32) -> Result { if let Err(e) = crate::shellmenu::pop_shell_menu(path, x, y) { let es = format!("popup_shell_menu error: {}", e); let esw = to_wstring(&es); diff --git a/src/shellmenu.rs b/src/shellmenu.rs index 54f894c..80bc0b3 100644 --- a/src/shellmenu.rs +++ b/src/shellmenu.rs @@ -6,7 +6,7 @@ extern "C" { fn PopupShellMenu(h: winapi::shared::windef::HWND, path: LPCWSTR, x: i32, y: i32); } -pub fn pop_shell_menu(path: String, x: usize, y: usize) -> Result<(), NwgError> { +pub fn pop_shell_menu(path: String, x: i32, y: i32) -> Result<(), NwgError> { // use winapi::um::winuser::GetForegroundWindow; // let h = GetForegroundWindow(); // 测试发现SetWindowSubclass跨线程不会成功,因为emacs module的运行线程不是gui线程。所以这里需要跟ctrl+tab那样的处理机制。 @@ -26,7 +26,7 @@ pub fn pop_shell_menu(path: String, x: usize, y: usize) -> Result<(), NwgError> if msg == (WM_USER + 1) { unsafe { let p = crate::to_wstring(&path); - PopupShellMenu(hwnd, p.as_ptr(), x as i32, y as i32); + PopupShellMenu(hwnd, p.as_ptr(), x, y); } nwg::stop_thread_dispatch(); }