FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Associate PDF file with browser
Posts: 253
Joined: Fri Feb 03, 2006 04:21 PM
Associate PDF file with browser
Posted: Sun May 28, 2023 08:18 PM

Hello,

I searched and did not find a way to associate a PDF file with standard internet browsing, via programming,

Anybody know ?

Thanks,
Ari

FWH 2501 - Harbour 3.2.0 - Embarcadero 7.43 - MySQL
São Paulo - SP - Brasil
www.sisrev.com.br
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Associate PDF file with browser
Posted: Mon May 29, 2023 10:58 AM
Dear Ari,

chatGPT answer:
You can use the Windows Registry to associate file extensions with default programs. Specifically, you'll need to modify the registry entry for the ".pdf" extension to associate it with a web browser. This can be done using the regedit command or programmatically through the Windows Registry API.
Locate the registry key: HKEY_CLASSES_ROOT\.pdf
Set the (Default) value to "AcroExch.Document" (for Adobe Acrobat Reader) or "ChromeHTML" (for Google Chrome), depending on the browser you want to associate.
You may also need to modify the registry keys under HKEY_CLASSES_ROOT\[AssociatedKey]\Shell\Open\Command to point to the correct browser executable
Code (fw): Select all Collapse
#include <Windows.h>
#include <stdio.h>

int main() {
    HKEY hKey;
    LPCSTR fileExtension = ".pdf";
    LPCSTR browserKey = "AcroExch.Document"; // Change this to "ChromeHTML" for Chrome

    // Open the registry key for the file extension
    if (RegOpenKeyEx(HKEY_CLASSES_ROOT, fileExtension, 0, KEY_WRITE, &hKey) != ERROR_SUCCESS) {
        printf("Failed to open registry key\n");
        return 1;
    }

    // Set the default value to the browser key
    if (RegSetValueEx(hKey, NULL, 0, REG_SZ, (BYTE*)browserKey, strlen(browserKey) + 1) != ERROR_SUCCESS) {
        printf("Failed to set registry value\n");
        RegCloseKey(hKey);
        return 1;
    }

    printf("PDF file association with the browser has been set successfully.\n");

    // Close the registry key
    RegCloseKey(hKey);

    return 0;
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 253
Joined: Fri Feb 03, 2006 04:21 PM
Re: Associate PDF file with browser
Posted: Mon May 29, 2023 11:19 AM
:D

Chat is really good!

thank you very much
Thanks,
Ari

FWH 2501 - Harbour 3.2.0 - Embarcadero 7.43 - MySQL
São Paulo - SP - Brasil
www.sisrev.com.br

Continue the discussion