⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.h

📁 《Visual C++ Bible》或者说是《Visual C++ 宝典》的对应的源码文件
💻 H
字号:
// mainfrm.h : interface of the DMainFrame class
//
/////////////////////////////////////////////////////////////////////////////
#include <afxtempl.h> // Connect to CArray template.

// Structure to track lines in text file.
class STRING  // : public CObject
{
  public:
    LPTSTR pText;
    int    ccLen;
};

// This declaration uses the CArray template 
// to provide a dynamic array of STRING records.
class StringArray : public CArray <STRING, STRING &>
{
  public:
    StringArray() {}
    STRING& operator=(STRING & s)
                       {m_pData->pText = s.pText;
                        m_pData->ccLen = s.ccLen;
                        return *m_pData;}
};

const int g_nTabCount=25;
const int g_nTabStop=4;

class DMainFrame : public CFrameWnd
{
public:
    DMainFrame();
protected: // create from serialization only
    DECLARE_DYNCREATE(DMainFrame)

// Attributes
public:
    BOOL          d_bTabs;        // Respect tabs or not.
    CFileDialog * d_pOpenFile;    // Ptr to OpenFile dialog.
    CFontDialog * d_pSetFont;     // Ptr to Font Picker dialog.
    CFont  *      d_pFont;        // Ptr to CFont object.
    COLORREF      d_crForeground; // Foreground text color.
    COLORREF      d_crBackground; // Background text color.
    LOGFONT       d_lf;           // Current logical font.
    LPINT         d_pnTabs;       // Array of tab settings.
    LPTSTR        d_lpTextBuffer; // Ptr to text buffer.
    DWORD         d_dwFileLength; // File length.
    StringArray   d_saTextInfo;   // Array of string info.
    int           d_cLines;       // Count of lines in text.
    int           d_cyLineHeight; // Height of one line of text.
    int           d_clHeight;     // Window height line count.
    int           d_iTopLine;     // Index of top-most line.
    int           d_cyClient;     // Window client area height.
    int           d_cxLeftMargin; // Margin to left of text.

    // [GETTEXT] New attributes.
    BOOL          d_bCapture;     // Mouse capture flag.
    BOOL          d_bMouseActive; // Whether mouse click activated window.
    BOOL          d_bTimerStarted;// Mouse move timer started.
    BYTE          d_bchFirstChar; // First character in char width table.
    COLORREF      d_crSelectFore; // Selected object foreground color.
    COLORREF      d_crSelectBack; // Selected object background color.
    CPoint        d_ptCaret;      // Location of keyboard caret.
    HCURSOR       d_hcrIBeam;     // Text area I-Beam.
    HCURSOR       d_hcrLArrow;    // Left arrow for drag/drop.
    HCURSOR       d_hcrRArrow;    // Right arrow for left margin.
    int           d_cxTabStop;    // Width of a tab stop.
    int           d_cxAveCharWidth; // Average width of a character.
    int           d_nFocusMode;   // Current selection and/or focus state.
    int           d_nSelectFirst; // Index of first selected line.
    int           d_nSelectLast;  // Index of last selected line.
    LPINT         d_piCharWidth;  // Table of character widths.
    UINT          d_nTimerID;     // ID of mouse move select timer.

// Operations
public:
    void BuildStringArray();
    BOOL CreateNewFont();
    void ResetScrollValues();
    // [GETTEXT] New operation for opening file from command line.
    void OpenTextFile(CString strFile);

    // [GETTEXT] New operations for caret handling.
    void MoveCaret(int nLine, int nChar);
    void MoveCaretChar(int nCharCount);
    void MoveCaretClick(CPoint ptHit);
    int  QueryClickChar(int iLine, CPoint point);
    int  QueryClickLine(CPoint point);

    // [GETTEXT] New operations for selection handling.
    void GetSelectedRect(CRect * prSelected);
    void InvertLines(int nFirst, int nLast);

// Overrides
    // ClassWizard generated virtual function overrides
    //{{AFX_VIRTUAL(DMainFrame)
    //}}AFX_VIRTUAL

// Implementation
public:
    virtual ~DMainFrame();
#ifdef _DEBUG
    virtual void AssertValid() const;
    virtual void Dump(CDumpContext& dc) const;
#endif

// Generated message map functions
protected:
    //{{AFX_MSG(DMainFrame)
    afx_msg void CmdFileOpen();
    afx_msg void CmdFormatFont();
    afx_msg void CmdFormatTabs();
    afx_msg void UpdFormatTabs(CCmdUI* pCmdUI);
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
    afx_msg void OnKillFocus(CWnd* pNewWnd);
    afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
    afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
    afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
    afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
    afx_msg int OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
    afx_msg void OnNcRButtonDown(UINT nHitTest, CPoint point);
    afx_msg void OnPaint();
    afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
    afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
    afx_msg void OnSetFocus(CWnd* pOldWnd);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnTimer(UINT nIDEvent);
    afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
    afx_msg void OnWinIniChange(LPCTSTR lpszSection);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

// [GETTEXT] Flags (for d_nFocusMode) indicate WM_SETFOCUS action required.
const int FOCUS_EMPTY  = 0;  // No file currently open (hide caret).
const int FOCUS_CARET  = 1;  // Caret visible (no selection).
const int FOCUS_SELECT = 2;  // Selection visible (hide caret).

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -