- // Fonction qui récupère l'URL courante d'Internet Explorer
- // Si retour != 0 liberer par HeapFree(GetProcessHeap(), 0, pBuffer)
- char* GetCurrentURLFromIE(void)
- {
- HWND hWnd, hWnd2, hWnd3; // Handles de fenêtre
- DWORD size; // Taille URL
- char *pURL = NULL; // Buffer de sortie
- // Récupération du handle de la fenêtre de IE
- hWnd = FindWindow("IEFrame",NULL);
- if(hWnd) {
- // Parcours de la hiérarchie de classes (merci Spy++) pour trouver l'Edit contenant l'URL
- hWnd = FindWindowEx(hWnd,0,"WorkerW",NULL); // Fenêtre de travail
- hWnd = FindWindowEx(hWnd,0,"ReBarWindow32",NULL); // Toolbar
- hWnd2 = FindWindowEx(hWnd,0,"Address Band Root",NULL); // Bandeau, IE 7
- if(hWnd2) hWnd = hWnd2;
- hWnd3 = FindWindowEx(hWnd,0,"ComboBoxEx32",NULL); // Combo Box Entendue, pas sous IE8
- if(hWnd3) hWnd = hWnd3;
- hWnd3 = FindWindowEx(hWnd,0,"ComboBox",NULL); // Combo Box, pas sous IE8
- if(hWnd3) hWnd = hWnd3;
- hWnd = FindWindowEx(hWnd,0,"Edit",NULL); // Edit contenant l'URL
- // Récupération de la taille de la chaine et allocation du buffer en conséquence
- size = (DWORD) SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0);
- if(size) {
- size++;
- pURL = (char*) HeapAlloc(GetProcessHeap(), 0, size);
- // Get de l'URL
- if(pURL) SendMessage(hWnd, WM_GETTEXT, size, (LPARAM) pURL);
- }
- }
- return pURL;
- }