[Windows Legacy] How to make task bar icon flashing

Hi, I m making a small app on Windows which can notify the user at a certain time. The user may minimize the application, so I would like to know is there a way or trick to make the taskbar icon flash in order to notify the user.

Thanks.

1 Like

It looks like it should be possible to do this in a native extension:

Perhaps this could be added to Lime, I’m not sure where the function call would go? We also would want to look at Mac and Linux alternatives

Cool, I guess this can go into the openfl.system.System class, since it handles the clipboard it might as well handle this. I lack C++ knowledge so I wont be able to work on a native extension for now, plus it probably wont make it to the legacy since the main focus now is openfl next. I guess I ll just use sound alert then…

One benefit of an extension is it would work for both legacy and current OpenFL, lime create extension MyExtension generates a sample project, the key would then be an #ifdef HX_WINDOWS block that makes the call to FlashWindow

0.0 Holy thats just WOWWW nice

Okay so is there any template on creating extension? Is it going to be in ndll form? Do I need to compile it using Visual Studio or can lime do it for me?

Create a template like this:

lime create extension NameOfYourExtension

That creates a folder with an extension project. You can include it in a regular project like this:

<include path="to/NameOfYourExtension" />

You could also make it available as a haxelib, by doing:

haxelib dev my-extension path/to/NameOfYourExtension

and in your project:

<haxelib name="my-extension" />

When you’re ready to compile your extension, use lime rebuild with the path to the extension or its haxelib name, if you use haxelib:

lime rebuild path/to/NameOfYourExtension windows
lime rebuild my-extension windows

You can use rebuild for other targets, too :slight_smile:

Holy mother of god I can write native codes now I feel so powerfullllll

Thank you!!

1 Like

Hmm, in the stack overflow page the example used a hwnd which I dont know where to get…

It looks like SDL will give you the window information, which includes (on Windows) an HWND:

SDL_SysWMinfo info;
SDL_GetWindowWMInfo (window, &info);
...
info.window

However, there does not appear to be a global way to get the SDL window reference. This is needed to use SDL_GetWindowWMInfo. It might be possible to get it on Lime 2 using this code in Haxe:

var sdlWindow = @:privateAccess Lib.application.window.backend.handle;

An alternative would be modifying Lime 2 or Lime legacy. This might actually be easier. Would you be interested in this?

1.) Using a Development Version of Lime

If you have not used a development version of Lime before, follow these steps:

https://github.com/openfl/lime#building-from-source

You need to have a GIT version of Lime in order to rebuild the C++ source, which we would need to add an additional function to blink the window :smile:

2.) Making the Change

The first step would (probably) be to make the change in the SDL window code. There, it would be simple to get the window reference, and ultimately cause the taskbar to flash.

Perhaps a good name would be Window::Alert ()

You would add it to the lime/ui/Window headers:

https://github.com/openfl/lime/blob/master/project/include/ui/Window.h
https://github.com/openfl/lime/blob/master/project/src/backend/sdl/SDLWindow.h

Then create the method in “SDLWindow.cpp”:

https://github.com/openfl/lime/blob/master/project/src/backend/sdl/SDLWindow.cpp

3.) Adding CFFI on the C++ Side

So that Haxe can call the new Window->Alert (); method, the next step is a CFFI function call that Haxe will be able to use. I would copy and modify an existing function like this one to create a “lime_window_alert” method:

https://github.com/openfl/lime/blob/master/project/src/ExternalInterface.cpp#L1030

Don’t forget to add the “DEFINE_PRIM” call (which makes it visible to Haxe) at the bottom file.

4.) Rebuilding

If that all went well, you can use the rebuild command, as before:

lime rebuild windows

5.) Call it from Haxe

The next (and final) step would be to add an alert () method to the Lime Window class:

https://github.com/openfl/lime/blob/master/lime/ui/Window.hx

If you follow the pattern of the other methods there, you would empty functions in the Flash and HTML5 backend “window” classes, and implement in the native one:

https://github.com/openfl/lime/blob/master/lime/_backend/native/NativeWindow.hx
https://github.com/openfl/lime/blob/master/lime/_backend/flash/FlashWindow.hx
https://github.com/openfl/lime/blob/master/lime/_backend/html5/HTML5Window.hx

The native one would make a CFFI call, using System.load to gain access to the CFFI method you made in C++, earlier. And now Haxe is calling C++ code :slight_smile:

Well I think this alert method is more suitable as an extension since it is really just for desktop platforms and not flash/mobile. If getting the handler through the very first method is not hard, I would go that way, What exactly are the steps to get a local handler?

I just wrote my last response again to make it a bit clearer (I hope!) :smile:

The key is the reference to the SDL window instance. You might be able to get this by using the @:privateAccess code I shared, I’m not sure. Otherwise this is totally doable from the “SDLWindow.cpp” file in Lime 2. If you had it working in Lime 2, I could show you how to do it for legacy as well

Nice article! Thanks for taking your time.

Ahhhh, okay I ll give it a try. Will reply as soon as I get it working in Lime 2, but first I ll need to update the dev versions which I accidentally installed at my user folder lol

Anyways, the privateAccess method seems to be very very convenient, is there a similar way for legacy too? I might at least give it a try.

Legacy doesn’t seem to expose the SDL window reference in Haxe anywhere :confused:

Thats sad… okay then I ll try it. Give me some time… need to dive into c++ :stuck_out_tongue:

Tried using the lime development build. Fails with tons of errors in ApplicationMain.hx and openfl.display.Stage.hx when building an empty project. Any help?

Could you double check and make sure that you are using the latest of both OpenFL and Lime? Also, if you are doing a Lime sample, please update lime-samples as well, as Lime 2.6 has changed some APIs

Thanks. Just updated everything and it was successfully built:P

1 Like

Tried to get the window handle. Lime says window is not a member of SDL_SysWMinfo

        SDL_SysWMinfo info;
	SDL_GetWindowWMInfo(sdlWindow, &info);

	FLASHWINFO fi;
	fi.cbSize = sizeof(FLASHWINFO);
	fi.hwnd = info.info.win.window;
	fi.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
	fi.uCount = count;
	fi.dwTimeout = speed;
	FlashWindowEx(&fi);

nvm I did it like this and it rebuilt successfully. Is this right?

If it compiles and it works, I’m going to guess so :wink:

But yeah, that looks like the idea