On my computer, running Windows 7, the title bars of the windows list the open file and then the program name, ie: “Book1 - Microsoft Excel”. Other users in my office, that seemingly have the same setup as me, only have the file name, ie: “Book1.” I am writing some Windows API and I need to have everyone list the program name in the title bar so I can find the window handle.
There must be some setting in Windows that I’m overlooking, but I can’t find it anywhere. I have Googled this to death and can’t find anything. Does anyone know where the setting for this is?
I’d suspect it’s a setting in Excel itself that does this. I’ve used a variety of text editors over the years that include options to hide the current file’s path in the title bar (so you don’t have something like “notepad - c:/users/username/documents/simson/meetings/2013/springs sales.txt” trying to show).
I don’t know what you mean by “writing some Windows API” (didn’t Microsoft already do that? ) but I’d wager there’s a better way to do what you want to do. Window titles can change for literally any reason (most commonly being localization-- what do you think “book1” reads if you’re in Russia?) and if you write code assuming the window title will look a certain way, it’ll be fragile and require constant maintenance.
Assuming you’re talking about Excel specifically, Microsoft has released a library to do Office interop, which should be a much better fit what you’re you’re trying to do and will be guaranteed to call into Excel using the correct window messages and not break based on localization settings or future changes to Excel.
I could give you a better answer if you tell me exactly what it is you want to accomplish.
Unfortunately, I am not talking about Excel, I just used that as an example. My code makes Excel interface with a BS third-party application that I am forced to use against my will. That application changes titles all the time, but on my machine, the title always contains the program name, so I can always find it regardless of the rest of the title. But on some other machines, the program name is not included in the title bar, so my code doesn’t work. I would love it if there was another way, I’m going to look through that page that Reply linked to as well.
What I am doing in a nutshell is taking data from Excel and entering it into the BS third-party software. It’s been running like clockwork on my machine for over a year, so I’d rather not make drastic changes. I understand what you’re saying about there being an easier way, but just getting that program name in the title bar will solve the problem for now.
If it were me (and assuming the other program has no API or scripting interface), I’d tell my management it can’t be done in a reasonable way and find an alternative. Frankly.
I’m really surprised there isn’t an easy answer to this. I thought there would be a box to check somewhere, or maybe a registry setting that would be easy to find. When I google it I can’t even find anyone else asking this question.
I guess I’ll write a loop that looks through the possible titles (there are five or six that should cover 99% of the cases) and keeps looking until it finds a handle that isn’t 0. Unless anyone else has a better idea.
I’m definitely going to look into it. If you have any tips or a link to a good website that explains it I would appreciate it. It sounds a lot better than what I’m doing now.
As far as I know, every program decides on its own what text should go in its title bar. Windows doesn’t control this though any system-wide setting that I’m aware of.
So a program could decide to include its name, or not, based on the version of Windows, the current screen resolution, or whether the name of the current month includes an R.
I’m not finding anything I can use. Everything I am finding talks about starting a new proess and then getting that process ID. I need to get a process ID of a program that is already running.