void CEmailSettingDlg::OnBnClickedOk()
{
UpdateData(1);
CEmailManagementDlg *pdlg = (CEmailManagementDlg*)AfxGetApp()->GetMainWnd();
if (m_str_BackGround == "蒲公英")
m_str_BackGround = "1";
if (m_str_BackGround == "書")
m_str_BackGround = "2";
if (m_str_BackGround == "天空")
m_str_BackGround = "3";
if (m_str_BackGround == "秦時明月")
m_str_BackGround = "4";
//刷新顯示新的背景
CString temp = pdlg->m_backGround; //暫存原背景圖數據
pdlg->m_backGround = m_str_BackGround;
** ::SendMessage(pdlg->m_hWnd, WM_PAINT, 0, 0);**
//UpdateWindow();
pdlg->m_backGround = temp;
//如果設置沒變,則不需要打開數據庫(出於效率考慮)
if (!(m_str_AutoReply == pdlg->m_auto_reply && m_str_BackGround == pdlg->m_backGround))
{
CString temp;
temp.Format("update user_psw_tab set auto_reply = '%s', back_ground = %d where user_name = '%s'", m_str_AutoReply, atoi(m_str_BackGround), pdlg->m_str_UserName);
TRACE(temp);
pdlg->m_db.ExecuteSQL(temp);
AfxMessageBox("更新成功!");
}
CDialogEx::OnOK();
}
void CEmailManagementDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // 用於繪制的設備上下文
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
// 使圖標在工作區矩形中居中
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;
// 繪制圖標
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // 用於繪制的設備上下文
CRect rc;
GetClientRect(&rc);
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap bmpBackground;
switch (atoi(m_backGround))
{
case 1:
bmpBackground.LoadBitmap(IDB_BITMAP_FLOWER);
break;
case 2:
bmpBackground.LoadBitmap(IDB_BITMAP_BOOK);
break;
case 3:
bmpBackground.LoadBitmap(IDB_BITMAP_SKY);
break;
case 4:
bmpBackground.LoadBitmap(IDB_BITMAP_QIN);
break;
}
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);
//CDialogEx::OnPaint(); //這句需要去掉
}
}
我想實現實時切換 CEmailManagementDlg的背景
CEmailSettingDlg設置背景數據,點擊確定後去刷新CEmailManagementDlg的背景
但是調試發現盡管SendMessage消息以後進入了CEmailManagementDlg的OnPaint函數,但是語句執行完以後並沒有改變背景,請問我哪裡錯了嗎。。
感謝各位幫忙 問題已經找到了。。。因為以下對控件變量之間改變值之後沒有UpdateData(0),所以實際上控件變量的值並沒有改變。。所以後面判斷時出問題了。。
if (m_str_BackGround == "蒲公英")
m_str_BackGround = "1";
if (m_str_BackGround == "書")
m_str_BackGround = "2";
if (m_str_BackGround == "天空")
m_str_BackGround = "3";
if (m_str_BackGround == "秦時明月")
m_str_BackGround = "4";