📄 skindialog.cpp
字号:
}
}
if(!strDown.IsEmpty())
{
strDown = m_SkinPath + strDown;
pDownBitmap = new CBitmap;
if(!LoadImageFile(strDown, pDownBitmap, size) )
{
delete pDownBitmap;
pDownBitmap = NULL;
}
}
if(!strDisable.IsEmpty())
{
strDisable = m_SkinPath + strDisable;
pDisableBitmap = new CBitmap;
if(!LoadImageFile(strDisable, pDisableBitmap, size) )
{
delete pDisableBitmap;
pDisableBitmap = NULL;
}
}
CBitmapBtn* pBmpBtn;
CString strWinText;
for(int i=0; i<nCount; i++)
{
pBmpBtn = (CBitmapBtn* )GetDlgItem(pBtnIDArray->GetAt(i));
if(pBmpBtn!=NULL)
{
pBmpBtn->GetWindowText(strWinText);
SetButton(pBmpBtn, strWinText, pNormalBitmap, pOverBitmap, pDownBitmap, pDisableBitmap);
}
}
if(pNormalBitmap!=NULL)
delete pNormalBitmap;
if(pOverBitmap!=NULL)
delete pOverBitmap;
if(pDownBitmap!=NULL)
delete pDownBitmap;
if(pDisableBitmap!=NULL)
delete pDisableBitmap;
}
void CSkinDialog::SetButton(CBitmapBtn *pBtn, CString strKey, CBitmap *pNormal, CBitmap *pOver, CBitmap *pDown, CBitmap *pDisable)
{
CString strInfo, strDefault;
strInfo = m_SkinIniFile.ReadString("BUTTONINFO", strKey, strDefault);
if(strInfo.IsEmpty())
{
pBtn->SetNormalState();
return;
}
int nLen = strInfo.GetLength();
int nLeft;
CRect rect;
nLeft = strInfo.Find(',');
strDefault = strInfo.Left(nLeft);
rect.left = atoi(strDefault);
nLen-= (nLeft+1);
strInfo = strInfo.Right(nLen);
nLeft = strInfo.Find(',');
strDefault = strInfo.Left(nLeft);
rect.top = atoi(strDefault);
nLen-= (nLeft+1);
strInfo = strInfo.Right(nLen);
nLeft = strInfo.Find(',');
strDefault = strInfo.Left(nLeft);
rect.right = atoi(strDefault);
nLen-= (nLeft+1);
strInfo = strInfo.Right(nLen);
nLeft = strInfo.Find(',');
strDefault = strInfo.Left(nLeft);
rect.bottom = atoi(strDefault);
nLen-= (nLeft+1);
strInfo = strInfo.Right(nLen);
CString strTip;
nLeft = strInfo.Find(',');
strTip = strInfo.Left(nLeft);
nLen-= (nLeft+1);
strInfo = strInfo.Right(nLen);
BOOL blChecked;
blChecked = (strInfo ==1) ? 1:0;
CDC* pDC = GetDC();
HBITMAP hNormalBmp, hOverBmp, hDownBmp, hDisableBmp;
hNormalBmp = CopyFromBitmap(pDC, rect, pNormal);
hOverBmp = CopyFromBitmap(pDC, rect, pOver);
hDownBmp = CopyFromBitmap(pDC, rect, pDown);
hDisableBmp = CopyFromBitmap(pDC, rect, pDisable);
pBtn->SetOwnerDrawState();
pBtn->SetBitmap(hNormalBmp, hOverBmp, hDownBmp,hDisableBmp);
ReleaseDC(pDC);
pBtn->MoveWindow(&rect);
pBtn->SetTooltipText(&strTip);
}
HBITMAP CSkinDialog::CopyFromBitmap(CDC* pDC, CRect& rect, CBitmap* pBitmap)
{
HBITMAP hBitmap = NULL;
if(pBitmap==NULL)
return hBitmap;
CBitmap* pNewBitmap = new CBitmap;
pNewBitmap->CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
CDC* pSrcDC = new CDC;
pSrcDC->CreateCompatibleDC(pDC);
pSrcDC->SelectObject(pBitmap);
CDC* pDesDC = new CDC;
pDesDC->CreateCompatibleDC(pDC);
pDesDC->SelectObject(pNewBitmap);
pDesDC->BitBlt(0,0,rect.Width(), rect.Height(),
pSrcDC, rect.left, rect.top, SRCCOPY);
pSrcDC->DeleteDC();
delete pSrcDC;
pDesDC->DeleteDC();
delete pDesDC;
hBitmap =(HBITMAP)pNewBitmap->Detach();
delete pNewBitmap;
return hBitmap;
}
void CSkinDialog::GetBkColorValue(COLORREF &crTransparent, COLORREF &crArrange)
{
int nLen;
int nLeft;
CString strDefault, strColor;
BYTE rgb[3];
strColor = m_SkinIniFile.ReadString("SCREEN", "TransparentColor", strDefault);
if(!strColor.IsEmpty())
{
nLen = strColor.GetLength();
nLeft = strColor.Find(',');
strDefault = strColor.Left(nLeft);
nLen-= (nLeft+1);
strColor = strColor.Right(nLen);
rgb[0] =(BYTE)atoi(strDefault);
nLeft = strColor.Find(',');
strDefault = strColor.Left(nLeft);
nLen-= (nLeft+1);
strColor = strColor.Right(nLen);
rgb[1] =(BYTE)atoi(strDefault);
rgb[2] =(BYTE)atoi(strColor);
crTransparent = RGB(rgb[0], rgb[1], rgb[2]);
}
strDefault.Empty();
strColor.Empty();
strColor = m_SkinIniFile.ReadString("SCREEN", "ArrangeColor", strDefault);
if(!strColor.IsEmpty())
{
nLen = strColor.GetLength();
nLeft = strColor.Find(',');
strDefault = strColor.Left(nLeft);
nLen-= (nLeft+1);
strColor = strColor.Right(nLen);
rgb[0] =(BYTE)atoi(strDefault);
nLeft = strColor.Find(',');
strDefault = strColor.Left(nLeft);
nLen-= (nLeft+1);
strColor = strColor.Right(nLen);
rgb[1] =(BYTE)atoi(strDefault);
rgb[2] =(BYTE)atoi(strColor);
crArrange = RGB(rgb[0], rgb[1], rgb[2]);
}
}
void CSkinDialog::LoadCtrlPosition()
{
CRect rect;
CString strKey,strDefault,strValue;
int nCount = pCtrlIDArray->GetSize();
for(int i=0; i<nCount; i++)
{
strKey.Format("%d",pCtrlIDArray->GetAt(i));
if(!strKey.IsEmpty())
{
strValue = m_SkinIniFile.ReadString("CTRLPOSITION", strKey, strDefault);
rect = GetRect(strValue);
CWnd* pWnd = GetDlgItem(pCtrlIDArray->GetAt(i));
if(pWnd !=NULL)
pWnd->MoveWindow(&rect);
}
}
}
CRect CSkinDialog::GetRect(CString strInfo)
{
CRect rect;
if(strInfo.IsEmpty())
{
rect.SetRect(0,0,0,0);
return rect;
}
CString strDefault;
int nLen = strInfo.GetLength();
int nLeft;
nLeft = strInfo.Find(',');
strDefault = strInfo.Left(nLeft);
rect.left = atoi(strDefault);
nLen-= (nLeft+1);
strInfo = strInfo.Right(nLen);
nLeft = strInfo.Find(',');
strDefault = strInfo.Left(nLeft);
rect.top = atoi(strDefault);
nLen-= (nLeft+1);
strInfo = strInfo.Right(nLen);
nLeft = strInfo.Find(',');
strDefault = strInfo.Left(nLeft);
rect.right = atoi(strDefault);
nLen-= (nLeft+1);
strInfo = strInfo.Right(nLen);
rect.bottom = atoi(strInfo);
return rect;
}
void CSkinDialog::OnExit()
{
SendMessage(WM_CLOSE,0,0);
}
void CSkinDialog::OnAbout()
{
//CAboutDialog dlg(this);
//dlg.DoModal();
CAboutDialog* pDlg;
pDlg = new CAboutDialog;
pDlg->Create(CAboutDialog::IDD,this);
DWORD ver = GetVersion();
ver &= 0x80000000;
if(ver != 0)
{
POINT pt;
GetCursorPos(&pt);
int width, height,w,h;
CRect rect;
pDlg->GetWindowRect(&rect);
width = rect.Width();
height= rect.Height();
rect.SetRect(0,0,0,0);
pDlg->MoveWindow(&rect);
pDlg->ShowWindow(SW_SHOW);
for(int i=0; i<100; i+=30)
{
w = (width*i)/100;
rect.left = pt.x - w/2;
rect.right= pt.x + (w-w/2);
h =(height*i)/100;
rect.top = pt.y - h/2;
rect.bottom = pt.y + (h-h/2);
pDlg->MoveWindow(&rect);
pDlg->UpdateWindow();
}
w = width;
rect.left = pt.x - w/2;
rect.right= pt.x + (w-w/2);
h =height;
rect.top = pt.y - h/2;
rect.bottom = pt.y + (h-h/2);
pDlg->MoveWindow(&rect);
pDlg->UpdateWindow();
}
else
{
POINT pt;
GetCursorPos(&pt);
int w,h;
CRect rect;
pDlg->GetWindowRect(&rect);
w = rect.Width();
h= rect.Height();
rect.left = pt.x - w/2;
rect.right= pt.x + (w-w/2);
rect.top = pt.y - h/2;
rect.bottom = pt.y + (h-h/2);
pDlg->MoveWindow(&rect);
HWND hWnd = pDlg->GetSafeHwnd();
HMODULE hModule =GetModuleHandle("User32.DLL");
if(hModule == NULL)
return;
typedef BOOL (WINAPI* SETLAYEREDWND)( HWND, COLORREF, BYTE, DWORD);
SETLAYEREDWND SetLayeredWindowPtr = NULL;
SetLayeredWindowPtr = (SETLAYEREDWND)GetProcAddress(hModule, "SetLayeredWindowAttributes");
if(SetLayeredWindowPtr)
{
LONG lStyle = GetWindowLong(hWnd, GWL_EXSTYLE) | 0x00080000;
SetWindowLong( hWnd, GWL_EXSTYLE, lStyle);
for(int nTQ=0; nTQ<100; nTQ++)
{
SetLayeredWindowPtr( hWnd,
0,
BYTE((255 * nTQ) / 100),
2);
if(nTQ==0)
pDlg->ShowWindow(SW_SHOW);
pDlg->UpdateWindow();
Sleep(15);
}
}
}
}
BOOL CAboutDialog::OnInitDialog()
{
CFont *pFont;
pFont = CFont::FromHandle((HFONT)GetStockObject(DEFAULT_GUI_FONT));
GetDlgItem(IDC_ABOUT_EDIT)->SetFont(pFont);
pFont->Detach();
CDialog::OnInitDialog();
CIniFile* pIniFile = ((CSkinDialog *)GetParent())->GetIniFile();
if(pIniFile==NULL)
return TRUE;
CString strDefault, strValue,strTemp;
strValue = pIniFile->ReadString("STRINGTABLE", "About_Static", strDefault);
GetDlgItem(IDC_ABOUT_STATIC)->SetWindowText(strValue);
strTemp = pIniFile->ReadString("STRINGTABLE", "About_Content", strDefault);
strValue = strTemp;
strTemp = pIniFile->ReadString("STRINGTABLE", "About_Content1", strDefault);
strValue+=strTemp;
GetDlgItem(IDC_ABOUT_EDIT)->SetWindowText(strValue);
return TRUE;
}
CIniFile* CSkinDialog::GetIniFile()
{
if(!m_SkinIniFile.GetIniPathName().IsEmpty())
return &m_SkinIniFile;
else
return NULL;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -