| |

VerySource

 Forgot password?
 Register
Search
View: 649|Reply: 1

Cai Niao Question: Why can't the background image be loaded?

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-5 10:20:01
| Show all posts |Read mode
The following is a function added to the dialog's onPaint that loads the background image. How can it not be loaded?
void CLoadPicDlg :: OnPaint ()
{
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);
CPaintDC dc (this); // device context for painting
        CRect rect;
        GetClientRect (&rect); // Get the size of the form
        CDC dcMem;
        dcMem.CreateCompatibleDC (&dc);
        CBitmap bmpBackground;
        bmpBackground.LoadBitmap (IDB_BK); // Load the background image
        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); // This function pastes a bitmap to the dialog box
//// ------------ The following code adds text to the dialog box
       dc.SetBkMode (TRANSPARENT);
       dc.SetTextColor (RGB (0, 0, 255));
       CString str;
       BYTE * pIP = (BYTE *)&m_dwIP;
       str.Format ("% d.% d.% d.% d:% d-% s", pIP [3], pIP [2], pIP [1], pIP [0], m_dwPort, m_strName);
       dc.DrawText (_T (str),&CRect (50, 50, 450, 100), DT_SINGLELINE | DT_CENTER);
}
else
{
CDialog :: OnPaint ();
}
}
Reply

Use magic Report

0

Threads

4

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-26 13:45:01
| Show all posts
Learn, UP
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list