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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Intercepting the Messagebox function

Status
Not open for further replies.

Redsz

Programmer
Jul 30, 2002
158
CA
I remember reading awhile ago about a way to intercept the messagebox function? If i remember correctly you were able to define a new format and specify a title if one did not exist.

Does anybody know how to do this?

Thx.
 
intercept? i don't understand what you mean?

to put a title on a messagebox..

Messagebox("Hello tek-tips",64,"This is a title")


Ali Koumaiha
TeknoSoft Inc
Farmington Hills, Michigan
 
We have literally hundreds of messebox function calls throughout our programs. What im looking for is a way to modify the looks of the messagebox function without going into each form and modify each individual messagebox function call.
 
You can't intercept a window natively in VFP. Because it requires callback function and you need a wrapper for that. There are several customizable "MessageBox API" wrapper at UT, also a "VFP Callback" wrapper if you want to search.

The only way to do it from VFP is using TIMER. But you can still see the window flashing for a moment.

Here is the example to change MessageBox position. Modify the code to suit your needs :
Local lcTitle, loSetPos

* ------------------
loSetPos = CreateObject('SetPos')
lcTitle = ' Set Position'
loSetPos.cTitle = lcTitle
loSetPos.Enabled = .T.
MessageBox('MB Position changed', 64, lcTitle)
loSetPos = Null
Release oSetPos


Define Class SetPos as Timer
Interval = 10
Enabled = .F.
cTitle = ''

Procedure Init
Declare Long FindWindowEx in User32 ;
Long hwndParent, Long hwndChildAfter, ;
String lpszClass, String lpszWindow

Declare Short SetWindowPos in User32 ;
Long hwnd, Long hWndInsertAfter, ;
Integer nHorz, Integer nVert, ;
Integer nWidth, Integer nHeight, Long nFlags
EndProc

Procedure Timer
Local lnhWnd, lnhFont, lcFont
lnhWnd = FindWindowEx(0, 0, Null, This.cTitle)
If (lnhWnd != 0)
This.Enabled = .F.
SetWindowPos(lnhWnd, 0, 100, 100, 0, 0, 0x1)
endif
EndProc

Procedure Destroy
Clear Dlls FindWindowEx, SetWindowPos
EndProc
EndDefine
* ------------------

Hope it helps


-- AirCon --
 
Have you tried using an INCLUDE file to replace Messagebox with MyMsgBox and then creating your own messagebox form?

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
You may want to think about creating your own message box class at this point. You would still have to go through and change all the current messageboxes to your class, but next time you wouldn't.
MESSAGEBOX() is pretty much a wrapper for the OS's message box. There isn't any sort of 'intercept' for it, and you can't change the appearance of it other than through API calls or Control Panel which would change message boxes globally for the OS.


-Dave S.-
[cheers]
Even more Fox stuff at:
 
I actually found the article i was referencing in my first partially cryptic post. However the problem is i can't get it to work. It's from the FoxPro advisor's February 2003 edition.
The article details how you can define the following in a standard Header File

#Define MESSAGEBOX caMessageBox


Then create a function in any of your procedure files.

function caMessagebox(tcText, tnType, tcTitle, tnTimeout)

#UNDEF MESSAGEBOX

.....
The function allows you to setup the format of the messagbox you are creating
.....

lnRetval = MESSAGEBOX( txText, tnType, lcTitle, tnTimeout )

#DEFINE MESSAGEBOX caMessagebox

RETURN lnRetVal
ENDFUNC


The above is a quick rundown of how the code is laid out. However it does not work. Im assuming when it says standard header file i can add the define to any of our existing <filename>.h files???
 
Here is what I have used since the days of 5.0 when I wanted to consistent messagebox that could handle multiple data types:

faq184-4348 Messagebox - INFO
faq184-4347 Messagebox - STOP
faq184-4346 Messagebox - YESNO

Although the current messagebox function can accept different data types (date, etc.) I still prefer this method. However, mine are contained in a method of one of my main classes so it is referred to as:

IF goMyApp.YESNO(&quot;Is this Helpful?&quot;)
goMyApp.Info(&quot;Cool&quot;)
ELSE
goMYApp.Stop(&quot;Ouch&quot;)
ENDIF


Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top