Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » TopWindow&PopUp, TrayIcon » [FEATURE] Setting TopWindow to urgent/flashing state
[FEATURE] Setting TopWindow to urgent/flashing state [message #30883] Thu, 27 January 2011 16:50 Go to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Hi everyone

Today I realized that U++ provides no way how to set the window into the "flashing state" that is often used in applications (e.g. IM apps) to attract user attention in an unobtrusive manner (certainly less disturbing than bringing the window to foreground Smile ).

So I propose to add methods Urgent(bool b = true) and IsUrgent() to TopWindow. The code is fairly simple:

In TopWindow.h:
class TopWindow : public Ctrl {
	// ...
	bool        frameless:1;
	bool        urgent:1;         // added
	byte        state;
	// ...
	TopWindow& FrameLess(bool b = true)               { frameless = b; return *this; }
	bool       IsFrameLess() const                    { return frameless; }
	TopWindow& Urgent(bool b = true);                                    // added
	bool       IsUrgent() const                       { return urgent; } // added
	TopWindow& NoAccessKeysDistribution()             { dokeys = false; return *this; }
	TopWindow& NoCloseBox(bool b = true)              { noclosebox = b; return *this; }
	// ...
}

In TopWindow.cpp:
TopWindow& TopWindow::Urgent(bool b)
{
	GuiLock __;
	urgent = b;
	SyncCaption();
	return *this;
}

In ToWinX11.cpp:
void TopWindow::SyncCaption0()
{
	// ...
		wm_hints->flags = InputHint|WindowGroupHint|StateHint;
		if(IsTopMost()) urgent = false;              // added
		if(urgent) wm_hints->flags |= XUrgencyHint;  // added
		wm_hints->initial_state = NormalState;
		wm_hints->input = XTrue;
	// ...
}

In TopWin32.cpp
void TopWindow::SyncCaption0()
{
	// ...
	if(hwnd) {
		::SetWindowLong(hwnd, GWL_STYLE, style);
		::SetWindowLong(hwnd, GWL_EXSTYLE, exstyle);
		SyncTitle();
// added:
		if(IsTopMost()) urgent = false;
		FLASHWINFO fi;
		fi.cbSize = sizeof(fi);
		fi.hwnd = GetHWND();
		fi.dwFlags = urgent?FLASHW_TIMERNOFG|FLASHW_ALL:FLASHW_STOP;
		fi.uCount = 0;
		fi.dwTimeout = 0;
		FlashWindowEx(&fi);
	}
	// ...
}


The behavior should be fairly standard: If you call Urgent(true); then the window title and item in taskbar are flashing until either Urgent(false); is called or the window is taken to foreground. If Urgent(true); is called on active window then it has no effect. The win32 implementation might have some bugs, I didn't test it on windows (and it is not implemented correctly in wine Smile ).

If you are wandering why I stumbled upon this, it is because it would be nice if theide would use it instead of popping up on finished builds and when breakpoint is hit when debugging.

Best regards,
Honza

[Updated on: Thu, 27 January 2011 17:12]

Report message to a moderator

Re: [FEATURE] Setting TopWindow to urgent/flashing state [message #30887 is a reply to message #30883] Thu, 27 January 2011 20:02 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Slight optimalization for SyncCapion0() in TopWin32.cpp:
		if(urgent){
			if(IsTopMost()) urgent = false;
			FLASHWINFO fi;
			fi.cbSize = sizeof(fi);
			fi.hwnd = GetHWND();
			fi.dwFlags = urgent?FLASHW_STOP:FLASHW_TIMERNOFG|FLASHW_ALL;
			fi.uCount = 0;
			fi.dwTimeout = 0;
			FlashWindowEx(&fi);
		}


Honza
Re: [FEATURE] Setting TopWindow to urgent/flashing state [message #30895 is a reply to message #30883] Thu, 27 January 2011 22:16 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1789
Registered: August 2008
Location: Czech Republic
Ultimate Contributor

Testedon windows Vista and it works fine Wink

Only problem is when compiling with Mingw, there is probably some bug in mingw headers, causing FLASHWINFO to be undeclared. So to fix it, following must be added at te top of TopWin32.cpp:
#ifdef COMPILER_MINGW
	extern "C"{
		struct FLASHWINFO {
			UINT  cbSize;
			HWND  hwnd;
			DWORD dwFlags;
			UINT  uCount;
			DWORD dwTimeout;
		};
		WINUSERAPI BOOL WINAPI FlashWindowEx(FLASHWINFO*);
	}
	#define FLASHW_STOP         0
	#define FLASHW_CAPTION      0x00000001
	#define FLASHW_TRAY         0x00000002
	#define FLASHW_ALL          (FLASHW_CAPTION | FLASHW_TRAY)
	#define FLASHW_TIMER        0x00000004
	#define FLASHW_TIMERNOFG    0x0000000C
#endif


Honza
Previous Topic: Trouble with IsMinimized / IsMaximized on X11
Next Topic: Windows that cant leave Mainwindow
Goto Forum:
  


Current Time: Wed Apr 24 10:13:22 CEST 2024

Total time taken to generate the page: 0.02238 seconds