首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> C++ >> 關於C++

透過 DDE 取得當前瀏覽器 URL:C++Builder 實作範例

     編輯:關於C++

參考 Delphi 版本,利用 TDdeClientConv 透過 DDE 協定從 Internet Explorer 取得當前視窗 URL,移植至 C++Builder。

核心代碼

// Unit1.cpp
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"

#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {}

// 取得指定服務的 URL
String TForm1::Get_URL(AnsiString Servicio) {
    TDdeClientConv *Cliente_DDE = new TDdeClientConv(NULL);
    char *temp;
    Cliente_DDE->SetLink(Servicio, "WWW_GetWindowInfo"); // 連接 DDE 服務與主題
    temp = Cliente_DDE->RequestData("0xFFFFFFFF");       // 要求資料
    Cliente_DDE->CloseLink();
    delete Cliente_DDE;
    return String(temp);
}

void __fastcall TForm1::Button1Click(TObject *Sender) {
    ShowMessage(Get_URL("Iexplore")); // 取得 IE 當前 URL
}
// Unit1.h
#ifndef Unit1H
#define Unit1H
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include "ddeman.hpp"

class TForm1 : public TForm {
__published:
    TButton *Button1;
    void __fastcall Button1Click(TObject *Sender);
private:
    String Get_URL(AnsiString Servicio);
public:
    __fastcall TForm1(TComponent* Owner);
};
extern PACKAGE TForm1 *Form1;
#endif

原理說明

  • DDE 服務名:"Iexplore" 對應 Internet Explorer。
  • DDE 主題:"WWW_GetWindowInfo" 是 IE 支援的標準主題。
  • 請求項目:"0xFFFFFFFF" 代表當前活動視窗。

點擊按鈕即彈出訊息框顯示當前 IE 視窗的完整 URL。此法簡單直接,適用於需快速整合瀏覽器 URL 的輕量級工具。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved