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

Tired of the VFP default messagebox? 2

Status
Not open for further replies.

Mike Gagnon

Programmer
Apr 6, 2002
8,067
CA
Try a new style messagebox that is more flexible, can be positionned anywhere, you can change the font, the background color, add buttons etc.
Code:
objShell = CreateObject("WScript.Shell")
Declare Sleep In kernel32 Integer dwMilliseconds
objIE = Createobject("InternetExplorer.Application")
strIETitle ="Message box"
strMsg ="This is my new style message box"
With objIE
	.Toolbar = .F.
	.StatusBar = .F.
	.Resizable = .F.
	.Navigate("about:blank")
	With .Document
		With .ParentWindow
			intWidth = .Screen.AvailWidth
			intHeight = .Screen.AvailHeight
			intWidthW = .Screen.AvailWidth * .40
			intHeightW = .Screen.AvailHeight * .05
			.resizeto(300,200)
			.moveto( (.Screen.AvailWidth)/6, (.Screen.AvailHeight)/6)
		Endwith
		.Write( &quot;<body> &quot; + strMsg + &quot; </body></html>&quot;)
		With .ParentWindow.Document.body
			.Style.backgroundcolor = &quot;LightBlue&quot;
			.Scroll=&quot;no&quot;
			.Style.Font = &quot;20pt 'Arial'&quot;
			.Style.BorderStyle = &quot;outset&quot;
			.Style.BorderWidth = &quot;4px&quot;
		Endwith
		.Title = strIETitle
		=Sleep(100)
		objShell.AppActivate(strIETitle)
	Endwith
Endwith
objIE.Visible = .T.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Very nice Mike!

Star's in order...

Darrell
 
Slight mod of your code:

Also, it might make sense to use a form with a brower
control added which is the same width and height of the
form.

This way it'll invoke faster, plus, you'll have more
control of the UI.

Darrell

[tt]
* IE Messagebox

#DEFINE IETitleText &quot; - Microsoft Internet Explorer&quot;

objShell = CREATEOBJECT(&quot;WScript.Shell&quot;)
objIE = CREATEOBJECT(&quot;InternetExplorer.Application&quot;)
objApi = CREATEOBJECT(&quot;clsWinApiCalls&quot;)

strIETitle = &quot;Message box&quot;
strMsg = &quot;This is my new style message box&quot;

WITH objIE
.TOOLBAR = .F.
.STATUSBAR = .F.
.RESIZABLE = .F.

.Navigate(&quot;about:blank&quot;)

WITH .DOCUMENT
WITH .ParentWindow
intWidth = .SCREEN.AvailWidth
intHeight = .SCREEN.AvailHeight
intWidthW = .SCREEN.AvailWidth * .40
intHeightW = .SCREEN.AvailHeight * .05
.resizeto(300,200)
.moveto( (.SCREEN.AvailWidth)/6, (.SCREEN.AvailHeight)/6)
ENDWITH

.WRITE( &quot;<body> &quot; + strMsg + &quot; </body></html>&quot;)

WITH .ParentWindow.DOCUMENT.body
.STYLE.backgroundcolor = &quot;LightBlue&quot;
.SCROLL=&quot;no&quot;
.STYLE.FONT = &quot;20pt 'Arial'&quot;
.STYLE.BORDERSTYLE = &quot;outset&quot;
.STYLE.BORDERWIDTH = &quot;4px&quot;
ENDWITH
.TITLE = strIETitle
objApi.SleepFor(10)
ENDWITH
ENDWITH
objIE.VISIBLE = .T.

DO WHILE !objApi.WinExits(strIETitle+IETitleText)
objApi.SleepFor(20)
ENDDO

objApi.SetWindowToForeGround(strIETitle+IETitleText)

DO WHILE objApi.WinExits(strIETitle+IETitleText)
objApi.SleepFor(20)
ENDDO

IF VARTYPE(cForeGroundWindow)==&quot;C&quot;
objApi.SetWindowToForeGround(cForeGroundWindow)
ENDIF



DEFINE CLASS clsWinApiCalls AS CUSTOM
nHWND = 0
PROCEDURE INIT
THIS.DECL()
ENDPROC

PROCEDURE SleepFor(lnMillSecs)
Sleep(lnMillSecs)
ENDPROC

FUNCTION WinExits(lcWindowTitle)
THIS.nHWND = FindWindow(NULL,lcWindowTitle)
RETURN THIS.nHWND >0
ENDFUNC

PROCEDURE SetWindowToForeGround(lcWindowTitle)
THIS.nHWND = FindWindow(NULL,lcWindowTitle)
*!* nHWND = FindWindow(Null,_screen.caption)
IF THIS.nHWND >0
THIS.ForceForegroundWindow()
ENDIF
ENDPROC

PROCEDURE ForceForegroundWindow
LOCAL nForeThread, nAppThread
nForeThread = GetWindowThreadProcessId(GetForegroundWindow(), 0)
nAppThread = GetCurrentThreadId()
IF nForeThread != nAppThread
AttachThreadInput(nForeThread, nAppThread, .T.)
BringWindowToTop(THIS.nHWND)
*!* ShowWindow(lnHWND,3)
AttachThreadInput(nForeThread, nAppThread, .F.)
ELSE
BringWindowToTop(THIS.nHWND)
*!* ShowWindow(lnHWND,3)
ENDIF
ENDPROC

PROCEDURE DECL
DECLARE INTEGER Sleep IN Win32API INTEGER

DECLARE LONG FindWindow IN Win32API STRING, STRING

DECLARE LONG BringWindowToTop IN Win32API LONG

DECLARE INTEGER GetCurrentThreadId IN kernel32

DECLARE INTEGER GetWindowThreadProcessId IN user32;
INTEGER HWND,;
INTEGER @ lpdwProcId

DECLARE INTEGER GetCurrentThreadId IN kernel32

DECLARE INTEGER AttachThreadInput IN user32 ;
INTEGER idAttach, ;
INTEGER idAttachTo, ;
INTEGER fAttach

DECLARE INTEGER GetForegroundWindow IN user32

DECLARE LONG GetSystemDirectory IN win32api STRING lpBuffer, LONG nSize

DECLARE LONG GetWindowsDirectory IN win32api STRING lpBuffer, LONG nSize

ENDPROC
ENDDEFINE
[/tt]
 
Also, it might make sense to use a form with a brower
control added which is the same width and height of the
form.

This way it'll invoke faster, plus, you'll have more
control of the UI.


Yes it could be, but I think in a thread recently, someone brought up the idea to design a web-browser application (meaning the application runs from the web-browser rather than the other way around).

BTW I noticed you made a bunch of API calls to make sure the window has focus, I would why you would that over the one liner:

objShell.AppActivate(strIETitle).

To further explain my idea was use an set of HTML pages to be loaded in the the above function to generate the interface. Here is another step toward that
[ol][li] Create a textfile (save it as test.htm) with the following:
Code:
<html>
<head>
<title>
</title>
</head>
<body bgcolor=&quot;#D4D0C8&quot;>
<div id=&quot;div_Form1&quot;>
<form id=&quot;Form1&quot; name=&quot;Form1&quot; style=&quot;font-family: Arial; font-size: 9pt; color: #000000; background: LightBlue&quot;>
<div id=&quot;div_Form1_COMPANY_NAME1&quot; style=&quot;position: absolute; left:110; Top:81&quot;>
<input id=&quot;Form1_COMPANY_NAME1&quot; name=&quot;Form1_COMPANY_NAME1&quot; type=&quot;TEXT&quot; value=&quot;&quot; style=&quot;font-family: Arial; font-size: 8pt; color: #000000; background: #FFFFFF&quot;>
</div>
<div id=&quot;div_Form1_CONTACT_NAME1&quot; style=&quot;position: absolute; left:110; Top:105&quot;>
<input id=&quot;Form1_CONTACT_NAME1&quot; name=&quot;Form1_CONTACT_NAME1&quot; type=&quot;TEXT&quot; value=&quot;&quot; style=&quot;font-family: Arial; font-size: 8pt; color: #000000; background: #FFFFFF&quot;>
</div>
<div id=&quot;div_Form1_CONTACT_TITLE1&quot; style=&quot;position: absolute; left:110; Top:129&quot;>
<input id=&quot;Form1_CONTACT_TITLE1&quot; name=&quot;Form1_CONTACT_TITLE1&quot; type=&quot;TEXT&quot; value=&quot;&quot; style=&quot;font-family: Arial; font-size: 8pt; color: #000000; background: #FFFFFF&quot;>
</div>
<div id=&quot;div_Form1_CUSTOMER_ID1&quot; style=&quot;position: absolute; left:110; Top:57&quot;>
<input id=&quot;Form1_CUSTOMER_ID1&quot; name=&quot;Form1_CUSTOMER_ID1&quot; type=&quot;TEXT&quot; value=&quot;&quot; style=&quot;font-family: Arial; font-size: 8pt; color: #000000; background: #FFFFFF&quot;>
</div>
<div id=&quot;div_Form1_Label1&quot; style=&quot;position: absolute; left:12; Top:8&quot;>
<span id=&quot;Form1_Label1&quot; name=&quot;Form1_Label1&quot; style=&quot;font-family: Times New Roman; font-size: 20pt; color: #000000; font-weight: bold; background: LightBlue&quot;>
CUSTOMER
</span>
</div>
<div id=&quot;div_Form1_LBLCOMPANY_NAME1&quot; style=&quot;position: absolute; left:10; Top:85&quot;>
<span id=&quot;Form1_LBLCOMPANY_NAME1&quot; name=&quot;Form1_LBLCOMPANY_NAME1&quot; style=&quot;font-family: Arial; font-size: 8pt; color: #000000; background: LightBlue&quot;>
Company name:
</span>
</div>
<div id=&quot;div_Form1_LBLCONTACT_NAME1&quot; style=&quot;position: absolute; left:10; Top:109&quot;>
<span id=&quot;Form1_LBLCONTACT_NAME1&quot; name=&quot;Form1_LBLCONTACT_NAME1&quot; style=&quot;font-family: Arial; font-size: 8pt; color: #000000; background: LightBlue&quot;>
Contact name:
</span>
</div>
<div id=&quot;div_Form1_LBLCONTACT_TITLE1&quot; style=&quot;position: absolute; left:10; Top:133&quot;>
<span id=&quot;Form1_LBLCONTACT_TITLE1&quot; name=&quot;Form1_LBLCONTACT_TITLE1&quot; style=&quot;font-family: Arial; font-size: 8pt; color: #000000; background: LightBlue&quot;>
Contact title:
</span>
</div>
<div id=&quot;div_Form1_LBLCUSTOMER_ID1&quot; style=&quot;position: absolute; left:10; Top:61&quot;>
<span id=&quot;Form1_LBLCUSTOMER_ID1&quot; name=&quot;Form1_LBLCUSTOMER_ID1&quot; style=&quot;font-family: Arial; font-size: 8pt; color: #000000; background: LightBlue&quot;>
Customer ID#:
</span>
</div>

</form>
</div>
</body>
</html>
[/li]
[li]Now use the following to load it:
Code:
objShell = Createobject(&quot;WScript.Shell&quot;)
Declare Sleep In kernel32 Integer dwMilliseconds
objIE = Createobject(&quot;InternetExplorer.Application&quot;)
strIETitle = &quot;Internet Explorer Test form&quot;+ REPLICATE(&quot; &quot;,180)
lcFunction = Filetostr(&quot;c:\test.htm&quot;)
Public blnFlag
blnFlag = .F.
With objIE
	.Toolbar = .F.
	.StatusBar = .F.
	.Resizable = .F.
	.Navigate(&quot;about:blank&quot;)
	.fullscreen= .t.
	With .Document
		.writeln(lcFunction)
		With .ParentWindow
			intWidth = .Screen.AvailWidth
			intHeight = .Screen.AvailHeight
			intWidthW = .Screen.AvailWidth * .50
			intHeightW  .Screen.AvailHeight* .50
			.resizeto(intWidthW, intHeightW)
			.moveto((intWidth - intWidthW)/2, (intHeight - intHeightW)/2)
		Endwith
		With .ParentWindow.Document.body
			.Style.backgroundcolor = &quot;LightBlue&quot;
			.Scroll=&quot;no&quot;
			.Style.Font = &quot;20pt 'Arial'&quot;
			.Style.BorderStyle = &quot;outset&quot;
			.Style.BorderWidth = &quot;4px&quot;
		Endwith
		.Title = strIETitle
		=Sleep(100)
		objShell.AppActivate(strIETitle)
	Endwith
Endwith
objIE.Visible = .T.
[/li][/ol]


P.S. Take out the fullscreen = .t. to be able to close the form, until an exit button can be added to the form. The data also has to be bound to the controls. But it is insteresting to take VFP outside of itself (run the IE from VFP) and take it back in itself (Bind the data to a VFP table).
I would estimate that the could be also used for actual Web-Type application, since the data can anywhere, and any functionality to be added to the form has to be added at the HTML level using VBScript, whether it is local or remote data.




Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
The reason I made all the API calls is that it won't show
in front most of the time on WinXP. It will only flash the
app on the task bar.

Darrell

P.S. Inspired by your post, I'm creating a form class hierarchy based on a browser control embedded within it.

That way, it will be easy to create apps that use the browser as the main application UI
with the form as the driver. Many benefits – such as using dtc objects that can hook to any data source, java, vb, scripts, etc. embedded on the html code in the browser control.

To create a new app all one has to due is create a small web page and have the form load it at run time. Plus, it makes it easy to maintain applications since the primary logic is run from a html page/ web server, etc.

Endless possibilities…

I prefer the browser because of its typographic control over most form based apps anyway.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top