Solved

Centering a Common Dialog Box in VB5

Posted on 1997-07-21
10
267 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
Comment Utility
Not possible .
0
 
LVL 6

Author Comment

by:anthonyc
Comment Utility
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
Comment Utility
coz CDLG is modal
0
 
LVL 9

Expert Comment

by:cymbolic
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 6

Author Comment

by:anthonyc
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…

763 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

6 Experts available now in Live!

Get 1:1 Help Now