Working with windows messages throw a guide sample

Published on by Yousfi Benameur

 
i have a periodical wallpaper with many pictures in a folder.
i use a code to set a wallpaper as bmp photo all 6 minutes.
when capturing some areas on desktop i dont want to see icons,links,personal things...
And i want to hide  them with a big image.
this code makes the desktop wallpaper shown on a form instantenously with windows messages and bindevent.
the wallpaper  image stays in temp folder as bmp format (mandatory for     any wallpaper).the wallpaper change is reflected de facto on the form.
    Can use any windows message from winUser.h with the same handling procedure message  in this code....
    see the solution sample in vfp9 in this location:
    home(1)+"SAMPLES\SOLUTION\EUROPA\WINDOWSEVENTS.SCX"
    and review the file  wmhandler.h (windows constants).
the used form is top level with alwaysOnBottom property set to true.For protecting  desktop screen can use instead alwaysOnTop property(can hide all screen even the windows taskbar). 
the handlemsg procedure is specific to windows messages (can test msg,wparam,lparam for any window given with its hwnd).
i used a similar code in this link:
http://yousfi.over-blog.com/2015/09/blurring-a-vfp-form-background.html

to test this code you must have mandatory a wallpaper desktop maker and access to the image bmp pointed in code.

Can also use any big  bmp image in same location and name to test the code (image in sys(2023) folder / temp folder).

 

 

Click on code to select [then copy] -click outside to deselect

*1*
_screen.windowstate=1
Publi yform
yform=Newobject("ybackground")
yform.Show
Read Events
Return
*
Define Class ybackground As Form
    BorderStyle = 0
	Top = 31
	Left = 275
	Height = 250
	Width = 375
	ShowWindow = 2
	Caption = "Form1"
	KeyPreview = .T.
	TitleBar = 1
	AlwaysOnBottom = .T.
	horigproc = 0
	Name = "Form1"

Add Object image1 As Image With ;
    	Anchor = 15, ;
		Stretch = 2, ;
		Height = 250, ;
		Left = 0, ;
		Top = 0, ;
		Width = 375, ;
		Name = "Image1"
        
	Procedure handlewinmsg
	Lparameters HWnd, Msg, wParam, Lparam
	#Define WM_SETTINGCHANGE 0x001A
	Local nReturn
	nReturn=0

	Do Case
	Case Msg = WM_SETTINGCHANGE   &&desktop wallpaper have changed (if the case)
		Thisform.ysetw()
	Otherwise
* pass control to the original window procedure
		nReturn = CallWindowProc(This.horigproc, This.hWindow,Msg, wParam, Lparam)
	Endcase
	Return
	Endproc

	Procedure ysetw
	Clea Resource(Thisform.image1.Picture)
	Thisform.image1.Picture=Addbs(Sys(2023))+"LedWallpaper_yousfi.bmp"   &&ledWallpaper built image bmp in temp folder
	Endproc

	Procedure Load
	Declare Integer CallWindowProc In user32;
		INTEGER lpPrevWndFunc, Integer hWindow, Long Msg,;
		INTEGER wParam, Integer Lparam
	Declare Integer GetWindowLong In user32;
		INTEGER hWindow, Integer nIndex
	Endproc

	Procedure KeyPress
	Lparameters nKeyCode, nShiftAltCtrl
	If nKeyCode=27
		Thisform.Release
	Endi
	Endproc

	Procedure Init
	With This
		.Left=0
		.Top=0
		.Width=Sysmetric(1)
		.Height=Sysmetric(2)-25  &&to see the windows taskbar(clicking icon can, change the wallpaper for ex.)
		.titlebar=0
	Endwith
	Messagebox("Dblclick to reduce-ESC to close-rightclick to help! ",0+32+4096,'',1000)
	#Define GWL_WNDPROC -4
	Thisform.horigproc = GetWindowLong(Thisform.HWnd, GWL_WNDPROC)
	#Define WM_SETTINGCHANGE 0x001A
	Bindevent(0, WM_SETTINGCHANGE, Thisform, "handlewinmsg")
	Endproc

	Procedure Destroy
	Clea Events
	Endproc


	Procedure image1.Init
	This.Picture=Addbs(Sys(2023))+"LedWallpaper_yousfi.bmp" &&here the wallpaper set (otherwise you dont have image appearing on form).
	Endproc

	Procedure image1.DblClick
	Thisform.WindowState=1
	Endproc
    Procedure image1.rightclick
    local m.myvar
    text to m.myvar noshow
    i have a periodical wallpaper with many pictures in a folder.i use  a code to set a wallpaper as bmp photo all 6 minutes.when capturing
    some areas on desktop i dont want to see icons,links, personal things...
     and i want to hide  them with a big image.
    this code makes the desktop wallpaper shown on a form instantenously with   windows messages and bindevent.
    the wallpaper  image   stays in temp folder as bmp format (mandatory for  any wallpaper).the wallpaper change is reflected de facto on the form.
    Can use any windows message from winUser.h with the same handling procedure  message  in this code....

    endtext
    messagebox(m.myvar,0+32+4096,"Summary help")

Enddefine
*
*-- EndDefine: ybackground

 

if you set form.alwaysontop=.t.  can protect the entier desktop .Pressing .ESC (or another ketpress event) to return to normal situation.
if you set form.alwaysontop=.t.  can protect the entier desktop .Pressing .ESC (or another ketpress event) to return to normal situation.
if you set form.alwaysontop=.t.  can protect the entier desktop .Pressing .ESC (or another ketpress event) to return to normal situation.

if you set form.alwaysontop=.t. can protect the entier desktop .Pressing .ESC (or another ketpress event) to return to normal situation.

Note - Hidding desktop icons:Under windows10 this can be done by a simple rightclick on desktop and check/uncheck item.

Note - Hidding desktop icons:Under windows10 this can be done by a simple rightclick on desktop and check/uncheck item.

Click on code to select [then copy] -click outside to deselect

 *2* created on monday 29 of january 2018
*this utility show/hide desktop icons (show=1, hide=0).its avoid some reading/writing on registry ("HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced")
*this solve the problem of hiding/*showing the desktop icons..
*can compile an exe as utility (add a config.fpw) and use the syntax below to run from window start.
*for exe:  yshowHide_desktop_api.exe 0    &&or  1  as parameter
*here for prg do yshowHide_desktop_api.prg with 0   &&1

Local m.x
m.x=Inputbox("Hide desktop (0)-showDesktop (1)","","1")
m.x=Int(Val(m.x))
If !Between(m.x,0,1)
  Return .F.
Endi
yshowHide(m.x)

Function yshowHide
  Lparameters ykey
  If Pcount()<>1 Or !Inlist(ykey,0,1)
    Messagebox("do yshowHide_desktop_api.peg with 0  (hide)  (1=show)",16+4096,"Error",1300)
    Return .F.
  Endi
  If Vartype(ykey)="C"  &&for exe parameters is seen as char (yshowHide_desktop_api.exe 0  or yshowHide_desktop_api.exe 0 1)
    ykey=Int(Val(ykey))  &&ykey passed as character !
  Endi
  Declare Integer FindWindowEx In user32;
    INTEGER  hwndParent,;
    INTEGER  hwndChildAfter,;
    STRING @ lpszClass,;
    STRING @ lpszWindow

  Declare Integer SendMessage In user32;
    INTEGER HWnd,;
    INTEGER Msg,;
    INTEGER wParam,;
    INTEGER Lparam
  _Screen.WindowState=1

  #Define WM_COMMAND 	0x0111
  hWindow = FindWindowEx(0, 0, "Progman", 0)
  hWindow = FindWindowEx(hWindow, 0, "SHELLDLL_DefView", 0)

  SendMessage(hWindow, WM_COMMAND, 0x7402,ykey)
Endfunc


 
*Important:*the code above was tested on visual foxpro 9 sp2 under windows 10 pro

To be informed of the latest articles, subscribe:
Comment on this post