Link to home
Start Free TrialLog in
Avatar of Matti
MattiFlag for Finland

asked on

Detecting a msgbox or input box of any application.

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

Avatar of Ark
Ark
Flag of Russian Federation image

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
Avatar of Matti

ASKER

Adjusted points from 400 to 600
Avatar of Matti

ASKER

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
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
Hi
What system do you use? w95/98/2000/NT?
Cheers
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, in TimerProc Sub should be
Dim i As Integer, not
Dim m
Cheers
Avatar of Matti

ASKER

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

Avatar of Matti

ASKER

Adjusted points from 600 to 800
Avatar of Matti

ASKER

Comment accepted as answer
Avatar of Matti

ASKER

Hi!

Excellent job Ark!

Thanx!


Matti

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
Avatar of Matti

ASKER

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
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