We help IT Professionals succeed at work.

Detecting a msgbox or input box of any application.

Matti
Matti asked
on
1,505 Views
Last Modified: 2010-04-24
Need good solution for my VB prog detecting a Msgbox of any application?

It need to cover Windows standard Msgboxes and CMdialog windows.
This solution shuld not use much resourses.

Background:
I have an quater screen size Vb app which stays top on other applications, and need to detect if other apps are showing messages or prompts to user.

Matti

Comment
Watch Question

Ark
CERTIFIED EXPERT

Commented:
Hi
My Syste-Wide shell hook - http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=1&txtCodeId=9153
can do this. Just working on complete code.

Cheers

Author

Commented:
Adjusted points from 400 to 600

Author

Commented:
Hi!

Ark, I tried it but it informs after the button has been pressed not when the Msgbox rises. I tried both exe and VB IDE and even add case Else to that hook.

Do You think some moore points will do it for me or it just can't be done.

The resource usage was fine in this but the hook was not correct to this job.


extra info:
If the solution you offer need other than VB code , this must also be freely available, pleace do not try Spy Works etc Third party solutions.  

Matti
Ark
CERTIFIED EXPERT

Commented:
Hi
It isn't so easy as I thought before. Shell hook allow to searc only for Top level windows. When these windows call their chailds (msgboxes etc) - Shell doesn't receive notification. Now I try to hook every window when it activated and unhook when deactivated, but it seems it 'eat' murch resourses.

Cheers
Ark
CERTIFIED EXPERT

Commented:
Hi
What system do you use? w95/98/2000/NT?
Cheers
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Ark
CERTIFIED EXPERT

Commented:
Sorry, in TimerProc Sub should be
Dim i As Integer, not
Dim m
Cheers

Author

Commented:
Hi!

All of these version.
The main app is targeted on all 32bit Windows versions.

It shuld be done by hooking MB_XXXX messages but I had some problems and like to have an alternative solution.


Now it take me a few hours to evaluate that last one, so do not rush.


Matti

Author

Commented:
Adjusted points from 600 to 800

Author

Commented:
Comment accepted as answer

Author

Commented:
Hi!

Excellent job Ark!

Thanx!


Matti

Ark
CERTIFIED EXPERT

Commented:
Hi
Thanks for point, Matti. Glad I can help you. I've made code with hooking, it works, but is very slowly. I think it's due to passing parameters between different processes. BTW, my code look only for STANDARD msgboxes, inputboxes or dialog boxes, i.e. with class "#32770". Some applications can use their own windows to do this, and it's almost impossible to catch them. Next step can be reading prompt and/or textbox value in InputBox. Do you need this code (no need more points)?

Cheers

Author

Commented:
Hi!


The resourse usage was the best point,I know that carefully selected filtering will keep it minimal.
I have also made one own code for this but it do not meet my own "standards". In this case yours was better thas why the points, and moore like total msg/Window hook in here will just kill the resourses. For example that funny dog MsgBox in MS Office-apps seems to know where it may been seen.

I detected it Zero to four in my system but those are relative results.

If you like send it I'm interesting, but what I'm gona make next is to compare window Rects and determine the position on the msgbox to filter it even moore. My app is a quater display size and it stays on top of all other windows, so in this case the msgbox is just a problem.

 

Matti
Ark
CERTIFIED EXPERT

Commented:
Hi

to move msgboxes:
add to declaration area of bas module:

Type RECT
     left As Long
     top As Long
     right As Long
     bottom As Long
End Type
Private Declare Function GetWindowRect& Lib "user32" (ByVal hwnd As Long, lpRect As RECT)
Private Declare Function MoveWindow& Lib "user32" (ByVal hwnd As Long, ByVal x As Long, _
ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As _
Long)

'Add this sub to bas module:

Private Sub MoveMsgBox(h As Long)
  Dim rc As RECT, rc1 As RECT
  GetWindowRect Form1.hwnd, rc
  GetWindowRect h, rc1
' dock MsgBox to the right edge of your window:
  MoveWindow h, rc.right, rc1.top, rc1.right - rc1.left, rc1.bottom - rc1.top, 1
End Sub

'And add col to this sub, for example, at the end of ShowChanges Sub:
 MoveMsgBox h

Cheers

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.