Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CommonDialog without stop the application 1

Status
Not open for further replies.

leinad49

Programmer
Aug 29, 2002
11
ES
Hello to everybody!!

I have an application running to control one process. Then during the execution of that process (it can't stop!!), the user can open a CommonDialog box (Open files) and select some file. But the problem is that CommonDialog box is a modal dialog and all the process is stopped.

Do you have any idea on how to open it without stop my application. I mean I need to open it and raise an event to inform my application that someone has close that dialog...

Many thanks in advance
 
If you are using a regular timer control to run your process, it will stop when the common dialog is open.

To avoid this, use the API timer statements to create a timer, and place your process code in the callback routine that the timer API uses.

Here's an example. You'll need a form with a text box, a command button, and your Common Dialog control. This is the code for the form.

Option Explicit

Private Sub Command1_Click()
CommonDialog1.ShowOpen
Debug.Print "CommonDialog closed"
End Sub

Private Sub Form_Load()
StartTimer
End Sub

Private Sub Form_Unload(Cancel As Integer)
StopTimer
End Sub


And you will need this code in a module:

Option Explicit

Public TimerID As Long

Public Declare Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long

Public Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long

Public Sub StartTimer()
TimerID = SetTimer(0, 0, 50, AddressOf TimeOut)
End Sub

Public Sub StopTimer()
KillTimer 0, TimerID
End Sub

Public Sub TimeOut(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
Static I As Single
I = I + 1
Form1.Text1.Text = I
End Sub


When you run the project, you will see the text counting up, showing the timer is running. This is done in the subroutine "TimeOut". This is where you would put the code to run your process.

When you click the command button, the Common Dialog is opened. Notice that the counter keeps running. When you close the dialog, the code after the open statement is executed. This is where you would put your code for the Common Dialog being closed by the user.

Note that when using a timer API like this, if your program ends without the form unload event being called ( like if you go into debug mode and then end the program ), the VB IDE will crash because the timer was not "killed". So save your work before running your program!

Hope this helps,

Robert
 
Many thanks for your answer Robert. I'm sure that will be very useful for a lot of my applications!!. But unfortunately I need that commondialog in some applications that are using the timer control instead of the API timer at the moment.

Finally I used the following steps. I created an ActiveX EXE project with its own commondialog in its own process, then from an ActiveX DLL class (that is used from the client program) I make a call to the commondialog to be opened (there are a little more deep things to threat with, but this is the idea and is working fine...)

Thanks a lot for your reply!
 
Glad that it helped you. You know that you can replace the timer controls in any project with the timer API calls. Just move the code in the timer control event to the callback sub of the API timer.

Robert
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top