谁能告诉我 怎么获得光标位置 ? 
在一个窗体上显示一个数据库的内容  光标在某一个字段上  怎么定位?
我是说 数据库有4个字段  在显示的数据库下面放4个Edit  开始的时候4个Edit都不可见  光标定位在哪个字段  相应地这个字段下面的Edit就出现

解决方案 »

  1.   

    二个API函数
    GetCursorPos
    GetCaretPos
      

  2.   

    CPoint point;
    GetCursorPos(&point);
    vc里面
      

  3.   

    晕,把分给我! ceocio是骗子!!  hoho~~~~
      

  4.   

    你告诉我怎么实现  我就给你分
    hkbarton(宁静至远||淡泊明志) :晕,把分给我! ceocio是骗子!!  hoho~~~~
      

  5.   

    procedure TForm1.Timer1Timer(Sender: TObject);
    var
    cursor_postion:tpoint;
    handle:hwnd;
    class_name:pchar;
    intResult:integer;
    strClassName:string;
    begin
    Timer1.Enabled :=false;
    getcursorpos(cursor_postion);
    handle:=windowfrompoint(cursor_postion);
    if handle<>0 then
       begin
       GetMem(class_name,256);
       intResult:=getclassname(handle,class_name,256);
       //showmessage(inttostr(intResult));//判断是否得到类型
       form1.Memo1.Lines.Add(Trim(string(class_name)));
       FreeMem(Class_Name);
       end;
    timer1.Enabled :=true;
    end;
      

  6.   

    能不能说的清楚一点  怎么用  谢谢您ghyghost(爱国人士) :二个API函数
    GetCursorPos
    GetCaretPos
      

  7.   

    GetCaretPos, 判断插入符的当前位置procedure TForm1.Timer1Timer(Sender: TObject);
    var
    cursor_postion:tpoint;
    handle:hwnd;
    class_name:pchar;
    intResult:integer;
    strClassName:string;
    begin
    Timer1.Enabled :=false;
    GetCaretPos(cursor_postion);
    handle:=windowfrompoint(cursor_postion);
    if handle<>0 then
       begin
       GetMem(class_name,256);
       intResult:=getclassname(handle,class_name,256);
       //showmessage(inttostr(intResult));//判断是否得到类型
       form1.Memo1.Lines.Add(Trim(string(class_name)));
       FreeMem(Class_Name);
       end;
    timer1.Enabled :=true;
    end;改一下函数名就可以了,
      

  8.   

    to  ghyghost(爱国人士) :   程序好象不大对,我要得到的是数据库中字段的名字__________________________________________________________________________________
    procedure TForm1.Timer1Timer(Sender: TObject);
    var
    cursor_postion:tpoint;
    handle:hwnd;
    class_name:pchar;
    intResult:integer;
    strClassName:string;
    begin
    Timer1.Enabled :=false;
    getcursorpos(cursor_postion);
    handle:=windowfrompoint(cursor_postion);
    if handle<>0 then
       begin
       GetMem(class_name,256);
       intResult:=getclassname(handle,class_name,256);
       //showmessage(inttostr(intResult));//判断是否得到类型
       form1.Memo1.Lines.Add(Trim(string(class_name)));
       FreeMem(Class_Name);
       end;
    timer1.Enabled :=true;
    end;
      

  9.   

    The GetCursorPos function retrieves the cursor's position, in screen coordinates. BOOL GetCursorPos(    LPPOINT lpPoint  // address of structure for cursor position  
       );
     ParameterslpPointPoints to a POINT structure that receives the screen coordinates of the cursor.  Return ValuesIf the function succeeds, the return value is nonzero.
    If the function fails, the return value is zero. To get extended error information, call GetLastError.ResThe cursor position is always given in screen coordinates and is not affected by the mapping mode of the window that contains the cursor. 
    The calling process must have WINSTA_READATTRIBUTES access to the window station. See Also
      

  10.   

    晕,你的字段用什么显示的?DBGrid? Label?
    用 OnMouseMove 事件不就行了
      

  11.   

    hiflower(花) :晕,你的字段用什么显示的?DBGrid? Label?
    用 OnMouseMove 事件不就行了谢谢您~!我的字段是用DBGrid显示的   您能帮我把代码写出来吗?
      

  12.   

    ghyghost(爱国人士) :你把你的程序要求详细一下如下:1:增加一个“设置”按钮,用来修改数据库中的项。(改成“修改”按纽了)
    例如: 将电视的价格提高100元。
    将掌上电脑的型号改变。2:增加一个“高级设置”按钮,用来添加数据项。(改成“添加”按纽了)
    增加一个新的可选物品,包括名字,价格等数据。
    在随即选取的时候,可以选择到这个物品。
      

  13.   

    procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    var
      RowIndex,ColumnIndex:Integer;
    begin
      RowIndex:=DBGrid1.MouseCoord(X,Y).Y-1;
      ColumnIndex:=DBGrid1.MouseCoord(X,Y).X-1;//根据 ColumnIndex 可得知字段名:Columns[ColumnIndex].FieldName
    end;
      

  14.   

    hiflower(花) :谢谢您~!  我试一下  成功了就给分
      

  15.   

    hiflower(花) :谢谢您~!  我试一下  成功了就给分  不过 您的程序是不是没写完
      

  16.   

    呵呵,那是上一行的注释内容,CSDN 帮我换行了。
    知道了字段名,你可以自己做了
      

  17.   

    那你还是没说清楚啊   知道字段名有什么用  要定位到具体的内容的  hiflower(花) :
    呵呵,那是上一行的注释内容,CSDN 帮我换行了。
    知道了字段名,你可以自己做了
      

  18.   

    var
    p:tpoint;
    getcursorpos(p);