list of Opened Window Titles

G

GeorgeMar

I have a function that closes a window if that window is opened. I use the
APIs FindWindow and PostMessage. To use FindWindow, you need to know the
Window Title. That usually works fine.

On the odd, occasion, the user will maximise the screen and the title
changes. The new title is a concatenation of the Application Window Title
and the Report name in brackets[]. This concatenation is dynamic and
therefore impossible to predict.

Is there a way to close the application by finding any window title that
contacts the first part of the concatenated title. e.g if the application
title is the first 10 chars of the whoe title, that will be consistent. Thus,
search on the first 10 chars only.

many thanks
george
 
D

Douglas J. Steele

See whether http://vbnet.mvps.org/code/system/winclasstitle.htm at Randy
Birch's VBNet helps.

Obligatory warning: Randy's site is aimed at VB programmers. There are
significant differences between the controls available on forms in VB and in
Access, so some of his examples don't port seamlessly into Access. This is
an example of that! (He's using a control array of labels, he's doing funky
things with his listbox that aren't required in Access, and many other
differences) Hopefully, though, you'll be able to figure out how he's
retrieving the Window Title.
 
G

GeorgeMar

Thank you again Doug!

You are very resourceful. I much appreciate your help.

I have found some codes from Dev Ashish "Preventing multiple instances of a
database" and I have made that work.

My only concern is the robustness. In the codes, the windows title is got
from apiGetWindowText. It returns the name of the database e.g "SISRpt :
Database (Access 2002 file format)". If the database opened is the database I
want to close, I use PostMessage to close it. It seems to close all its
child windows, including any message dialogues. As a precaution though, I
have made all my messages VbDefaultButton2, in the case of VbYesNo, i.e to
default to No when the apps closes.

The question I have is: Is that secure? Are there any pitfalls with this
method that I should be mindful of?

many thanks
george


Douglas J. Steele said:
See whether http://vbnet.mvps.org/code/system/winclasstitle.htm at Randy
Birch's VBNet helps.

Obligatory warning: Randy's site is aimed at VB programmers. There are
significant differences between the controls available on forms in VB and in
Access, so some of his examples don't port seamlessly into Access. This is
an example of that! (He's using a control array of labels, he's doing funky
things with his listbox that aren't required in Access, and many other
differences) Hopefully, though, you'll be able to figure out how he's
retrieving the Window Title.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


GeorgeMar said:
I have a function that closes a window if that window is opened. I use the
APIs FindWindow and PostMessage. To use FindWindow, you need to know the
Window Title. That usually works fine.

On the odd, occasion, the user will maximise the screen and the title
changes. The new title is a concatenation of the Application Window Title
and the Report name in brackets[]. This concatenation is dynamic and
therefore impossible to predict.

Is there a way to close the application by finding any window title that
contacts the first part of the concatenated title. e.g if the application
title is the first 10 chars of the whoe title, that will be consistent.
Thus,
search on the first 10 chars only.

many thanks
george
 
D

Douglas J. Steele

I'm not sure that vbDefaultButton2 will make a difference. My recollection
is that if the message box doesn't have a Cancel button on it, you can run
into problems trying to close it in an automated fashion.

What exactly are you trying to accomplish?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


GeorgeMar said:
Thank you again Doug!

You are very resourceful. I much appreciate your help.

I have found some codes from Dev Ashish "Preventing multiple instances of
a
database" and I have made that work.

My only concern is the robustness. In the codes, the windows title is got
from apiGetWindowText. It returns the name of the database e.g "SISRpt :
Database (Access 2002 file format)". If the database opened is the
database I
want to close, I use PostMessage to close it. It seems to close all its
child windows, including any message dialogues. As a precaution though, I
have made all my messages VbDefaultButton2, in the case of VbYesNo, i.e to
default to No when the apps closes.

The question I have is: Is that secure? Are there any pitfalls with this
method that I should be mindful of?

many thanks
george


Douglas J. Steele said:
See whether http://vbnet.mvps.org/code/system/winclasstitle.htm at Randy
Birch's VBNet helps.

Obligatory warning: Randy's site is aimed at VB programmers. There are
significant differences between the controls available on forms in VB and
in
Access, so some of his examples don't port seamlessly into Access. This
is
an example of that! (He's using a control array of labels, he's doing
funky
things with his listbox that aren't required in Access, and many other
differences) Hopefully, though, you'll be able to figure out how he's
retrieving the Window Title.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


GeorgeMar said:
I have a function that closes a window if that window is opened. I use
the
APIs FindWindow and PostMessage. To use FindWindow, you need to know
the
Window Title. That usually works fine.

On the odd, occasion, the user will maximise the screen and the title
changes. The new title is a concatenation of the Application Window
Title
and the Report name in brackets[]. This concatenation is dynamic and
therefore impossible to predict.

Is there a way to close the application by finding any window title
that
contacts the first part of the concatenated title. e.g if the
application
title is the first 10 chars of the whoe title, that will be consistent.
Thus,
search on the first 10 chars only.

many thanks
george
 
G

GeorgeMar

What I'm trying to do is this: I have an apps (Main) that has a button for
the user to preview reports based on a selection the user makes from a
datasheet. So, each preview will have a different data selection.

The report is generated from another apps (Report) in the background, that
contains all the reports and their underlying queries. With this approach,
if the user previews the report (an instance of Report is created) and
doesn't close the apps that instance remains open even when the user leaves
the Main apps. Therefore, there can be several instances opened if the user
is not closing them.

So, what I am doing is to make sure that when the user makes a preview that
the previous instance closes. Also, if the user closes Main, it closes any
opened Report instances.

When an apps window is closed with PostMessage, any message dialogue is
automatically executed, as if the user hits enter on the keyboard. Thus, the
default button is executed. The default in Windows is usually button1, so,
by changing it to button2, I make sure that NO or Cancel is executed,
avoiding an unpredictable outcome.

All this seems to work now with the API functions I have instituted. This
approach will also be useful for me when I create the DetectIdle and close
the apps after a period. If a message dialogue is opened it will
automatically close it.

I guess it is all working successfully, but I was anxious to know if this
approach is the right one to take. So far, so good.

Thanks again for your help.
George

Douglas J. Steele said:
I'm not sure that vbDefaultButton2 will make a difference. My recollection
is that if the message box doesn't have a Cancel button on it, you can run
into problems trying to close it in an automated fashion.

What exactly are you trying to accomplish?

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


GeorgeMar said:
Thank you again Doug!

You are very resourceful. I much appreciate your help.

I have found some codes from Dev Ashish "Preventing multiple instances of
a
database" and I have made that work.

My only concern is the robustness. In the codes, the windows title is got
from apiGetWindowText. It returns the name of the database e.g "SISRpt :
Database (Access 2002 file format)". If the database opened is the
database I
want to close, I use PostMessage to close it. It seems to close all its
child windows, including any message dialogues. As a precaution though, I
have made all my messages VbDefaultButton2, in the case of VbYesNo, i.e to
default to No when the apps closes.

The question I have is: Is that secure? Are there any pitfalls with this
method that I should be mindful of?

many thanks
george


Douglas J. Steele said:
See whether http://vbnet.mvps.org/code/system/winclasstitle.htm at Randy
Birch's VBNet helps.

Obligatory warning: Randy's site is aimed at VB programmers. There are
significant differences between the controls available on forms in VB and
in
Access, so some of his examples don't port seamlessly into Access. This
is
an example of that! (He's using a control array of labels, he's doing
funky
things with his listbox that aren't required in Access, and many other
differences) Hopefully, though, you'll be able to figure out how he's
retrieving the Window Title.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


I have a function that closes a window if that window is opened. I use
the
APIs FindWindow and PostMessage. To use FindWindow, you need to know
the
Window Title. That usually works fine.

On the odd, occasion, the user will maximise the screen and the title
changes. The new title is a concatenation of the Application Window
Title
and the Report name in brackets[]. This concatenation is dynamic and
therefore impossible to predict.

Is there a way to close the application by finding any window title
that
contacts the first part of the concatenated title. e.g if the
application
title is the first 10 chars of the whoe title, that will be consistent.
Thus,
search on the first 10 chars only.

many thanks
george
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top