| | |
Return the window title
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2008
Posts: 99
Reputation:
Solved Threads: 1
Just wondering if theres a function to get the window title of your browser.
Like if you were to visit www.myspace.com your window title would be: www.myspace.com - Mozilla Firefox
or w/e browser you happen to use.
Is there a way to get the title of a window?
Like if you were to visit www.myspace.com your window title would be: www.myspace.com - Mozilla Firefox
or w/e browser you happen to use.
Is there a way to get the title of a window?
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
•
•
•
•
Just wondering if theres a function to get the window title of your browser.
Like if you were to visit www.myspace.com your window title would be: www.myspace.com - Mozilla Firefox
or w/e browser you happen to use.
Is there a way to get the title of a window?
GetWindowText() once you have the handle to the correct window. Call EnumWindows() to get a list of all the top-level windows so that you can get the handle to the browser window. The problem is -- how will you know which one is the browser?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Mar 2008
Posts: 1,428
Reputation:
Solved Threads: 116
> The problem is -- how will you know which one is the browser?
Simple
You can use Spy++ to find out the browsers class name and then you can narrow down which windows are browsers. I found out these:
Now using AD's suggestion, using EnumWindows you can narrow it down only to the internet explorers.
Another helpful function you could try, FindWindow.
If you have firefox, test out this code and the title of the browser should change, if not simply change to class name to work with IExplorer.
but this only works with one browser, so your probably better to stick with AD's technique.
Hope this helps.
Simple
You can use Spy++ to find out the browsers class name and then you can narrow down which windows are browsers. I found out these: C++ Syntax (Toggle Plain Text)
Firefox's Class: MozillaUIWindowClass IExplorer Class: IEFrame
Now using AD's suggestion, using EnumWindows you can narrow it down only to the internet explorers.
Another helpful function you could try, FindWindow.
If you have firefox, test out this code and the title of the browser should change, if not simply change to class name to work with IExplorer.
C++ Syntax (Toggle Plain Text)
#include<windows.h> int main() { HWND firefox = FindWindow("MozillaUIWindowClass", NULL); SetWindowText(firefox, "Found it!!"); return 0; }
Hope this helps.
I need pageviews! most fun profile ever :)
Hey, in the past I've messed with those functions a bit, here're the results. Might help you a bit.
Finds a window given a caption:
Enumerates all windows and displays some information about them. Then allows to hide a window.
Finds a window given a caption:
c Syntax (Toggle Plain Text)
#include <windows.h> #include <stdio.h> int main(int argc, char *argv[]){ HWND hWnd; char windowName[512]; printf("Window to look for: "); fgets(windowName, 512, stdin); if (hWnd = FindWindow(NULL, windowName)){ printf("hWnd : %Xh with caption:\n\t",hWnd ); GetWindowText(hWnd, windowName, 512); } else printf("No window found with that caption!"); return 0; }
Enumerates all windows and displays some information about them. Then allows to hide a window.
c Syntax (Toggle Plain Text)
#include <windows.h> #include <stdio.h> char windowName[63]; int DisplayWindows(HWND hWnd, LPARAM lParam); int main(int argc, char *argv[]){ EnumWindows((WNDENUMPROC) DisplayWindows,(LPARAM) NULL); printf("What window do you want to hide? (give the hWnd)\nhWnd: "); int hWnd; scanf("%d", &hWnd); if (!IsWindow((HWND)hWnd)){ printf("Window doesn't exist!"); return 0; } if(!ShowWindow((HWND) hWnd, SW_HIDE)){ printf("Window was already hidden..."); } return 0; } int DisplayWindows(HWND hWnd, LPARAM lParam){ GetWindowText(hWnd, windowName, 63); if (windowName[0] == '\0') return 1; printf("hWnd: %d\nClass: ", hWnd); GetClassName(hWnd, windowName, 63); puts(windowName); printf("Caption:"); GetWindowText(hWnd, windowName, 63); puts(windowName); printf("\n"); return 1; }
Last edited by Clockowl; Aug 13th, 2008 at 11:00 am.
•
•
Join Date: Feb 2009
Posts: 7
Reputation:
Solved Threads: 1
Your code works! But it includes those windows which are hidden or those programs without interface. In short, how to get the captions of windows that can be seen?
Firefox has a visible window, I would like to include it but my firewall, by your method, can be seen but has no visible window so I would like to exclude it.
Can anyone shed some light to this?
Firefox has a visible window, I would like to include it but my firewall, by your method, can be seen but has no visible window so I would like to exclude it.
Can anyone shed some light to this?
You can probably get the state of a window by using an API, have you tried looking for it? I don't know any from the top of my head. If there isn't any, you could try and hide the window, and if the function ShowWindow() returns 0, it was already in the state you tried to set it in. I think. Better check on that though.
Last edited by Clockowl; Feb 4th, 2009 at 1:55 pm.
•
•
Join Date: Nov 2007
Posts: 978
Reputation:
Solved Threads: 208
IsWindowVisible() might be useful.
•
•
Join Date: Feb 2009
Posts: 7
Reputation:
Solved Threads: 1
thanks mitrmkar, that was really a help. I'm also glad that this thread is alive. I got my solution though. I used key strokes and mouse clicks to get the windows that are being used, although your method is useful too. I'll weigh in if which one will be more useful to my operation.
but another problem is here. i have this snippet in my code.
summary is, when the active window changes, the currentwindow variable should change value, record the current active window title to a file and copy the value to the lastwindow variable. if the active window has not changed, it will do nothing and wait until mouseclicks or keypresses are done in another window for recording. But it seems that everytime i activate this part of the script, even though i did not change window, it still types in the window title, which it should not.
the values that are being recorded are window captions. is something wrong with the stored values? they seem to be the same when i try to printf them but come out different using this script.
but another problem is here. i have this snippet in my code.
C++ Syntax (Toggle Plain Text)
//from the top part of the code char lastwindow[MAX_PATH]; char currentwindow[MAX_PATH]; /* this one is from the bottom, where it runs when a key or mouse button is pressed (a very common activity when using the pc) and eliminates the chance of getting hidden windows. FStrem is a text file to where it records rather than using the printf() */ HWND mainwindow; mainwindow = GetForegroundWindow(); GetWindowText(mainwindow,currentwindow,sizeof(currentwindow)); if(lastwindow==currentwindow) {} else if(lastwindow!=currentwindow) { strcpy (lastwindow,currentwindow); FStream << "\n\n[" << currentwindow << "]\n\n"; }
summary is, when the active window changes, the currentwindow variable should change value, record the current active window title to a file and copy the value to the lastwindow variable. if the active window has not changed, it will do nothing and wait until mouseclicks or keypresses are done in another window for recording. But it seems that everytime i activate this part of the script, even though i did not change window, it still types in the window title, which it should not.
the values that are being recorded are window captions. is something wrong with the stored values? they seem to be the same when i try to printf them but come out different using this script.
•
•
Join Date: Feb 2009
Posts: 7
Reputation:
Solved Threads: 1
•
•
•
•
Hey, in the past I've messed with those functions a bit, here're the results. Might help you a bit.
Finds a window given a caption:
c Syntax (Toggle Plain Text)
#include <windows.h> #include <stdio.h> int main(int argc, char *argv[]){ HWND hWnd; char windowName[512]; printf("Window to look for: "); fgets(windowName, 512, stdin); if (hWnd = FindWindow(NULL, windowName)){ printf("hWnd : %Xh with caption:\n\t",hWnd ); GetWindowText(hWnd, windowName, 512); } else printf("No window found with that caption!"); return 0; }
Enumerates all windows and displays some information about them. Then allows to hide a window.
c Syntax (Toggle Plain Text)
#include <windows.h> #include <stdio.h> char windowName[63]; int DisplayWindows(HWND hWnd, LPARAM lParam); int main(int argc, char *argv[]){ EnumWindows((WNDENUMPROC) DisplayWindows,(LPARAM) NULL); printf("What window do you want to hide? (give the hWnd)\nhWnd: "); int hWnd; scanf("%d", &hWnd); if (!IsWindow((HWND)hWnd)){ printf("Window doesn't exist!"); return 0; } if(!ShowWindow((HWND) hWnd, SW_HIDE)){ printf("Window was already hidden..."); } return 0; } int DisplayWindows(HWND hWnd, LPARAM lParam){ GetWindowText(hWnd, windowName, 63); if (windowName[0] == '\0') return 1; printf("hWnd: %d\nClass: ", hWnd); GetClassName(hWnd, windowName, 63); puts(windowName); printf("Caption:"); GetWindowText(hWnd, windowName, 63); puts(windowName); printf("\n"); return 1; }
![]() |
Similar Threads
- Open In New Window Php (PHP)
- Calendar window is not coming for the Dynamic rows (JavaScript / DHTML / AJAX)
- HELP! With Javascripts Pop-Up Window (JavaScript / DHTML / AJAX)
- write issues (JavaScript / DHTML / AJAX)
- Using Global Low-Level Hooks Without Using A Dll (Computer Science)
- !Help! spyware/virus problem! (Viruses, Spyware and other Nasties)
- Cryptography Fun (Python)
- spyware i remove keeps coming back (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: How to use an array element in if-statement?
- Next Thread: HELP!! trying to write a quiz program part 1
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






