I'm creating a plugin similar to Visual Assist's multiple clipboard feature, which is to store the list of text that are most recently copied, to an internal clipboard. Upon Ctrl-Shift-V hotkey, a popup menu with these text will appear, for the user to select which text he wants to paste.
To do that, in the plugin, I subclass _nppHandle, trap WM_COMMAND with LOWORD(wParam) == IDM_EDIT_CUT and IDM_EDIT_COPY to retrieve the text to be copied (and of course passing back the message to Npp's wndproc). This approach works when copying/cutting the text via Edit menu or the right-click context menu. However, I am unable to catch Ctrl+C and Ctrl+X shortcut key. I don't receive any WM_KEYDOWN in my subclass wndproc too. Any clues how I can resolve this?
I went to look further into this problem. First, I'll describe what I did, then I describe my observations and findings. Need people to help confirm my observations, and to offer an explanation if possible.
What I did:
Download Npp 4.1.2 source code and compile it (in VS.NET 2005). Put breakpoints in the message procedure of NPP's main window, for some of the scintilla commands: Notepad_plus.cpp -> void Notepad_plus::command(int id), lines 2190, 2196, 2202, 2206, 2212, 2219, 2557, 2570. These corresponds to the scintilla commands: undo, redo, cut, copy, paste, delete, select all and duplicate line respectively.
Then I run this compiled version of Npp in debug mode (without any plugins). I tried to activate these commands both using the menu item, as well as the associated hotkeys (which were not remapped).
Observations:
1) When using the menu items, all breakpoints above were triggered
2) When using the corresponding hotkeys, only paste (Ctrl+V) triggers the breakpoint. In the scintilla component (SciLexer.dll), all these hotkeys were caught by the message WM_KEYDOWN
3) The same things were observed when the hotkeys were remapped, and tried again
Findings:
1) Menu items work as expected, with WM_COMMAND being received by NPP's windows procedure
2) Most hotkeys for scintilla commands (except Paste) do not get translated into keyboard accelerators in NPP into WM_COMMAND message, but instead, are caught by scintilla via WM_KEYDOWN message. (Win32 documentation says that they will get translated)
Am I the only one who face this issue? Can anyone compiling npp from source kindly confirm this? Thanks in advance :-)
I want to make my multi-clipboard plugin shortcut mapping-friendly (instead of currently hardcoded to Ctrl-C/X). I realise that this is also being done with Hex-editor plugin (v0.83, HEXDialog.cpp, LRESULT HexEdit::runProcList(...), line 600)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for your reply. But as I mentioned in my post, I've already subclassed Notepad++ and successfully sniffer for copy and paste messages. Just couldn't receive the accelerator keys of Ctrl+C/X messages even though msdn says that accelerator keys are also translated to WM_COMMAND.
Just tried it again, subclassing the two scintila handles and listening for WM_CUT/COPY. Unfortunately it doesn't seemed to work as well. Using Microsoft Spy++, (Microsoft) Notepad receives the WM_COPY/CUT/PASTE for Ctrl+C/X/V, while Notepad++ (using all child/parent/same thread/same process windows settings) doesn't. Seems like they're not generated at all in Npp?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry, it's rather *SCI_* than *WM_*.
Here're all the messages about cut, copy, paste and delete operations :
SCI_CUT
SCI_COPY
SCI_PASTE
SCI_CLEAR
SCI_CANPASTE
Don
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
My suggestion was not to sniffer the WM_COPY, WM_CUT and WM_PASTE message, you should sniffer the messages IDM_EDIT_CUT, IDM_EDIT_COPY and IDM_EDIT_PASTE messages of Notepad.
Best Regards
Jens
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you both for your suggestions. I've tried them before, and have just retried them again to be doubly sure. Here're the results:
IDM_EDIT_CUT/COPY:
These are only catchable in Npp's main hwnd, and are only sent from the main menu and right-click context menu, not from Ctrl+C/X hotkeys
SCI_CUT/COPY (and also WM_CUT/COPY):
These are not sent to any of the 3 hwnd at all. If I'm not wrong, SCI_* are messages sent by the programmer to scintilla to programmatically do clipboard operations.
My only current workable result is to handle IDM_EDIT_* in main hwnd for cut/copy from menu commands, and to handle WM_KEYDOWN in both scintilla hwnd for Ctrl+C/X hotkeys. This code is in the link above (3rd post in this thread). If you want to see other permutation of code, please let me know, I'll post them up. Thanks! :-)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm creating a plugin similar to Visual Assist's multiple clipboard feature, which is to store the list of text that are most recently copied, to an internal clipboard. Upon Ctrl-Shift-V hotkey, a popup menu with these text will appear, for the user to select which text he wants to paste.
To do that, in the plugin, I subclass _nppHandle, trap WM_COMMAND with LOWORD(wParam) == IDM_EDIT_CUT and IDM_EDIT_COPY to retrieve the text to be copied (and of course passing back the message to Npp's wndproc). This approach works when copying/cutting the text via Edit menu or the right-click context menu. However, I am unable to catch Ctrl+C and Ctrl+X shortcut key. I don't receive any WM_KEYDOWN in my subclass wndproc too. Any clues how I can resolve this?
If anyone's interested, the current plugin code (with this issue) can be found here: http://www.peepor.net/loonchew/programming/NppMultiClipboardPlugin_beta_0.1.zip
I went to look further into this problem. First, I'll describe what I did, then I describe my observations and findings. Need people to help confirm my observations, and to offer an explanation if possible.
What I did:
Download Npp 4.1.2 source code and compile it (in VS.NET 2005). Put breakpoints in the message procedure of NPP's main window, for some of the scintilla commands: Notepad_plus.cpp -> void Notepad_plus::command(int id), lines 2190, 2196, 2202, 2206, 2212, 2219, 2557, 2570. These corresponds to the scintilla commands: undo, redo, cut, copy, paste, delete, select all and duplicate line respectively.
Then I run this compiled version of Npp in debug mode (without any plugins). I tried to activate these commands both using the menu item, as well as the associated hotkeys (which were not remapped).
Observations:
1) When using the menu items, all breakpoints above were triggered
2) When using the corresponding hotkeys, only paste (Ctrl+V) triggers the breakpoint. In the scintilla component (SciLexer.dll), all these hotkeys were caught by the message WM_KEYDOWN
3) The same things were observed when the hotkeys were remapped, and tried again
Findings:
1) Menu items work as expected, with WM_COMMAND being received by NPP's windows procedure
2) Most hotkeys for scintilla commands (except Paste) do not get translated into keyboard accelerators in NPP into WM_COMMAND message, but instead, are caught by scintilla via WM_KEYDOWN message. (Win32 documentation says that they will get translated)
Am I the only one who face this issue? Can anyone compiling npp from source kindly confirm this? Thanks in advance :-)
I want to make my multi-clipboard plugin shortcut mapping-friendly (instead of currently hardcoded to Ctrl-C/X). I realise that this is also being done with Hex-editor plugin (v0.83, HEXDialog.cpp, LRESULT HexEdit::runProcList(...), line 600)
Subclass Notepad and sniffer the messages of copy and paste. For an example look into HexEditor Plugin. http://sourceforge.net/projects/npp-plugins/
Best Regards
Jens
Thanks for your reply. But as I mentioned in my post, I've already subclassed Notepad++ and successfully sniffer for copy and paste messages. Just couldn't receive the accelerator keys of Ctrl+C/X messages even though msdn says that accelerator keys are also translated to WM_COMMAND.
Anyway, I manage to workaround by subclassing both scintilla windows and catching WM_KEYDOWN for Ctrl+C/X. Here is the final version
http://www.peepor.net/loonchew/programming/NppMultiClipboardPlugin_1.0.zip
Nice plugin.
What you need is subclass scintilla (but not notepad++) then intercept the WM_COPY and WM_CUT message.
Let me know if it works.
Don
Just tried it again, subclassing the two scintila handles and listening for WM_CUT/COPY. Unfortunately it doesn't seemed to work as well. Using Microsoft Spy++, (Microsoft) Notepad receives the WM_COPY/CUT/PASTE for Ctrl+C/X/V, while Notepad++ (using all child/parent/same thread/same process windows settings) doesn't. Seems like they're not generated at all in Npp?
Sorry, it's rather *SCI_* than *WM_*.
Here're all the messages about cut, copy, paste and delete operations :
SCI_CUT
SCI_COPY
SCI_PASTE
SCI_CLEAR
SCI_CANPASTE
Don
My suggestion was not to sniffer the WM_COPY, WM_CUT and WM_PASTE message, you should sniffer the messages IDM_EDIT_CUT, IDM_EDIT_COPY and IDM_EDIT_PASTE messages of Notepad.
Best Regards
Jens
Thank you both for your suggestions. I've tried them before, and have just retried them again to be doubly sure. Here're the results:
IDM_EDIT_CUT/COPY:
These are only catchable in Npp's main hwnd, and are only sent from the main menu and right-click context menu, not from Ctrl+C/X hotkeys
SCI_CUT/COPY (and also WM_CUT/COPY):
These are not sent to any of the 3 hwnd at all. If I'm not wrong, SCI_* are messages sent by the programmer to scintilla to programmatically do clipboard operations.
My only current workable result is to handle IDM_EDIT_* in main hwnd for cut/copy from menu commands, and to handle WM_KEYDOWN in both scintilla hwnd for Ctrl+C/X hotkeys. This code is in the link above (3rd post in this thread). If you want to see other permutation of code, please let me know, I'll post them up. Thanks! :-)