zoukankan      html  css  js  c++  java
  • Delphi调用WINAPI时到底应该是指针还是结构体(注意是Delphi变量本身就是指针)

    看MSDN,GetWindowRect的说明如下:

    BOOL WINAPI GetWindowRect(
      _In_  HWND   hWnd,
      _Out_ LPRECT lpRect // 注意,没*号指针
    );

    BOOL WINAPI GetWindowPlacement(
      _In_    HWND            hWnd,
      _Inout_ WINDOWPLACEMENT *lpwndpl  // 注意,有*号指针,这里可能已经是双重指针
    );

    但是实际调用直接传递Rect结构体,而不是指针:
    procedure TWinControl.UpdateBounds;
    var
      ParentHandle: HWnd; // 4字节
      Rect: TRect; // 16字节
      WindowPlacement: TWindowPlacement; // 44字节
    begin
      // 非最小化状态下,取得Win控件显示区域
      if IsIconic(FHandle) then // API
      begin
        WindowPlacement.Length := SizeOf(WindowPlacement);
        GetWindowPlacement(FHandle, @WindowPlacement); // API,传递的是指针
        Rect := WindowPlacement.rcNormalPosition;
      end else
        GetWindowRect(FHandle, Rect); // API,取得客户区,注意第二个参数是结构体本身,而不是结构体指针,在Delphi里直接使用
    end;
    
    
    
  • 相关阅读:
    文件操作与函数
    编码格式
    if、while、for快速掌握
    运算符、数据类型、数据结构
    正则表达式
    面向对象--属性
    面向对象--对象的创建
    函数的内置属性
    类型检查
    函数表达式 及 闭包
  • 原文地址:https://www.cnblogs.com/findumars/p/4770275.html
Copyright © 2011-2022 走看看