Solved

Centering a Common Dialog Box in VB5

Posted on 1997-07-21
10
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses
Course of the Month3 days, 16 hours left to enroll

630 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