对不起,少写可两个字符.应该是:
::GetCaretPos();
::ClientToScreen();
我试过了,可以的.
<h2>unit1.cpp:</h2>
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::REMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if(Button!=mbRight)
return;
POINT p;
if(GetCaretPos(&p)==false)
return;
if
:ClientToScreen(RE->Handle,&p)==false)
return;
PopTest->Popup(p.x,p.y);
}
//---------------------------------------------------------------------------
<h2>unit1.h:</h2>
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <Menus.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TRichEdit *RE;
TPopupMenu *PopTest;
TMenuItem *Test1;
void __fastcall REMouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
<h2>unit1.dfm:</h2>
object Form1: TForm1
Left = 192
Top = 112
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object RE: TRichEdit
Left = 16
Top = 12
Width = 425
Height = 281
Font.Charset = GB2312_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Lines.Strings = (
'#include "Unit1.h"'
'//--------------------------------------------------------------' +
'-----'
'--------'
'#pragma package(smart_init)'
'#pragma resource "*.dfm"'
'TForm1 *Form1;'
'//--------------------------------------------------------------' +
'-----'
'--------'
'__fastcall TForm1::TForm1(TComponent* Owner)'
' : TForm(Owner)'
'{'
'}'
'//--------------------------------------------------------------' +
'-----'
'--------'
'void __fastcall TForm1::REMouseDown(TObject *Sender, TMouseButto' +
'n '
'Button,'
' TShiftState Shift, int X, int Y)'
'{'
' POINT p;'
' if(GetCaretPos(&p)==false)'
' return;'
''
' if
:ClientToScreen(RE->Handle,&p)==false)'
' return;'
' PopTest->Popup(p.x,p.y);'
'}')
ParentFont = False
TabOrder = 0
OnMouseDown = REMouseDown
end
object PopTest: TPopupMenu
Left = 472
Top = 140
object Test1: TMenuItem
Caption = 'Test'
end
end
end