#if !defined(AFX_DIALOGFAV_H__78F898B7_133F_11D3_8E6B_00805F254148__INCLUDED_)
#define AFX_DIALOGFAV_H__78F898B7_133F_11D3_8E6B_00805F254148__INCLUDED_#include "DirTreeCtrl.h" // Added by ClassView#define _FAVDIALOG
#include "MainFrm.h"#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DialogFav.h : header file
///////////////////////////////////////////////////////////////////////////////
// CDialogFav dialogclass CDialogFav : public CDialog
{
// Construction
public: CRect m_rcOldRect; void LargeWindow();
bool IsSmall;
CDC m_dcSmallIcon;
CString m_strPathName;
CString m_DefaultPath;
CDirTreeCtrl m_DirTree;
CDialogFav(CWnd* pParent = NULL); // standard constructor
CMainFrame *m_pMain;// Dialog Data
//{{AFX_DATA(CDialogFav)
enum { IDD = IDD_DIALOGFAV };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDialogFav)
public:
virtual int DoModal();
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
// int m_cxBorder;
// int m_cyBorder;
HICON m_hIcon;
CRect Rect;
int SCREENCX,SCREENCY;
afx_msg HCURSOR OnQueryDragIcon();
int pos1,pos2; // Generated message map functions
//{{AFX_MSG(CDialogFav)
virtual BOOL OnInitDialog();
afx_msg void OnSelchangedDirtree(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
afx_msg UINT OnNcHitTest(CPoint point);
afx_msg void OnPaint();
afx_msg void OnSmallButton();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DIALOGFAV_H__78F898B7_133F_11D3_8E6B_00805F254148__INCLUDED_)
#define AFX_DIALOGFAV_H__78F898B7_133F_11D3_8E6B_00805F254148__INCLUDED_#include "DirTreeCtrl.h" // Added by ClassView#define _FAVDIALOG
#include "MainFrm.h"#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DialogFav.h : header file
///////////////////////////////////////////////////////////////////////////////
// CDialogFav dialogclass CDialogFav : public CDialog
{
// Construction
public: CRect m_rcOldRect; void LargeWindow();
bool IsSmall;
CDC m_dcSmallIcon;
CString m_strPathName;
CString m_DefaultPath;
CDirTreeCtrl m_DirTree;
CDialogFav(CWnd* pParent = NULL); // standard constructor
CMainFrame *m_pMain;// Dialog Data
//{{AFX_DATA(CDialogFav)
enum { IDD = IDD_DIALOGFAV };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDialogFav)
public:
virtual int DoModal();
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
// int m_cxBorder;
// int m_cyBorder;
HICON m_hIcon;
CRect Rect;
int SCREENCX,SCREENCY;
afx_msg HCURSOR OnQueryDragIcon();
int pos1,pos2; // Generated message map functions
//{{AFX_MSG(CDialogFav)
virtual BOOL OnInitDialog();
afx_msg void OnSelchangedDirtree(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnNcLButtonDblClk(UINT nHitTest, CPoint point);
afx_msg UINT OnNcHitTest(CPoint point);
afx_msg void OnPaint();
afx_msg void OnSmallButton();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DIALOGFAV_H__78F898B7_133F_11D3_8E6B_00805F254148__INCLUDED_)
解决方案 »
- sublime Text2 关于GBK乱码的问题
- 导航条的判断代码没起作用,大家帮忙看看哈,急
- JS中多个setInterval同时运行100个function还是单个setInterval运行100个funtion,哪个效率更高
- js loop问题
- js闭包与变量问题
- ajax 工具提示 109行报错缺少对象
- 梅花雪大侠,能进来一下子吗
- 一个简单关于参数传递的问题!
- http://www.csdn.net/expert/topic/1075/1075694.xml?temp=.4609033(帮帮我吧!!!)
- 如何在程序中清除保存在浏览器缓存中的网页.请进来看一下.
- 我的问题!!!
- 一个页面关闭之前如何将数据库中相应信息删除??
//#include "stdafx.h"
//#include "IE6mdi.h"
#include "WindowTabCtrl.h"
//#include "ViewManager.h"
#include "PopupMenu.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif#define CX_BORDER 1
#define CY_BORDER 1
/////////////////////////////////////////////////////////////////////////////
// CWindowTabCtrlCWindowTabCtrl::CWindowTabCtrl()
{
// m_hLinkCursor = NULL;
m_nPrevPointedItem=-1;
m_bOverTab=false;
m_nActiveItem=-1;
m_bFloatPaint=false;
// m_rectUpDn(0,0,0,0);
// m_rctPage(0,0,0,0);
m_bAutoRaising=true;
m_bHasFocus=false;
m_crSelColor = RGB(202, 0, 202);
m_crUnselColor = RGB(50, 50, 50);
m_rcDocModified = RGB(255, 0, 0);
}CWindowTabCtrl::~CWindowTabCtrl()
{
// delete image list
VERIFY(m_imageList.DeleteImageList()); m_SelFont.DeleteObject();
m_UnselFont.DeleteObject();
}
BEGIN_MESSAGE_MAP(CWindowTabCtrl, CTabCtrl)
//{{AFX_MSG_MAP(CWindowTabCtrl)
ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_RBUTTONDOWN()
ON_WM_DRAWITEM()
ON_WM_SETFOCUS()
ON_WM_PAINT()
ON_WM_KILLFOCUS()
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
ON_NOTIFY_REFLECT(TCN_SELCHANGING, OnSelchanging)
ON_MESSAGE(WM_MOUSELEAVE,OnMouseLeave)
ON_MESSAGE(ID_FILE_CLOSE,ChildClose)
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CWindowTabCtrl message handlersvoid CWindowTabCtrl::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
{
m_nActiveItem = GetCurSel();
m_nPrevPointedItem=-1;
//*pResult = 0; CRect rctUpdate;
GetClientRect(&rctUpdate); // We will set visible bits back on here (see comments in OnSelchanging),
// since now we know which item became active and can redraw CLBTabCtrl.
ValidateRect(&rctUpdate);//Clean-up any pending WM_PAINTs
DWORD dwStyle = ::GetWindowLong(m_hWnd,GWL_STYLE);
if ((dwStyle & WS_VISIBLE) == 0)
::SetWindowLong(m_hWnd, GWL_STYLE, (dwStyle | WS_VISIBLE));//switch on WS_VISIBLE
//m_nActiveItem=GetCurSel();
if(::IsWindow(m_Spin.m_hWnd))
{
//As so the CLBSpinButtonCtrl lives within CLBTabCtrl,we have to
// update its (CLBSpinButtonCtrl) state when tab order has changed
UINT nLeftItem=FindLeftDownItem();
NMUPDOWN nmUpDn;
nmUpDn.iDelta=0;
nmUpDn.iPos=nLeftItem;
nmUpDn.hdr.code=UDN_DELTAPOS;
nmUpDn.hdr.hwndFrom=m_Spin.m_hWnd;
nmUpDn.hdr.idFrom=::GetDlgCtrlID(m_Spin.m_hWnd); ::SendMessage(::GetParent(m_Spin.m_hWnd),
WM_NOTIFY,(WPARAM)nmUpDn.hdr.idFrom,
(LPARAM)&nmUpDn);
}////////my change
// rctUpdate.bottom=m_rctPage.top+2;
// rctUpdate.top=0;
/////////////
// If the right side of update region overlaps the up-down control,
// we have to exclude the up-down control from update region
// to reduce flickering
if(!m_rectUpDn.IsRectEmpty())
{
rctUpdate.right= m_rectUpDn.left;
}
//Let's repaint tabs,since the active tab has changed
InvalidateRect(&rctUpdate,FALSE);
UpdateWindow();// return FALSE;
TC_ITEM ti;
ti.mask = TCIF_PARAM| TCIF_IMAGE;
GetItem(m_nActiveItem, &ti);
CView * pView = (CView *) ti.lParam; ((CMDIFrameWnd *)AfxGetMainWnd())->MDIActivate(pView->GetParent());
if (pView->GetParent()->IsIconic())
pView->GetParent()->ShowWindow(SW_SHOWMINIMIZED);
*pResult = 0;}int CWindowTabCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CTabCtrl::OnCreate(lpCreateStruct) == -1)
{
MessageBox("error at create",NULL,MB_OK);
return -1;
}
// ModifyStyle(0, TCS_OWNERDRAWFIXED);
// m_brushBkgnd.CreateSolidBrush(RGB(0,0,0));
HFONT hf = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
CFont * ft = CFont::FromHandle(hf);
SetFont(ft); if(!m_imageList.Create(GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),ILC_COLOR8|ILC_MASK,4,4))
{
TRACE(_T("COXTabWorkspace::OnCreate: Create() image list failed\n"));
return -1;
} SetColors( m_crSelColor ,
m_crUnselColor ,
m_rcDocModified );
SetImageList(&m_imageList);
return 0;
}void CWindowTabCtrl::ResizeTabs()
{
CRect rc;
GetClientRect(rc);
int iNumWin = theViewManager.GetWindowNum();
int x = 140; // def item width
if ((x+4) * iNumWin > rc.Width()) x = (rc.Width()) / iNumWin - 4;
SetItemSize(CSize(x,rc.Height()));
UpdateWindow();
}void CWindowTabCtrl::OnSize(UINT nType, int cx, int cy)
{
CTabCtrl::OnSize(nType, cx, cy);
ResizeTabs();
}void CWindowTabCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
TCHITTESTINFO hti;
hti.pt = CPoint(GetMessagePos());
ScreenToClient(&hti.pt);
int iTab = HitTest(&hti);
if (iTab < 0)
return;
SetCurSel(iTab); // Select it TCITEM tci;
tci.mask = TCIF_PARAM| TCIF_IMAGE;
GetItem(iTab, &tci);
CView* pView = reinterpret_cast<CView*>(tci.lParam);
static_cast<CMDIFrameWnd*>(AfxGetMainWnd())->MDIActivate(pView->GetParent());
CString tt=pView->GetDocument()->GetTitle();
tt="关闭 "+tt.Left(8)+"...";
// Now, process the popup menu for the tab control
POINT ptScreen = point;
// Convert the mouse point to screen coordinates since that is what is used by
// the TrackPopupMenu() function.
ClientToScreen(&ptScreen);
CPopupMenu cMenu;
cMenu.CreatePopupMenu();
// if(((CMainFrame*)AfxGetMainWnd())->m_bDown)//假如当前VIEW是下载
// {
// cMenu.AppendMenu(MF_BYPOSITION |MF_STRING, IDC_CLOSEONE, tt);
// }
// else
// { cMenu.AppendMenu(MF_BYPOSITION |MF_STRING, ID_FILE_CLOSE, tt);
//if(((CMainFrame*)AfxGetMainWnd())->bHTML)
//{ cMenu.AppendMenu(MF_STRING, ID_GO_BACK, _T("后退 backspace"));
cMenu.AppendMenu(MF_STRING, ID_GO_FORWARD, _T("前进 Alt+右"));
cMenu.AppendMenu(MF_STRING, ID_VIEW_STOP, _T("停止 Esc"));
cMenu.AppendMenu(MF_STRING, ID_VIEW_REFRESH, _T("刷新 F5"));
cMenu.AppendMenu(MF_SEPARATOR);
cMenu.AppendMenu(MF_STRING, ID_KILL_ALL, _T("完全关闭"));
cMenu.AppendMenu(MF_SEPARATOR);
//}
cMenu.AppendMenu(MF_STRING, ID_FILE_SAVE, _T("保存 Ctrl+S"));
cMenu.AppendMenu(MF_STRING, ID_FILE_SAVE_AS, _T("另存为..."));
cMenu.AppendMenu(MF_SEPARATOR);
cMenu.AppendMenu(MF_STRING, ID_FILE_PRINT, _T("打印 Ctrl+P"));
cMenu.AppendMenu(MF_STRING, ID_FILE_PRINT_PREVIEW, _T("打印预览"));
// }
cMenu.LoadToolBarResource(IDR_TAB_MENU);
cMenu.RemapMenu(&cMenu);
cMenu.EnableMenuItems(&cMenu, AfxGetMainWnd());
// insert a separator item at the top
cMenu.InsertMenu(1, MF_BYPOSITION | MF_SEPARATOR, 0, _T("")); // insert title item
// note: item is not selectable (disabled) but not grayed
//cMenu.InsertMenu(1, MF_BYPOSITION | MF_STRING | MF_DISABLED, 0, _T("关闭当前窗口")); ::SetMenuDefaultItem(cMenu.m_hMenu, 0, TRUE); cMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, ptScreen.x, ptScreen.y, AfxGetMainWnd());
cMenu.DestroyMenu();
CTabCtrl::OnRButtonDown(nFlags, point);
}
void CWindowTabCtrl::SetColors(COLORREF bSelColor, COLORREF bUnselColor,
COLORREF rcDocModified)
{
m_crSelColor = bSelColor;
m_crUnselColor = bUnselColor;
m_rcDocModified = rcDocModified;
Invalidate();
}
void CWindowTabCtrl::SetFonts(int nSelWeight, BOOL bSelItalic, BOOL bSelUnderline,
int nUnselWeight, BOOL bUnselItalic, BOOL bUnselUnderline)
{
// Free any memory currently used by the fonts.
m_SelFont.DeleteObject();
m_UnselFont.DeleteObject(); // Get the current font
LOGFONT lFont;
CFont *pFont = GetFont();
if (pFont)
pFont->GetLogFont(&lFont);
else
{
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
lFont = ncm.lfMessageFont;
} // Create the "Selected" font
lFont.lfWeight = static_cast<LONG>(nSelWeight);
lFont.lfItalic = static_cast<BYTE>(bSelItalic);
lFont.lfUnderline = static_cast<BYTE>(bSelUnderline);
m_SelFont.CreateFontIndirect(&lFont); // Create the "Unselected" font
lFont.lfWeight = static_cast<LONG>(nUnselWeight);
lFont.lfItalic = static_cast<BYTE>(bUnselItalic);
lFont.lfUnderline = static_cast<BYTE>(bUnselUnderline);
m_UnselFont.CreateFontIndirect(&lFont); SetFont((nSelWeight > nUnselWeight) ? &m_SelFont : &m_UnselFont);
}void CWindowTabCtrl::SetFonts(CFont* pSelFont, CFont* pUnselFont)
{
ASSERT(pSelFont && pUnselFont); LOGFONT lFont;
int nSelHeight, nUnselHeight; m_SelFont.DeleteObject();
m_UnselFont.DeleteObject(); pSelFont->GetLogFont(&lFont);
m_SelFont.CreateFontIndirect(&lFont);
nSelHeight = lFont.lfHeight; pUnselFont->GetLogFont(&lFont);
m_UnselFont.CreateFontIndirect(&lFont);
nUnselHeight = lFont.lfHeight; SetFont((nSelHeight > nUnselHeight)? &m_SelFont : &m_UnselFont);
}void CWindowTabCtrl::SetIconDisplay(BOOL bDisplayIt)
{
m_bDisplayIcons = bDisplayIt;
}void CWindowTabCtrl::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CRect rcTab = CRect(&(lpDrawItemStruct->rcItem));
int nTabIndex = lpDrawItemStruct->itemID;
if (nTabIndex < 0)
return;
BOOL bSelected = (nTabIndex == GetCurSel());
TCHAR szLabel[_MAX_PATH];
TCITEM tci;
tci.mask = TCIF_TEXT | TCIF_IMAGE | TCIF_PARAM;
tci.pszText = szLabel;
tci.cchTextMax = _MAX_PATH - 1;
if (!GetItem(nTabIndex, &tci))
return;
CDC dc;
if (!dc.Attach(lpDrawItemStruct->hDC))
return;
DWORD dwStyle = GetStyle();
rcTab.NormalizeRect();
if ((dwStyle & TCS_BOTTOM) == 0)
{
rcTab.DeflateRect(CX_BORDER, CY_BORDER);
rcTab.top += ::GetSystemMetrics(SM_CYEDGE);
}
dc.SetBkMode(TRANSPARENT);
dc.FillSolidRect(rcTab, ::GetSysColor(COLOR_BTNFACE));
CView* pView = reinterpret_cast<CView*>(tci.lParam);
CDocument* pDoc = pView->GetDocument();
/*
// Draw image
//if (m_bDisplayIcons)
//{
CImageList* pImageList = GetImageList();
CMDIChildWnd* pViewFrame = static_cast<CMDIChildWnd*>(pView->GetParent());
HICON hIcon = reinterpret_cast<HICON>(GetClassLong(pViewFrame->m_hWnd, GCL_HICONSM));
pImageList->Replace(nTabIndex, hIcon); if (pImageList && tci.iImage >= 0)
{
rcTab.left += dc.GetTextExtent(_T(" ")).cx; // Set a little margin
// Get the height of image
IMAGEINFO info;
pImageList->GetImageInfo(tci.iImage, &info);
CRect ImageRect(info.rcImage);
int nYpos = rcTab.top;
pImageList->Draw(&dc, tci.iImage, CPoint(rcTab.left, nYpos), ILD_TRANSPARENT);
rcTab.left += ImageRect.Width();
}
//}
*/
if (bSelected)
{
if (pDoc->IsModified())
dc.SetTextColor(m_rcDocModified);
else
dc.SetTextColor(m_crSelColor);
dc.SelectObject(&m_SelFont);
rcTab.top -= ::GetSystemMetrics(SM_CYEDGE);
}
else
{
if (pDoc->IsModified())
dc.SetTextColor(m_rcDocModified);
else
dc.SetTextColor(m_crUnselColor);
dc.SelectObject(&m_UnselFont);
}
dc.DrawText(szLabel, rcTab, DT_SINGLELINE | DT_TOP | DT_LEFT);//左边显示TAB标题
dc.Detach();
}void CWindowTabCtrl::PreSubclassWindow()
{
// TODO: Add your specialized code here and/or call the base class
CTabCtrl::PreSubclassWindow();
// Get default menu font.
// We shall use it to draw tab's text.
//
// If somebody don't like this font
// he or she always can use the AfxGetPropSheetFont implementation
// from "ccdata.cpp", located with MFC source files. NONCLIENTMETRICS nclim;
nclim.cbSize=sizeof(NONCLIENTMETRICS);
::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS),
&nclim,0);
m_hMenuFont= ::CreateFontIndirect(&nclim.lfMenuFont);
//Create pens for drawing CLBTabCtrl
COLORREF clr = ::GetSysColor(COLOR_3DHILIGHT);
m_hPenLight = ::CreatePen(PS_SOLID,1,clr);
clr=::GetSysColor(COLOR_3DDKSHADOW);
m_hPenShadow = ::CreatePen(PS_SOLID,1,clr);
clr=::GetSysColor(COLOR_3DSHADOW);
m_hPenItemShadow = ::CreatePen(PS_SOLID,1,clr); //Look for msctls_updown32 control and if it is present, modify its size,
//position and subclass it to CLBSpinButtonCtrl, which have autodisabling
//arrow buttons.
//The msctls_updown32 control exists when CLBTabCtrl is not in stacked mode.
CWnd* pWnd = GetWindow(GW_CHILD);
while(pWnd)
{
char buf[]="msctls_updown32";
int nRet=::GetClassName(pWnd->m_hWnd,buf,sizeof(buf)/sizeof (buf[0]));
if(nRet && strcmp(buf,"msctls_updown32"))
{
pWnd = pWnd->GetWindow(GW_HWNDNEXT);
}
else
{
//The msctls_updown32 control is found.
//
pWnd->GetWindowRect(&m_rectUpDn);
ScreenToClient(&m_rectUpDn); //Update size and position of msctls_updown32 control
m_rectUpDn.DeflateRect(3,2);
m_rectUpDn.OffsetRect(3,5);
pWnd->MoveWindow(&m_rectUpDn);
//Subclass common msctls_updown32 control to
//my CLBSpinButtonCtrl, which have autodisabling arrow buttons.
m_Spin.SubclassWindow(pWnd->m_hWnd); pWnd=0;
}
}
m_nActiveItem=GetCurSel();
CRect rctItem;
GetItemRect(0,&rctItem);
GetClientRect(&m_rctPage);
m_rctPage.top=rctItem.bottom;
// ModifyStyle(0, TCS_OWNERDRAWFIXED); //TODO must go!
}BOOL CWindowTabCtrl::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
static short flag=0;
UINT time;
static DWORD t1,t2,t3=22000;
time=GetDoubleClickTime();
if((pMsg->message == WM_LBUTTONDBLCLK )||(pMsg->message ==WM_LBUTTONDOWN))
{
if(pMsg->message == WM_LBUTTONDBLCLK )
{
t1=GetTickCount();
flag=1;
}
if(pMsg->message == WM_LBUTTONDOWN)
{
if(flag==1)
{
t2=GetTickCount();
t3=t2-t1;
if(t3<time)
{
ChildClose();
//pFrame->pChild->SetFocus(); //(CWnd*)(pChild->GetNextWindow(GW_HWNDPREV))->SetFocus(); // pChild->SetFocus();
// MessageBox("sadf",NULL,MB_OK);
//click_3();
flag=0;
return true;
}
flag=0;
}
} }
return CTabCtrl::PreTranslateMessage(pMsg);
}void CWindowTabCtrl::OnSetFocus(CWnd* pOldWnd)
{
m_bHasFocus = true;
//CTabCtrl::OnSetFocus(pOldWnd);
CTabCtrl::OnSetFocus(pOldWnd);
// TODO: Add your message handler code here
}void CWindowTabCtrl::OnPaint()
{
CRect rcPnt,rcItem,rcActive,rectCli;
CDC dc;
CBitmap bmp;
GetClientRect(&rectCli);
CPaintDC dcReal(this); // device context for painting
//To reduce flickering we are drawing to memory DC,
//and then BitBlting result to the screen.
//So we have to create compatible memory DC and select bitmap into it.
dc.CreateCompatibleDC(&dcReal);
bmp.CreateCompatibleBitmap(&dcReal,rectCli.Width(),rectCli.Height());
CBitmap *pOldBitmap;
pOldBitmap=dc.SelectObject(&bmp); //Copy update rect to rcPnt
rcPnt=dcReal.m_ps.rcPaint;
COLORREF clrFill=::GetSysColor(COLOR_3DFACE); //As so I bypassed WM_ERASEBCKGND, do its job here
dc.FillSolidRect(&rcPnt,clrFill); HPEN hOldPen;
DRAWITEMSTRUCT drawItemStruct; hOldPen = (HPEN)::GetCurrentObject(dc.m_hDC,OBJ_PEN);
//Active item should be wider then other items.
//So here we calculate and apply the width difference.
GetItemRect(m_nActiveItem,&rcActive);
//if(m_nActiveItem!=(int)FindLeftDownItem()) // if acive item is not leftmost,
// rcActive.left-=3; // then move to the left its left side.
TCHITTESTINFO thi;
thi.pt=CPoint(rcActive.right+5,rcActive.bottom-4);
int nPos = HitTest(&thi);
//if(nPos>=0) // if acive item is not rightmost,
// rcActive.right+=3; // then move to the right its left side. //Active item should be higher then other items.
//So here we apply the height difference.
//rcActive.top+=2; if (m_bFloatPaint )
{
//
//The mouse is moving over inactive item - raise it
//
m_bFloatPaint=false;
//Get the mouse position for the last dispatched message and
// find index of item, over which the mouse is(was).
TCHITTESTINFO tci;
tci.pt=CPoint(::GetMessagePos());
ScreenToClient(&tci.pt);
int nItemFloat=HitTest(&tci);
if(nItemFloat>=0)
{
GetItemRect(nItemFloat,&rcItem);
rcItem.DeflateRect(ITEM_DEFLATE,0);
rcItem.top-=FLOAT_ITEM_HEIGHT_SHIFT;
dc.FillSolidRect(&rcItem,RGB(127,126,126));
//Draw item's text,bitmap,...
drawItemStruct.rcItem=rcItem;
drawItemStruct.hDC=dc.GetSafeHdc();
drawItemStruct.itemID=nItemFloat;
DrawItem(&drawItemStruct); //Draw item's rect
//HINT_ACTIVATE_RIGHT_SIDE is a flag indicating, that the
//right side of rect should be drawn as for active item (darker).
DrawItemRect(dc,rcItem,HINT_ACTIVATE_RIGHT_SIDE);
}
}
else
{
//If we are here, then complex repaint is required.
CRect rectTemp;
if(rectTemp.IntersectRect(m_rctPage,rcPnt) && rcActive.bottom == m_rctPage.top)
{
//Let's draw Property Page bounding rectangle as 3D. rectTemp=m_rctPage;
::SelectObject(dc.m_hDC,m_hPenLight);
dc.MoveTo(rectTemp.left,rectTemp.bottom+1);
dc.LineTo(rectTemp.left,rectTemp.top+1); if(rcActive.left>=0)
{
dc.LineTo(rcActive.left,rcActive.bottom+1);
if(m_rectUpDn.IsRectEmpty())
{
dc.MoveTo(rcActive.right,rcActive.bottom+1);
}
else
{
if(rcActive.right >= m_rectUpDn.left)
{
dc.MoveTo(m_rectUpDn.left-SHIFT_FROM_CUT_TO_SPIN+2,
rcActive.bottom+1);
}
else
{
dc.MoveTo(rcActive.right,rcActive.bottom+1); }
}
dc.LineTo(rectTemp.right-2,rcActive.bottom+1);
}
else
{
CRect rectItemLeftmost;
UINT nItemLeftmost=FindLeftDownItem();
GetItemRect(nItemLeftmost,&rectItemLeftmost);
dc.LineTo(rectTemp.right-2,rcActive.bottom+1);
}
::SelectObject(dc.m_hDC,m_hPenItemShadow);
dc.LineTo(rectTemp.right-2,rectTemp.bottom-2);
dc.LineTo(rectTemp.left,rectTemp.bottom-2); ::SelectObject(dc.m_hDC,m_hPenShadow);
dc.MoveTo(rectTemp.right-1,rcActive.bottom+1);
dc.LineTo(rectTemp.right-1,rectTemp.bottom-1);
dc.LineTo(rectTemp.left-2,rectTemp.bottom-1); } int nCount = GetItemCount(); for(int i=0;i< nCount;i++)
{
if(i!=m_nActiveItem)
{
//Let's draw all inactive items which intersects invalidated
//rect (rcPaint).
GetItemRect(i,&rcItem);
if (rectTemp.IntersectRect(&rcItem,&rcPnt))
{
rcItem.DeflateRect(ITEM_DEFLATE,0); //Draw item's text,bitmap,...
drawItemStruct.rcItem=rcItem;
drawItemStruct.hDC=dc.GetSafeHdc();
drawItemStruct.itemID=i;
//drawItemStruct.CtlType=
DrawItem(&drawItemStruct);
DrawItemRect(dc,rcItem);
}
}
} }
if (rcPnt.IntersectRect(&rcActive,&rcPnt) && rcActive.left > 0)
{
//Current update region intersects the active item,
// so we should repaint it.
rcItem=rcActive;
//dc.
//DrawEdge(&rcItem
dc.FillSolidRect(&rcItem,RGB(80,80,80));
dc.SetTextColor(RGB(217,217,217));
//clrFill);
//dc.FillSolidRect( //Draw item's text,bitmap,...
drawItemStruct.rcItem=rcItem;
drawItemStruct.hDC=dc.GetSafeHdc();
drawItemStruct.itemID=m_nActiveItem;
DrawItem(&drawItemStruct); DrawItemRect(dc,rcItem,HINT_ACTIVATE_RIGHT_SIDE|HINT_ACTIVE_ITEM);
// if(m_bHasFocus)
// DrawFocus(dc);
} //Copy drawing from memory device context to the screen.
dcReal.BitBlt(0,0,rectCli.Width(),rectCli.Height(),&dc,0,0,SRCCOPY); //Restore device context defaults.
::SelectObject(dc.m_hDC,hOldPen);
dc.SelectObject(pOldBitmap);
}void CWindowTabCtrl::OnKillFocus(CWnd* pNewWnd)
{
m_bHasFocus = false;
CTabCtrl::OnKillFocus(pNewWnd);
// TODO: Add your message handler code here
}BOOL CWindowTabCtrl::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;// my add for owndraw 4.26
//return CTabCtrl::OnEraseBkgnd(pDC);
}LRESULT CWindowTabCtrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message != TCM_SETCURSEL)
return CTabCtrl::WindowProc(message, wParam, lParam);
else
{ // We need to handle this message to alter CLBTabCtrl state,
// which may change due to user keyboard input ('Control-Tab')
// or because of direct SendMessage.
//
// After CLBTabCtrl control handles TCM_SETCURSEL message,
// the system will draw the tab control, by sending to it
// WM_PAINT/WM_ERASEBKGND messages.
// Since we perform actual redraw in TCN_SELCHANGE handler ,
// we have to avoid these WM_PAINT/WM_ERASEBKGND messages
// to get rid of flickering.
//
// Since up-down control do not receive WM_PAINT/WM_ERASEBKGND messages
// if it is invisible, so we temporary set the appropriate visible bits
// off and the control thinks it is visible even though it is not.
// We shall set visible bits back on in TCN_SELCHANGE handler, when
// it is good time to redraw CLBTabCtrl. DWORD dwStyle = ::GetWindowLong(m_hWnd,GWL_STYLE);
if (dwStyle & WS_VISIBLE)
::SetWindowLong(m_hWnd, GWL_STYLE, (dwStyle & ~ WS_VISIBLE));
LRESULT nResult = CTabCtrl::WindowProc(message, wParam, lParam);
//Now let's meet with TCN_SELCHANGE message
NMHDR nmhdr;
nmhdr.hwndFrom = m_hWnd;
nmhdr.idFrom = ::GetDlgCtrlID(m_hWnd);
nmhdr.code = TCN_SELCHANGE; ::SendMessage(::GetParent(m_hWnd),WM_NOTIFY,
WPARAM(nmhdr.idFrom),LPARAM(&nmhdr));
return nResult;
}
}UINT CWindowTabCtrl::FindLeftDownItem() const
{
//Helper function
//Finds leftmost down item. CRect rctLeft(100000,0,0,0),rctCur;
int nCount = GetItemCount()-1;
UINT nItem=0;
for(int i=0;i<nCount;i++)
{
GetItemRect(i,&rctCur);
if(rctCur.left > 0 && rctCur.left <= rctLeft.left)
{
if(rctCur.bottom > rctLeft.bottom)
{
rctLeft=rctCur;
nItem=i;
}
}
}
return nItem;
}
void CWindowTabCtrl::DrawFocus(CDC &dc)
{
// Helper function
// Draws a focus rect over active item CRect rctItem;
GetItemRect(m_nActiveItem,&rctItem);
if(rctItem.left >=0)
{
//if(m_nActiveItem!=(int)FindLeftDownItem())
// rctItem.left-=3;
// TCHITTESTINFO thi;
// thi.pt=CPoint(rctItem.right+5,rctItem.bottom-4);
// int nPos = HitTest(&thi);
// if(nPos>=0)
// rctItem.right+=3; if(!m_rectUpDn.IsRectEmpty()&& rctItem.right >= m_rectUpDn.left)
{
// rctItem.right = m_rectUpDn.left;//-SHIFT_FROM_CUT_TO_SPIN;
// rctItem.right-=2;
// rctItem.left+=3;
}
else
rctItem.DeflateRect(3,0); rctItem.top+=1;
dc.DrawFocusRect(&rctItem);
}
}void CWindowTabCtrl::DrawItemRect(CDC &dc, CRect &rcItem,int nHint)
{
//Let's draw items rect.
rcItem.bottom-=1;
if(rcItem.left>0)
{
bool bDoNotCut=true; ::SelectObject(dc.m_hDC,m_hPenLight);
if(nHint & HINT_ACTIVE_ITEM)
dc.MoveTo(rcItem.left,rcItem.bottom);
//dc.MoveTo(rcItem.left,rcItem.bottom+2);
else
dc.MoveTo(rcItem.left,rcItem.bottom);
// dc.LineTo(rcItem.left,rcItem.top+2);
// dc.LineTo(rcItem.left+2,rcItem.top);
dc.LineTo(rcItem.left,rcItem.top);
dc.LineTo(rcItem.left+2,rcItem.top);
if(!m_rectUpDn.IsRectEmpty() && rcItem.right >= m_rectUpDn.left)
{
// CLBTabCtrl is not in stacked mode and current item overlaps
// msctls_updown32 control. So let's decrease current item's
// width.
rcItem.right=m_rectUpDn.left;//-SHIFT_FROM_CUT_TO_SPIN;
dc.LineTo(rcItem.right,rcItem.top);
bDoNotCut=false;
}
else
dc.LineTo(rcItem.right,rcItem.top);
// dc.LineTo(rcItem.right-2,rcItem.top);
if(!nHint)
::SelectObject(dc.m_hDC,m_hPenItemShadow);
else
{
if(nHint & HINT_ACTIVATE_RIGHT_SIDE)
{
::SelectObject(dc.m_hDC,m_hPenShadow);
}
}
if(bDoNotCut)
{
if(nHint & HINT_ACTIVE_ITEM)
{
dc.LineTo(rcItem.right,rcItem.top);
dc.LineTo(rcItem.right,rcItem.bottom);
//dc.LineTo(rcItem.right,rcItem.top+2);
//dc.LineTo(rcItem.right,rcItem.bottom+2);
}
else
{
dc.LineTo(rcItem.right,rcItem.top);
dc.LineTo(rcItem.right,rcItem.bottom);
// dc.LineTo(rcItem.right,rcItem.top+2);
// dc.LineTo(rcItem.right,rcItem.bottom+1);
}
}
else
{
// CLBTabCtrl is not in stacked mode and current item overlaps
// msctls_updown32 control. So let's draw current item's rect
// as cut.
int nYPos=rcItem.top+2;
//int nYPos=rcItem.top; nYPos+=rcItem.Height()/5;
// rcItem.right+=1;
if(nYPos < rcItem.bottom)
dc.LineTo(rcItem.right,nYPos); nYPos+=rcItem.Height()/3;
// rcItem.right-=2;
if(nYPos < rcItem.bottom)
dc.LineTo(rcItem.right,nYPos); nYPos+=rcItem.Height()/5;
// rcItem.right+=1;
if(nYPos < rcItem.bottom)
dc.LineTo(rcItem.right,nYPos); nYPos+=rcItem.Height()/5;
// rcItem.right+=1;
if(nYPos < rcItem.bottom)
dc.LineTo(rcItem.right,nYPos);
if(nHint & HINT_ACTIVE_ITEM)
{
dc.LineTo(rcItem.right,rcItem.bottom);
//dc.LineTo(rcItem.right,rcItem.bottom+2);
}
else
dc.LineTo(rcItem.right,rcItem.bottom);
//dc.LineTo(rcItem.right,rcItem.bottom+1); }
}
}LRESULT CWindowTabCtrl::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
// MessageBox("mouse leaves",NULL,MB_OK);
//This handler is called when mouse leaves CLBTabCtrl
m_bOverTab=false;
if(m_nPrevPointedItem>=0)
{
if (m_nPrevPointedItem!=m_nActiveItem)
{
//If we are here,then mouse leaved the raised item, so
//we have to redraw it as normal (unraised). CRect rectItem;
GetItemRect(m_nPrevPointedItem,&rectItem);
rectItem.top-=FLOAT_ITEM_HEIGHT_SHIFT;
//If the right side of item overlaps the up-down control,
//we have to exclude the up-down control from update region
//to reduce flickering
if(!m_rectUpDn.IsRectEmpty() && rectItem.right >= m_rectUpDn.left)
rectItem.right = m_rectUpDn.left; InvalidateRect(&rectItem);
UpdateWindow();
}
m_nPrevPointedItem=-1;
}
return 0;
}void CWindowTabCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default ///MessageBox("mouse moves",NULL,MB_OK);
if(m_bAutoRaising)
{
if(!m_bOverTab )
{
// We are here if the mouse just entered the CLBTabCtrl
//
// Let's use _TrackMouseEvent API to be notified when the mouse leaves.
// This API tries to use the window manager's
// implementation of TrackMouseEvent if it is present,
// otherwise it emulates. m_bOverTab=true;
TRACKMOUSEEVENT stTRACKMOUSEEVENT;
stTRACKMOUSEEVENT.cbSize = sizeof(stTRACKMOUSEEVENT);
stTRACKMOUSEEVENT.hwndTrack=m_hWnd;
stTRACKMOUSEEVENT.dwFlags=TME_LEAVE;
_TrackMouseEvent(&stTRACKMOUSEEVENT);
}
CRect rectItem(0,0,0,0); // Here we shall get mouse position for the last dispatched message and
// test if mouse is over any tab item.
TCHITTESTINFO thi;
thi.pt=point;
int nItem=HitTest(&thi);
if(nItem>=0)
{
if(nItem!=m_nPrevPointedItem )
{
// Mouse is over new inactive item.
if(m_nPrevPointedItem>=0 && m_nPrevPointedItem!=m_nActiveItem)
{
// Redraw the item, over which mouse was on the previous step.
// We redraw it as normal (unraised).
GetItemRect(m_nPrevPointedItem,&rectItem);
rectItem.top-=FLOAT_ITEM_HEIGHT_SHIFT;
// If the right side of item overlaps the up-down control,
// we have to exclude the up-down control from update region
// to reduce flickering.
if(!m_rectUpDn.IsRectEmpty() && rectItem.right >= m_rectUpDn.left)
rectItem.right= m_rectUpDn.left; InvalidateRect(&rectItem);
UpdateWindow();
}
if(nItem!=m_nActiveItem)
{
//Redraw the item, over which mouse is now.
//We redraw it as raised.
GetClientRect(&rectItem);
ValidateRect(&rectItem);
GetItemRect(nItem,&rectItem);
m_bFloatPaint=true;
rectItem.top-=FLOAT_ITEM_HEIGHT_SHIFT;
// If the right side of item overlaps the up-down control,
// we have to exclude the up-down control from update region
// to reduce flickering
if(!m_rectUpDn.IsRectEmpty() && rectItem.right >= m_rectUpDn.left)
rectItem.right= m_rectUpDn.left; InvalidateRect(&rectItem);
UpdateWindow();
}
m_nPrevPointedItem=nItem;
}
}
}
CTabCtrl::OnMouseMove(nFlags, point);
}void CWindowTabCtrl::OnSelchanging(NMHDR* pNMHDR, LRESULT* pResult)
{
// After CLBTabCtrl control (or its parent) handles TCN_SELCHANGING message,
// the system will send to it WM_PAINT/WM_ERASEBKGND messages.
// Since at that moment we still don't know which item has become active,
// and can not properly draw items, we have to avoid these
// WM_PAINT/WM_ERASEBKGND messages to get rid of flickering.
//
// Since up-down control do not receive WM_PAINT/WM_ERASEBKGND messages
// if it is invisible, so we temporary set the appropriate visible bits off
// and the control thinks it is visible even though it is not.
// We will set visible bits back on in TCN_SELCHANGE handler, when
// it is good time to redraw CLBTabCtrl. CRect rctUpdate;
GetClientRect(&rctUpdate);
ValidateRect(&rctUpdate); //Clean-up any pending WM_PAINTs
DWORD dwStyle = ::GetWindowLong(m_hWnd,GWL_STYLE);
if (dwStyle & WS_VISIBLE)
::SetWindowLong(m_hWnd, GWL_STYLE, (dwStyle & ~ WS_VISIBLE));//switch off WS_VISIBLE
*pResult = 0;
}
bool CWindowTabCtrl::SetAutoRaising(bool bOn)
{
// User should have an opportunity to swith on/off the
// autoraising feature of the CLBTabCtrl control. bool bPrev = m_bAutoRaising;
m_bAutoRaising = bOn;
return bPrev;
}void CWindowTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
//Let's draw items text CDC dc;
dc.Attach(lpDrawItemStruct->hDC); //Set current font equal to default menu font.
dc.SelectObject(m_hMenuFont);
char buf[255];
int nCurItem = lpDrawItemStruct->itemID; TCITEM tcitem;
//Get text of item.
tcitem.mask=TCIF_TEXT|TCIF_IMAGE;
tcitem.pszText =buf;
tcitem.iImage =0;
tcitem.cchTextMax=sizeof(buf);
GetItem(nCurItem,&tcitem);
CRect rect=lpDrawItemStruct->rcItem;
rect.OffsetRect(1,4); // Draw Item text.
if(!m_rectUpDn.IsRectEmpty() &&
lpDrawItemStruct->rcItem.right >= m_rectUpDn.left)
{
//The current item is cut on the right side.
if(nCurItem == m_nActiveItem)
{
//If current item is active, then we should decrease its width
//as so, the length of the visible text should be the same as when
//this tab will be inactive.
//if(m_nActiveItem!=(int)FindLeftDownItem())
// rect.left+=3;
TCHITTESTINFO thi;
thi.pt=CPoint(lpDrawItemStruct->rcItem.right+5,
lpDrawItemStruct->rcItem.bottom-4);
int nPos = HitTest(&thi);
//if(nPos>=0)
// rect.right-=3;
} //Decrease the length of the visible text, since
//the right side is cut.
//rect.right=m_rectUpDn.left-SHIFT_FROM_CUT_TO_SPIN-1;
//rect.left+=4;
::DrawText(lpDrawItemStruct->hDC,buf,-1,&rect,DT_LEFT|DT_TOP);
}
else
{
::DrawText(lpDrawItemStruct->hDC,buf,-1,&rect,DT_LEFT|DT_TOP);
}
dc.Detach();
}void CWindowTabCtrl::SelOld()
{
if(theViewManager.GetWindowNum()>1)
SetCurSel( m_nActiveItem);
}BOOL CWindowTabCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
// if (m_hLinkCursor)
//{
//SetCursor(LoadCursor(AfxGetInstanceHandle(),/*IDC_CROSS));// */MAKEINTRESOURCE(IDC_TAB)));
//::SetCursor(m_hLinkCursor);
// return TRUE;
// }
return CTabCtrl::OnSetCursor(pWnd, nHitTest, message);
}void CWindowTabCtrl::ChildClose()
{
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
// CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
//CMainFrame *pFrame = (CMainFrame *)AfxGetMainWnd();
//CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
pFrame->SendMessage(WM_COMMAND,ID_FILE_CLOSE);
//(AfxGetMainWnd()->GetActiveFrame())->
ResizeTabs();}