カラーダイアログで、基本色(48色)のみのダイアログを表示したいのですが、わかりません。
CColorDialogの場合、作成した色、作成ボタンを非表示にしたいのですが、
作成ボタン(CColorDialog.m_cc.Flags)の無効までは出来ましたが、
ここから進んでいません。
どうか宜しくお願いします。
環境は、WindowsXP(SP2) VC++6.0 MFC です。
とりあえず、非表示であれば、CColorDialogを派生したクラスを作り
WM_INITDIALOGで
this->GetDlgItem(0x02cf)->ShowWindow(SW_HIDE);
とすれば消えるようです。
だた、0x02cfはSpy++で調べた値なので微妙です。
(DLGS.Hにあるかと思ったけどなかった)
ほかのコントロールもおそらく消せるでしょう。
消した後ダイアログのサイズ変更やOKボタン等の移動が必要でしょうね。
適当にやってみた。
MyColorDialog.cpp(抜粋)
CMyColorDialog::CMyColorDialog(COLORREF clrInit, DWORD dwFlags, CWnd* pParentWnd) :
CColorDialog(clrInit, dwFlags, pParentWnd)
{
this->m_cc.Flags |= CC_PREVENTFULLOPEN;
}
BOOL CMyColorDialog::OnInitDialog()
{
CColorDialog::OnInitDialog();
// TODO: この位置に初期化の補足処理を追加してください
HWND hStatic;
CRect rctStatic, rctDialog, rctButton;
// 基本色のStaticコントロール
hStatic = ::FindWindowEx(this->GetSafeHwnd(), NULL, _T("Static"), NULL);
// 基本色選択領域のStaticコントロール
hStatic = ::FindWindowEx(this->GetSafeHwnd(), hStatic, _T("Static"), NULL);
// 作成した色のStaticコントロール
hStatic = ::FindWindowEx(this->GetSafeHwnd(), hStatic, _T("Static"), NULL);
// 非表示にする
::ShowWindow(hStatic, SW_HIDE);
// 作成した色選択領域のStaticコントロール
hStatic = ::FindWindowEx(this->GetSafeHwnd(), hStatic, _T("Static"), NULL);
// クライアント座標を取得
::GetWindowRect(hStatic, rctStatic);
this->ScreenToClient(rctStatic);
// (Tabキーで)フォーカスがいかないように
::EnableWindow(hStatic, FALSE);
// 以下 「作成した色選択領域のStatic」 を基点にサイズ/位置を変更
// ダイアログのサイズを変更
this->GetClientRect(rctDialog);
const int diff = rctDialog.bottom - rctStatic.top;
this->CalcWindowRect(rctDialog, CWnd::adjustOutside);
this->SetWindowPos(NULL, 0, 0, rctDialog.Width(), rctDialog.Height() - diff, SWP_NOMOVE | SWP_NOZORDER);
// OKボタンの位置を変更
CWnd* pButton;
pButton = this->GetDlgItem(IDOK);
pButton->GetWindowRect(rctButton);
this->ScreenToClient(rctButton);
rctButton.OffsetRect(0, -diff);
pButton->MoveWindow(rctButton);
// キャンセルボタンの位置を変更
pButton = this->GetDlgItem(IDCANCEL);
pButton->GetWindowRect(rctButton);
this->ScreenToClient(rctButton);
rctButton.OffsetRect(0, -diff);
pButton->MoveWindow(rctButton);
return TRUE; // コントロールにフォーカスを設定しないとき、戻り値は TRUE となります
// 例外: OCX プロパティ ページの戻り値は FALSE となります
}
Blueさん、ありがとうございます。
これを元にやってみます。
ツイート | ![]() |