2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ToastNootificationを出すアプリケーションをmingwでコンパイルするのは諦めた話

Last updated at Posted at 2021-02-11

はじめに

Windows 10には通知システムが搭載されており、Toastと呼ばれている。

利用するには

#include <wrl/implements.h>
#include <wrl/event.h>
#include <windows.ui.notifications.h>

あたりのヘッダーが必要になる。

WRLのmingwでのサポート

まず次の2つのヘッダーについてみていく。

#include <wrl/implements.h>
#include <wrl/event.h>

/mingw64/x86_64-w64-mingw32/include/wrlを見てみると

  • wrapper/corewrappers.h
  • client.h
  • internal.h
  • module.h

のみが存在している。つまりこれらのヘッダーはない。

MSYS2 / Thread: [Msys2-users] MSYS2 and Windows Runtime Library
メーリスに2018年の会話が残っていた。つまるところまだ実装されていないということらしい。

要するにCOMなので、実装するにはIDLを書いて、widlでコンパイルしてヘッダーを生成する必要がある。MSが配ってるwrl/event.hを見に行くとそんなに難しくなさそうに見えてwrl/implements.hに依存している。そしてwrl/implements.hを生成させるのは結構これがでかいのでだいぶつらそうではある。

Because 'implements.h' is not available, you have to create one
yourself. MSVC headers usually do not compile verbatim using GCC. It
will require quite a little time and energy to make a header that is
both binary-compatible with the MSVC one and source-compatible with GCC.

どのへんがquite a little time and energyの範疇に収まってるのか疑問だが、まあmingw/wineに関わる人は常人ではないのでこれくらいはその範疇なんだろう、知らんけど。

windows.ui.notifications.h

Toastを使うための必須アイテムであるが、これまたmingwでは提供されていない。つまりお決まりのIDLを書いて(ryの作業が必要になるわけだがここでこんな情報があった。

1495998 - windows.ui.notifications.h is missing on mingw for bug 1155505

Yeah, it won't be quick to fix, I'm afraid. winrt mode extends .idl syntax quite a lot. I implemented some of those features in widl, but it's still not up to the task to generate windows.ui.notifications.h. It will be quite a bit of work.

mozillaの連中が「ちょっと実装しようとしたけど生成には至らん、簡単じゃねーよ」と言ってる時点でまあさじを投げ出したい気持ちでいっぱいになる。

ざっとMSが配ってるIDL見てきたけど、

// Type definition
namespace Windows
{
    namespace UI
    {
        namespace Notifications
        {
            [contract(Windows.Foundation.UniversalApiContract, 3.0)]
            enum AdaptiveNotificationContentKind
            {
                Text = 0
            };

contract属性とかどうすればいいのか検討もつかん。

まとめ

膨大に時間が有り余っていてCOMを扱えるだけの技術力が有り、ろくなドキュメントもないwidlを扱える人がいたらぜひ実装してください。私はさじを投げました。

追記: 2023/12/19

たまたま業務でコードを読解していて知ったのだが、トースト通知をするだけならShell_NotifyIconWで行けるらしい。

[ 372_フォームを使用しないタスクトレイ常駐アプリ ] - Mr.XRAY

windows.ui.notifications.h使おうとしたのはあれかな、UWP向けの記事かなにか見て惑わされたのかもしれない。

・・・とかぼやいていたら社内の有識者からこんな情報が

いつからかバルーンのAPIを呼び出すとトーストで表示されるようになりました。
バルーンに戻した的な話:
https://admx.help/?Category=Windows_10_2016&Policy=Microsoft.Policies.TaskBar2::EnableLegacyBalloonNotifications&Language=ja-jp
https://www.naporitansushi.com/windows11-balloon-notification-enable/

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?