Community
    • Login

    Minimize notepad++ to tray instead of closing.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    26 Posts 6 Posters 7.0k 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.
    • TheMARK2580T
      TheMARK2580 @PeterJones
      last edited by

      @peterjones said in Minimize notepad++ to tray instead of closing.:

      But there isn’t anything you can do to keep the main upper-right Windows X to prevent it from closing Notepad++ – that’s a Windows-standard “close this application” which Notepad++ will not override.

      A large number of applications can be minimized to tray, the closing place. For example, torrent client, discord, anvir task manager, telegramm. It is strange that N++ still does not have such a functionality or plugin. I know that there are a bunch of other buttons to close a tab, close all tabs, etc., but I have a habit that is more than 5 years old, I used to use AkelPad which started instantly, unlike N ++ even completely clean, without plugins, installed on M2, it still starts for a significant amount of time.

      1 Reply Last reply Reply Quote 0
      • Robert CarnegieR
        Robert Carnegie
        last edited by

        I did something that might address your situation, but it’s on my work computer and it uses the “AutoHotkey” macro scripting software. And it doesn’t directly use the system tray. Let me know if you want to try it, and I’ll fetch it - though I may need my boss’s permission as well.

        What I’ve got addresses the touch-screen keyboard software “FITALY” and imposes different behaviour on it. I think that one issue that I had was that I accidentally closed FITALY instead of minimising it or maybe aiming for top right of the “keyboard”.

        So, about once a second, if FITALY is not running, my macro starts FITALY. It’s not very complicated - at least not that part.

        In your case, this could automatically start Notepad++. So by the time you realise that you accidentally closed it, it is already coming back. And I think that can be as minimised, if that’s your preference.

        The AutoHotkey script itself can have an icon in the system tray, and probably some customised menu options. Pausing or closing the macro are standard.

        TheMARK2580T 1 Reply Last reply Reply Quote 2
        • TheMARK2580T
          TheMARK2580 @Robert Carnegie
          last edited by

          @robert-carnegie No, I don’t need some program that will restart notepad ++ once in a while, I just need it to NOT close at all and go to the tray instead.

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

            @themark2580 said in Minimize notepad++ to tray instead of closing.:

            I just need it to NOT close at all and go to the tray instead.

            At this point, we fellow Notepad++ users in the Community have done all we can for you. We have given you workarounds, and explained that it’s working as designed. We cannot make changes to the codebase in this forum. This is explained in the “Please Read This Before Posting”, and explained in the FAQ section of the Forum at “Feature Request or Bug Report”.

            TheMARK2580T 1 Reply Last reply Reply Quote 1
            • TheMARK2580T
              TheMARK2580 @PeterJones
              last edited by

              @peterjones Okay, thanks for trying. I brought a button to close all tabs on the panel, I try to relearn and use it. 😁
              NbmSD6CMFi.png

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

                An issue appears to have been opened:
                Minimize to tray instead of closing

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

                  Often people that want things don’t bother to think through the design enough. In this case, what is missing is "If the close command is to minimize the window instead of closing, how do you actually close the app when you want to?

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

                    Here is a PythonScript that will minimize Notepad++ to the system tray (if Notepad++ is so configured in its Preferences) when the upper-right X button is pressed. To truly quit Notepad++, hold the Shift key while pressing the X.

                    I call the script ExitNppMinimizesToSystemTray.py and here is its code:

                    # -*- coding: utf-8 -*-
                    from __future__ import print_function
                    
                    from Npp import *
                    import ctypes
                    from ctypes import wintypes
                    import platform
                    
                    #-------------------------------------------------------------------------------
                    
                    user32 = ctypes.WinDLL('user32')
                    
                    notepad.hwnd = user32.FindWindowW(u'Notepad++', None)
                    
                    LRESULT = wintypes.LPARAM
                    
                    WndProcType = ctypes.WINFUNCTYPE(
                        LRESULT,  # return type
                        wintypes.HWND, wintypes.UINT, wintypes.WPARAM, wintypes.LPARAM  # arguments
                        )
                    
                    running_32bit = platform.architecture()[0] == '32bit'
                    
                    SetWindowLong = user32.SetWindowLongW if running_32bit else user32.SetWindowLongPtrW
                    SetWindowLong.restype = WndProcType
                    SetWindowLong.argtypes = [wintypes.HWND, wintypes.INT, WndProcType]
                    
                    SendMessageW = user32.SendMessageW
                    SendMessageW.restype = LRESULT
                    SendMessageW.argtypes = [ wintypes.HWND, wintypes.UINT, wintypes.WPARAM, wintypes.LPARAM ]
                    
                    GWL_WNDPROC = -4
                    
                    WM_CLOSE = 0x10
                    WM_SYSCOMMAND = 0x112
                    SC_MINIMIZE = 0xF020
                    VK_SHIFT = 0x10
                    
                    #-------------------------------------------------------------------------------
                    
                    class ENMTST(object):
                    
                        def __init__(self):
                            self.new_npp_wnd_proc_hook_for_SetWindowLong = WndProcType(self.new_npp_wnd_proc_hook)
                            self.orig_npp_wnd_proc = SetWindowLong(notepad.hwnd, GWL_WNDPROC, self.new_npp_wnd_proc_hook_for_SetWindowLong)
                    
                        def new_npp_wnd_proc_hook(self, hwnd, msg, wParam, lParam):
                            retval = True
                            if msg == WM_CLOSE and not self.shift_held():
                                SendMessageW(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0)
                                retval = False  # set to False if we don't want further processing of this message
                            if retval: retval = self.orig_npp_wnd_proc(hwnd, msg, wParam, lParam)
                            return retval
                    
                        def shift_held(self):
                            return (user32.GetAsyncKeyState(VK_SHIFT) & 0x8000) != 0
                    
                    #-------------------------------------------------------------------------------
                    
                    # to run from startup.py, put these lines (uncommented) in that file:
                    #import ExitNppMinimizesToSystemTray
                    #ExitNppMinimizesToSystemTray.ENMTST()
                    
                    if __name__ == '__main__': ENMTST()
                    
                    PeterJonesP TheMARK2580T 2 Replies Last reply Reply Quote 2
                    • PeterJonesP
                      PeterJones @Alan Kilborn
                      last edited by PeterJones

                      @alan-kilborn ,

                      Wow, that’s powerful! I was expecting it to stop the X, and maybe even File > Exit and Alt+F4. When it minimizes to the tray, even the right-click Close Tray Icon won’t exit out.

                      Further, a standard taskkill /im notepad++.exe was even intercepted (whether from my restart-notepad++ user-defined-command or from a command prompt). It took a taskkill /F /IM notepad++.exe to override that hook, or killing it through task manager. (But the overpowered nature of the script did encourage me to add /F to my restart-notepad++ user command, because when I want a restart, I really mean it.)

                      If the developers do implement such a feature , I hope they provide a way so that WindowCloseX works as configured, but File > Exit and Alt+F4 work as normal (or at least Alt+F4 – there has to be a common). Or add a new Tray Right Click command to “Fully Close Notepad++” when that option is in place. I’ve said as much in the feature request.

                      Alan KilbornA 1 Reply Last reply Reply Quote 1
                      • PeterJonesP PeterJones referenced this topic on
                      • PeterJonesP PeterJones referenced this topic on
                      • Alan KilbornA
                        Alan Kilborn @PeterJones
                        last edited by

                        @peterjones said in Minimize notepad++ to tray instead of closing.:

                        If the developers do implement such a feature

                        I really don’t see that happening; it seems a very special-case need – and for that case a script is sufficient IMO.

                        1 Reply Last reply Reply Quote 2
                        • Alan KilbornA
                          Alan Kilborn
                          last edited by

                          BTW, I noticed that the menu that appears when one right-clicks the tray icon is always in English, no matter what Notepad++'s localization preference is set to. That’s fine for me, so I’m not inclined to open an issue about it.

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

                            @alan-kilborn said in Minimize notepad++ to tray instead of closing.:

                            I’m not inclined to open an issue about it

                            Okay, then I have. I think that’s a general-purpose enough desire to not require a “generic user” be the one to ask for it. There shouldn’t be a menu or dialog label in the main application that isn’t translatable, IMO.

                            PeterJonesP 1 Reply Last reply Reply Quote 2
                            • Snabel42S
                              Snabel42 @Alan Kilborn
                              last edited by

                              @alan-kilborn for most applications wit this behavior, I believe I’ve seen that all other methods of closing the application besides using the X will still close the application

                              The usual suspects of file menu/exit or quit, ALT+F4, tray right click + exit all quit the application

                              Not saying this is right or wrong, but in my experience that’s the most common behavior.

                              1 Reply Last reply Reply Quote 2
                              • PeterJonesP PeterJones referenced this topic on
                              • TheMARK2580T
                                TheMARK2580 @Alan Kilborn
                                last edited by

                                @alan-kilborn I’m only interested in closing to an icon, not +folding. I still have no idea how to use this script)

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

                                  @themark2580 ,

                                  I still have no idea how to use this script

                                  1. Install PythonScript plugin (use Plugins Admin to install it)
                                  2. Plugins > Python Script > New script, name = ExitNppMinimizesToSystemTray.py
                                    (If it doesn’t default to the %AppData%\Notepad++\Plugins\Config\PythonScript\scripts directory, make sure you choose that directory; but for a fresh installation of PythonScript, it should default there)
                                  3. Paste the script that @Alan-Kilborn shared and save
                                  4. Look at Plugins > Python Script > Scripts to make sure it’s there.
                                    • If you choose that script, it will run, and the Windows-standard close-window-X (or File > Close) will minimize Notepad++ – and, if you have the Settings > Preferences > Misc > Minimize to System Tray turned on, then it will minimize to the tray rather than to the normal taskbar area
                                    • This will keep that “feature” until you use Shift + close-window-X to really exit.
                                  5. If you want it to always automatically run that script, so that the close-window-X override is always minimize-to-tray for you
                                    1. Plugins > Python Script > Configuration… and set Initialisation to ATSTARTUP and click OK
                                    2. Look at Plugins > Python Script > Scripts
                                      • if there is an entry called startup (user), ctrl+click on that entry to edit it.
                                        (Do not confuse that with startup in the same menu, which is separate, and you should not edit it)
                                      • if it does not exist, use Plugins > Python Script > New script, and give it the name startup.py in the same directory as you put the first script
                                    3. in the user startup.py that you’re now editing, add
                                      import ExitNppMinimizesToSystemTray
                                      ExitNppMinimizesToSystemTray.ENMTST()
                                      
                                      and save the changes
                                    4. The next time you run Notepad++, it will automatically run that script, and now windows-close-X will just minimize-to-tray instead of exiting Notepad++. As a reminder, to really exit Notepad++, you now must use shift + windows-close-X
                                  TheMARK2580T 1 Reply Last reply Reply Quote 1
                                  • TheMARK2580T
                                    TheMARK2580 @PeterJones
                                    last edited by TheMARK2580

                                    @peterjones

                                    All this does not matter, because with the script, the X button simply becomes the “minimize window” button and nothing more. Clicking on X does not prompt you to save changes to the file. I want it to be standard functionality, not a third-party script that forces me to download another additional plugin, perform some third-party manipulation, or install another additional program.

                                    PeterJonesP Alan KilbornA 3 Replies Last reply Reply Quote 0
                                    • PeterJonesP
                                      PeterJones @TheMARK2580
                                      last edited by PeterJones

                                      @themark2580 said in Minimize notepad++ to tray instead of closing.:

                                      All this does not matter

                                      Wow. Thanks for telling me and Alan that we’ve wasted all the time we’ve spent trying to help you.

                                      You asked how to use the script, and I told you how. If you don’t want to use it, you don’t have to.

                                      X button simply becomes the “minimize window” button and nothing more.

                                      You told us you wanted to change the behavior of the X. We told you how.

                                      I want it to be standard functionality

                                      Well, as we tried to make clear, it’s not standard functionality. And as the Forum FAQs and the “Read this before posting” say very plainly, this Forum is not where official feature requests go. Read the “Read this before posting” and the FAQ it links you to, and you can find out where feature requests actually go. (Edit: you had already created the issue, I forgot. But that makes me even more confused why you are demanding here that it be made standard functionality when you already knew we couldn’t do anything about it)

                                      Good luck.

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

                                        @themark2580 ,

                                        Clicking on X does not prompt you to save changes to the file.

                                        To get that functionality, one would just enter one extra line in the script, editor.saveAll() , before triggering the minimize. But since you aren’t interested in plugins, it’s irrelevant to you.

                                        Hopefully, future readers might get something out of this addition.

                                        TheMARK2580T 1 Reply Last reply Reply Quote 3
                                        • TheMARK2580T
                                          TheMARK2580 @PeterJones
                                          last edited by

                                          @peterjones Does this trigger a save request or does it save everything without asking?

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

                                            @themark2580 ,

                                            Just like the File > Save All, it will save all files that are already named, and it will prompt on any unnamed files (new 1 and its ilk)

                                            1 Reply Last reply Reply Quote 3
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors