Date
Apr. 18th, 2024
 
2024年 3月 10日

Post: MFC: 对话框添加背景图片

MFC: 对话框添加背景图片

Published 12:06 Jun 03, 2010.

Created by @ezra. Categorized in #Programming, and tagged as #Windows.

Source format: Markdown

Table of Content

有两种实现方法,分别是:

  • 插入一个 Bitmap 的资源图片,假设资源名称为 IDC_BITMAP1
  • CXXXDialog::OnPaint() 中实现:
void CMyDialogDlg::OnPaint() {

    if (IsIconic()) {

        CPaintDC dc(this); // 用于绘制的设备上下文

        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

        // 使图标在工作区矩形中居中

        int cxIcon = GetSystemMetrics(℠_CXICON);

        int cyIcon = GetSystemMetrics(℠_CYICON);

        CRect rect;

        GetClientRect(&rect);

        int x = (rect.Width() - cxIcon + 1) / 2;

        int y = (rect.Height() - cyIcon + 1) / 2;

        // 绘制图标

        dc.DrawIcon(x, y, m_hIcon);

    } else {

        //

        // 给窗体添加背景

        //

        CPaintDC dc(this);

        CRect rc;

        GetClientRect(&rc);

        CDC dcMem;

        dcMem.CreateCompatibleDC(&dc);

        CBitmap bmpBackground;

        bmpBackground.LoadBitmap(IDB_BITMAP1);

        BITMAP bitmap;

        bmpBackground.GetBitmap(&bitmap);

        CBitmap* pbmpPri = dcMem.SelectObject(&bmpBackground);

        dc.StretchBlt(0,0,rc.Width(), rc.Height(), &dcMem,0,0,bitmap.bmWidth, bitmap.bmHeight, SRCCOPY);
    }
}
Pinned Message
HOTODOGO
I'm looking for a SOFTWARE PROJECT DIRECTOR / SOFTWARE R&D DIRECTOR position in a fresh and dynamic company. I would like to gain the right experience and extend my skills while working in great teams and big projects.
Feel free to contact me.
For more information, please view online résumé or download PDF
本人正在寻求任职 软件项目经理 / 软件技术经理 岗位的机会, 希望加⼊某个新鲜⽽充满活⼒的公司。
如有意向请随时 与我联系
更多信息请 查阅在线简历下载 PDF