简体   繁体   中英

How to create a Toast Notification (with Buttons!) using win32api?

I've been using the win10toast library (link to the init file that I'm trying to modify) for a while now, and I have a question:

How could I modify the module to have a toast notification with two buttons kinda like this with the win32gui, win32api, win32con libs?

I've been playing around with the init code, trying to add a child to self.hwnd = CreateWindow(...) around line 83 like this:

class ToastNotifier(object):

....

    style = WS_CLIPCHILDREN | WS_VISIBLE | WS_OVERLAPPED | WS_SYSMENU
            styleButton = WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON

            self.hwnd = CreateWindow(self.classAtom, "Taskbar", style,
                                     0, 0, CW_USEDEFAULT,
                                     CW_USEDEFAULT,
                                     0, 0, self.hinst, None)

           """ self.hwndButton = CreateWindow("Button", "OK", styleButton,
                                     0, 0, CW_USEDEFAULT,
                                     CW_USEDEFAULT,
                                     self.hwnd, None, 0, None)"""

            self.hwndButton = CreateWindow("Button",  # Predefined class; Unicode assumed
                                        "OK",      # Button text
                                        styleButton,  # Styles
                                        0,         #// x position
                                        0,         #// y position
                                        35,        #// Button width
                                        35,        #// Button height
                                        self.hwnd,     #// Parent window
                                        None,       #// No menu.
                                        0,
                                        None)

....

but it doesn't work the way I want to (The '1', '2' Toast notification should have the button OK, not display it on a separate window).

I contacted the module's author be he didn't know how to do it. I'm still trying to learn python, and I don't know much about win32api . Any tip? Thanks!

This is really old, and you may have solved it or not, but I'm pretty sure you are on the right track, I dug into the win32gui library for python, and when I looked at the arguments, the first argument requires a unicode literal string, and the word that is really sticking out to me is that it says "unicode assumed",and I believe we can just avoid that assumption by passing it a unicode string literal as follows u"String" . Somehow, I feel like the parent-child relation here is causing an issue as well, will update when I find more.

An application that needs to logically divide its main window should do so in the window procedure of the main window rather than by using child windows.

I'm not well versed on how this is achievable, but I'm sure there is a way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM