📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "TryDecrypt006.h"
#include "MainFrm.h"
#include "TryDecrypt006Doc.h"
#include "TryDecrypt006View.h"
#include "TryDecrypt006View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CEdit* PMyEdit;
extern PTryDecrypt006Doc;
extern CMainFrame* PMainFrame;
extern CTry006View* PTry006View;
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
//}}AFX_MSG_MAP
ON_UPDATE_COMMAND_UI(ID_INDICATOR_POS, OnUpdateLine)
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_POS,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
PMainFrame=this;
}
CMainFrame::~CMainFrame()
{
}
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_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);
DragAcceptFiles();
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
void CMainFrame::OnUpdateLine(CCmdUI *pCmdUI)
{
// The pointer to my edit.
//extern CEdit* pmyEdit;
// The point where the user clicked the mouse.
//CPoint myPt;
//myPt.x=10;myPt.y=10;
//int n = PMyEdit->CharFromPos(myPt);
//int nLineIndex = HIWORD(n);
//int nCharIndex = LOWORD(n);
//TRACE(TEXT("nLineIndex = %d, nCharIndex = %d\r\n"), nLineIndex, nCharIndex);
pCmdUI->Enable();
CString strLine;
strLine.Format( "行:%d",PMyEdit->LineFromChar()+1);// ,nCharIndex
pCmdUI->SetText( strLine );
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
/*
Status Bars: Updating the Text of a Status-Bar Pane
Home | Overview | How Do I | Tutorial
This article explains how to change the text that appears in an MFC status bar pane. A status bar — a window object of classCStatusBar — contains several “panes.” Each pane is a rectangular area of the status bar that you can use to display information. For example, many applications display the status of the CAPS LOCK, NUM LOCK, and other keys in the rightmost panes. Applications also often display informative text in the leftmost pane (pane 0), sometimes called the “message pane.” For example, the default MFC status bar uses the message pane to display a string explaining the currently selected menu item or toolbar button. The figure in Status Bars shows a status bar from an AppWizard-created MFC application.
By default, MFC does not enable a CStatusBar pane when it creates the pane. To activate a pane, you must use the ON_UPDATE_COMMAND_UI macro for each pane on the status bar and update the panes. Because panes do not send WM_COMMAND messages (they aren’t like toolbar buttons), you can’t use ClassWizard to create an update handler to activate a pane; you must type the code manually.
For example, suppose one pane has ID_INDICATOR_PAGE as its command identifier and that it contains the current page number in a document. The following procedure describes how to create a new pane in the status bar.
To make a new pane
Define the pane’s command ID.
Open the ResourceView in the Project Workspace window. Open the Symbol Browser with the Resource Symbols command on the View menu, and click New. Type a command ID name: for example, ID_INDICATOR_PAGE. Specify a value for the ID, or accept the value suggested by the Symbol Browser. For example, for ID_INDICATOR_PAGE, accept the default value. Close the Symbol Browser.
Define a default string to display in the pane.
With the ResourceView open, double-click String Table in the window that lists resource types for your application. With the String Table editor open, choose New String from the Insert menu. In the String Properties window, select your pane’s command ID (for example, ID_INDICATOR_PAGE) and type a default string value, such as “Page ”. Close the string editor. (You need a default string to avoid a compiler error.)
Add the pane to the indicators array.
In file MAINFRM.CPP, locate the indicators array. This array lists command IDs for all of the status bar’s indicators, in order from left to right. At the appropriate point in the array, enter your pane’s command ID, as shown here for ID_INDICATOR_PAGE:
static UINT BASED_CODE indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
ID_INDICATOR_PAGE,
};
The recommended way to display text in a pane is to call the SetText member function of class CCmdUI in an update handler function for the pane. For example, you might want to set up an integer variable m_nPage that contains the current page number and use SetText to set the pane’s text to a string version of that number.
Note The SetText approach is recommended. It is possible to perform this task at a slightly lower level by calling the CStatusBar member function SetPaneText. Even so, you still need an update handler. Without such a handler for the pane, MFC automatically disables the pane, erasing its content.
The following procedure shows how to use an update handler function to display text in a pane.
To make a pane display text
Add a command update handler for the command.
You can’t use ClassWizard to write a handler for a status bar pane, so manually add a prototype for the handler, as shown here for ID_INDICATOR_PAGE (in MAINFRM.H):
afx_msg void OnUpdatePage(CCmdUI *pCmdUI);
In the appropriate .CPP file, add the handler’s definition, as shown here for ID_INDICATOR_PAGE (in MAINFRM.CPP):
void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
pCmdUI->Enable();
}
In the appropriate message map, add the ON_UPDATE_COMMAND_UI macro (outside the “{{AFX” comments), as shown here for ID_INDICATOR_PAGE (in MAINFRM.CPP):
ON_UPDATE_COMMAND_UI(ID_INDICATOR_PAGE, OnUpdatePage)
Add code to the handler to display your text.
For ID_INDICATOR_PAGE, expand the OnUpdatePage handler from step 1 above, adding the last three lines:
void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
pCmdUI->Enable();
CString strPage;
strPage.Format( "Page %d", m_nPage );
pCmdUI->SetText( strPage );
}
Once you define the value of the m_nPage member variable (of class CMainFrame), this technique causes the page number to appear in the pane during idle processing in the same manner that the application updates other indicators. If m_nPage changes, the display changes during the next idle loop.
What do you want to know more about?
Updating user-interface objects, such as toolbar buttons and menu items, as program conditions change
See Also CStatusBar
--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -