_Help File Web Links_ by Robert Lord Listing One 1 // URLHelp.c -- written by Bob Lord 3/96 2 3 #include 4 #include 5 #include 6 #include 7 8 extern HWND FindWindowByTitle(LPCSTR lpszTitle); 9 10 const char cszDDECommandKey[] = 11 "SOFTWARE\\classes\\http\\shell\\open\\command"; 12 const char cszDDEExecKey[] = 13 "SOFTWARE\\classes\\http\\shell\\open\\ddeexec"; 14 const char cszDDEApplicationKey[] = 15 "SOFTWARE\\classes\\http\\shell\\open\\ddeexec\\Application"; 16 const char cszDDETopicKey[] = 17 "SOFTWARE\\classes\\http\\shell\\open\\ddeexec\\Topic"; 18 19 HDDEDATA CALLBACK DdeCallback(UINT uType, UINT uFmt, HCONV hconv, HSZ hsz1, 20 HSZ hsz2, HDDEDATA hdata, DWORD dwData1, 21 DWORD dwData2) 22 { 23 switch (uType) 24 { 25 case XTYP_ADVDATA: 26 return (HDDEDATA)DDE_FACK; 27 28 default: 29 return (HDDEDATA)NULL; 30 } 31 } 32 33 LONG GetRegSzValue(HKEY hKey, LPCTSTR lpSubKey, LPCTSTR lpName, 34 LPSTR *lplpszValue) 35 { 36 LONG result; 37 HKEY hkRegKey; 38 DWORD dwType; 39 DWORD dwSize; 40 41 result = RegOpenKeyEx(hKey, lpSubKey, 0L, KEY_READ, &hkRegKey); 42 if (result == ERROR_SUCCESS) 43 { 44 result = RegQueryValueEx(hkRegKey, lpName, NULL, &dwType, NULL, 45 &dwSize); 46 if (result == ERROR_SUCCESS) 47 { 48 *lplpszValue = NULL; 49 if (dwType == REG_SZ) 50 if (dwSize != 0 && dwSize <= UINT_MAX) 51 { 52 *lplpszValue = malloc(dwSize); 53 if (*lplpszValue != NULL) 54 result = RegQueryValueEx(hkRegKey, lpName, NULL, 55 &dwType,*lplpszValue,&dwSize); 56 } 57 } 58 RegCloseKey(hkRegKey); 59 if (*lplpszValue == NULL) 60 result = ERROR_INVALID_FUNCTION; 61 } 62 return result; 63 } 64 65 __declspec(dllexport) void DisplayURL(LPCSTR lpszURL) 66 { 67 LPSTR lpszCommand=NULL; 68 LPSTR lpszExec=NULL; 69 LPSTR lpszURLExec=NULL; 70 LPSTR lpszApplication=NULL; 71 LPSTR lpszTopic=NULL; 72 DWORD idInst=0; 73 HSZ hszService, hszTopic, hszItem; 74 HCONV hConv; 75 HDDEDATA hData; 76 HCURSOR hcurStarting, hcurOld; 77 78 hcurStarting = LoadCursor(NULL, IDC_APPSTARTING); 79 hcurOld = SetCursor(hcurStarting); 80 81 GetRegSzValue(HKEY_LOCAL_MACHINE, cszDDEExecKey, NULL, &lpszExec); 82 if (lpszExec) 83 { 84 lpszURLExec = malloc(lstrlen(lpszExec) - 2 + lstrlen(lpszURL) + 1); 85 if (lpszURLExec) 86 { 87 char *pFrom = lpszExec; 88 char *pTo = lpszURLExec; 89 90 while (*pFrom != '%' && *(pFrom + 1) != '1') 91 *pTo++ = *pFrom++; 92 lstrcpy(pTo, lpszURL); 93 pFrom += 2; 94 lstrcat(pTo, pFrom); 95 } 96 } 97 free(lpszExec); 98 99 GetRegSzValue(HKEY_LOCAL_MACHINE, cszDDECommandKey, NULL, &lpszCommand); 100 GetRegSzValue(HKEY_LOCAL_MACHINE, cszDDEApplicationKey, NULL, 101 &lpszApplication); 102 GetRegSzValue(HKEY_LOCAL_MACHINE, cszDDETopicKey, NULL, &lpszTopic); 103 104 if (lpszCommand && lpszURLExec && lpszApplication && lpszTopic) 105 { 106 if (DdeInitialize(&idInst, DdeCallback, 107 APPCLASS_STANDARD | APPCMD_CLIENTONLY, 0L) == DMLERR_NO_ERROR) 108 { 109 hszService = DdeCreateStringHandle(idInst, lpszApplication, 110 CP_WINANSI); 111 hszTopic = DdeCreateStringHandle(idInst, lpszTopic, CP_WINANSI); 112 if (hszService && hszTopic) 113 { 114 hConv = DdeConnect(idInst, hszService, hszTopic, NULL); 115 if (!hConv) 116 WinExec(lpszCommand, SW_SHOWNORMAL); 117 hConv = DdeConnect(idInst, hszService, hszTopic, NULL); 118 if (hConv) 119 { 120 DdeClientTransaction((LPSTR)lpszURLExec, 121 lstrlen(lpszURLExec) + 1, hConv, 0, 0, XTYP_EXECUTE, 122 TIMEOUT_ASYNC, NULL); 123 DdeDisconnect(hConv); 124 } 125 } 126 127 if (lstrcmp(lpszApplication, "IExplore") != 0) 128 { 129 if (hszTopic) 130 DdeFreeStringHandle(idInst, hszTopic); 131 hszTopic = DdeCreateStringHandle(idInst, "WWW_GetWindowInfo", 132 CP_WINANSI); 133 hszItem = DdeCreateStringHandle(idInst, "-1", CP_WINANSI); 134 if (hszService && hszTopic && hszItem) 135 { 136 hConv = DdeConnect(idInst, hszService, hszTopic, NULL); 137 if (hConv) 138 { 139 char *pStart, *pEnd; 140 HWND hwnd; 141 142 hData = DdeClientTransaction(NULL, 0, hConv, hszItem, 143 CF_TEXT, XTYP_REQUEST, 1000, NULL); 144 if (hData) 145 { 146 pStart = DdeAccessData(hData, NULL); 147 148 ++pStart; 149 while (*pStart != '\"') 150 ++pStart; 151 pStart += 3; 152 pEnd = pStart; 153 while (*pEnd != '\"') 154 ++pEnd; 155 *pEnd = 0; 156 157 hwnd = FindWindowByTitle(pStart); 158 if (hwnd) 159 { 160 if (IsIconic(hwnd)) 161 ShowWindow(hwnd, SW_RESTORE); 162 SetForegroundWindow(hwnd); 163 } 164 165 DdeUnaccessData(hData); 166 } 167 168 DdeDisconnect(hConv); 169 } 170 } 171 if (hszItem) 172 DdeFreeStringHandle(idInst, hszItem); 173 } 174 if (hszTopic) 175 DdeFreeStringHandle(idInst, hszTopic); 176 if (hszService) 177 DdeFreeStringHandle(idInst, hszService); 178 DdeUninitialize(idInst); 179 } 180 } 181 free(lpszURLExec); 182 free(lpszTopic); 183 free(lpszApplication); 184 free(lpszCommand); 185 186 SetCursor(hcurOld); 187 } Listing Two 1 // FindWin.c -- written by Bob Lord 3/96 2 3 #include 4 5 static HWND hwndFound; 6 7 static BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) 8 { 9 char szWindowTitle[256]; 10 unsigned length; 11 12 length = lstrlen((char *)lParam) + 1; 13 GetWindowText(hwnd, szWindowTitle, length); 14 if (lstrcmp((char *)(LPCSTR)lParam, szWindowTitle) == 0) 15 { 16 hwndFound = hwnd; 17 return FALSE; 18 } 19 return TRUE; 20 } 21 22 HWND FindWindowByTitle(LPCSTR lpszTitle) 23 { 24 hwndFound = 0; 25 EnumWindows(EnumWindowsProc, (LPARAM)lpszTitle); 26 return hwndFound; 27 }