热情软件屋

 

如何正确调用GetClientRect和DrawText


编号:QA003471
建立日期: 2000年10月26日 最后修改日期:2000年10月26日
所属类别:

LEng_YiMin:
    操作系统: Windows98
    编程工具: Pb
    问题: 我在编写一个 Powerbuilder 程序的时侯遇到一个问题:
    比如:
     1: 首先建立一个 Visual Custom User Object 并声明 Local External Function:
     Function ulong GetDC (ulong hWnd) Library "USER32.DLL"
     Function int DrawText(ulong hdc, ref string stext, int cnt,ref RECT qrc, uint tfmt) library user32.dll"
     Function boolean GetClientRect(ulong hdc, ref RECT rc ) Library USER32.DLL"
     function boolean rawEdge(ulong hdc,ref RECT qrc, uint edge,
     Uint grfFlags) library "user32.dll"
     其中: RECT 是一 User Object Structure ,成员如下:
     left, Top, Right, Bottom ( 均为 ULONG 类型 )
    在 pbm_lButtonClk ( 自定义 User Even ) 中写如下脚本:
    RECT clientRC
    String ls_S1
    ls_S1="AAAAA"
    GetClientRect(GetDC(handle(this)), clientRC)
    DrawText(GetDC(handle(this)), ls_S1, -1, clientRC, 1+4+32)
    DrawEdge(GetDC(handle(this)), clientRC, 4, 1+2+4+8 )
    问题有三:
     1: GetClientRect 无法改变 RECT 成员变量
     2: DrawText 执行出错
     3: 手工改变 clientRC 四个变量 比如:
     clientRC.Right=PixelsToUnits(30, XPixelsToUnits!)
     clientRC.Bottom=PixelsToUnits(20, YPixelsToUnits!)
    则 DrawEdge 执行正常, DrawText 仍无法执行
    用 VB 试之 GetClientRect 也无法改变 RECT 成员变量
     DrawEdge , DrawText 均执行正常,琢磨几日不得要领, 查看 SDK API 帮助文件发现 对 RECT 的解释是有区别的. 但仍不知道究竟如何运用之。请您指点如何声明及运用上述 3 个函数, 特别是 GetClientRect,DrawText。望不吝赐教, 不胜感激。

回答:

    我认为有几个错误在里面:
    1)函数声明错误DrawText应声明如下,变量名不能随便更改
    FUNCTION ulong DrawText(ulong hdc,ref string lpStr,ulong nCount,ref RECT lpRect,ulong wFormat) LIBRARY "user32.dll" ALIAS FOR "DrawTextA"
    2)函数GetClientRect是用来取得Mdi Windows的Client区域,应用错误
     可以改为
     clientRC.Right=UnitsToPixels (this.width, XUnitsToPixels! )
     clientRC.Bottom=UnitsToPixels (this.height, YUnitsToPixels! )
    3)定义RECT结构顺序错误,应该是left,top,right,bottom 而且应该为LONG
    4)应该定义ReleaseDc释放内存
    以上我在PB7.0中成功测试过。

此问题由mrliu回答。

 
把这个问题推荐给朋友
   
   
您的意见类别
您的名字
您的电子邮件
您的建议(请尽可能详细)
 
 

版权所有 1997-2008 热情软件屋
如果您有任何建议和意见, 请给我发个电子邮件 askpro@china-askpro.com
Web Designed by ZebraStudio