请问我为什么在 Rich Edit Controls中通过linelength() 获得的总是第行的长度??

Xmotion 2002-07-11 03:32:09
很急,快帮帮我
...全文
115 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
acptvc 2002-07-11
  • 打赏
  • 举报
回复
关于这个问题,其实MSDN上面对这个函数已经有详细地说明了,使用CRichEditCtrl::LineLength函数可以获得一个rich edit control中的一行的长度,该函数的原型如下:
int LineLength(
int nLine = -1
) const;

这里参数nLine的含义跟我们平常接触到的大多数概念不完全一样,它并不是行数,而是该rich edit control中的字符位置,根据此位置计算位于第几行,该函数就获取的是第几行的长度,如果给出的值为-1,则获取的是当前行(光标所在行)的长度。

例如控件中有下列的内容:
abcde
afsljkjgkjkdf
s
......

则调用CRichEditCtrl::LineLength(i),i从0到6,返回值都是5,即第一行的长度。(之所以是i从0到6,因为包括了回车换行的字符,但其长度不记),要到i=7,8,9,……的时候,获取的是第二行的长度,当给出的字符的位置超出了第一行和第二行的字符的总和时,获取的才是第三行的长度。

如果需要进一步的信息,您可以参看:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_CRichEditCtrl.3a3a.LineLength.asp
等相关MSDN信息。


- 微软全球技术中心 VC技术支持

本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款
(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。

为了为您创建更好的讨论环境,请参加我们的用户满意度调查
(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
Xmotion 2002-07-11
  • 打赏
  • 举报
回复
错了,是第一行的长度
TMS Components for IntraWeb allows rich design-time editing of webpages from the Delphi IDE directly on IntraWeb forms. IntraWeb and the TMS Components for IntraWeb allow an unprecedented RAD way of web application development with Delphi, making web development as easy as dropping components on a form. Message dialog Modal dialog control Async events Async updates Input capabilities Highly customisable Treeview Async events Async updates Nodes with checkboxes Nodes with radiobuttons Link, hint, color, images per node Smooth controls TTIWSmoothTimeLine: timeline component TTIWSmoothGauge: gauge component TTIWSmoothLEDLabel: LED label component TTIWSmoothLabel: label with gradient/texture fill Labels TTIWDateLabel: label showing todays date TTIWPopupMenuLabel: label with attached popup menu TTIWGradientLabel: label with gradient background TTIWCalculatingLabel component: client-side calculating label TTIWNoSpamEmail component : email hyperlink that cannot be traced by spambots Menus TTIWStaticMenu: static menu with hover effect TTIWMainMenu, TTIWSideMenu: dropdown menu controls TTIWPopupMenuButton: button with attached popup menu TTIWDocumentPopup: right-click popup menu for document Edit controls TTIWAdvEdit, TTIWDBAdvEdit: advanced edit control TTIWAdvLUEdit, TTIWDBAdvLUEdit: advanced lookup edit control TTIWEMailEdit: edit control with regular expression validation for email TTIWAdvSpinEdit, TTIWDBAdvSpinEdit: data-aware and not data-aware spin edit controls TTIWAdvTimeEdit, TTIWDBAdvTimeEdit: edit component specific for entering time values TTIWAdvDateEdit, TTIWDBAdvDateEdit: edit component specific for entering date values TTIWCCNumEdit: credit card number edit control with client side basic validation TTIWCCExpEdit: credit card expiry date edit control with client side basic validation TTIWFilePicker: edit control with attached file picker button TTIWPersistentEdit: edit control with cookie persistency TTIWEditLinkLink: client side edit to listbox link TTIWTextAreaLimiter component : multi-line textbox with full client-side length limitation and display
TMS Components for IntraWeb allows rich design-time editing of webpages from the Delphi IDE directly on IntraWeb forms. IntraWeb and the TMS Components for IntraWeb allow an unprecedented RAD way of web application development with Delphi, making web development as easy as dropping components on a form. Message dialog Modal dialog control Async events Async updates Input capabilities Highly customisable Treeview Async events Async updates Nodes with checkboxes Nodes with radiobuttons Link, hint, color, images per node Smooth controls TTIWSmoothTimeLine: timeline component TTIWSmoothGauge: gauge component TTIWSmoothLEDLabel: LED label component TTIWSmoothLabel: label with gradient/texture fill Labels TTIWDateLabel: label showing todays date TTIWPopupMenuLabel: label with attached popup menu TTIWGradientLabel: label with gradient background TTIWCalculatingLabel component: client-side calculating label TTIWNoSpamEmail component : email hyperlink that cannot be traced by spambots Menus TTIWStaticMenu: static menu with hover effect TTIWMainMenu, TTIWSideMenu: dropdown menu controls TTIWPopupMenuButton: button with attached popup menu TTIWDocumentPopup: right-click popup menu for document Edit controls TTIWAdvEdit, TTIWDBAdvEdit: advanced edit control TTIWAdvLUEdit, TTIWDBAdvLUEdit: advanced lookup edit control TTIWEMailEdit: edit control with regular expression validation for email TTIWAdvSpinEdit, TTIWDBAdvSpinEdit: data-aware and not data-aware spin edit controls TTIWAdvTimeEdit, TTIWDBAdvTimeEdit: edit component specific for entering time values TTIWAdvDateEdit, TTIWDBAdvDateEdit: edit component specific for entering date values TTIWCCNumEdit: credit card number edit control with client side basic validation TTIWCCExpEdit: credit card expiry date edit control with client side basic validation TTIWFilePicker: edit control with attached file picker button TTIWPersistentEdit: edit control with cookie persistency TTIWEditLinkLink: client side edit to listbox link TTIWTextAreaLimiter component : multi-line textbox with full client-side length limitation and display
TMS Components for IntraWeb allows rich design-time editing of webpages from the Delphi IDE directly on IntraWeb forms. IntraWeb and the TMS Components for IntraWeb allow an unprecedented RAD way of web application development with Delphi, making web development as easy as dropping components on a form. Message dialog Modal dialog control Async events Async updates Input capabilities Highly customisable Treeview Async events Async updates Nodes with checkboxes Nodes with radiobuttons Link, hint, color, images per node Smooth controls TTIWSmoothTimeLine: timeline component TTIWSmoothGauge: gauge component TTIWSmoothLEDLabel: LED label component TTIWSmoothLabel: label with gradient/texture fill Labels TTIWDateLabel: label showing todays date TTIWPopupMenuLabel: label with attached popup menu TTIWGradientLabel: label with gradient background TTIWCalculatingLabel component: client-side calculating label TTIWNoSpamEmail component : email hyperlink that cannot be traced by spambots Menus TTIWStaticMenu: static menu with hover effect TTIWMainMenu, TTIWSideMenu: dropdown menu controls TTIWPopupMenuButton: button with attached popup menu TTIWDocumentPopup: right-click popup menu for document Edit controls TTIWAdvEdit, TTIWDBAdvEdit: advanced edit control TTIWAdvLUEdit, TTIWDBAdvLUEdit: advanced lookup edit control TTIWEMailEdit: edit control with regular expression validation for email TTIWAdvSpinEdit, TTIWDBAdvSpinEdit: data-aware and not data-aware spin edit controls TTIWAdvTimeEdit, TTIWDBAdvTimeEdit: edit component specific for entering time values TTIWAdvDateEdit, TTIWDBAdvDateEdit: edit component specific for entering date values TTIWCCNumEdit: credit card number edit control with client side basic validation TTIWCCExpEdit: credit card expiry date edit control with client side basic validation TTIWFilePicker: edit control with attached file picker button TTIWPersistentEdit: edit control with cookie persistency TTIWEditLinkLink: client side edit to listbox link TTIWTextAreaLimiter component : multi-line textbox with full client-side length limitation and display
unit TreeViewFunctions; interface uses Windows, Messages, SysUtils, Variants, Classes, ComCtrls, Controls, Forms, FileCtrl, StrUtils, Masks, Vcl.OleCtrls, SHDocVw, IOUtils; procedure SaveTreeViewExplandState(TreeView: TTreeView; FileName: string); procedure LoadTreeViewExplandState(TreeView: TTreeView; FileName: string); function ExtractNewFolderPath(FileName: string; NewText: string): string; procedure HideHideHorizontalScrollBar(TreeView: TTreeView); function IsEmptyDir(sDir: String): Boolean; function AttachMentsExists(FileName: String): Boolean; procedure SetIcons(TreeView: TTreeView; list: TStringList); procedure EnumText(s: string; aItem: TTreeNode); function AttachmentsFolder(FileName: String): string; function ExtractNodeFullPath(TreeView: TTreeView): string; function Get_node_path(node: TTreeNode): string; function ExtractTreeViewFileName(RootPath: string; TreeView: TTreeView): string; /// /// Node.Selected := true; Node.Focused := true; /// /// /// Node.Selected := true; Node.Focused := true; /// /// /// Node.Selected := true; Node.Focused := true; /// function OpenFile(Path: string; RichEdit: TRichEdit; TreeView: TTreeView) : Boolean; overload; function OpenFile(Path: string; Webbrowser: TWebbrowser; TreeView: TTreeView) : Boolean; overload; procedure GetDirectories(Tree: TTreeView; Directory: string; Item: TTreeNode; IncludeFiles: Boolean); procedure DirToTreeView(Tree: TTreeView; Directory: string; Root: TTreeNode; IncludeFiles: Boolean; FileExt: string); procedure QSetPerpoty(TreeView: TTreeView); function ItemExist(Text: string; TreeView: TTreeView): Boolean; function RemoveDirs(folderPath: string): Boolean; function __RenameFile(OldName: string; Title: string): Boolean; function RenameFolder(filePath: string; Title: string): Boolean; var list: TStringList; implementation { // "D:\C++Builder学习大全文版\index.htm" // "D:\C++Builder学习大全文版\" // "index_files" // "D:\C++Builder学习大全文版\index_files" var s, s1, s2: string; begin s := 'D:\C++Builder学习大全文版\index.htm'; s1:=ExtractNewFolderPath(s,'_files'); s2 := ExtractNewFolderPath(s, '_AttachMents'); Memo1.lines.Add(s); Memo1.Lines.Add(s1); Memo1.lines.Add(s2); end; } function ExtractNewFolderPath(FileName: string; NewText: string): string; var _filesFolder: string; // "D:\C++Builder学习大全文版\" _filesFolderName: string; // "index_files" _filesFolderPath: String; begin _filesFolder := ExtractFilePath(FileName); _filesFolderName := ChangeFileExt(ExtractFileName(FileName), '') + NewText; _filesFolderPath := _filesFolder + _filesFolderName; Result := _filesFolderPath; end; { SaveTreeViewExplandState(TreeView1,'TreeView.txt'); } procedure SaveTreeViewExplandState(TreeView: TTreeView; FileName: string); var list: TStringList; i: Integer; begin list := TStringList.Create; With TreeView do begin for i := 0 to Items.Count - 1 do begin if Items.Item[i].Expanded then list.Add(IntToStr(i)); end; list.Add(IntToStr(Selected.AbsoluteIndex)); end; list.SaveToFile(FileName); list.free; end; { LoadTreeViewExplandState(TreeView1, 'abc.txt'); } procedure LoadTreeViewExplandState(TreeView: TTreeView; FileName: string); var list: TStringList; i: Integer; node: TTreeNode; begin list := TStringList.Create; with list do begin list.LoadFromFile(FileName); for i := 0 to Count - 2 do // 最后一行放的是最后选的那个节点索引 begin TreeView.Items[StrToInt(list[i])].Expand(False); end; node := TreeView.Items[StrToInt(list[Count - 1])]; TreeView.Select(TreeView.Items[StrToInt(list[Count - 1])], []); // node.Selected := True; // node.Focused := True; TreeView.SetFocus; TreeView.Focused; free; end; end; { FUNCTION ulong ShowScrollBar(ulong hwnd,ulong wBar,ulong bShow) LIBRARY "user32.dll" constant long SB_HORZ = 0 constant long SB_VERT = 1 constant long SB_BOTH = 3 } procedure HideHideHorizontalScrollBar(TreeView: TTreeView); begin // no responed NEW FORM TEST // ShowScrollBar(TreeView.Handle,SB_HORZ,False); end; // procedure // begin // { 当拖拽的高度不够的时候自动滚动滚动条 } // with TreeView1 do // begin // if (Y < 15) then // SendMessage(Handle, WM_VSCROLL, SB_LINEUP, 0) // else if (Height - Y < 15) then // SendMessage(Handle, WM_VSCROLL, SB_LINEDOWN, 0); // end; // end; { 返回 附件文件夹 "D:\C++Builder学习大全文版\新建文本文档.htm" D:\C++Builder学习大全文版\新建文本文档_Attachments } function AttachmentsFolder(FileName: String): string; begin Result := ExtractFilePath(FileName) + ChangeFileExt(ExtractFileName(FileName), '') + '_Attachments'; end; function AttachMentsExists(FileName: String): Boolean; var f: string; begin f := ExtractFilePath(FileName) + ChangeFileExt(ExtractFileName(FileName), '') + '_Attachments'; Result := DirectoryExists(f); end; procedure EnumText(s: string; aItem: TTreeNode); var node: TTreeNode; str: string; begin node := aItem; while node nil do begin if s = '' then str := node.Text else str := s + '\' + node.Text; list.Add(str); /// ////////////////////////// if node.HasChildren then EnumText(str, node.getFirstChild); node := node.getNextSibling; end; end; function IsEmptyDir(sDir: String): Boolean; var sr: TSearchRec; begin Result := True; if Copy(sDir, Length(sDir) - 1, 1) '\' then sDir := sDir + '\'; if FindFirst(sDir + '*.*', faAnyFile, sr) = 0 then repeat if (sr.Name '.') and (sr.Name '..') then begin Result := False; break; end; until FindNext(sr) 0; FindClose(sr); end; { 是文件 夹的设置为1 是文件 的设置为 2 } procedure SetIcons(TreeView: TTreeView; list: TStringList); var i: Integer; begin with TreeView do begin for i := 0 to Items.Count - 1 do begin if DirectoryExists(list.Strings[i]) then begin Items[i].ImageIndex := 0; Items[i].SelectedIndex := 0; Items[i].StateIndex := 0; end; if FileExists(list.Strings[i]) then begin Items[i].ImageIndex := 1; Items[i].SelectedIndex := 1; Items[i].StateIndex := 1; end; if (AttachMentsExists(list.Strings[i])) then if not IsEmptyDir(AttachmentsFolder(list.Strings[i])) then begin // Form1.Memo1.LINES.Add( AttachmentsFolder(list.Strings[i])); Items[i].ImageIndex := 2; Items[i].SelectedIndex := 2; Items[i].StateIndex := 2; end; end; end; end; procedure QSetPerpoty(TreeView: TTreeView); begin with TreeView do begin // Align := alBottom; // Anchors := [akLeft, akTop, akBottom, akRight]; Items.Clear; // BorderStyle := bsNone; Cursor := crHandPoint; ReadOnly := True; ShowHint := True; RowSelect := True; ShowButtons := True; ShowRoot := True; ShowLines := False; SortType := stText; HideSelection := False; RightClickSelect := True; DragMode := dmAutomatic; // Color := RGB(238, 243, 246); end; end; { 实际重命名 C:\windows\test.txt C:\windows\csadsajas.txt MoveFile(PChar('C:\1.txt'),PChar('C:\ABC.txt')); if not __RenameFile('C:\tree.txt','TreeView') then Application.MessageBox('重命名文件失败','重命名',MB_ICONERROR); } { 重命名文件 } function __RenameFile(OldName: string; Title: string): Boolean; var NewName: string; begin NewName := Format('%s%s%s', [ExtractFilePath(OldName), Title, ExtractFileExt(OldName)]); Result := MoveFile(PChar(OldName), PChar(NewName)); end; // 重命名文件夹 // RenameFolder('C:\1\','2'); // MoveFile('C:\1','C:\2'); // MoveFile('C:\1\','C:\2\'); function RenameFolder(filePath: string; Title: string): Boolean; var s, s1: string; begin // filePath:='C:\Windows\System32\'; // s = ExtractFileDir(filepath) = 'C:\Windows\System32' s := ExtractFileDir(filePath); // s1 = ExtractFileDir(s) = 'C:\Windows' // s1 ='C:\Windows' +'\'+ titles s1 := ExtractFileDir(s) + '\' + Title; Result := MoveFile(PChar(s), PChar(s1)); end; { IOUtils } function RemoveDirs(folderPath: string): Boolean; begin Result := False; if TDirectory.IsEmpty(folderPath) then begin TDirectory.Delete(folderPath); Result := True; end else begin if Application.MessageBox('确定要删除这个文件夹吗? 删除后无法恢复!', '提示', MB_ICONQUESTION + MB_YESNO) = ID_YES then begin TDirectory.Delete(folderPath, True); Result := True; end; end; // if TDirectory.Exists(folderPath) then // begin // Application.MessageBox('删除文件失败'+#13#10+'文件正确被使用?','错误',MB_ICONERROR+MB_OK); // Result:=False; // end; end; { if not ItemExist('Edit1.Text',TreeView1) then TreeView1.Items.AddChild(Treeview1.Selected,'Edit1.Text'); } function ItemExist(Text: string; TreeView: TTreeView): Boolean; var i: Integer; begin Result := False; if (Trim(Text) '') then begin for i := 0 to TreeView.Items.Count - 1 do if Trim(Text) = Trim(TreeView.Items[i].Text) then begin Result := True; Exit; end; end; Result := False; end; // ------------------------------------------------------------------------------ { TreeView获得的完整路径 aaaa\ssss\bbbb } function ExtractNodeFullPath(TreeView: TTreeView): string; var Path: string; Parent: TTreeNode; // Node: TTreeNode; begin Path := TreeView.Selected.Text; Parent := TreeView.Selected.Parent; while Parent nil do begin Path := Parent.Text + '\' + Path; Parent := Parent.Parent; end; Result := Path; end; function Get_node_path(node: TTreeNode): string; var Path: string; TreeNode: TTreeNode; begin Path := node.Text; TreeNode := node.Parent; while TreeNode nil do begin Path := TreeNode.Text + '\' + Path; TreeNode := TreeNode.Parent; end; Result := Path; end; { 获得文件完整路径 C:\abc\int.cpp } function ExtractTreeViewFileName(RootPath: string; TreeView: TTreeView): string; var FileName: string; begin Result := ''; if TreeView.Selected = nil then Exit; FileName := RootPath + ExtractNodeFullPath(TreeView); // 当前选的文件名 if not FileExists(FileName) then Exit; Result := FileName; end; { 用RICHEDIT打开TREEVIEW的文件 } function OpenFile(Path: string; RichEdit: TRichEdit; TreeView: TTreeView) : Boolean; overload; var FileName: string; begin Result := False; FileName := ExtractTreeViewFileName(Path, TreeView); if FileExists(FileName) then begin RichEdit.Lines.LoadFromFile(FileName); Result := True; end end; function OpenFile(Path: string; Webbrowser: TWebbrowser; TreeView: TTreeView) : Boolean; overload; var FileName: string; begin Result := False; FileName := ExtractTreeViewFileName(Path, TreeView); if FileExists(FileName) then begin Webbrowser.Navigate(FileName); Result := True; end end; { 将1个目录里面所有的文件添加到TREEVIEW GetDirectories(TreeView1, 'D:\DATA', nil, True); } procedure GetDirectories(Tree: TTreeView; Directory: string; Item: TTreeNode; IncludeFiles: Boolean); var SearchRec: TSearchRec; ItemTemp: TTreeNode; begin Tree.Items.BeginUpdate; if Directory[Length(Directory)] '\' then Directory := Directory + '\'; if FindFirst(Directory + '*.*', faDirectory, SearchRec) = 0 then begin repeat if (SearchRec.Attr and faDirectory = faDirectory) and (SearchRec.Name[1] '.') then begin if (SearchRec.Attr and faDirectory > 0) then Item := Tree.Items.AddChild(Item, SearchRec.Name); ItemTemp := Item.Parent; GetDirectories(Tree, Directory + SearchRec.Name, Item, IncludeFiles); Item := ItemTemp; end else if IncludeFiles then if SearchRec.Name[1] '.' then Tree.Items.AddChild(Item, SearchRec.Name); until FindNext(SearchRec) 0; FindClose(SearchRec); Tree.Items.EndUpdate; end; end; { 将1个目录里面所有的文件添加到TREEVIEW DirToTreeView(TreeView1,'D:\Data\',nil,True,'.cpp'); } procedure DirToTreeView(Tree: TTreeView; Directory: string; Root: TTreeNode; IncludeFiles: Boolean; FileExt: string); var SearchRec: TSearchRec; Node1: TTreeNode; begin with Tree.Items do begin BeginUpdate; if Directory[Length(Directory)] '\' then Directory := Directory + '\'; if FindFirst(Directory + '*.*', faDirectory, SearchRec) = 0 then begin Application.ProcessMessages; repeat { 添加文件夹 } if (SearchRec.Attr and faDirectory = faDirectory) and (SearchRec.Name[1] '.') then begin if SameText(RightStr(SearchRec.Name, 12), '_AttachMents') then // 不添加 _AttachMents这个文件夹 Continue; if (SearchRec.Attr and faDirectory > 0) then Root := AddChild(Root, SearchRec.Name); Node1 := Root.Parent; DirToTreeView(Tree, Directory + SearchRec.Name, Root, IncludeFiles, FileExt); Root := Node1; end else if IncludeFiles then { 添加文件 } if SearchRec.Name[1] '.' then { .TXT .txt .TxT .tXT 为一样的 } if SameText(RightStr(SearchRec.Name, 4), FileExt) then { 只添加 .CPP格式文件 } AddChild(Root, SearchRec.Name); until FindNext(SearchRec) 0; FindClose(SearchRec) end; EndUpdate; end; end; end.

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧