<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Get status bar text (PythonScript)]]></title><description><![CDATA[<p dir="auto">I am trying to get the status bar text (any of the bar’s sections) via PythonScript but apparently I cannot do that because it only provides a <strong>setStatusBar</strong> function but not a getter one.</p>
<p dir="auto">So I used the code from <a href="https://community.notepad-plus-plus.org/post/32089">this</a> post, however the text returned by the function is a bunch of <code>NUL</code> characters. The number of characters is correct though, which indicates that it does return the text. For example when a file is “UTF-8” (shown in section STATUSBARSECTION.UNICODETYPE of the status bar) the text I get is <code>NULNULNULNULNUL</code>, five characters.</p>
<p dir="auto">I have no idea how to modify a Win32 API function to fix this, anyone can help?</p>
<p dir="auto">The function used is copied from the linked post.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/26046/get-status-bar-text-pythonscript</link><generator>RSS for Node</generator><lastBuildDate>Thu, 18 Jun 2026 17:29:53 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/26046.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 24 Aug 2024 18:12:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Get status bar text (PythonScript) on Sat, 24 Aug 2024 23:12:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/peterjones" aria-label="Profile: PeterJones">@<bdi>PeterJones</bdi></a></p>
<p dir="auto">Works perfectly, thank you.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/96274</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/96274</guid><dc:creator><![CDATA[dr0ider_x]]></dc:creator><pubDate>Sat, 24 Aug 2024 23:12:29 GMT</pubDate></item><item><title><![CDATA[Reply to Get status bar text (PythonScript) on Sat, 24 Aug 2024 20:21:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dr0ider_x" aria-label="Profile: dr0ider_x">@<bdi>dr0ider_x</bdi></a> ,</p>
<p dir="auto">I get the same results using Scott’s 2018 script.</p>
<p dir="auto">That old script made some assumptions that weren’t necessarily always true (I think it was written for just the 32-bit Notepad++, and might not have been tried with 64-bit Notepad++).</p>
<p dir="auto">Even my old statusbar code doesn’t work anymore (which i’ll have to fix, if I ever want to use it again; bummer).</p>
<p dir="auto">But I knew I had seen successful statusbar interaction at some point more recent than that, so grepped through some of my archives, and found that being explicit about the <code>SendMessage()</code> argument and return types (<code>.restype</code> and <code>.argtypes</code>), and by passing the <em>address</em> of the text_buffer instead of the text buffer itself, I was able to edit Scott’s 2018 script to work in v8.6.9 with either PythonScript 2 or PythonScript 3.</p>
<pre><code class="language-py">import ctypes
from ctypes.wintypes import BOOL, HWND, WPARAM, LPARAM, UINT

def npp_get_statusbar(statusbar_item_number):
    LRESULT = LPARAM
    WNDENUMPROC = ctypes.WINFUNCTYPE(BOOL, HWND, LPARAM)
    FindWindow = ctypes.windll.user32.FindWindowW
    SendMessage = ctypes.windll.user32.SendMessageW
    SendMessage.restype = LRESULT
    SendMessage.argtypes = [ HWND, UINT, WPARAM, LPARAM ]
    EnumChildWindows = ctypes.windll.user32.EnumChildWindows
    GetClassName = ctypes.windll.user32.GetClassNameW
    create_unicode_buffer = ctypes.create_unicode_buffer
    WM_USER = 0x400; SB_GETTEXTLENGTHW = WM_USER + 12; SB_GETTEXTW = WM_USER + 13

    npp_get_statusbar.STATUSBAR_HANDLE = None

    def get_data_from_statusbar(statusbar_item_number):
        retcode = SendMessage(npp_get_statusbar.STATUSBAR_HANDLE, SB_GETTEXTLENGTHW, statusbar_item_number, 0)
        length = retcode &amp; 0xFFFF
        type = (retcode &gt;&gt; 16) &amp; 0xFFFF
        text_buffer = create_unicode_buffer(length)
        retcode = SendMessage(npp_get_statusbar.STATUSBAR_HANDLE, SB_GETTEXTW, statusbar_item_number, ctypes.addressof(text_buffer))
        retval = '{}'.format(text_buffer[:length])
        return retval

    def EnumCallback(hwnd, lparam):
        curr_class = create_unicode_buffer(256)
        GetClassName(hwnd, curr_class, 256)
        if curr_class.value.lower() == "msctls_statusbar32":
            npp_get_statusbar.STATUSBAR_HANDLE = hwnd
            return False
        return True

    EnumChildWindows(FindWindow(u"Notepad++", None), WNDENUMPROC(EnumCallback), 0)

    return get_data_from_statusbar(statusbar_item_number) if npp_get_statusbar.STATUSBAR_HANDLE else None
</code></pre>
<p dir="auto">With that, an interactive PythonScript console can get the active language correctly from the status bar:</p>
<pre><code>&gt;&gt;&gt; npp_get_statusbar(0)
'Python file'
</code></pre>
]]></description><link>https://community.notepad-plus-plus.org/post/96273</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/96273</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Sat, 24 Aug 2024 20:21:08 GMT</pubDate></item></channel></rss>