Solved

Centering a Common Dialog Box in VB5

Posted on 1997-07-21
10
270 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBA filters 2 51
message box in access 4 41
Add a task in Outlook from access 11 35
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 42
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
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…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now