Community
    • Login

    Open with search

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    35 Posts 5 Posters 8.6k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pdanesP
      pdanes
      last edited by

      I have a database application that opens a text file with NP. I would like to be able to find specific text in the file on opening. I do not see anything like a search/find switch among the command line opening parameters. Is there a way to do this? I have been trying with SendKeys, but I’m running into problems with foreigh keyboard layouts, and the text I want to insert using SendKeys does not get inserted properly but instead the characters which the foreign keyboard layout uses are inserted. (I use SendKeys to insert a digit one, but instead I get a plus sign, because the foreign keyboard maps the 1 key to a plus. If I could open via a command line with a find parameter already populated, I would avoid the SendKeys problem.

      1 Reply Last reply Reply Quote 1
      • Terry RT
        Terry R
        last edited by Terry R

        @pdanes said in Open with search:

        I would like to be able to find specific text in the file on opening.

        There were some posts a while ago that looked into the exact same request you have. I suggest you start reading that and see if it helps, otherwise come back to this post and add in additional information once you have read that. Perhaps someone from that thread may be able to supply additional help.

        https://community.notepad-plus-plus.org/topic/20312/how-to-start-a-search-automatically?page=1

        Terry

        pdanesP 1 Reply Last reply Reply Quote 2
        • pdanesP
          pdanes
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • pdanesP
            pdanes @Terry R
            last edited by

            @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.

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @pdanes
              last edited by

              @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

              pdanesP 1 Reply Last reply Reply Quote 3
              • pdanesP
                pdanes @PeterJones
                last edited by pdanes

                @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.

                PeterJonesP 1 Reply Last reply Reply Quote 0
                • guy038G
                  guy038
                  last edited by

                  Hello, @pdanes and All,

                  I’m not a coder but I presume that the value of VM_USER is 1024

                  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

                  pdanesP 1 Reply Last reply Reply Quote 1
                  • PeterJonesP
                    PeterJones @pdanes
                    last edited by

                    @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

                    pdanesP 1 Reply Last reply Reply Quote 0
                    • pdanesP
                      pdanes @guy038
                      last edited by

                      @guy038 Yes, that list helps. Thank you.

                      1 Reply Last reply Reply Quote 0
                      • pdanesP
                        pdanes @PeterJones
                        last edited by

                        @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.

                        PeterJonesP 1 Reply Last reply Reply Quote 0
                        • PeterJonesP
                          PeterJones @pdanes
                          last edited by PeterJones

                          @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 True

                          You 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 is IDM_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)

                          pdanesP 2 Replies Last reply Reply Quote 0
                          • pdanesP
                            pdanes @PeterJones
                            last edited by

                            @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.

                            PeterJonesP 1 Reply Last reply Reply Quote 0
                            • pdanesP
                              pdanes @PeterJones
                              last edited by

                              @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.

                              1 Reply Last reply Reply Quote 1
                              • PeterJonesP
                                PeterJones @pdanes
                                last edited by

                                @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.)

                                pdanesP 2 Replies Last reply Reply Quote 1
                                • pdanesP
                                  pdanes @PeterJones
                                  last edited by

                                  @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.

                                  1 Reply Last reply Reply Quote 2
                                  • pdanesP
                                    pdanes @PeterJones
                                    last edited by pdanes

                                    @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?

                                    Alan KilbornA 1 Reply Last reply Reply Quote 0
                                    • Alan KilbornA
                                      Alan Kilborn @pdanes
                                      last edited by

                                      @pdanes

                                      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.

                                      pdanesP 1 Reply Last reply Reply Quote 0
                                      • pdanesP
                                        pdanes
                                        last edited by

                                        @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.

                                        1 Reply Last reply Reply Quote 0
                                        • pdanesP
                                          pdanes @Alan Kilborn
                                          last edited by

                                          @Alan-Kilborn Where is this ‘original source’ that you mention for 32770?

                                          Alan KilbornA 1 Reply Last reply Reply Quote 0
                                          • Alan KilbornA
                                            Alan Kilborn @pdanes
                                            last edited by

                                            @pdanes

                                            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. :-)

                                            pdanesP 2 Replies Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors