WxPython implementation window flashes in the taskbar

Source: Internet
Author: User

To remind users of this purpose, we usually use window flickering effects, such as QQ and Jabber instant chat tools. When receiving messages from friends, we usually flash the icons in the tray, if the chat window is opened, the button of the opened chat window will flash in the taskbar, and sometimes the title bar of the window will flash.

In fact, implementing such a flickering function is very simple. If you are familiar with windows APIs, you will be familiar with the FlashWindow function. This function can implement a simple window blinking function, the window only flashes. The function declaration is as follows:

[C ++]
Bool winapi FlashWindow (
_ In _ HWND hWnd,
_ In _ BOOL bInvert
);

Bool winapi FlashWindow (
_ In _ HWND hWnd,
_ In _ BOOL bInvert
); If you want to define the number and frequency of window flashes, you can use another function flashjavaswex. The declaration is as follows:

[C ++]
Bool winapi flashmediawex (
_ In _ PFLASHWINFO pfwi
);

Bool winapi flashmediawex (
_ In _ PFLASHWINFO pfwi
); This function receives a struct parameter PFLASHWINFO. The struct declaration is as follows:

[C ++]
Typedef struct {
UINT cbSize;
HWND hwnd;
DWORD dwFlags;
UINT uCount;
DWORD dwTimeout;
} FLASHWINFO, * PFLASHWINFO;

Typedef struct {
UINT cbSize;
HWND hwnd;
DWORD dwFlags;
UINT uCount;
DWORD dwTimeout;
} FLASHWINFO, * PFLASHWINFO; the main parameter is dwFlags, which has multiple combinations:

FLASHW_ALL (0x00000003): flashes the title bar of the window and the taskbar button at the same time, which is equal to FLASHW_CAPTION | FLASHW_TRAY;
FLASHW_CAPTION (0x00000001): flashing window title bar;
FLASHW_STOP (0): stops flashing. The system resets the window to the initial state.
FLASHW_TIMER (0x00000004): flashes continuously, knowing that the FLASHW_TOP mark is set
FLASHW_TIMERNOFG (0x0000000C): flashes until the front-end of the window is displayed.
FLASHW_TRAY (0x00000002): Click to flash the window on the taskbar;
The uCount parameter indicates the number of flashes. Of course, if the dwFlags value is FLASHW_TIMER or FLASHW_STOP, this parameter is invalid. DwTimeout is the flickering frequency (MS ).

Here, we use Python + wxPython to compile how to use the flashjavaswex function to achieve window flickering. The Code is as follows:

[Python]
#-*-Coding: UTF-8 -*-
'''''
Filename: winapi. py
'''
From ctypes import *
Import win32con
 
_ All _ = ['flash']
 
Flash1_wex = windll. user32.flash1_wex
 
Class FLASHWINFO (Structure ):
_ Fields _ = [('cbsize', c_uint ),
('Hwnd', c_uint ),
('Dwflags ', c_uint ),
('Ucount', c_uint ),
('Dwtimeout', c_uint)]

Def flash (hwnd ):
''' Flash a window with caption and tray .'''
Info = FLASHWINFO (0, hwnd, <SPAN style = "LINE-HEIGHT: 1.5em"> win32con. FLASHW_ALL | win32con. FLASHW_TIMERNOFG </SPAN> <SPAN style = "LINE-HEIGHT: 1.5em">, 0, 0) </SPAN>
Info. cbSize = sizeof (info)
Flashmediawex (byref (info ))

#-*-Coding: UTF-8 -*-
'''
Filename: winapi. py
'''
From ctypes import *
Import win32con

_ All _ = ['flash']

Flash1_wex = windll. user32.flash1_wex

Class FLASHWINFO (Structure ):
_ Fields _ = [('cbsize', c_uint ),
('Hwnd', c_uint ),
('Dwflags ', c_uint ),
('Ucount', c_uint ),
('Dwtimeout', c_uint)]

Def flash (hwnd ):
'''Flash a window with caption and tray .'''
Info = FLASHWINFO (0, hwnd, win32con. FLASHW_ALL | win32con. FLASHW_TIMERNOFG, 0, 0)
Info. cbSize = sizeof (info)
Flashmediawex (byref (info) method to call this function in the wx. Frame window:

[Python]
Import winapi
Winapi. flash (self. GetHandle ())

Import winapi
The winapi. flash (self. GetHandle () function flash implements the flashing window title bar and taskbar button, and stops flashing until the window is activated.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.