2007-03-27 17:47:10 +00:00
|
|
|
/*
|
|
|
|
* CiderPress
|
|
|
|
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
|
|
|
|
* See the file LICENSE for distribution terms.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Code for my buttons with bitmaps.
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "MyBitmapButton.h"
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN_MESSAGE_MAP(MyBitmapButton, CButton)
|
2014-11-04 00:26:53 +00:00
|
|
|
ON_WM_SYSCOLORCHANGE()
|
2007-03-27 17:47:10 +00:00
|
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
|
|
|
2014-11-25 22:34:14 +00:00
|
|
|
BOOL MyBitmapButton::ReplaceDlgCtrl(CDialog* pDialog, int buttonID)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
CWnd* pWnd = pDialog->GetDlgItem(buttonID);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (pWnd == NULL)
|
2014-11-04 00:26:53 +00:00
|
|
|
return FALSE;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
|
|
|
#if 0
|
2014-11-04 00:26:53 +00:00
|
|
|
DWORD styles = pWnd->GetStyle();
|
|
|
|
//DWORD stylesEx = pWnd->GetExStyle();
|
|
|
|
CString caption;
|
|
|
|
CRect rect;
|
|
|
|
pWnd->GetWindowText(caption);
|
|
|
|
pWnd->GetWindowRect(&rect);
|
|
|
|
pDialog->ScreenToClient(&rect);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
// pWnd->DestroyWindow();
|
|
|
|
if (Create(caption, styles, rect, pDialog, buttonID) == FALSE) {
|
2014-11-18 21:05:15 +00:00
|
|
|
LOGI("ERROR: unable to replace dialog ctrl (buttonID=%d)",
|
2014-11-04 00:26:53 +00:00
|
|
|
buttonID);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
#endif
|
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
/* latch on to their window handle */
|
|
|
|
Attach(pWnd->m_hWnd);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
return TRUE;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 22:34:14 +00:00
|
|
|
BOOL MyBitmapButton::SetBitmapID(int id)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
fBitmapID = id;
|
|
|
|
UpdateBitmap();
|
|
|
|
return TRUE;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 22:34:14 +00:00
|
|
|
void MyBitmapButton::UpdateBitmap(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-04 00:26:53 +00:00
|
|
|
HBITMAP hNewBits;
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
if (fBitmapID == -1) {
|
2014-11-25 22:34:14 +00:00
|
|
|
LOGE("ERROR: UpdateBitmap called before bitmap set");
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
hNewBits = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(),
|
|
|
|
MAKEINTRESOURCE(fBitmapID), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
|
2014-11-18 05:13:13 +00:00
|
|
|
if (hNewBits == NULL) {
|
2014-11-25 22:34:14 +00:00
|
|
|
LOGW("WARNING: LoadImage failed (bitID=%d)", fBitmapID);
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(false);
|
|
|
|
return;
|
|
|
|
}
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
ASSERT(GetBitmap() == fhBitmap);
|
2007-03-27 17:47:10 +00:00
|
|
|
|
2014-11-04 00:26:53 +00:00
|
|
|
::DeleteObject(SetBitmap(hNewBits));
|
|
|
|
fhBitmap = hNewBits;
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|
|
|
|
|
2014-11-25 22:34:14 +00:00
|
|
|
void MyBitmapButton::OnSysColorChange(void)
|
2007-03-27 17:47:10 +00:00
|
|
|
{
|
2014-11-19 22:54:24 +00:00
|
|
|
LOGD("MyBitmapButton 0x%p tracking color change", this);
|
2014-11-04 00:26:53 +00:00
|
|
|
UpdateBitmap();
|
2007-03-27 17:47:10 +00:00
|
|
|
}
|