VFP window dont draggable when maximized !

Published on by Yousfi Benameur


Actually can drag a window with the mouse pointer to the edges of the screen to snap it or maximize it.
Inverse to this feature :the maximized windows can also be dragged down from the title bar to restore them to their original size.
This new behavior exists in Windows 10 , Windows 8 as well even 7.

try on IE normal drag to maximized, Firefox or even on notepad : docking and undocking is possible.

the code below builds a top level window with API createWindowEx and shows the behavior in docking when dragging with mouse to the screen edges  and maximize.
the vfp window dont support the undocking  by dragging with mouse when maximized.that a verified fact.
this window as all windows created from createWindowEx supports it.
the vfp window and its controls seem to be created with another artifact(another API ?).That why it have a singular behavior face to this docking event.
in this test i made some texts shown on a top level window (createWindowEX API configuration in with dwStyle and dwExstyle)
i made the standard windows message to callWindowProc API to process the messages in particlar the WM_PAINT whose draws on the surface window.
it paints the window surface (as a timer with interval compatible with eyes sensibility to see a continous & static drawing: exactly like TV for comparing).
with this when moving the window the text dont disappear ans should be persistent.

to test, drag the window by mouse to the top of screen, left,right,bottom.
use also the shortcuts appearing on the window text.
this example is adapted from http://www.news2news.com/vfp/index.php?example=50

Note 1:the registry can enable or Disable Drag from Maximized Windows in Windows 7 and Windows 8 and Windows 10
HKEY_CURRENT_USER\Control Panel\Desktop 
DragFromMaximize DWORD
0 = disable
1 = enable
this option is also in control panel (in french go to):
"Panneau de configuration\Options d’ergonomie\Options d’ergonomie\Rendre la souris plus facile à utiliser" (see photo 2 below)

Note 2:
windows shortcuts working on vfp9 window (or all windows):
Windows + Up-Arrow: Maximizes the current window.
Windows + Down-Arrow: Restores the original size of a maximized window - for other windows, minimizes them.
Windows + Left-Arrow: Docks the current window on the left side of the screen
Windows + Right-Arrow:Docks the current window on the right side of the screen
*
I dont know how vfp window was created.Maybe its original definition blocks the maximized undocking.its an old story ...
What i experiment is that a window created with the API CreateWindowEx have the same behavior as all OS windows and can be docked or undocked when maximized.



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



*this example is adapted from http://www.news2news.com/vfp/index.php?example=50
*it build a top level window with API createWindowEx and shows the behavior in docking when dragging with mouse to the screen edges  and maximize.
*the vfp window dont support the undocking  by dragging with mouse when maximized.that a verified fact.
*this window as all windows cretaed from createWindowEx supports it.

Clea All
Do Declare
*Winuser onstants & Extended Window Styles
#Define WS_EX_TRANSPARENT     32
#Define SW_NORMAL  1
#Define WS_OVERLAPPED 0
#Define WS_CAPTION  0xC00000
#Define WS_SYSMENU  0x80000
#Define WS_THICKFRAME  0x40000
#Define WS_MINIMIZEBOX  0x20000
#Define WS_MAXIMIZEBOX  0x10000
#Define ANSI_CHARSET          0
#Define OUT_DEFAULT_PRECIS    0
#Define OUT_DEVICE_PRECIS     5
#Define OUT_OUTLINE_PRECIS    8
#Define CLIP_DEFAULT_PRECIS   0
#Define CLIP_STROKE_PRECIS    2
#Define DEFAULT_QUALITY       0
#Define PROOF_QUALITY         2
#Define DEFAULT_PITCH         0
#Define FW_BOLD             700
#Define TRANSPARENT           1
#Define OPAQUE                2
#Define  WM_SYSCOMMAND  0x0112
#Define WM_PAINT 0x000F

Local HWnd,lnSize,lcClass,dwExStyle,dwStyle
HWnd =  GetActiveWindow()
lcClass = Space(250)

lnSize = RealGetWindowClass (HWnd, @lcClass , Len(lcClass ))
lcClass = Strtran (Substr(lcClass, 1,lnSize), Chr(0),"")


dwExStyle=  WS_OVERLAPPED  && WS_CHILD style is not set, so it's a top-level window.
dwStyle   =  WS_CAPTION+WS_SYSMENU+WS_MAXIMIZEBOX+WS_MINIMIZEBOX +WS_THICKFRAME

Publi  hNew
hNew = CreateWindowEx (dwExStyle, lcClass, "A top level Window created with API createWindowEx dragged when maximized and dockable ",;
dwStyle, 100, 100, 890, 400, 0, 0, 0, 0)  &&o for desktop hwnd

= ShowWindow (hNew, SW_NORMAL)
hDC = GetDC (hNew)


_Screen.WindowState=1

#Define GWL_WNDPROC -4
Publi hOrigProc
hOrigProc=0
hOrigProc = GetWindowLong(hNew, GWL_WNDPROC)
***************
Public oHandler
oHandler=Newobject("myhandler")
Bindevent(hNew,WM_PAINT,oHandler,"WindowProc")



Procedure  _print (HWnd,x,Y,Size,lcText, lnColor, lnAngle)
hFont = CreateFont (;
    size,0, lnAngle,lnAngle, FW_BOLD, 0,0,0, ANSI_CHARSET,;
	OUT_OUTLINE_PRECIS, CLIP_STROKE_PRECIS,;
	PROOF_QUALITY, DEFAULT_PITCH, "Times New Roman")
hDC = GetWindowDC (HWnd)
* select new font into the device context
* and delete the old one
= DeleteObject (SelectObject (hDC, hFont))

* set text color on a transparent background
= SetTextColor (hDC, lnColor)
= SetBkMode (hDC, TRANSPARENT)

* the printing
= TextOut (hDC, x, Y, lcText, Len(lcText))

* release system resources
= DeleteObject (hFont)
= ReleaseDC (HWnd, hDC)
Endproc

Procedure  Declare
Declare Integer RealGetWindowClass In user32;
	INTEGER  HWnd,;
	STRING @ pszType,;
	INTEGER  cchType
Declare Integer GetActiveWindow In user32
Declare Integer CreateWindowEx In user32;
	INTEGER dwExStyle,;
	STRING lpClassName,;
	STRING lpWindowName,;
	INTEGER dwStyle,;
	INTEGER x,;
	INTEGER Y,;
	INTEGER nWidth,;
	INTEGER nHeight,;
	INTEGER hWndParent,;
	INTEGER hMenu,;
	INTEGER hInstance,;
	INTEGER lpParam
Declare Integer ShowWindow In user32;
	INTEGER HWnd,;
	INTEGER nCmdShow
Declare Integer GetDC In user32 Integer HWnd
Declare Integer TextOut In gdi32;
	INTEGER hdc,;
	INTEGER x,;
	INTEGER Y,;
	STRING  lpString,;
	INTEGER nCount
Declare Integer ReleaseDC In user32;
	INTEGER HWnd, Integer hdc
Declare Integer CreateFont In gdi32;
	INTEGER nHeight, Integer nWidth,;
	INTEGER nEscapement, Integer nOrientation,;
	INTEGER fnWeight, Integer fdwItalic,;
	INTEGER fdwUnderline, Integer fdwStrikeOut,;
	INTEGER fdwCharSet,;
	INTEGER fdwOutputPrecision,;
	INTEGER fdwClipPrecision,;
	INTEGER fdwQuality,;
	INTEGER fdwPitchAndFamily,;
	STRING  lpszFace

Declare Integer GetWindowDC In user32 Integer hWindow
Declare Integer SelectObject In gdi32 Integer hdc, Integer hObject
Declare Integer DeleteObject In gdi32 Integer hObject
Declare Integer SetTextColor In gdi32 Integer hdc, Integer crColor

Declare Integer SetBkMode In gdi32;
	INTEGER hdc, Integer iBkMode
Declare Integer CallWindowProc In user32;
	INTEGER lpPrevWndFunc, Integer hWindow, Long Msg,;
	INTEGER wParam, Integer Lparam
Declare Integer GetWindowDC In user32 Integer hWindow
Declare Integer GetWindowLong In user32;
	INTEGER HWnd, Integer nIndex
Declare Long BeginPaint In User32 ;
	LONG HWnd,;
	STRING @lpPaint
Declare Long EndPaint In User32 ;
	LONG HWnd,;
	STRING @lpPaint

Endproc
****************************
Define Class   MyHandler As Session
Procedure WindowProc
	Lparameters hWindow As Integer,  nMsgID As Integer, wParam As Integer, Lparam As Integer
	hDC = GetDC (hWindow)
	Local nReturn
	nReturn=0
	Do Case
		Case nMsgID=WM_PAINT
			Local lvPaintStruct
			lvPaintStruct = Space(56)
			=BeginPaint(hWindow, @lvPaintStruct)
			****************************
			Local lpString
			Set Memowidth To 180
			TEXT to   lpString noshow
the window created with API createWindowEx is top level and shown in taskbar
if dragged toward the screen top its maximized (docked)
if dragged from maximized its restored.

try these shortcuts available in windows 7,8,10
Windows + Up-Arrow: Maximizes the current window.
Windows + Down-Arrow: Restores the original size of a maximized window - for other windows, minimizes them.
Windows + Left-Arrow: Docks the current window on the left side of the screen
Windows + Right-Arrow:Docks the current window on the right side of the screen

Note:if you move the window the text is not cleared (normal there is a persistent painting...because a routine add with CallWindowProc API)
Can build controls as textbox,editbox,image,label,....with APIs....as VFP does.

I guess that is the "genese" of all standard windows and controls...maybe vfp is an exception (to confirm).
			ENDTEXT

			Local x,Y,xcolor
			x=50
			Y=40
			For i=1 To Memlines(m.lpString)
				Do Case
					Case Between(i,1,4)
						m.xcolor=255
					Case Between(i,5,9)
						m.xcolor=Rgb(0,0,255)
					Otherwise
						m.xcolor=Rgb(255*Rand(),255*Rand(),255*Rand())
				Endcase
				= _print (hNew,x,Y,18,Mline(m.lpString,i), m.xcolor, 0)
				Y=Y+20
			Endfor
			= ReleaseDC (hWindow, hDC)
			********************
			=EndPaint(hWindow, @lvPaintStruct)

		Otherwise
			* pass control to the original window procedure
			nReturn = CallWindowProc(hOrigProc, hWindow, m.nMsgID, m.wParam, m.lParam)
	Endcase
	Return nReturn
Endcase
Endproc

Enddefine
*EndDefine myHandler
*************************



windows style in :https://msdn.microsoft.com/en-us/library/windows/desktop/ms632600%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
windows style in :https://msdn.microsoft.com/en-us/library/windows/desktop/ms632600%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

windows style in :https://msdn.microsoft.com/en-us/library/windows/desktop/ms632600%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

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