📄 xptabctrl.cpp
字号:
loop_width:
movsd // copies 4 bytes and increments source and destination by 4 (we need only 3 bytes copied 'one pixel' RGB triplet)
dec edi // adjust edi to 'as incremented by 3'
add esi,nBmpWdtPS // adjust esi to the next source line
loop loop_width // loop one hotizontal destination line
cmp ebx, nHeight1 // check is it the last line
je do_last // if not last, do incrementing here
inc ebx // increment vertical counter
add edi, nPadD // adjust destination index by possible padding to DWORD
mov esi, ebx // reset the source index: add vertical counter * 3
shl esi, 1 // (is the same as * 2 +1*)
add esi, ebx // +1*
add esi, pcImg // add to the beginning of the source
jmp loop_height // loop whole height
do_last: // the last pixel is done by
movsw // moving first two bytes
movsb // and than by moving the very last byte
}
#endif // __USE_MASM__
dcMem.SelectObject(pBmpOld); bmpMem.DeleteObject(); // recreate rotated bitmap
bmpMem.CreateCompatibleBitmap(pDC,szBmp.cx,szBmp.cy);
dcMem.SelectObject(&bmpMem);
bihOut.biWidth =szBmp.cx; bihOut.biHeight=bBody?-szBmp.cy:szBmp.cy;
SetDIBits(*pDC, bmpMem.operator HBITMAP(),0,szBmp.cy,pcImgRotate,&biOut,DIB_RGB_COLORS); // set rotated bitmap bits
delete pcImgRotate;
}
if(pcImg) delete pcImg;
// 6th blit mirrored/rotated image to the screen
pDC->BitBlt(rcItem.left,rcItem.top,szBmp.cx,szBmp.cy,&dcMem,0,0,SRCCOPY); //
dcMem.SelectObject(pBmpOld);
}
//----------------------------------------------------------------------------------------------------------
// draw tab item context: possible icon and text
void CXPTabCtrl::DrawTabItem(CDC* pDC, int ixItem, const CRect& rcItemC, UINT uiFlags)
{
TC_ITEM tci; CString sText;
tci.mask =TCIF_TEXT | TCIF_IMAGE;
tci.pszText =sText.GetBuffer(128);
tci.cchTextMax=127;
GetItem(ixItem,&tci);
sText.ReleaseBuffer();
BOOL bSel =(uiFlags&2)?TRUE:FALSE;
BOOL bBottom=(uiFlags&8)?TRUE:FALSE;
CRect rcItem=rcItemC;
if(bSel) rcItem.bottom -= 1;
else rcItem.bottom += 2;
rcItem.left+=(bBottom?3:6); // text & icon
rcItem.top +=(bBottom?3:2) + (bSel ? 1 : (bBottom?0:3));
int nOldMode=pDC->SetBkMode(TRANSPARENT);
HIMAGELIST hilTabs = (HIMAGELIST)TabCtrl_GetImageList(GetSafeHwnd()); // icon
if(hilTabs && tci.iImage>=0)
{ ImageList_Draw(hilTabs, tci.iImage, *pDC, rcItem.left+(bSel?2:0), rcItem.top+(bSel?0:-2), ILD_TRANSPARENT);
rcItem.left+=19;
}
else rcItem.OffsetRect(-2,0);
if(sText.GetLength())
{ CFont* pOldFont=pDC->SelectObject(GetFont()); // prepare dc
rcItem.right-=3; // text
CRect rect(0,0,rcItem.Width(),20);
::DrawText(pDC->GetSafeHdc(),sText.GetBuffer(sText.GetLength()+4),-1,rect,DT_CALCRECT|DT_SINGLELINE|DT_MODIFYSTRING|DT_END_ELLIPSIS);
sText.ReleaseBuffer();
rcItem.OffsetRect((bBottom?-1:0),(bSel?1:-1));
pDC->DrawText(sText, rcItem, DT_NOPREFIX|DT_CENTER);
pDC->SelectObject(pOldFont);
}
pDC->SetBkMode(nOldMode);
}
//----------------------------------------------------------------------------------------------------------
BOOL CXPTabCtrl::IsExtendedTabTheamedXP()
{
if(!m_bTabExtended || !::IsWindow(GetSafeHwnd()))
return FALSE;
DWORD dwStyle=GetStyle();
m_eTabOrientation=(dwStyle&TCS_BOTTOM)?e_tabBottom:e_tabTop;
if(dwStyle&TCS_VERTICAL)
m_eTabOrientation=(m_eTabOrientation==e_tabTop)?e_tabLeft:e_tabRight;
#ifdef USE_DEFAULT_XP_TOPTAB
if(m_eTabOrientation==e_tabTop) return FALSE;
#endif
return IsThemeActiveXP()?TRUE:FALSE;
}
//==========================================================================================================
// these two messages are necessary only to properly redraw deselected tab background, because
void CXPTabCtrl::OnTabSelChanging(NMHDR* pNMHDR, LRESULT* pResult) // selected rect was inflated by 2 points
{
UNUSED_ALWAYS(pNMHDR);
m_ixSelOld=GetCurSel();
*pResult=0L;
}
//----------------------------------------------------------------------------------------------------------
void CXPTabCtrl::OnTabSelChanged(NMHDR* pNMHDR, LRESULT* pResult)
{
UNUSED_ALWAYS(pNMHDR);
if(m_ixSelOld>=0 && m_ixSelOld!=GetCurSel() && IsExtendedTabTheamedXP()) // else
{
CWnd* pWndParent=GetParent();
if(pWndParent)
{
CRect rcOldSel; GetItemRect(m_ixSelOld, rcOldSel);
rcOldSel.InflateRect(2,2);
ClientToScreen(&rcOldSel);
pWndParent->ScreenToClient(&rcOldSel);
pWndParent->InvalidateRect(rcOldSel);
} }
*pResult=1L;
}
/***********************************************************************************************************/
// Helper functions
/***********************************************************************************************************/
int DWordAlign(int n)
{
const int rem=n%4;
if(rem) n+=(4-rem);
return n;
}
//----------------------------------------------------------------------------------------------------------
BOOL IsThemeActiveEx()
{ // check theme activity always (could change during application running)
HINSTANCE hDll=LoadLibrary(CString((LPCTSTR)IDS_UTIL_UXTHEME)); // 'UxTheme.dll'
if(hDll==NULL) return FALSE; // the DLL won't be available on anything except Windows XP
UINT (PASCAL *pfnIsThemeActive)();
(FARPROC&)pfnIsThemeActive=GetProcAddress(hDll,CString((LPCTSTR)IDS_UTIL_THEMEACT)); // 'IsThemeActive'
UINT uiThemeActive=0;
if(pfnIsThemeActive)
uiThemeActive=pfnIsThemeActive();
FreeLibrary(hDll);
return uiThemeActive?TRUE:FALSE;
}
//----------------------------------------------------------------------------------------------------------
#define PACKVERSION(major,minor) MAKELONG(minor,major)
DWORD GetWinVersion()
{
static DWORD c_dwWinVers=0; // check win version only once (will not change during application)
if(!c_dwWinVers)
{ OSVERSIONINFO osvi; ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); // Initialize the OSVERSIONINFO structure.
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&osvi);
c_dwWinVers=PACKVERSION(osvi.dwMajorVersion,osvi.dwMinorVersion);
}
return c_dwWinVers;
}
//----------------------------------------------------------------------------------------------------------
BOOL IsWinXP() { return GetWinVersion()>=PACKVERSION(5,1)?TRUE:FALSE; }
//----------------------------------------------------------------------------------------------------------
BOOL IsThemeActiveXP() { return (IsWinXP() && IsThemeActiveEx())?TRUE:FALSE; }
//----------------------------------------------------------------------------------------------------------
#define WPART_NAME_SZ 128
HRESULT DrawThemesPart(HDC hDC, int iPartId, int iStateId, LPCSTR uiPartNameID, LPRECT prcBox)
{
if(!IsWinXP()) return E_FAIL;
HINSTANCE hDll=LoadLibrary(CString((LPCTSTR)IDS_UTIL_UXTHEME)); // 'UxTheme.dll'
if(!hDll) return E_FAIL;
BOOL (PASCAL* pfnIsThemeActive)(); UINT hTheme=0;
(FARPROC&)pfnIsThemeActive=GetProcAddress(hDll,CString((LPCTSTR)IDS_UTIL_THEMEACT)); // 'IsThemeActive'
HRESULT hResult=E_FAIL;
if(pfnIsThemeActive && pfnIsThemeActive())
{ CString sPartName((LPCTSTR)uiPartNameID);
if(sPartName.GetLength()>0)
{ WCHAR swPartName[WPART_NAME_SZ];
MultiByteToWideChar(CP_ACP,0,(LPCSTR)sPartName,-1,swPartName,sizeof(swPartName)/sizeof(WCHAR));
UINT (PASCAL* pfnOpenThemeData)(HWND hwnd, LPCWSTR pszClassList);
(FARPROC&)pfnOpenThemeData=GetProcAddress(hDll,CString((LPCTSTR)IDS_UTIL_THEMEOPN));// 'OpenThemeData'
if(pfnOpenThemeData && (hTheme=pfnOpenThemeData(NULL, swPartName))!=0)
{ UINT (PASCAL* pfnDrawThemeBackground)(UINT htheme,HDC hdc,int iPartID,int iStateID,const RECT* prcBx,const RECT* prcClip);
(FARPROC&)pfnDrawThemeBackground=GetProcAddress(hDll,CString((LPCTSTR)IDS_UTIL_THEMEBCKG)); // 'DrawThemeBackground'
if(pfnDrawThemeBackground)
hResult=pfnDrawThemeBackground(hTheme, hDC, iPartId, iStateId, prcBox, NULL);
} } }
FreeLibrary(hDll);
return hResult;
}
//----------------------------------------------------------------------------------------------------------
void CXPTabCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
CTabCtrl::OnLButtonDown(nFlags, point);
if(m_tabCurrent != GetCurFocus())
{
m_tabPages[m_tabCurrent]->ShowWindow(SW_HIDE);
m_tabCurrent=GetCurFocus();
m_tabPages[m_tabCurrent]->ShowWindow(SW_SHOW);
m_tabPages[m_tabCurrent]->SetFocus();
}
}
void CXPTabCtrl::SetRectangle()
{
CRect tabRect, itemRect;
int nX, nY, nXc, nYc;
GetClientRect(&tabRect);
GetItemRect(0, &itemRect);
nX=itemRect.left;
nY=itemRect.bottom+1;
nXc=tabRect.right-itemRect.left-1;
nYc=tabRect.bottom-nY-1;
m_tabPages[0]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_SHOWWINDOW);
for(int nCount=1; nCount < m_nNumberOfPages; nCount++){
m_tabPages[nCount]->SetWindowPos(&wndTop, nX, nY, nXc, nYc, SWP_HIDEWINDOW);
}
}
void CXPTabCtrl::Init()
{
m_tabCurrent=0;
m_tabPages[0]->Create(IDD_INDEXSET, this);
m_tabPages[1]->Create(IDD_INPUTDATA, this);
m_tabPages[2]->Create(IDD_QUERYDATA, this);
m_tabPages[3]->Create(IDD_PAITXTDATA, this);
m_tabPages[4]->Create(IDD_ABOUTBOX, this);
m_tabPages[0]->ShowWindow(SW_SHOW);
m_tabPages[1]->ShowWindow(SW_HIDE);
m_tabPages[2]->ShowWindow(SW_HIDE);
m_tabPages[3]->ShowWindow(SW_HIDE);
m_tabPages[4]->ShowWindow(SW_HIDE);
SetRectangle();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -