Hello,
I searched and did not find a way to associate a PDF file with standard internet browsing, via programming,
Anybody know ?
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
#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;
}
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 87 guests