2006-05May-26
Downloading all images in a page
The following code receives a reference to IE or the web browser control. The code loops through all
IMG tags and downloads those that have a picture associated with it. If you also retrieve the text of
a web page, you can store all the content of the page.
Lparameters toWeb
Local loImg, lnImg
DECLARE INTEGER URLDownloadToFile IN urlmon Long, STRING, ;
STRING, Long, Long
loImg = toWeb.Document.getElementsByTagName("img")
For lnImg=0 to loImg.Length-1
If not Empty(loImg.item(m.lnImg).Src)
URLDownloadToFile( ;
0, ;
loImg.item(m.lnImg).Src, ;
"img"+Transform(m.lnImg)+"."+;
JustExt(loImg.item(m.lnImg).Src), ;
0, 0 ;
)
EndIf
EndFor
2006-05May-25
VFP evaluates the ControlSource more often than you might think
When you activate or deactivate a form, VFP evaluates the ControlSource several times, even though
Refresh isn't called, at all. As long as the ControlSource expression is valid, that's hardly an issue.
Invalid ControlSources, however, show a peculiar behavior. In this case we're talking about properties
being the ControlSource.
When you deactivate a form, VFP validates the ControlSource using a similar method
as VARTYPE() uses. If the object exists, but the property doesn't, VFP detects this without reporting any error .
Not before you activate the form, VFP accesses the ControlSource ignoring the fact that the property
doesn't exist anymore. This causes an error.
However, if the ControlSource is a property of an object that doesn't exist anymore, the first VARTYPE-like
test fails. In this case, you get the error message already when you deactivate the form, not when you re-activate it. In
my particular situation this error message finally ended in a C5 error. Here's a program that demonstrates that
VFP attempts to access the control source when you deactivate the form:
Clear
Public goForm
goForm = CreateObject("MyForm")
goForm.Show()
Define Class MyForm as Form
Left = 150
oItem = NULL
Add Object myCheckbox as Checkbox with ;
ControlSource = "Thisform.oItem.lSource"
Procedure Load
This.oItem = CreateObject("myItem")
EndProc
Procedure Refresh
Activate Screen
? "Refresh"
EndProc
EndDefine
Define Class myItem as Custom
lSource = .T.
Procedure This_Access( tcProp )
Activate Screen
? "myItem." + m.tcProp
Return This
EndProc
EndDefine
2006-05May-23
Detecting a dopped down combo
VFP triggers the DropDown event when the dropdown part of a combobox is opened. Unfortuantely,
there's no correlating DropUp event of any sort. So, you have to rely on other events that are
triggered in this case. The most important one is the When event. To distiguish a user moving the
focus into the combobox and the user clicking on the dropdown button, you can use a flag that you
set to .T. in the DropDown event. If When is triggered, and the flag is .T., then the user closed
the dropdown area. Set the flag to .F. in this case.
There are exceptions, however. One such exception is that pressing ENTER closes the dropdown area
without raising the When event. You can use the KeyPress event to watch out for this situation. The
flag must be set and the user pressed ENTER. Clear the flag in this case.
2006-05May-12
Displaying an empty page
Displaying a page in a web browser control is easy. Just call Navigate2(). If you need to clear the
display you can use the following line:
oBrowser.Navigate2( "about:blank" )
2006-05May-12
Clicking sound
When you call the Navigate2 method in the web browser
control, the browser plays the "start navigation" sound. By default, that's a
brief clicking sound. To avoid the sound you need to hide the control while
calling Navigate2. As this causes a lot of flickering, you want to lock the form
while the control is invisible. For ActiveX controls you need to use the
LockWindowUpdate() API function.
DECLARE INTEGER
LockWindowUpdate IN USER32 INTEGER nHandle
llVisible = m.Browser.Visible
LockWindowUpdate(Thisform.HWnd)
Browser.Visible = .F.
Browser.Navigate2( m.tcTarget )
Browser.Visible = m.llVisible
LockWindowUpdate(0)
If you ever use this function in your own code, make sure your error handler starts with
LockWindowUpdate(0)
to disable the lock.
2006-05May-12
Tabindex and SetFocus
TabIndex defines in which order VFP cycles through the container. It doesn't, however, define which control
receives the focus if you set the focus to the parent object. If you call the SetFocus() method of a container,
VFP sets the focus to the element that has been instantiated first. That is, VFP scans the Objects collection in
pyhsical order and sets the focus to the first element that can receive the focus. VFP does NOT set the
focus to the control with the lowest TabIndex. The following program demonstrates this.
Public goForm
goForm = CreateObject("MyForm")
goForm.Show()
goForm.myContainer.SetFocus()
Define Class MyForm as Form
Add object Text1 as Textbox with Top = 0
Add Object myContainer as MyContainer with Top = 30
Add object Text2 as Textbox with Top = 130
EndDefine
Define Class myContainer as Container
Add Object Text1 as Textbox with Top=0, TabIndex = 2
Add Object Text2 as Textbox with Top=25, TabIndex = 1
Add Object Text3 as Textbox with Top=50, TabIndex = 3
EndDefine