Solved

Centering a Common Dialog Box in VB5

Posted on 1997-07-21
10
275 Views
Last Modified: 2006-11-17
All,

I need to center (or position, it doesn't matter) a common dialog control.  I've tried using the FindWindow API call.  The problem is, I can't capture the window.  If I call the findwindow API, prior to showing the CDLG, It returns nothing.  If I call it in a timer that I enable prior to showing, it doesn't work (CDLG is modal).   Any help?

Anthony
0
Comment
Question by:anthonyc
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 3

Expert Comment

by:ESI
ID: 1428608
Not possible .
0
 
LVL 6

Author Comment

by:anthonyc
ID: 1428609
You have to give more of an explanation than "Not Possible" to expect a grade at all..  Right now, I reject the answer.  I'm sure it's possible.

Anthony
0
 
LVL 3

Expert Comment

by:ESI
ID: 1428610
coz CDLG is modal
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 9

Expert Comment

by:cymbolic
ID: 1428611
ESI is right.  As a modal form, before it runs, you can't get it.  After it runs, you can't get it.  Get it?
0
 
LVL 9

Expert Comment

by:cymbolic
ID: 1428612
Also, while it's running, you aren't running, so you can't get it! To do what you want, you have to use your own controls, in which case you can position the form before making it visible, even if you make it modal.
0
 
LVL 6

Author Comment

by:anthonyc
ID: 1428613
Well I am still certain there is a way.  I understand what you told me, and it's nothing that I didn't know!  I will still reject the answer.  Sorry, no cheap points from me.

Anthony
0
 
LVL 2

Accepted Solution

by:
vorlon earned 200 total points
ID: 1428614
anthonyc,
All the above comments/answers are correct. There is no way to center/position the commondialog box because the common dialog box is a modal form. That means that no code from you're application will run while the dialog box is being displayed. This along with the fact that the common dialog box is a Windows system call (resides in Windows DLL's) there's no way for you to get access at it from you're code using VB (C, C++ yes but not VB).

However, there have two ways of getting around this that I can think of:

1) Create a form that will look/behave just like a common dialog box using the drive, directory, and file list controls. Then you can center it (place it anywhere you want) in the Form_Load event. This is the easiest method...

2) Create a second application that it's only purpose is to look for the Common Dialog Box and position it where you want. This application doesn't have to be visible. Assuming you'll be using Visual Basic, place some code in the Sub Main procedure; no other procedure is necessary and no forms are necessary. This code would search for the Common Dialog Box and when found move it. This second application would be called from the main application.

NOTE: I don't know much about threads so I can't say much, however, it might be possible to create the second application as a separate thread of the main application. That might be better than creating the second application.

Hope this clarifies a bit of the confusion and hope it helps.
Vorlon
0
 
LVL 6

Author Comment

by:anthonyc
ID: 1428615
Thanks!  At least this is a response, with some reason.  I thought of both ideas before.  The second one is not really reasonable, and the first one is stupid.  I can call the common dialog DLL myself.  When you do that, the CDLG window position is at the top/left portion of the owner.  If I make a usercontrol, where the user positions the control is where the topleft is.   I am answering my own question.

Anthony
0
 
LVL 1

Expert Comment

by:dgb001
ID: 1428616
I found out that the CommonDialog Control will appear in the Top-Left Corner of its parent. Therefore, if you place it inside a PictureBox Control, it will appear in the Top Left corner of the Control. Therefore if you can center the corner of the PictureBox, you can center the CommonDialog Control as well.

NB: As much as I would like to claim credit for this answer, I did in fact copy it from elsewhere - but any points gratefully receievd nonetheless.

0
 
LVL 3

Expert Comment

by:ESI
ID: 1428617
A third solution I'd like to add to those Vorlon gave, and which might be as simple as the 1st :

Open a tiny & invisible form from which the CLDG will be called, centering it indeed on the flight.



0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question