Solved

Centering a Common Dialog Box in VB5

Posted on 1997-07-21
10
273 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro which automatically send Excel spreadsheet to Outlook problem 2 67
MS Date Picker 64 bit 32 bit issue 12 55
Help me. 3 56
Send outlook email from VBS Script 2 30
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

803 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