Open with search
-
Thank you, that looks promising. Sorry I didn’t manage to locate that myself - I’m new to this forum and still fumbling a bit.
-
@Terry-R I’ve read and tried out the material in that thread, but I’m getting stuck. There are many references to things like NppMessage.NPPM_MENUCOMMAND, which I don’t understand and can’t find any explanations for. I’m using VBA in this case, which does make available the SendMessage function, but nothing I have tried has worked. I can start NPP and have it open the proper file, but I’m stuck on running the search dialog. Is NppMessage.NPPM_MENUCOMMAND a constant? If so, should I not be able to just pass the equivalent value? What would that value be? Or is it a pointer to function? How would I address it? Sorry I’m being such a dunce, but this is something just a bit beyond my experience. I’ve done similar things within the bounds of Microsoft’s Office package, but the components of that are quite tightly integrated, with a simple interface and adequate documentation. This is just enough more complicated that I can’t even figure out exactly what questions to ask.
-
@pdanes said in Open with search:
NPPM_MENUCOMMAND
https://npp-user-manual.org/docs/plugin-communication/ has the descriptions for all of the Notepad++ messages, and links to where you can map the names to message numbers, and to the list of Scintilla messages
-
@PeterJones Yes, thank you – that is one of the many pages I looked at, but no luck. The messages are defined there, as you say. I also looked up the values supposedly given in Notepad_plus_msgs.h, but again ran into a wall.
NPPM_MENUCOMMAND is defined as NPPMSG + 48
NPPMSG is defined as WM_USER + 1000
and WM_USER is not defined at all.So what do I use as a parameter to SendMessage? 48? 1048? I tried both a neither did anything. In fact, nothing I have tried has done anything. Notepad++ starts, opens the correct file and then just sits. Functional, responsive normally to keyboard inputs, but not one of my attempts with SendMessage has had the slightest effect. I’m getting the correct Windows handle - I’ve verified that repeatedly.
I’m obviously missing something quite fundamental, but I haven’t a clue what.
If it helps, I don’t want anything especially extravagant, I don’t think. All I want is to open the search dialog to the initial page, like with ctrl/F, put in a short text, around ten chars max, and execute the find function once. The end use takes it from there.
-
Hello, @pdanes and All,
I’m not a coder but I presume that the value of
VM_USER
is1024
Refer to the link, below, at line
55
:https://github.com/notepad-plus-plus/notepad-plus-plus/blob/master/scintilla/test/MessageNumbers.py
Best Regards,
guy038
-
@pdanes said in Open with search:
NPPM_MENUCOMMAND is defined as NPPMSG + 48
NPPMSG is defined as WM_USER + 1000
and WM_USER is not defined at all.
So what do I use as a parameter to SendMessage? 48? 1048?Sorry, given you knew how to Send message from VB, I assumed you knew that the MS defined WM_USER constant was 1024, and that if the #defines add, you would know to add the values. So 48 + 1000 + 1024 = 2072.
At one point, I ran a translation for all those constants, for my so-called PerlScript project; the translation can be found in my source code at https://github.com/pryrt/Win32-Mechanize-NotepadPlusPlus/blob/master/lib/Win32/Mechanize/NotepadPlusPlus/Notepad/Messages.pm – though it still shows the addition rather than the final sum
-
@guy038 Yes, that list helps. Thank you.
-
@PeterJones I tried that, and it seems to be doing something. When I pass the parameters properly, the SendMessage function returns one, when I do something else, it returns zero. However, it still does not launch the Find dialog. What I’m using is this:
hNppWnd = FindWindow(“Notepad++”, vbNullString)
i = SendMessage(hNppWnd, 2072, 0, 0)which does not throw an error, but nothing happens, or at least, nothing visible. Notepad++ is open in and visible, the proper file is open, but no Find dialog ever appears.
-
@pdanes ,
Per Plugin Communications # NPPM_MENUCOMMAND,
NPPM_MENUCOMMAND
Calls all possible Notepad++ menu commands.
Parameters:####
wParam [in]
int, must be zero.lParam [in]
int commandID, see menuCmdID.h for all possible values.Return value:
Returns TrueYou sent message ID of 2072, which is NPPM_MENUCOMMAND. So good. But you send lParam of 0, which doesn’t match any of the command ID values, so it won’t run any menu command. You actually have to pick a menu command for it to run.
To pick the right lParam value for the commandID, you have to look in menuCmdID.h
Looking at the commands, there is
IDM_SEARCH_FIND
, which isIDM_SEARCH + 1
=IDM + 3000 + 1
=40000 + 3000 + 1
=43001
.So you should send
hNppWnd = FindWindow(“Notepad++”, vbNullString) i = SendMessage(hNppWnd, 2072, 0, 43001)
In my so-called PerlScript, I can access that correctly using any of
perl -MWin32::Mechanize::NotepadPlusPlus=:all -le "notepad->menuCommand($NPPIDM{IDM_SEARCH_FIND})" perl -MWin32::Mechanize::NotepadPlusPlus=:all -le "notepad->menuCommand(43001)" perl -MWin32::Mechanize::NotepadPlusPlus=:all -le "notepad->SendMessage(2072, 0, 43001)" perl -MWin32::Mechanize::NotepadPlusPlus=:all -le "Win32::GuiTest::SendMessage( notepad->{_hwnd}, 2072, 0, 43001)"
(getting less abstract with each line, with the final one basically being the equivalent of my modified versin of your VBA code)
-
@PeterJones I don’t know what I’m doing wrong - I feel like a little kid that just can’t seem to hit the toilet, no matter how much the adults help me aim.
hNppWnd = FindWindow("Notepad++", vbNullString) i = SendMessage(hNppWnd, 2072, 0, 43001)
Tried this, along with all sort of other variations, like IDM_FILE_OPEN, IDM_FILE_CLOSE, IDM_FILE_SAVEAS and numerous others, from looking up in the menuCmdID.h file. Not one does anything - I’m still at the same place as when I started. NPP starts, opens the file and that’s it. SendMessage acts like it’s working, but nothing happens, no matter what I try.
-
@PeterJones JESUS!!! I got it. THIS is what finally worked:
hNppWnd = FindWindow("Notepad++", vbNullString) i = SendMessage(hNppWnd, 2072, 0, ByVal 43001)
The ByVal keyword made it work. I have no idea why, but I was flailing, try ing anything I could think of, and that clicked.
-
@pdanes ,
I don’t have access to VBA while at home this week, and probably won’t have time to debug this for you when at work next week, so I cannot debug this problem for you.
My best guess is that you don’t have what you think you have. Has your found a valid hNppWnd? Is SendMessage properly defined in VBA?And, with the update posted while I was replying:
The ByVal keyword made it work
Ah, yes, VBA defaults to ByRef. I don’t remember using SendMessage from VBA, so I had never been reminded that you would need to force ByVal when sending a value. (They have to allow ByRef in the SendMessage, because sometimes, it is a reference, like when you need a string in wParam or lParam.)
-
@PeterJones I thought literals were always passed ByVal anyway, and I’ve never used that keyword in the call - only in the definition. I had no idea it could even be used here, or what the significance is, but I saw it in some code example somewhere, so I tried it.
Time to do some more reading, looks like.
Thank you, thank you, thank you. I think I may be able to get it going from here. I’ll post back as I go.
-
@PeterJones Spoke too soon - I’m stuck again. I can’t figure out how to get hold of the search dialog, or address the controls on it. The line:
i = SendMessage(hNppWnd, 2072, 0, ByVal 43001)
spawns the dialog, but nothing I have tried has returned the handle to it. The lines:
i = FindWindow(hNppWnd, vbNullString) hWndNppFind = FindWindowEx(hNppWnd, 0, vbNullString, vbNullString)
return a success code of one only when I specify vbNullString in all the parameters. When I put any sort of text into the parameters, including the clearly visible correct title, the calls return zero. The FindWindowEx call does return some sort of number that looks like a window handle, but it’s the wrong one, and when I pause execution before the two lines and manually close the find dialog that I was so excited about finally being able to open with SendMessage, the results are the same, so it’s obviously not getting that dialog. I then used a routine named EnumWindowsProc that I found online, and located the handle to the dialog there, with the exact text of the title that it refuses to find and a different handle number. When I manually put that handle number into this call:
i = SendMessage(3804974, WM_SETTEXT, 0, ByVal "Some more text that is pointless, but assists tracking")
The number does direct it to the dialog, but the text goes into the dialog’s title bar.
I’ve spent the last two days looking up and trying stuff from every API forum and tutorial site I can find, and results zero. The dialog is open, it has a window handle, and using that handle does direct activity to that dialog. But I can’t figure out how to locate it with code, and I can’t figure out how to put text into the search box and fire the search. Can you shed some light on where I’m being dumb this time?
-
spawns the dialog, but nothing I have tried has returned the handle to it
A key line for this in the original source is:
hFindWnd = FindWindow("#32770", "Find") 'Find dialog handle
Perhaps it is strange that you haven’t mentioned 32770 in your discussion?
I’ve lurked on this issue, tempted to say something, but then backing off because VB/VBA is not something I’m great at (just don’t do it enough).
Since I did speak up, I’m wondering if you are tied to VB in some way, because (sorry) you don’t seem to be a great VB programmer. :-)
I ask because I could have given you the same solution, but in Python and definitely working.
-
@Alan-Kilborn I’m not a great VB programmer - I should think that would be obvious. I’m primarily a database designer and administrator, but I occasionally get asked to do odd things that are outside my specialty, and when I can’t figure out things on my own, I go to the appropriate forums. This is a stand-alone Access app, with VBA driving the details. VBA is not the same as VB, but I am tied to VBA, since that is the entire app. This is a portable, single-file DB, rather than a full-blown client-server system.
The line you cite did indeed latch onto the dialog properly - returned the correct handle of 3804974. Thank you. I have not mentioned 32770 because I have not the slightest idea of its significance, or that I needed it. If you have any further advice, on what I need to do to load the search string and fire the search, I would be ecstatic to hear it.
-
@Alan-Kilborn Where is this ‘original source’ that you mention for 32770?
-
Where is this ‘original source’ that you mention for 32770?
The “original source” is the code in the thread that @Terry-R originally pointed you to; and what I assume is your starting point for your current effort.
If you have any further advice, on what I need to do to load the search string and fire the search
I probably should stay out of it, given my non-expert status in VB. :-)
-
@Alan-Kilborn I went back and looked, but still don’t see it. In any case, you seem to know how to do this, or at least you said you could provide a properly working setup in Python. If you really do know how to get hold of the search text box, put something in it and launch the search, would you please be so kind as to post it here? I can slog my way through Python code, to some degree. I’ve built web-scraping gadgets in it, although I am also quite far from being a great Python programmer. But if you can show me the necessary calls, I’ll try to make them functional in VBA.
-
@Alan-Kilborn Hooray - I got the text into the search box.
hWndNppFind = FindWindowEx(hFindWnd, 0, "ComboBox", vbNullString) i = SendMessage(hWndNppFind, WM_SETTEXT, 0, ByVal "Some more text that is pointless, but assists tracking")
Now trying to click the Searc button. Maybe I’ll get this done after all.