Usuário com melhor resposta
Pegar URL C++

Pergunta
-
Respostas
-
Código enviado por : Fabio Galuppo
#include <windows.h> #include <tchar.h> struct FindWindowByClassNameArgs { const TCHAR* className; HWND hwndFounded; }; struct FindWindowByCaptionArgs { const TCHAR* caption; HWND hwndFounded; }; BOOL CALLBACK EnumChildByClassName(HWND hwndControl, LPARAM lParam) { TCHAR buffer[256]; GetClassName( hwndControl, buffer, sizeof(buffer) / sizeof(buffer[0]) ); FindWindowByClassNameArgs* args = (FindWindowByClassNameArgs*) lParam; if( _tcsstr( buffer , args->className ) ) { args->hwndFounded = hwndControl; return FALSE; } return TRUE; } BOOL CALLBACK EnumChildByCaption(HWND hwndControl, LPARAM lParam) { TCHAR buffer[256]; GetWindowText( hwndControl, buffer, sizeof(buffer) / sizeof(buffer[0]) ); FindWindowByCaptionArgs* args = (FindWindowByCaptionArgs*) lParam; if( _tcsstr( buffer , args->caption ) ) { args->hwndFounded = hwndControl; return FALSE; } return TRUE; } HWND FindWindowByClassName( HWND hwndChild, const TCHAR* className ) { FindWindowByClassNameArgs args = { className, NULL }; EnumChildWindows( hwndChild, EnumChildByClassName, (LPARAM) &args ); return args.hwndFounded; } HWND FindWindowByCaption( HWND hwndChild, const TCHAR* caption ) { FindWindowByCaptionArgs args = { caption, NULL }; EnumChildWindows( hwndChild, EnumChildByCaption, (LPARAM) &args ); return args.hwndFounded; } BOOL CALLBACK EnumVS2008DocumentationProc(HWND hwndChild, LPARAM lParam) { //Procura pelo Window Caption da janela TCHAR buffer[256]; GetWindowText( hwndChild, buffer, sizeof(buffer) / sizeof(buffer[0]) ); if( _tcsstr( buffer ,_T("Microsoft Visual Studio 2008 Documentation") ) ) { HWND h1 = FindWindowByClassName( hwndChild, _T("MDIClient") ); HWND h2 = FindWindowByClassName( h1, _T("EzMdiContainer") ); HWND h3 = FindWindowByClassName( h2, _T("GenericPane") ); HWND h4 = FindWindowByCaption( h3, _T("MsoDockTop") ); HWND h5 = FindWindowByClassName( h4, _T("MsoCommandBar") ); HWND h6 = FindWindowByClassName( h5, _T("Edit") ); LRESULT lineLength = SendMessage( h6, EM_LINELENGTH, 0, 0 ); TCHAR* url = new TCHAR[lineLength + 1]; url[0] = (int) lineLength; url[lineLength] = _T('\0'); LRESULT result = SendMessage( h6, EM_GETLINE, 0, (LPARAM) url ); _tprintf( _T("%s\n"), url ); delete url; } return TRUE; } BOOL CALLBACK EnumIE8Proc(HWND hwndChild, LPARAM lParam) { //Procura pelo Class Name TCHAR buffer[256]; GetClassName( hwndChild, buffer, sizeof(buffer) / sizeof(buffer[0]) ); if( _tcsstr( buffer ,_T("IEFrame") ) ) { HWND h1 = FindWindowByClassName( hwndChild, _T("WorkerW") ); HWND h2 = FindWindowByClassName( h1, _T("ReBarWindow32") ); HWND h3 = FindWindowByClassName( h2, _T("Address Band Root") ); HWND h4 = FindWindowByClassName( h3, _T("Edit") ); LRESULT lineLength = SendMessage( h4, EM_LINELENGTH, 0, 0 ); TCHAR* url = new TCHAR[lineLength + 1]; url[0] = (int) lineLength; url[lineLength] = _T('\0'); LRESULT result = SendMessage( h4, EM_GETLINE, 0, (LPARAM) url ); _tprintf( _T("%s\n"), url ); delete url; } return TRUE; } int main() { //EnumChildWindows(GetDesktopWindow(), EnumVS2008DocumentationProc, NULL); EnumChildWindows(GetDesktopWindow(), EnumIE8Proc, NULL); return 0; }
- Marcado como Resposta gu_bertu segunda-feira, 28 de dezembro de 2009 19:54
Todas as Respostas
-
Localize quais janelas dos browsers você quer interceptar com a API FindWindow ou FindWindowEx.
Nesta API você passará num dos argumentos, o título da Janela. Se estiver tudo certo, receberá o HWND. Com este valor você poderá enumerar recursivamente as janelas filhas com a API EnumChildWindows até achar o HWND do controle desejado.
No caso do IE, a barra de endereço é um Edit, quando você obter seu HWND é só chamar a API GetWindowText. Ela preencherá um buffer com o endereço do browser.
Para entender melhor estes passos, utilize o Spy++ que encontra-se no menu Visual Studio Tools.
Fabio Galuppo -
#include <windows.h> #include <tchar.h> struct FindWindowByClassNameArgs { const TCHAR* className; HWND hwndFounded; }; struct FindWindowByCaptionArgs { const TCHAR* caption; HWND hwndFounded; }; BOOL CALLBACK EnumChildByClassName(HWND hwndControl, LPARAM lParam) { TCHAR buffer[256]; GetClassName( hwndControl, buffer, sizeof(buffer) / sizeof(buffer[0]) ); FindWindowByClassNameArgs* args = (FindWindowByClassNameArgs*) lParam; if( _tcsstr( buffer , args->className ) ) { args->hwndFounded = hwndControl; return FALSE; } return TRUE; } BOOL CALLBACK EnumChildByCaption(HWND hwndControl, LPARAM lParam) { TCHAR buffer[256]; GetWindowText( hwndControl, buffer, sizeof(buffer) / sizeof(buffer[0]) ); FindWindowByCaptionArgs* args = (FindWindowByCaptionArgs*) lParam; if( _tcsstr( buffer , args->caption ) ) { args->hwndFounded = hwndControl; return FALSE; } return TRUE; } HWND FindWindowByClassName( HWND hwndChild, const TCHAR* className ) { FindWindowByClassNameArgs args = { className, NULL }; EnumChildWindows( hwndChild, EnumChildByClassName, (LPARAM) &args ); return args.hwndFounded; } HWND FindWindowByCaption( HWND hwndChild, const TCHAR* caption ) { FindWindowByCaptionArgs args = { caption, NULL }; EnumChildWindows( hwndChild, EnumChildByCaption, (LPARAM) &args ); return args.hwndFounded; } BOOL CALLBACK EnumVS2008DocumentationProc(HWND hwndChild, LPARAM lParam) { //Procura pelo Window Caption da janela TCHAR buffer[256]; GetWindowText( hwndChild, buffer, sizeof(buffer) / sizeof(buffer[0]) ); if( _tcsstr( buffer ,_T("Microsoft Visual Studio 2008 Documentation") ) ) { HWND h1 = FindWindowByClassName( hwndChild, _T("MDIClient") ); HWND h2 = FindWindowByClassName( h1, _T("EzMdiContainer") ); HWND h3 = FindWindowByClassName( h2, _T("GenericPane") ); HWND h4 = FindWindowByCaption( h3, _T("MsoDockTop") ); HWND h5 = FindWindowByClassName( h4, _T("MsoCommandBar") ); HWND h6 = FindWindowByClassName( h5, _T("Edit") ); LRESULT lineLength = SendMessage( h6, EM_LINELENGTH, 0, 0 ); TCHAR* url = new TCHAR[lineLength + 1]; url[0] = (int) lineLength; url[lineLength] = _T('\0'); LRESULT result = SendMessage( h6, EM_GETLINE, 0, (LPARAM) url ); _tprintf( _T("%s\n"), url ); delete url; } return TRUE; } BOOL CALLBACK EnumIE8Proc(HWND hwndChild, LPARAM lParam) { //Procura pelo Class Name TCHAR buffer[256]; GetClassName( hwndChild, buffer, sizeof(buffer) / sizeof(buffer[0]) ); if( _tcsstr( buffer ,_T("IEFrame") ) ) { HWND h1 = FindWindowByClassName( hwndChild, _T("WorkerW") ); HWND h2 = FindWindowByClassName( h1, _T("ReBarWindow32") ); HWND h3 = FindWindowByClassName( h2, _T("Address Band Root") ); HWND h4 = FindWindowByClassName( h3, _T("Edit") ); LRESULT lineLength = SendMessage( h4, EM_LINELENGTH, 0, 0 ); TCHAR* url = new TCHAR[lineLength + 1]; url[0] = (int) lineLength; url[lineLength] = _T('\0'); LRESULT result = SendMessage( h4, EM_GETLINE, 0, (LPARAM) url ); _tprintf( _T("%s\n"), url ); delete url; } return TRUE; } int main() { //EnumChildWindows(GetDesktopWindow(), EnumVS2008DocumentationProc, NULL); EnumChildWindows(GetDesktopWindow(), EnumIE8Proc, NULL); return 0; }
-
Código enviado por : Fabio Galuppo
#include <windows.h> #include <tchar.h> struct FindWindowByClassNameArgs { const TCHAR* className; HWND hwndFounded; }; struct FindWindowByCaptionArgs { const TCHAR* caption; HWND hwndFounded; }; BOOL CALLBACK EnumChildByClassName(HWND hwndControl, LPARAM lParam) { TCHAR buffer[256]; GetClassName( hwndControl, buffer, sizeof(buffer) / sizeof(buffer[0]) ); FindWindowByClassNameArgs* args = (FindWindowByClassNameArgs*) lParam; if( _tcsstr( buffer , args->className ) ) { args->hwndFounded = hwndControl; return FALSE; } return TRUE; } BOOL CALLBACK EnumChildByCaption(HWND hwndControl, LPARAM lParam) { TCHAR buffer[256]; GetWindowText( hwndControl, buffer, sizeof(buffer) / sizeof(buffer[0]) ); FindWindowByCaptionArgs* args = (FindWindowByCaptionArgs*) lParam; if( _tcsstr( buffer , args->caption ) ) { args->hwndFounded = hwndControl; return FALSE; } return TRUE; } HWND FindWindowByClassName( HWND hwndChild, const TCHAR* className ) { FindWindowByClassNameArgs args = { className, NULL }; EnumChildWindows( hwndChild, EnumChildByClassName, (LPARAM) &args ); return args.hwndFounded; } HWND FindWindowByCaption( HWND hwndChild, const TCHAR* caption ) { FindWindowByCaptionArgs args = { caption, NULL }; EnumChildWindows( hwndChild, EnumChildByCaption, (LPARAM) &args ); return args.hwndFounded; } BOOL CALLBACK EnumVS2008DocumentationProc(HWND hwndChild, LPARAM lParam) { //Procura pelo Window Caption da janela TCHAR buffer[256]; GetWindowText( hwndChild, buffer, sizeof(buffer) / sizeof(buffer[0]) ); if( _tcsstr( buffer ,_T("Microsoft Visual Studio 2008 Documentation") ) ) { HWND h1 = FindWindowByClassName( hwndChild, _T("MDIClient") ); HWND h2 = FindWindowByClassName( h1, _T("EzMdiContainer") ); HWND h3 = FindWindowByClassName( h2, _T("GenericPane") ); HWND h4 = FindWindowByCaption( h3, _T("MsoDockTop") ); HWND h5 = FindWindowByClassName( h4, _T("MsoCommandBar") ); HWND h6 = FindWindowByClassName( h5, _T("Edit") ); LRESULT lineLength = SendMessage( h6, EM_LINELENGTH, 0, 0 ); TCHAR* url = new TCHAR[lineLength + 1]; url[0] = (int) lineLength; url[lineLength] = _T('\0'); LRESULT result = SendMessage( h6, EM_GETLINE, 0, (LPARAM) url ); _tprintf( _T("%s\n"), url ); delete url; } return TRUE; } BOOL CALLBACK EnumIE8Proc(HWND hwndChild, LPARAM lParam) { //Procura pelo Class Name TCHAR buffer[256]; GetClassName( hwndChild, buffer, sizeof(buffer) / sizeof(buffer[0]) ); if( _tcsstr( buffer ,_T("IEFrame") ) ) { HWND h1 = FindWindowByClassName( hwndChild, _T("WorkerW") ); HWND h2 = FindWindowByClassName( h1, _T("ReBarWindow32") ); HWND h3 = FindWindowByClassName( h2, _T("Address Band Root") ); HWND h4 = FindWindowByClassName( h3, _T("Edit") ); LRESULT lineLength = SendMessage( h4, EM_LINELENGTH, 0, 0 ); TCHAR* url = new TCHAR[lineLength + 1]; url[0] = (int) lineLength; url[lineLength] = _T('\0'); LRESULT result = SendMessage( h4, EM_GETLINE, 0, (LPARAM) url ); _tprintf( _T("%s\n"), url ); delete url; } return TRUE; } int main() { //EnumChildWindows(GetDesktopWindow(), EnumVS2008DocumentationProc, NULL); EnumChildWindows(GetDesktopWindow(), EnumIE8Proc, NULL); return 0; }
- Marcado como Resposta gu_bertu segunda-feira, 28 de dezembro de 2009 19:54
-
Observações:1. Isto é só uma prova de conceito, e tem MUITO que evoluir - tratamento de handles nulos não tem, entre outros;2. Mistura C com C++, não é um ótimo design de código, mas faz o trabalho - e deve dar uma direção para vc.
Fabio Galuppo