• Login
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.
  • G
    guy038
    last edited by Dec 28, 2020, 3:21 PM

    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

    P 1 Reply Last reply Dec 28, 2020, 8:23 PM Reply Quote 1
    • P
      PeterJones @pdanes
      last edited by Dec 28, 2020, 4:06 PM

      @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

      P 1 Reply Last reply Dec 28, 2020, 8:28 PM Reply Quote 0
      • P
        pdanes @guy038
        last edited by Dec 28, 2020, 8:23 PM

        @guy038 Yes, that list helps. Thank you.

        1 Reply Last reply Reply Quote 0
        • P
          pdanes @PeterJones
          last edited by Dec 28, 2020, 8:28 PM

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

          P 1 Reply Last reply Dec 28, 2020, 11:17 PM Reply Quote 0
          • P
            PeterJones @pdanes
            last edited by PeterJones Dec 28, 2020, 11:19 PM Dec 28, 2020, 11:17 PM

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

            P 2 Replies Last reply Dec 29, 2020, 12:09 AM Reply Quote 0
            • P
              pdanes @PeterJones
              last edited by Dec 29, 2020, 12:09 AM

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

              P 1 Reply Last reply Dec 29, 2020, 12:19 AM Reply Quote 0
              • P
                pdanes @PeterJones
                last edited by Dec 29, 2020, 12:17 AM

                @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
                • P
                  PeterJones @pdanes
                  last edited by Dec 29, 2020, 12:19 AM

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

                  P 2 Replies Last reply Dec 29, 2020, 12:22 AM Reply Quote 1
                  • P
                    pdanes @PeterJones
                    last edited by Dec 29, 2020, 12:22 AM

                    @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
                    • P
                      pdanes @PeterJones
                      last edited by pdanes Dec 30, 2020, 8:47 PM Dec 30, 2020, 8:44 PM

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

                      A 1 Reply Last reply Dec 30, 2020, 9:11 PM Reply Quote 0
                      • A
                        Alan Kilborn @pdanes
                        last edited by Dec 30, 2020, 9:11 PM

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

                        P 1 Reply Last reply Dec 30, 2020, 9:28 PM Reply Quote 0
                        • P
                          pdanes
                          last edited by Dec 30, 2020, 9:25 PM

                          @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
                          • P
                            pdanes @Alan Kilborn
                            last edited by Dec 30, 2020, 9:28 PM

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

                            A 1 Reply Last reply Dec 30, 2020, 9:38 PM Reply Quote 0
                            • A
                              Alan Kilborn @pdanes
                              last edited by Dec 30, 2020, 9:38 PM

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

                              P 2 Replies Last reply Dec 30, 2020, 9:50 PM Reply Quote 0
                              • P
                                pdanes @Alan Kilborn
                                last edited by pdanes Dec 30, 2020, 9:51 PM Dec 30, 2020, 9:50 PM

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

                                A 1 Reply Last reply Dec 31, 2020, 1:21 AM Reply Quote 0
                                • P
                                  pdanes @Alan Kilborn
                                  last edited by Dec 30, 2020, 10:21 PM

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

                                  P 1 Reply Last reply Dec 30, 2020, 10:43 PM Reply Quote 0
                                  • P
                                    pdanes @pdanes
                                    last edited by pdanes Dec 30, 2020, 10:45 PM Dec 30, 2020, 10:43 PM

                                    I’m ready to go jump off a bridge. When I use this:

                                        i = SendMessage(hWndNppFind, WM_SETTEXT, 0, ByVal "._HS 68")
                                    

                                    the search box gets populated correctly. but when I use this:

                                        HSHesla = "._HS 68"
                                        i = SendMessage(hWndNppFind, WM_SETTEXT, 0, ByVal HSHesla)
                                    

                                    the search box gets populated with heiroglyphics. When I use this:

                                        HSHesla = "._HS 68"
                                        i = SendMessage(hWndNppFind, WM_SETTEXT, 0, HSHesla)
                                    

                                    I still get heiroglyphics, but different ones. Why the hell does this have to be so damn complicated?

                                    P 1 Reply Last reply Dec 30, 2020, 10:59 PM Reply Quote 0
                                    • P
                                      pdanes @pdanes
                                      last edited by Dec 30, 2020, 10:59 PM

                                      Got it, sort of. I can get text into the search box and I figured out how to click to Find button. It works. All I’ve got left is how to get the contents of my variable into the search text box, instead of a constant.

                                      P 1 Reply Last reply Dec 30, 2020, 11:09 PM Reply Quote 0
                                      • P
                                        pdanes @pdanes
                                        last edited by Dec 30, 2020, 11:09 PM

                                        Got it all, finally. This is what made the text populate correctly from a variable:

                                            i = SendMessage(hWndNppFind, WM_SETTEXT, 0, ByVal CStr(HSHesla))
                                        

                                        Christ on a crutch - this is the most annoying, non-intuitive setup I’ve seen in a long time.

                                        Many thanks to everyone for the tips.

                                        P 1 Reply Last reply Dec 30, 2020, 11:35 PM Reply Quote 1
                                        • P
                                          PeterJones @pdanes
                                          last edited by Dec 30, 2020, 11:35 PM

                                          @pdanes said in Open with search:

                                          • this is the most annoying, non-intuitive setup I’ve seen in a long time

                                          This is because you are trying to use VBA to talk to the C-style world. It’s nothing specific to Notepad++, and you would have the same issues talking with any message-based app from VBA.

                                          I only try such gymnastics once every few years, and forget the details between; fortunately, I am able to dig up my old code to remind myself how it works.

                                          But you are making good progress. And soon you will have a working example from which you can base future VBA/C crossovers.

                                          P 1 Reply Last reply Dec 31, 2020, 9:05 AM Reply Quote 0
                                          16 out of 35
                                          • First post
                                            16/35
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors