0
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 5 years have passed since last update.

c++ builder XE4, 10.2 Tokyo > TForm > 最初のフォームを切り替える > onShow / window message

Last updated at Posted at 2015-09-04
動作環境
C++ Builder XE4
Rad Studio 10.2 Tokyo Update 2 (追記: 2017/12/26)

やりたいこと

  • アプリ実行時に、最初のフォームを実行時引数に基づき変更する

とりあえず「実行時引数に基づき」は後で実装するとして「フォームを変更する」だけやってみる。

try1 (onShowで処理)

OnShowに以下のコードを実装してみた。

void __fastcall TForm1::FormShow(TObject *Sender)
{
	Form2->ShowModal();
	this->Close();
}

やっているのはFormShowで別のフォームを表示しておき、そのフォーム(Form2)がクローズされた時にForm1を閉じる。

上記の問題点は、タスクバーにアプリケーションアイコンが表示されないこと


try2 (window messageで処理)

以下のようにフォームが表示された直後に処理を実装する方法を使うことになるのだろうか。
http://www.din.or.jp/~egawa-n/delphi/tips/form_showed.html

上記をもとに、以下を実装してみた。

Unit1.h
//---------------------------------------------------------------------------

# ifndef Unit1H
# define Unit1H
# include <System.Classes.hpp>
# include <Vcl.Controls.hpp>
# include <Vcl.StdCtrls.hpp>
# include <Vcl.Forms.hpp>
# include "Unit2.h"
class TForm1 : public TForm
{
__published:
	void __fastcall FormShow(TObject *Sender);
private:
	void __fastcall funcAfterOnShow(TMessage msg);
	static const int WM_SHOWED = WM_USER + 1;

public:
	__fastcall TForm1(TComponent* Owner);

BEGIN_MESSAGE_MAP
	MESSAGE_HANDLER(WM_SHOWED, TMessage, funcAfterOnShow);
END_MESSAGE_MAP(TForm)

};
extern PACKAGE TForm1 *Form1;
# endif
Unit1.cpp
//---------------------------------------------------------------------------

# include <vcl.h>
# pragma hdrstop

# include "Unit1.h"
//---------------------------------------------------------------------------
# pragma package(smart_init)
# pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow(TObject *Sender)
{

	PostMessage(Handle, WM_SHOWED, 0, 0);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::funcAfterOnShow(TMessage msg)
{
	this->Hide();
	Form2->ShowModal();
	this->Close();
}
//---------------------------------------------------------------------------

こちらでも、タスクバーのアイコンが消えてしまった。

Form1の表示を消そうと this->Hide()をすることにより、アイコンも消えてしまうようだ。

this->Hide()をコメントアウトにすることで、Form1が表示されたままではあるが、タスクバーにアイコンが表示されるようになった。

0
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
0
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?