掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
スタティックの背景について (ID:61857)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
OS:WindowsXP Pro SP2 VS.NET 2003 CDialogクラスで背景をグラデーション描画し、配置したスタティックの 文字はフォントを指定しています。グラデーションもテキストも 表示されるのですが、背景が透過しません。スタティックのプロパティを 変えたり、OnCtlColorを使ったりしましたがうまくいきません。 IDC_xxx_STATICのプロパティSimpleをTRUEにしています。 フォントを設定しなければ背景が透過するのですが... ご指導、よろしくお願いします。 以下、ソースです。 xxx.h UINT nID; CFont m_f; BOOL CxxxDlg::OnInitDialog() { CDialog::OnInitDialog(); setFont(); return TRUE; } HBRUSH CxxxDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); nID = pWnd->GetDlgCtrlID(); // IDの取得 switch (nCtlColor) { case CTLCOLOR_STATIC: pDC->SetBkMode(TRANSPARENT); // 透過モード if(nID == IDC_xxx_STATIC) { pDC->SetTextColor(RGB(255, 0, 0)); } } return hbr; } void CxxxDlg::OnPaint() { CPaintDC dc(this); // device context for painting CRect rect; GetClientRect(&rect); int r, g, b; r = 0; g = 0; b = 255; // 青色 int TopHeight = (rect.bottom - rect.top) / 4; // 純色とする部分 int Zone = TopHeight / 10; // 色を変化させる単位 int OrgBottom = rect.bottom; int OrgWidth = rect.right - rect.left; int OrgHeight = OrgBottom - rect.top; rect.bottom = rect.top + TopHeight; CBrush bluBrush; bluBrush.CreateSolidBrush(RGB(r,g, b)); dc.FillRect(&rect, &bluBrush); rect.top = rect.bottom; rect.bottom = rect.top + Zone; b -= 8; // 青色の濃度を変える while (rect.bottom < OrgBottom && b > 16) { bluBrush.DeleteObject(); bluBrush.CreateSolidBrush( RGB(r, g, b)); dc.FillRect(&rect, &bluBrush); // 矩形の塗り潰し rect.top = rect.bottom; rect.bottom = rect.top + Zone; b -= 8; } bluBrush.DeleteObject(); bluBrush.CreateSolidBrush(RGB(r, g, b)); rect.bottom = OrgBottom; dc.FillRect(&rect, &bluBrush); // 残りの矩形を塗り潰す bluBrush.DeleteObject(); } int CxxxDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CDialog::OnCreate(lpCreateStruct) == -1) return -1; this->ShowWindow(SW_SHOW); return 0; } void CxxxDlg::setFont() { CDC* pDC = GetDC(); CString f = _T("MS UI Gothic"); m_f.CreateFont(28, 0, 0, 0, FW_NORMAL, // 太さ FALSE, // イタリック体 FALSE, // アンダーライン FALSE, // 取り消し線 DEFAULT_CHARSET, // 文字セット OUT_DEFAULT_PRECIS, // 出力精度 CLIP_DEFAULT_PRECIS, // クリッピング精度 PROOF_QUALITY, // 出力品質 DEFAULT_PITCH | FF_DONTCARE, // ピッチとフォント・ファミリ f // フォントの書体 ); GetDlgItem(IDC_xxx_STATIC)->SetFont(&m_f); ReleaseDC(pDC); }
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.