--- nono/util/viewcgrom/viewcgrom.cpp 2026/04/29 17:04:52 1.1.1.2 +++ nono/util/viewcgrom/viewcgrom.cpp 2026/04/29 17:04:55 1.1.1.3 @@ -4,7 +4,7 @@ // Copyright (C) 2012-2019 isaki@NetBSD.org // -#include +#include "wxheader.h" #include #include #include @@ -29,10 +29,6 @@ #define ROUND(x, y) (((x) + (y - 1)) / (y)) #define ROUND8(x) ROUND(x, 8) -/* 独自のイベントタイプ */ -DECLARE_EVENT_TYPE(WXEVT_CREATE, -1); -DEFINE_EVENT_TYPE(WXEVT_CREATE); - class MyFrame; struct ctxmenu_t { @@ -63,7 +59,7 @@ class MyFrame : public wxFrame MyFrame(); private: - void OnCreate(wxCommandEvent& event); + void OnWindowCreate(wxWindowCreateEvent& event); void OnOpen(wxCommandEvent& event); void DoOpenDialog(); void DoOpen(); @@ -193,7 +189,7 @@ BEGIN_EVENT_TABLE(MyFrame, inherited) EVT_MENU(wxID_OPEN, MyFrame::OnOpen) EVT_MENU(wxID_EXIT, MyFrame::OnExit) EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) - EVT_COMMAND(wxID_ANY, WXEVT_CREATE, MyFrame::OnCreate) + EVT_WINDOW_CREATE(MyFrame::OnWindowCreate) END_EVENT_TABLE() // ショートカット用データ @@ -317,14 +313,13 @@ MyFrame::MyFrame() line = -1; DoUpdateAddr(); - /* すぐに OnCreate を呼ぶように仕掛けておく */ - wxCommandEvent event(WXEVT_CREATE); - AddPendingEvent(event); + Connect(wxEVT_CREATE, + wxWindowCreateEventHandler(MyFrame::OnWindowCreate), NULL, this); } -// ウィンドウ作成イベントのつもり +// ウィンドウ作成イベント void -MyFrame::OnCreate(wxCommandEvent& event) +MyFrame::OnWindowCreate(wxWindowCreateEvent& event) { if (!::wxGetApp().filename.IsEmpty()) { /* 引数でファイルが指定されていればそれを使う */ @@ -333,6 +328,10 @@ MyFrame::OnCreate(wxCommandEvent& event) /* ファイルオープン */ DoOpen(); } + + // 一度処理したら抜いておく (こうしないと複数回呼ばれる) + Disconnect(wxEVT_CREATE, + wxWindowCreateEventHandler(MyFrame::OnWindowCreate)); } // オープン