📄 control.h
字号:
/*------------------------------------------------------------------------------*
* File Name: Control.h *
* Creation: TD 11/12/2002 *
* Purpose: Origin C support for Windows controls *
* Copyright (c) OriginLab Corp.2002 *
* All Rights Reserved *
* *
* Modification Log: *
*------------------------------------------------------------------------------*/
#ifndef _CONTROL_H
#define _CONTROL_H
//#include <Common.h>
//#include <String.h>
//#include <Page.h>
#include <MSWin.h>
/** >User Interface Controls
This class is only available to OriginPro users.
Example:
*/
class Control : public Window
{
public:
/**
Example:
Control cntl;
cntl = MyDlg.GetItem(IDC_BUTTON1);
*/
Control();
/**
*/
Control(Control& ctrl);
/**
Example:
Control cntl = MyDlg.GetItem(IDC_BUTTON_OPEN);
BOOL bRet = cntl.SetToolTip("Open File");
*/
BOOL SetToolTip(LPCSTR lpcszTxt);
/**
Example:
Control cntl = MyDlg.GetItem(IDC_CHECK1);
cntl.Value = 1;
ASSERT( 1 == cntl.Value );
*/
int Value;
};
/** >User Interface Controls
This class is only available to OriginPro users.
Example:
*/
class Edit : public Control
{
public:
/**
*/
Edit();
/**
*/
Edit(Control& ctrl);
/**
Call this function to retrieve the bounds of the current selection.
Example:
Edit ed = MyDlg.GetItem(IDC_EDIT1);
long nStartChar, nEndChar;
ed.GetSel(nStartChar, nEndChar);
Parameters:
nStartChar
Zero-based index of the first character in the current selection.
nEndChar
Zero-based index of the last character in the current selection.
Return:
void
SeeAlso:
SetSel();
*/
void GetSel(int& nStartChar, int& nEndChar);
/**
Call this function to set the selection in the Edit control
Example:
Edit ed = MyDlg.GetItem(IDC_EDIT1);
ed.SetSel(32000, 32000); // move to end of all text
Parameters:
nStartChar = Zero-based index of the first character in the current selection.
nEndChar = Zero-based index of the last character in the current selection.
bNoScroll = Indicates whether the caret should be scrolled into view.
If FALSE, the caret is scrolled into view. If TRUE, the caret is not scrolled into view.
Return:
void
SeeAlso:
GetSel();
*/
void SetSel(int nStartChar, int nEndChar, BOOL bNoScroll = FALSE);
/**
Replaces the current selection in this Edit control with specified text.
Example:
Edit ed = MyDlg.GetItem(IDC_EDIT1);
ed.SetSel(32000, 32000); // move to end of all text
string str = "Sample"
ed.ReplaceSel(str);
Parameters:
lpcszNewText = Pointer to a null-terminated string containing the replacement text.
bCanUndo = To specify that this function can be undone, set the value of this parameter to TRUE. The default value is FALSE.
Return:
void
SeeAlso:
SetSel();
*/
void ReplaceSel(LPCTSTR lpcszNewText, BOOL bCanUndo = FALSE);
/**
Get index of first character in a line
Example:
Edit ed = MyDlg.GetItem(IDC_EDIT1);
int nIndex = ed.LineIndex();
Parameters:
nLine = Contains the index value for the desired line in the text of the edit control, or contains -1.
If nLine is -1, it specifies the current line, that is, the line that contains the caret.
Return:
The character index of the line specified in nLine or -1 if the specified line number is greater then the number of lines in the edit control.
Remarks:
Call this function to retrieve the character index of a line within a multiple-line edit control.
The character index is the number of characters from the beginning of the edit control to the specified line.
*/
int LineIndex( int nLine = -1 ) const;
/**
Example:
Edit ed = MyDlg.GetItem(IDC_EDIT1);
int nLine = ed.LineFromChar();
*/
int LineFromChar( int nIndex = -1 ) const;
/**
Example:
Edit ed = MyDlg.GetItem(IDC_EDIT1);
int nLength = ed.LineLength();
*/
int LineLength( int nLine = -1 ) const;
/**
Example:
Edit ed = MyDlg.GetItem(IDC_EDIT1);
int nCount = ed.GetLineCount();
*/
int GetLineCount( ) const;
};
//--------------------------------------------------------------------------
// RichEdit control
//--------------------------------------------------------------------------
typedef struct _charformat {
UINT cbSize;
DWORD dwMask;
DWORD dwEffects;
LONG yHeight;
LONG yOffset;
COLORREF crTextColor;
BYTE bCharSet;
BYTE bPitchAndFamily;
char szFaceName[LF_FACESIZE];
} CHARFORMAT;
/* CHARFORMAT masks */
#define CFM_BOLD 0x00000001
#define CFM_ITALIC 0x00000002
#define CFM_UNDERLINE 0x00000004
#define CFM_STRIKEOUT 0x00000008
#define CFM_PROTECTED 0x00000010
#define CFM_LINK 0x00000020 /* Exchange hyperlink extension */
#define CFM_SIZE 0x80000000
#define CFM_COLOR 0x40000000
#define CFM_FACE 0x20000000
#define CFM_OFFSET 0x10000000
#define CFM_CHARSET 0x08000000
/* CHARFORMAT effects */
#define CFE_BOLD 0x0001
#define CFE_ITALIC 0x0002
#define CFE_UNDERLINE 0x0004
#define CFE_STRIKEOUT 0x0008
#define CFE_PROTECTED 0x0010
#define CFE_LINK 0x0020
#define CFE_AUTOCOLOR 0x40000000 /* NOTE: this corresponds to */
/* CFM_COLOR, which controls it */
/* Event notification masks */
#define ENM_NONE 0x00000000
#define ENM_CHANGE 0x00000001
#define ENM_UPDATE 0x00000002
#define ENM_SCROLL 0x00000004
#define ENM_KEYEVENTS 0x00010000
#define ENM_MOUSEEVENTS 0x00020000
#define ENM_REQUESTRESIZE 0x00040000
#define ENM_SELCHANGE 0x00080000
#define ENM_DROPFILES 0x00100000
#define ENM_PROTECTED 0x00200000
#define ENM_CORRECTTEXT 0x00400000 /* PenWin specific */
#define ENM_SCROLLEVENTS 0x00000008
#define ENM_DRAGDROPDONE 0x00000010
/** >User Interface Controls
This class is only available to OriginPro users.
Example:
*/
class RichEdit : public Control
{
public:
/**
*/
RichEdit();
/**
*/
RichEdit(Control& ctrl);
/**
Sets the character formatting attributes in the current selection in this RichEdit control.
Example:
RichEdit richEdit = EditBoxes.GetItem(IDC_RICHEDIT1);
CHARFORMAT cf;
cf.dwEffects = CFE_BOLD;
cf.dwMask = CFM_STRIKEOUT|CFM_BOLD;
richEdit.SetSelectionCharFormat(cf);
CHARFORMAT cfResult;
richEdit.GetSelectionCharFormat(cfResult);
ASSERT((cfResult.dwMask&(CFM_STRIKEOUT|CFM_BOLD)) == (CFM_STRIKEOUT|CFM_BOLD));
ASSERT((cfResult.dwEffects & (CFE_STRIKEOUT|CFE_BOLD) ) == CFE_BOLD);
Parameters:
cf = CHARFORMAT structure containing the new character
formatting attributes for the current selection.
Return:
Nonzero if successful; otherwise, 0.
Remarks:
Call this function to set the character formatting attributes
for the text in the current selection in this RichEdit control.
Only the attributes specified by the dwMask member of cf are
changed by this function.
SeeAlso:
RichEdit::GetSelectionCharFormat
*/
BOOL SetSelectionCharFormat(CHARFORMAT& cf);
/**
Gets the starting and ending positions of the current
selection in this RichEdit control.
Example:
RichEdit richEdit = EditBoxes.GetItem(IDC_RICHEDIT1);
long nStartChar, nEndChar;
richEdit.GetSel(nStartChar, nEndChar);
string str;
str.Format("Start:%d, End:%d\n", nStartChar, nEndChar);
MessageBox(NULL, str, "Rich Edit Sample");
Parameters:
nStartChar = Zero-based index of the first character in
the current selection.
nEndChar = Zero-based index of the last character in
the current selection.
Return:
void
Remarks:
Call this function to retrieve the bounds of
the current selection in this RichEdit control.
SeeAlso:
RichEdit::SetSel
*/
void GetSel(long& nStartChar, long& nEndChar);
/**
Sets the selection in this RichEdit control.
Example:
RichEdit richEdit = EditBoxes.GetItem(IDC_RICHEDIT1);
// Select the character between 0 and 10
richEdit.SetSel(0, 10);
long nStartChar, nEndChar;
richEdit.GetSel(nStartChar, nEndChar);
ASSERT(0 == nStartChar && 10 == nEndChar);
Parameters:
nStartChar = Zero-based index of the first character
in the current selection.
nEndChar = Zero-based index of the last character
in the current selection.
Return:
void
Remarks:
Call this function to set the selection within this RichEdit control.
To select all the text in this RichEdit control, call SetSel
with a start index of 0 and an end index of -1.
SeeAlso:
RichEdit::GetSel
*/
void SetSel(long nStartChar, long nEndChar);
/**
Replaces the current selection in this RichEdit control with specified text.
Example:
RichEdit richEdit = EditBoxes.GetItem(IDC_RICHEDIT1);
richEdit.SetSel(0, -1);
string str = "Sample";
richEdit.ReplaceSel(str, FALSE);
ASSERT( richEdit.Text == str );
Parameters:
lpszNewText = Pointer to a null-terminated string
containing the replacement text.
bCanUndo = To specify that this function can be undone,
set the value of this parameter to TRUE. The default value is FALSE.
Return:
void
Remarks:
Call this function to replace the current selection in this
RichEdit control with the specified text. To replace all the
text in this RichEdit control, use the function Text.
If there is no current selection, the replacement text is inserted
at the insertion point, that is, the current caret location.
SeeAlso:
RichEdit::SetSel
*/
void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo = FALSE);
/**
Gets the text of the current selection in this RichEdit control
Example:
RichEdit richEdit = EditBoxes.GetItem(IDC_RICHEDIT1);
richEdit.SetSel(0, -1);
string str = richEdit.GetSelText();
ASSERT( richEdit.Text == str );
Parameters:
nStartChar = Zero-based index of the first character
in the current selection.
nEndChar = Zero-based index of the last character
in the current selection.
Return:
The string containing the current selection.
Remarks:
Call this function to retrieve the text from
the current selection in this RichEdit control.
SeeAlso:
none.
*/
string GetSelText();
/**
Sets the read-only option for this RichEdit control
Example:
RichEdit richEdit = EditBoxes.GetItem(IDC_RICHEDIT1);
richEdit.SetReadOnly(FALSE);
Parameters:
bReadOnly = Indicates if this RichEdit control should be read only.
Return:
Nonzero if successful; otherwise, 0.
Remarks:
Call this member function to change the read-only
option for this RichEdit control.
SeeAlso:
none.
*/
BOOL SetReadOnly(BOOL bReadOnly = TRUE);
/**
Determines the topmost visible line in this RichEdit control.
Example:
RichEdit richEdit = EditBoxes.GetItem(IDC_RICHEDIT1);
int nFirstVisible = richEdit.GetFirstVisibleLine();
// Scroll the rich edit control so that the first visible line is the first line of text.
if (nFirstVisible > 0)
richEdit.LineScroll(-nFirstVisible, 0);
Return:
Zero-based index of the uppermost visible line in this RichEdit control.
Remarks
Call this function to determine the topmost
visible line in this RichEdit control.
SeeAlso:
RichEdit::LineScroll.
*/
int GetFirstVisibleLine();
/**
Determines if the contents of this RichEdit control have changed since the last save.
Example:
RichEdit richEdit = EditBoxes.GetItem(IDC_RICHEDIT1);
BOOL bModify = richEdit.GetModify();
Parameters:
nStartChar = Zero-based index of the first character in the current selection.
nEndChar = Zero-based index of the last character in the current selection.
Return:
Nonzero if the text in this RichEdit control has been modified; otherwise 0.
Remarks
Call this function to determine if the contents of this RichEdit
control have been modified. Window maintains an internal flag
indicating whether the contents of the rich edit control
have been changed. This flag is cleared when the edit control
is first created and can also be cleared by calling the
SetModify member function.
SeeAlso:
none.
*/
BOOL GetModify();
/**
Sets or clears the modification flag for this RichEdit control.
Example:
RichEdit richEdit = EditBoxes.GetItem(IDC_RICHEDIT1);
richEdit.SetModify();
Parameters:
bModified = A value of TRUE indicates that the text has been modified,
and a value of FALSE indicates it is unmodified. By default, the modified flag is set.
Return:
void
Remarks
Call this function to set or clear the modified flag for an edit control.
The modified flag indicates whether or not the text within the edit control
has been modified. It is automatically set whenever the user changes the text.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -