実際に動かして動作を確認する
書き換えたwinmain.cをコンパイルして実行する。
起動したらすぐに終了しても大丈夫だ。それだけで十分な数のメッセージが取得できている。ここでそれぞれ取得されたログデータは次のとおり。
長くなるが、比較を行いたいのでそれぞれ記録されたデータの全容を記載しておく。
log1.txtのサンプル
message: 799
message: 49336
message: 512
message: 96
message: 15
message: 96
message: 49246
message: 49246
message: 96
message: 275
message: 275
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 161
message: 799
message: 49336
message: 15
message: 96
message: 96
message: 96
message: 49246
message: 49246
message: 96
message: 96
message: 96
message: 96
message: 257
message: 96
message: 275
message: 275
message: 96
message: 96
message: 275
message: 275
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 160
message: 160
message: 160
message: 674
message: 160
message: 160
message: 160
message: 160
message: 160
message: 512
message: 674
message: 512
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 161
message: 160
message: 160
message: 512
message: 674
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 96
message: 96
message: 275
message: 275
message: 160
message: 512
message: 674
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 513
message: 96
message: 96
message: 49246
message: 49246
message: 512
message: 96
message: 275
message: 514
message: 275
message: 96
message: 256
message: 256
message: 96
message: 512
message: 512
message: 96
message: 257
message: 96
message: 96
message: 257
message: 96
message: 96
message: 257
message: 96
message: 512
message: 96
message: 96
message: 275
message: 275
message: 96
message: 96
message: 49246
message: 96
message: 49246
message: 96
message: 512
message: 275
message: 512
message: 512
message: 275
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 96
message: 96
message: 275
message: 275
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 160
message: 160
message: 160
message: 674
message: 49681
message: 49681
message: 49681
message: 160
message: 512
message: 674
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 513
message: 96
message: 96
message: 49246
message: 49246
message: 512
message: 96
message: 512
message: 275
message: 514
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 275
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 512
message: 160
message: 512
message: 674
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 160
message: 161
log2.txtのサンプル
message: 36
message: 129
message: 131
message: 1
message: 24
message: 70
message: 70
message: 28
message: 134
message: 127
message: 127
message: 127
message: 6
message: 641
message: 642
message: 7
message: 133
message: 20
message: 71
message: 5
message: 3
message: 127
message: 799
message: 127
message: 49336
message: 36
message: 132
message: 32
message: 512
message: 127
message: 15
message: 49230
message: 648
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 161
message: 533
message: 174
message: 274
message: 16
message: 144
message: 70
message: 71
message: 134
message: 6
message: 28
message: 8
message: 641
message: 642
message: 2
message: 130
message: 36
message: 129
message: 131
message: 1
message: 24
message: 70
message: 70
message: 28
message: 134
message: 127
message: 127
message: 127
message: 6
message: 641
message: 642
message: 7
message: 133
message: 20
message: 71
message: 5
message: 3
message: 127
message: 799
message: 49336
message: 36
message: 127
message: 15
message: 127
message: 49230
message: 648
message: 257
message: 134
message: 6
message: 28
message: 8
message: 641
message: 642
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 32
message: 160
message: 32
message: 160
message: 132
message: 32
message: 174
message: 160
message: 674
message: 132
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 132
message: 32
message: 512
message: 674
message: 132
message: 32
message: 512
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 33
message: 32
message: 161
message: 70
message: 71
message: 28
message: 134
message: 6
message: 641
message: 642
message: 7
message: 274
message: 533
message: 36
message: 561
message: 674
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 534
message: 70
message: 36
message: 71
message: 3
message: 533
message: 70
message: 562
message: 32
message: 160
message: 32
message: 160
message: 132
message: 32
message: 512
message: 674
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 134
message: 6
message: 28
message: 8
message: 641
message: 642
message: 132
message: 32
message: 160
message: 132
message: 32
message: 512
message: 674
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 33
message: 70
message: 71
message: 28
message: 134
message: 6
message: 641
message: 642
message: 7
message: 32
message: 513
message: 132
message: 32
message: 512
message: 132
message: 32
message: 514
message: 256
message: 256
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 257
message: 257
message: 257
message: 132
message: 32
message: 512
message: 134
message: 6
message: 28
message: 8
message: 641
message: 642
message: 70
message: 28
message: 134
message: 6
message: 641
message: 642
message: 7
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 134
message: 6
message: 28
message: 8
message: 641
message: 642
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 160
message: 132
message: 32
message: 160
message: 132
message: 32
message: 160
message: 674
message: 49681
message: 132
message: 32
message: 160
message: 132
message: 32
message: 512
message: 674
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 33
message: 70
message: 71
message: 28
message: 134
message: 6
message: 641
message: 642
message: 7
message: 32
message: 513
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 514
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 512
message: 132
message: 32
message: 160
message: 132
message: 32
message: 512
message: 674
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 160
message: 32
message: 161
message: 533
message: 274
message: 16
message: 144
message: 70
message: 71
message: 134
message: 6
message: 28
message: 8
message: 641
message: 642
message: 2
message: 130
ここからわかるように、メッセージループからウィンドウプロシージャが呼ばれるというよりも、メッセージループもウィンドウプロシージャもそれぞれの仕組みに従ってイベントがファイアしている動きをしていることがわかる。似たような動きに見えるが、実際には異なるものとして扱った方が適切ということになりそうだ。
実際に動かして理解していくことが大切
Windows APIで提供されている構造体や関数は、Microsoft Docsにドキュメントがまとまっている。サンプルコードも多く掲載されているので、Windows APIの全体像は比較的つかみやすいだろう。
しかしながら、実際にどのように動作するかは自分で作って実際に試してみるのがお薦めだ。ドキュメントを読んだだけの理解では、自分の都合がよいように解釈していることがある。往々にして人間は自分にとって都合がよいように理解しがちなのだ。こんな感じで自分で動きを追ってみると、APIの全体像や構造がよく見えてくる。ぜひとも実際に試して動きを追ってみてもらえればと思う。
参考
- Module 1. Your First Windows Program - Win32 apps | Microsoft Docs
- WNDCLASSA (winuser.h) - Win32 apps | Microsoft Docs
- Window Class Styles (Winuser.h) - Win32 apps | Microsoft Docs
- LoadCursorA function (winuser.h) - Win32 apps | Microsoft Docs
- GetSysColor function (winuser.h) - Win32 apps | Microsoft Docs
- Window Styles (Winuser.h) - Win32 apps | Microsoft Docs