473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Detect a Modal Dialog Box

Hello,

I'm thinking this may be an easy one but I am getting frustrated. How
can I detect if a process is showing a modal dialog. Like "Are you sure
you want to exit?", or an error message etc...

I stumbled across the GetWindow API but am unsure how to work it
properly. The only examples I found are in VBA or VB6.

Private Declare Function GetWindow _
Lib "user32" (ByVal hWnd As IntPtr, ByVal nCmdShow As Int32) As IntPtr

Private Const GW_FIRST As Int32 = 0
Private Const GW_LAST As Int32 = 1
Private Const GW_NEXT As Int32 = 2
Private Const GW_PREV As Int32 = 3
Private Const GW_OWNER As Int32 = 4
Private Const GW_CHILD As Int32 = 5
Private Const GW_STYLE As Int32 = (-16)
Private Const WS_DISABLED As Int32 = &H8000000

Am I on the right track here or is the above even correct...can someone
give me a kickstart? Or is there an even simpler method to detect a
modal dialog? Thanks for your help!

Jeremy

Nov 21 '05 #1
1 2704
Alight I found the correct API call:

Private Declare Function apiGetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal Hwnd As IntPtr, ByVal _
nIndex As Long) As IntPtr

and I found a function to return true if a modal window is detected.
The problem is it is written for detecting a window in your own
application. I would like to detect a modal window in a exteranl app in
which I return the process.

Function IsFormModal(ByVal frm As Form) As Boolean
Dim f As Form

For Each f In Forms
If Not (f Is frm) Then
If (apiGetWindowLong(f.hWnd, GW_STYLE) And WS_DISABLED)
= 0 Then
' there is another enabled form, so this form
' can't be modal
Exit Function
End If
End If
Next
' all other forms are disabled, therefore this form is modal
IsFormModal = True
End Function

How can I tweak this to loop through windows in an exteranl process in
which I return the Process.MainWindowHandle? Thanks!

Jeremy

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gilles T. | last post by:
Hi, How I can refresh a modal dialog in asp.net? I open a modal dialog in first with a dropdownlist. To add a element in my dropdownlist (table), I open a second modal dialog to ask element and...
2
by: cassidyc | last post by:
Hi, I was wondering if anyone has come accross this issue? And if they have any solutions I have that can create new copies of itself Form1 as = new form1(); af.show(); This form can also...
10
by: Guadala Harry | last post by:
I have a modal dialog that currently does all of the following except item 4. 1. lets users select a graphic from a list of thumbnails (and when selected, displays the full-size image in a...
1
by: Jeremy | last post by:
I apologize for the repost but I am frustrated and desperate for a solution. I need to detect if an external application is displaying a modal form. I.E. dialog box or error message. I found...
2
by: sthrudel | last post by:
Hi! I'm working on a web application in Asp.net and what I would like to have is a cross borwser modal dialog which accepts user's input. I would like to catch what the user clicked on the...
21
by: Bob Darlington | last post by:
I have a routine which checks idle time and opens a pop up screen to advise users before shutting them down. The pop up has an option for the user to keep the application open, in which case the...
2
by: =?Utf-8?B?TGVuaTIwMDA=?= | last post by:
Hi, I would like to write a c# application. to detect if a modal dialog opens on another application, (e.g. notepad.exe save changes dialog when you click exit ) and auto cancel it. How do I detect...
10
by: Xu, Qian | last post by:
Hi All, Is it possible to detect whether a (confirmation or prompt) dialog is present? And furthermore, how to press OK, Cancel buttons of a dialog? I am writing a javascript based test...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.