S@)- You can detect when someone switches between your application and another

You can detect a change to the hardware configuration of a device or the computer. For example, you may want to detect when media such as USB drive is inserted into the computer and act upon that event.

 

Sample: to run the sample, click on the Enable Event button. Once the event is active, insert a USB drive or other device. If you insert a USB drive, the sample will display JPEG and MP3 files.

 

Details:

 

This sample uses the following binding to handle media detection:

 

BINDEVENT(_VFP.hWnd, WM_DEVICECHANGE, THIS, "handlewinmsg")

BINDEVENT(_VFP.hWnd, WM_USER_SHNOTIFY, THIS, "handlewinmsg")

 

Note: WM_USER_SHNOTIFY is based on the WM_USER message

 

In addition, this sample uses a number of Shell functions to detect device changes.

 

You can find additional information about shell events in MSDN:

 

WM_DEVICECHANGE Message

WM_USER Message

Shell Programmer’s Guide

SHChangeNotifyRegister function

                                

Click on the Constants button to view values for the #DEFINES.

 You can detect when someone switches between your application and another

You can detect when files or directories are added, updated or deleted to your system using Windows messages.

 

Sample: to run the sample, click on the Enable Event button. Once the event is active, open up Windows Explorer and try adding, removing or renaming a file or folder. You can also change a file’s attributes such as making it read-only.

 

Details:

 

This sample uses the following binding to handle file detection:

 

BINDEVENT(_VFP.hWnd, WM_USER_SHNOTIFY, THIS, "handlewinmsg")

 

Note: WM_USER_SHNOTIFY is based on the WM_USER message

 

In addition, this sample uses a number of Shell functions to detect changes to files and directories.        

 

You can find additional information about shell events in MSDN:

 

WM_USER Message

Shell Programmer’s Guide

SHChangeNotifyRegister function

 

Click on the Constants button to view values for the #DEFINES.

Ç You can detect when someone switches between your application and another

You can detect when someone switches between your application and another.

 

Sample: to run the sample, click on the Enable Event button. Once the event is active, try switching between applications using your mouse or ALT+TAB.

 

Details:

 

This sample uses the following binding to handle application switching:

 

BINDEVENT(_VFP.hWnd, WM_ACTIVATE, THIS, "handlewinmsg")

 

Note that you can also bind to a Top-Level form if your application has the Visual FoxPro desktop hidden.

 

BINDEVENT(myTopLevelForm.hWnd, WM_ACTIVATE, THIS, "handlewinmsg")

 

The WM_ACTIVATE message

 

WA_INACTIVE

WA_ACTIVE

WA_CLICKACTIVE

 

You can find additional information about application activation events in MSDN:

 

WM_ACTIVATE Message

 

Click on the Constants button to view values for these #DEFINES.

Ê You can detect when someone switches between your application and another

You can detect when the Windows Theme is changed.

                                                                                            

Sample: to run the sample, click on the Enable Event button. Once the event is active, open the Display Control Panel. Once opened, you can switch Themes from the Themes or Appearance tabs.

 

Details:

 

This sample uses the following binding to handle Theme changes:

 

BINDEVENT(_SCREEN.hWnd, WM_THEMECHANGED, THIS, "handlewinmsg")

 

Note: MSDN indicates the wParam and lParam parameters passed to the message handler are reserved.

 

You can find additional information about Theme events in MSDN:

 

WM_THEMECHANGED Message

 

Click on the Constants button to view values for the #DEFINES.

"c You can detect when someone switches between your application and another

The operating system broadcasts a message to all running applications whenever a power management event occurs such as system stand-by or hibernation. Additionally, messages are broadcast when one attempts to shutdown Windows. You can trap for these events and perform necessary actions or even prevent the power suspension or shutdown from occurring.

                                                                                            

Sample: to run the sample, click on the Enable Event button. Once the event is active, click on the Start menu and select Shut Down. When the dialog appears, select either Stand by or Hibernate. A dialog will appear asking if you want to go in Stand By mode. All responses are recorded to the edit box on the right side. In fact, if you select Yes, when you resume from Stand By mode, power events will still be received. You are also prompted if you attempt to shutdown Windows.

 

Details:

 

This sample uses the following binding to detect power management changes:

 

BINDEVENT(_VFP.hWnd, WM_POWERBROADCAST, THIS, "handlewinmsg")

 

You can find additional information about Power Management events in MSDN:

 

System Shutdown events

WM_QUERYENDSESSION Message

 

Power Management events

WM_POWERBROADCAST Message

 

Click on the Constants button to view values for the #DEFINES.

PLPARAMETER oForm LOCAL loError, lnHgt, lnWdt TRY lnHgt=oForm.cntEvent.Height lnWdt=oForm.cntEvent.Width oForm.cntEvent.AddObject("edtEvent","Editbox") WITH oForm.cntEvent.edtEvent .Top = 2 .Left = 2 .Height = lnHgt - 50 .Width = lnWdt - 4 .Anchor = oForm.cntEvent.Anchor .Visible = .T. ENDWITH oForm.cntEvent.AddObject("chkCaption","Checkbox") WITH oForm.cntEvent.chkCaption .Top = lnHgt - 25 .Left = 2 .Caption = "Show titlebar caption" .Fontname = 'Tahoma' .FontSize = 9 .AutoSize = .T. .Value = .T. .Anchor = 12 .Visible = .T. ENDWITH oForm.cntEvent.AddObject("chkGrad","Checkbox") WITH oForm.cntEvent.chkGrad .Top = lnHgt - 25 .Caption = "Display titlebar gradient" .Fontname = 'Tahoma' .FontSize = 9 .AutoSize = .T. .Left = lnWdt - .Width - 50 .Value = .F. .Anchor = 12 .Visible = .T. ENDWITH BINDEVENT(oForm.cntEvent.chkCaption,"Click", oForm, "vfprefresh", 1) BINDEVENT(oForm.cntEvent.chkGrad,"Click", oForm, "vfprefresh",1) CATCH TO loError MESSAGEBOX(loError.Message) ENDTRY§LPARAMETER oForm LOCAL loError, lnHgt, lnWdt TRY lnHgt=oForm.cntEvent.Height lnWdt=oForm.cntEvent.Width oForm.cntEvent.AddObject("oleTreeView","olecontrol","mscomctllib.treectrl.2") WITH oForm.cntEvent.oleTreeView .Top = 2 .Left = 2 .Height = lnHgt - 4 .Width = lnWdt - 4 .Anchor = oForm.cntEvent.Anchor .Visible = .T. ENDWITH CATCH TO loError MESSAGEBOX(loError.Message) ENDTRY!­ You can detect when someone switches between your application and another

With Windows Message events, you can use Activate and Paint messages when working with GDI+ for custom graphics drawing.

 

Sample: to run the sample, click on the Enable Event button. Once the event is active, you should see some GDI+ text graphics on the Visual FoxPro titlebar. Try switching between applications using your mouse or ALT+TAB and you will see Paint and Activate events causing the titlebar to repaint the text in different colors. If you click on the Gradient checkbox, you will see the titlebar displayed in a gradient.

 

Details:

 

This sample uses the following binding to handle application paint events:

 

BINDEVENT(_VFP.hWnd, WM_NCPAINT, THIS, "handlewinmsg")

BINDEVENT(_VFP.hWnd, WM_NCACTIVATE, THIS, "handlewinmsg")

 

Note that you can also bind to a specific form by passing in its hWnd:

 

BINDEVENT(myForm.hWnd, WM_NCPAINT, THIS, "handlewinmsg")

 

The sample uses the GDI+ Graphics class library in the FFC folder.

 

You can find additional information about application paint events and GDI+ in MSDN:

 

WM_NCPAINT Message

WM_NCACTIVATE Message

 

Click on the Constants button to view values for #DEFINES.

# You can detect when someone switches between your application and another

With Windows Message events, you can trap for window events in your Visual FoxPro application such as when new ones are opened or existing ones closed.

 

Sample: to run the sample, click on the Enable Event button. Once the event is active, you should see a list of all open windows in the treeview (note: dockable ones may not appear initially). Try opening and closing different types of windows and watch the list update.

 

Details:

 

This sample uses the following binding to handle windowing events:

 

BINDEVENT(0, WM_CREATE, THIS, "handlewinmsg",4)

BINDEVENT(hWnd, WM_DESTROY, THIS,"handlewinmsg",4)

BINDEVENT(hWnd, WM_SETTEXT, THIS,"handlewinmsg",4)

BINDEVENT(hWnd, WM_SETFOCUS, THIS,"handlewinmsg",4)

BINDEVENT(hWnd, WM_WINDOWPOSCHANGED, THIS,"handlewinmsg",4)

 

Note: you should use care when working with these events as they may produce unexpected results or even crashes if not properly handled.

 

You can find additional information about windowing events in MSDN:

 

WM_CREATE Message

 

Click on the Constants button to view values for #DEFINES.

#] You can detect when someone switches between your application and another

With Windows Message events, you can trap for window events in your Visual FoxPro application such as when new ones are opened or existing ones closed.

 

Sample: to run the sample, click on the Enable Event button. Once the event is active, you should see a list of all open windows in the treeview (note: dockable ones may not appear initially). Try opening and closing different types of windows and watch the list update.

 

Details:

 

This sample uses the following binding to handle windowing events:

 

BINDEVENT(0, WM_CREATE, THIS, "handlewinmsg",4)

BINDEVENT(hWnd, WM_DESTROY, THIS,"handlewinmsg",4)

BINDEVENT(hWnd, WM_SETTEXT, THIS,"handlewinmsg",4)

BINDEVENT(hWnd, WM_SETFOCUS, THIS,"handlewinmsg",4)

BINDEVENT(hWnd, WM_WINDOWPOSCHANGED, THIS,"handlewinmsg",4)

 

Note: you should use care when working with these events as they may produce unexpected results or even crashes if not properly handled. Additionally, it is not recommended that you try this sample with the debugger.

 

You can find additional information about windowing events in MSDN:

 

WM_CREATE Message

 

Click on the Constants button to view values for #DEFINES.