编程路上的小丑

用心对你好

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  4 随笔 :: 0 文章 :: 0 评论 :: 0 Trackbacks

1>    首先导入资源图片bmp格式的

2>    然后相应该对话框类(CERPDlg)的函数OnPaint,在其中写入:

void CERPDlg::OnPaint()

{

       //CPaintDC dc(this); // device context for painting

       if (IsIconic())

    {

        CPaintDC dc(this); // device context for painting

             

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

             

        // Center icon in client rectangle

        int cxIcon = GetSystemMetrics(SM_CXICON);

        int cyIcon = GetSystemMetrics(SM_CYICON);

        CRect rect;

        GetClientRect(&rect);

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

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

             

        // Draw the icon

        dc.DrawIcon(x, y, m_hIcon);

    }

    else

    {

        //CDialog::OnPaint();

        CPaintDC dc(this);

        CRect rect;

        GetClientRect( &rect );

        CDC dcMem;

        dcMem.CreateCompatibleDC( &dc );

        CBitmap bmpBackground;

        bmpBackground.LoadBitmap( IDB_BITMAP1);//此处的要和导入进来的ID一致

        BITMAP bitmap;

        bmpBackground.GetBitmap( &bitmap );

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

        dc.StretchBlt( 0, 0, rect.Width(), rect.Height(), &dcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, SRCCOPY );

    }

}

其中else里面的代码是自己写的,其他地方的是自己生成的。

posted on 2012-09-18 21:54 用心对你好 阅读(292) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理