?? mainfrm.cpp
字號:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "CToobarDemo.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_TIMER()
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(ID_BUTTON1111, OnButton11)
ON_COMMAND(IDD_SHOW_HIDE_IE_BAR, OnShowHideIeBar)
ON_UPDATE_COMMAND_UI(IDD_SHOW_HIDE_IE_BAR, OnUpdateShowHideIeBar)
ON_NOTIFY(TVN_SELCHANGED,IDS_TREECTRL,OnSelchanged)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CLOCK,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
//刪除控件對象
delete[] pButton1;
delete[] pEdit1;
delete[] pEdit2;
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndToolBar.CreateCombo( WS_CHILD | CBS_DROPDOWNLIST |
CBS_AUTOHSCROLL | WS_VSCROLL | CBS_HASSTRINGS, &m_pCombo,
IDC_COMBOX, 200, 300 ))
{
TRACE0("Failed to create combo box.\n");
return -1;
}
m_pCombo.AddString("組合框選擇一");
m_pCombo.AddString("組合框選擇二");
m_pCombo.AddString("組合框選擇三");
m_pCombo.AddString("組合框選擇四");
//Don't forget the initial position.
m_pCombo.SetCurSel(0);
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
SetTimer(1,1000,NULL);
//創建對話條,ID為創建的對話條IDD_DIABAR,但并不在主框架上顯示
if (!m_WzdDialogBar.Create(this, IDD_DIABAR,WS_CHILD|WS_VISIBLE,-1))
{
TRACE0( "Failed to create dialog bar\n" );
return -1; // fail to create
}
//動態創建按鈕控件1
pButton1 = new CButton();
CRect rect1(70,2,155,28);//按鈕控件的大小位置
if(!pButton1->Create("對話條響應",WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,rect1,&m_WzdDialogBar,ID_BUTTON1111))
{
AfxMessageBox("創建按鈕控件失?。?quot;);
return false;
}
//動態創建編輯控件1
pEdit1=new CEdit();
CRect rect2(170,2,245,28);//編輯控件的大小位置
if(!pEdit1->Create(WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL,rect2,&m_WzdDialogBar,ID_EDIT1111))
{
AfxMessageBox("創建編輯框控件失??!");
return false;
}
//pEdit1->EnableWindow(false);
if ( !m_wndReBar.Create( this ) )
{
TRACE0( "Failed to create rebar\n" );
return -1; // fail to create
}
//將創建的對話條載入到伸縮條
m_wndReBar.AddBar( &m_WzdDialogBar,"伸縮條", NULL, RBBS_GRIPPERALWAYS | RBBS_FIXEDBMP);
//動態創建編輯控件2
pEdit2=new CEdit();
CRect rect4(440,2,515,28);//編輯控件的大小位置
if(!pEdit2->Create(WS_CHILD|WS_VISIBLE|WS_BORDER|ES_AUTOHSCROLL,rect4,this,ID_EDIT2222))
{
AfxMessageBox("創建編輯框控件失??!");
return false;
}
//將編輯控件2加載到伸縮條
m_wndReBar.AddBar( pEdit2,"伸縮條2", NULL, RBBS_GRIPPERALWAYS | RBBS_FIXEDBMP);
//創建自制控制條并初始化
if(!m_IEBar.Create(this, IDD_IEBAR, CBRS_LEFT, 100) || !m_IEBar.InitIEBar())
pTreeCtrl = m_IEBar.GetTreeCtrl();//獲取樹形控件
ASSERT(pTreeCtrl);
// modify tree styles
pTreeCtrl->ModifyStyle(NULL, TVS_HASLINES | TVS_LINESATROOT | TVS_HASBUTTONS);//設置樹形控件風格
HTREEITEM t_hRoot = pTreeCtrl->InsertItem("消息分類");//插入根節點
for(int i=0; i<20; i++)//插入子節點
{
CString t_ItemStr;
t_ItemStr.Format("消息命令%d", i+1);
HTREEITEM hItem = pTreeCtrl->InsertItem(t_ItemStr, t_hRoot) ;
pTreeCtrl->SetItemData(hItem, i+1 ); //為子節點設置值便于調用
}
m_IEBar.EnableDocking(CBRS_ORIENT_HORZ);//水平??? DockControlBar(&m_IEBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CTime time;
time=CTime::GetCurrentTime();
CString s=time.Format("%H:%M:%S");
m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CLOCK),s);
CFrameWnd::OnTimer(nIDEvent);
}
void CMainFrame::OnClose()
{
// TODO: Add your message handler code here and/or call default
KillTimer(1);
CFrameWnd::OnClose();
}
void CMainFrame::OnButton1()
{
//AfxMessageBox("伸縮條命令響應成功");
pEdit1->SetWindowText("");
pEdit2->SetWindowText("");
}
void CMainFrame::OnButton11()
{
pEdit1->SetWindowText("響應成功");
pEdit2->SetWindowText("響應成功");
//AfxMessageBox("伸縮條命令響應成功");
}
void CMainFrame::DoDataExchange(CDataExchange* pDX)
{
// TODO: Add your specialized code here and/or call the base class
CFrameWnd::DoDataExchange(pDX);
// DDX_Text(pDX, IDC_EDITCHAR, m_Char);
}
void CMainFrame::OnShowHideIeBar()
{
// TODO: Add your command handler code here
ShowControlBar(&m_IEBar, (m_IEBar.GetStyle() & WS_VISIBLE) == 0, FALSE);
}
void CMainFrame::OnUpdateShowHideIeBar(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck((m_IEBar.GetStyle() & WS_VISIBLE) != 0);
}
void CMainFrame::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
{
NMTREEVIEW *pTreeView=(NMTREEVIEW*)pNMHDR;
HTREEITEM SelItem;//定義條目
SelItem=pTreeCtrl->GetSelectedItem(); //獲取當前被選擇的tree view項
DWORD m;
m=pTreeCtrl->GetItemData(SelItem);//回與一個項關聯的32位的應用程序指定值
CString str;
str.Format("這是消息命令%d",m);
if (m>0)
AfxMessageBox(str); //命令響應
pResult=0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -