PDA

View Full Version : Window Blink/Flash



VireX
14th April 2007, 05:49
does anyone have any idea on how to get your window to blink or flash on the startmenu just like when people message you on MSN or AIM??

marcel
14th April 2007, 06:58
Yes, but only on Windows:



#include <Windows.h>
...
FLASHWINFO finfo;
finfo.cbSize = sizeof( FLASHWINFO );
finfo.hwnd = this->winId();
finfo.uCount = 20; // Flash 20 times
finfo.dwTimeout = 400; // Duration in milliseconds between flashes
finfo.dwFlags = FLASHW_TRAY; //Flash only taskbar button
::FlashWindowEx( &finfo );


Here, "this" is a QMainWindow derivate, so winId will work. It won't work on a regular widget so be careful to call FlashWindowEx from the main window only.

I believe this can also be done on Mac. The result will be the app icon bouncing in the dock. I don't know how yet...

On how many platforms do you plan to run your app?

Regards

VireX
14th April 2007, 07:23
Thanks, I'll see if this works, I been looking for that struct in MSDN docs. Hard to find :S...
Although MAc and Linux may be an idea for way later its the last thing on my mind.

marcel
14th April 2007, 07:25
On Mac:



#include <Notification.h>
...
NMRecPtr notifRequestData = new NMRecPtr;
notifRequestData->nmMark = 1; //Make the app icon bounce
notifRequestData->nmIcon = NULL;
notifRequestData->nmSound = NULL;
notifRequestData->nmStr = NULL;
notifRequestData->nmResp = NULL;

NMInstall( notifRequestData );



Make sure to use NMRemove when you're done using the NMRecPtr and delete it.

Note that you have to do this separately for Mac and Win because Qt does not have support for user notification.

Regards.

marcel
14th April 2007, 07:26
Thanks, I'll see if this works, I been looking for that struct in MSDN docs. Hard to find :S...
Although MAc and Linux may be an idea for way later its the last thing on my mind.

It works, I just tested it!

VireX
14th April 2007, 07:48
No It doesn't work, because including windows.h not only causes many compiler errors in my project, but for some reason, windows.h does not recognize FLASHWINFO... It's quite weird. It's in MSDN so I don't see why it isn't working.

marcel
14th April 2007, 07:50
Could you show me your #include section?
I tested it here and it works.

VireX
14th April 2007, 08:00
This is quite awkward. Is FLASHWINFO new or something?
Because my compiler does NOT recognize FLASHWINFO (even on a plain Win32 API project), meaning that it probably is not defined in my windows.h

Could it be because I use Dev-Cpp with mingw?

marcel
14th April 2007, 08:01
FlashWindowEx and FLASHWINFO are in Winuser.h, which is included by Windows.h.

Compiler errors caused by header inclusion order can be solved quite easy...

marcel
14th April 2007, 08:03
This is quite awkward. Is FLASHWINFO new or something?
Because my compiler does NOT recognize FLASHWINFO (even on a plain Win32 API project), meaning that it probably is not defined in my windows.h

Could it be because I use Dev-Cpp with mingw?

I am not that familiar with mingw. Try looking for Winuser.h and see if they are defined there. If they are, then just include Winuser.h.

I guess it worked for be because I'm using VS 2003.

jpn
14th April 2007, 08:21
Qt 4.3 introduces QApplication::alert() (http://doc.trolltech.com/4.3/qapplication.html#alert).

marcel
14th April 2007, 08:27
Qt 4.3 introduces QApplication::alert() (http://doc.trolltech.com/4.3/qapplication.html#alert).

If VireX wants to use it, no problem here...

VireX
14th April 2007, 08:39
Well thats pretty obvious. #include <windows.h>, thats my only include, and it WOULD work if it was truly defined in winuser.h, and since it is a simple plain Win32 project, there is no mistake or mixup with Qt. It's definitely a problem with my windows.h or Dev-C++ in general. Either that or FLASHWINFO doesn't exist.

Qt 4.3 is not out yet. The only download is qt-win-opensrc... it's not the mingw version so I cannot get it to work.

marcel
14th April 2007, 08:57
Have you included the windows api src in your mingw install?
I just downloaded it from http://prdownloads.sf.net/mingw/w32api-3.6-src.tar.gz?download

I can find in there both windows.h and winuser.h and FlashWindowEx is defined in winuser.h.

Maybe your mingw install is not OK.

Edit:
Dev-c++ should have an include path option. Make sure the path for the windows api is added there.

Regards.

VireX
14th April 2007, 17:19
My winuser.h has FLASHWINFO defined, and it is included.
If it wasn't included I would have more errors than just FLASHWINFO.

Compiler errors:

g++.exe -c flashtest.cpp -o flashtest.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include"

flashtest.cpp: In function `LRESULT WindowProcedure(HWND__*, UINT, WPARAM, LPARAM)':
flashtest.cpp:90: error: `FLASHWINFO' undeclared (first use this function)
flashtest.cpp:90: error: (Each undeclared identifier is reported only once for each function it appears in.)

flashtest.cpp:90: error: expected `;' before "finfo"
flashtest.cpp:91: error: `finfo' undeclared (first use this function)
flashtest.cpp:92: error: invalid use of `this' in non-member function
flashtest.cpp:95: error: `FLASHW_ALL' undeclared (first use this function)

flashtest.cpp:95: error: `FLASHW_TIMERNOFG' undeclared (first use this function)
flashtest.cpp:96: error: `FlashWindowEx' undeclared (first use this function)

make.exe: *** [flashtest.o] Error 1



case IDBUTTON:{
Sleep(1000);
MessageBox(hwnd, (LPCTSTR)"test!", (LPCTSTR)"test!", MB_OK|MB_ICONEXCLAMATION);
FLASHWINFO finfo;
finfo.cbSize = sizeof( FLASHWINFO );
finfo.hwnd = hwnd;
finfo.uCount = 20; // Flash 20 times
finfo.dwTimeout = 400; // Duration in milliseconds between flashes
finfo.dwFlags = FLASHW_ALL|FLASHW_TIMERNOFG; //Flash only taskbar button
FlashWindowEx( &finfo );
break;
}


Oh btw you guys should rly consider removing the line number from geshi filter, annoying...

But this error, look how ridiculous this is:
#include <winuser.h>
MOUSEMOVEPOINT mmp;

VireX
14th April 2007, 17:49
I got it to work when using:
#define _WIN32_WINNT 0x0501
#define WINVER 0x0501

marcel
14th April 2007, 17:51
Nice... I wasn't sure where the error came from...

VireX
14th April 2007, 19:44
Tried to develop some sort of efficient way to do this:
Because FLASHWINFO only works if WINNT is greater than 0x0500! Meaning its an XP/2k-Only feature... Therefore, I had to get the version info. Which works fine, but FLASHWINFO still says "undeclared first use this function". Quite odd... any other ideas?



#include <windows.h>
int GetWinXP(){
OSVERSIONINFO osVer;
int xp = 0;
osVer.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(GetVersionEx(&osVer) != 0){
if(osVer.dwPlatformId == VER_PLATFORM_WIN32_NT){
xp = 1;
}
}
return xp;
}
void CLobby::SendMsg(){ // A SLOT()
QString qsMsg;
// do some Qt Stuff
MsgSend->clear();
if(GetWinXP() == 1){
#undef _WIN32_WINNT
#undef WINVER
#define _WIN32_WINNT 0x0501
#define WINVER 0x0501
#include <winuser.h>
FLASHWINFO finfo;
finfo.cbSize = sizeof( FLASHWINFO );
finfo.hwnd = this->winId();
finfo.uCount = 20; // Flash 20 times
finfo.dwTimeout = 400; // Duration in milliseconds between flashes
finfo.dwFlags = 1|2|12; //Flash only taskbar button
FlashWindowEx( &finfo );
}
}
}

marcel
14th April 2007, 19:56
Maybe because Windows.h includes winuser.h before you def and undef the windows versions.

What version of windows do you have?

Regards.

VireX
14th April 2007, 20:32
WinXP of course the best windows.

marcel
14th April 2007, 20:35
Perhaps this is a bug in mingw?
What if you move the defines to the top? Before including windows.h...

Should work.

fullmetalcoder
16th April 2007, 11:17
Qt 4.3 is not out yet
Qt 4.3 is out but only as a beta...

Alternatively you can always use a combination of QWidget::show() QWidget::raise() and QWidget::setFocus() which on most platform will cause a blinking when the window can not be actually shown, raised and focused...