人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當(dāng)前位置:蘿卜系統(tǒng)下載站 > 技術(shù)開發(fā)教程 > 詳細(xì)頁面

尋找windows的任務(wù)欄  

尋找windows的任務(wù)欄  

更新時間:2022-10-06 文章作者:未知 信息來源:網(wǎng)絡(luò) 閱讀次數(shù):

譯:DBoy

    有些時候也許你想知道當(dāng)前windows的任務(wù)欄在窗口的什么位置,這當(dāng)然也可以用Delphi來實現(xiàn)。Windows API 函數(shù)允許您得到有關(guān)任務(wù)欄(也可稱為應(yīng)用程序欄)的信息。訪問下面的微軟MSDN地址可以了解到更多有關(guān)于這個函數(shù)調(diào)用的信息:       http://msdn.microsoft.com/library/psdk/shellcc/shell/Functions/SHAppBarMessage.htm 。這篇文檔主要集中在為該函數(shù)傳遞ABM_GETTASKBARPOS消息上。
    你可以按照下面的方法自己創(chuàng)建一個應(yīng)用程序,或從以下的Borland代碼中心網(wǎng)址下載到程序的原代碼:http://codecentral.borland.com/codecentral/ccweb.exe/download?id=15681 。
    首先,也許你很想知道這個API究竟是在哪個單元聲明的。在MSDN中它被聲明在shellapi.h里,而在Delphi中它被聲明在shellapi.pas里。因此你要把shellapi添加到你的uses列表中。然后請看下面的函數(shù)示例:
// FindTaskBar 返回任務(wù)欄的位置,寫到ARect中。
function FindTaskBar(var ARect: TRect): Integer;
var
AppData: TAppBarData;
begin
  // ’Shell_TrayWnd’ 是任務(wù)欄窗口的名子
  AppData.Hwnd := FindWindow(’Shell_TrayWnd’, nil);
  if AppData.Hwnd = 0 then
    RaiseLastWin32Error;
  AppData.cbSize := SizeOf(TAppBarData);
  //當(dāng)有錯誤發(fā)生時, SHAppBarMessage 會返回False (0)
  if SHAppBarMessage(ABM_GETTASKBARPOS, AppData) = 0 then
    raise Exception.Create(’SHAppBarMessage returned false when trying ’ +
      ’to find the Task Bar’’s position’);
  // 否則的話,我們就成功了,把結(jié)果寫到Result中。
  Result := AppData.uEdge;
  ARect := AppData.rc;
end;

    當(dāng)你把以上代碼加到你的應(yīng)用程序時,你就可以使用該函數(shù)了。添加一個TLabel和TButton到你的Form中,在Button的click事件中加入以下的代碼。
var
  Rect: TRect;
  DestLeft: Integer;
  DestTop: Integer;
begin
  DestLeft := Left;
  DestTop := Top;
  case FindTaskBar(Rect) of
    ABE_BOTTOM:
    begin
      DestLeft := Trunc((Screen.Width - Width) / 2.0);
      DestTop := Rect.Top - Height;
    end;
    ABE_LEFT:
    begin
      DestTop := Trunc((Screen.Height - Height) / 2.0);
      DestLeft := Rect.Right;
    end;
    ABE_RIGHT:
    begin
      DestTop := Trunc((Screen.Height - Height) / 2.0);
      DestLeft := Rect.Left - Width;
    end;
    ABE_TOP:
    begin
      DestLeft := Trunc((Screen.Width - Width) / 2.0);
      DestTop := Rect.Bottom;
    end;
  end;
  Label1.Caption := Format(’Found at Top: %d Left: %d Bottom: %d Right: %d)’,
    [Rect.Top, Rect.Left, Rect.Bottom, Rect.Right]);
  // Move us to the task bar
  while (Left <> DestLeft) or (Top <> DestTop) do
  begin
    if Left < DestLeft then
      Left := Left + 1
    else if Left <> DestLeft then
      Left := Left - 1;

    if Top < DestTop then
      Top := Top + 1
    else if Top <> DestTop then
      Top := Top - 1;

    Application.ProcessMessages;
  end;
end;

溫馨提示:喜歡本站的話,請收藏一下本站!

本類教程下載

系統(tǒng)下載排行

網(wǎng)站地圖xml | 網(wǎng)站地圖html
主站蜘蛛池模板: 安顺市| 呼图壁县| 金乡县| 东台市| 班戈县| 九江县| 长阳| 交口县| 怀远县| 潮安县| 黎平县| 泸西县| 乌拉特后旗| 太仓市| 乌拉特中旗| 从江县| 德庆县| 崇明县| 佛学| 广水市| 东港市| 天津市| 泰来县| 砚山县| 榆树市| 金乡县| 巴塘县| 二手房| 龙泉市| 迭部县| 曲松县| 蚌埠市| 普兰店市| 含山县| 涡阳县| 虞城县| 延安市| 澄迈县| 黄冈市| 台前县| 五河县|