#include "Gra.ch"
#include "Xbp.ch"
#include "Appevent.ch"
#include "Font.ch"
#include "OS.ch"
#include "DLL.ch"
#define HWND_DESKTOP 0
#define LOGPIXELSX 88
#define LOGPIXELSY 90
#define DESKTOPVERTRES 117
#define DESKTOPHORZRES 118
DLLFUNCTION GetDeviceCaps(hDC,Index) USING STDCALL FROM GDI32.DLL
DLLFUNCTION GetDC( hDC ) USING STDCALL FROM USER32.DLL
PROCEDURE APPSYS
LOCAL cTitle := "Horizontal Ruler"
LOCAL hWndDlg := DllCall( "User32.dll", DLL_STDCALL, "FindWindowA", 0, cTitle )
IF !( hWndDlg == 0 )
DllCall( "User32.dll", DLL_STDCALL, "SetForegroundWindow", hWndDlg )
DllCall( "User32.dll", DLL_STDCALL, "BringWindowToTop", hWndDlg )
DllCall( "User32.dll", DLL_STDCALL, "ShowWindow", hWndDlg, 1 )
DllCall( "User32.dll", DLL_STDCALL, "UpdateWindow", hWndDlg )
*** It is a second instance.... Bye Bye
QUIT
ENDIF
RETURN
PROCEDURE Main
LOCAL oDlg, oXbp, drawingArea, oPS
LOCAL nEvent, mp1, mp2
LOCAL lIsW98Run
LOCAL hWnd := 0
LOCAL aDesk := AppDesktop():currentSize()
LOCAL aSize := {aDesk[1]-100,62}
LOCAL xDesk := {0,0}
LOCAL aNewPos := {0,0}
LOCAL aPos := {0,0}
LOCAL cText
LOCAL i
LOCAL hDC := GetDC( HWND_DESKTOP )
LOCAL nXLogPixel := GetDeviceCaps( hDC, LOGPIXELSX )
LOCAL nYLogPixel := GetDeviceCaps( hDC, LOGPIXELSY )
LOCAL nDHORZRES := GetDeviceCaps( hDC, DESKTOPHORZRES ) // native Monitor Size !
LOCAL nDVERTRES := GetDeviceCaps( hDC, DESKTOPVERTRES ) // native Monitor Size !
LOCAL nDPi,nFaktor
LOCAL aDragArea
LOCAL nX, nY
LOCAL lMove := .F.
* ------------------------------------------------- *
*
* add Zoll/cm on upper site
*
* ------------------------------------------------- *
// native Monitor Size
xDesk[1] := nDHORZRES
xDesk[2] := nDVERTRES
// Scale
nFaktor := xDesk[1] / aDesk[1]
// up to 125% old style = 120DPi
IF nFaktor < 1.26
nFaktor := 1
ENDIF
// real Pixel / Zoll
nDPi := ROUND(nFaktor*nXLogPixel,0)
// new add Zoll/cm on upper side
aSize[2] := aSize[2]+40
// start Position
aPos := {50,aDesk[2]-aSize[2]}
* ------------------------------------------------- *
IF Os(OS_FAMILY) == "WIN9X"
lIsW98Run := .T. // W98 is running
ELSE
lIsW98Run := .F. // XP is running
ENDIF
oDlg := XbpDialog():new( AppDesktop(), , aPos, aSize, , .F.)
oDlg:taskList := .T.
oDlg:title := "Horizontal Ruler"
oDlg:Border := XBPDLG_NO_BORDER
oDlg:maxButton := .F.
oDlg:minButton := .T.
oDlg:icon :=100
oDlg:drawingArea:rbClick := {|aPos, uNIL, obj| MenuTPZ(hWnd,oDlg,aPos) }
oDlg:create()
hWnd := oDlg:getHWND()
drawingArea := oDlg:drawingArea
drawingArea:setColorBG( GRA_CLR_PALEGRAY )
drawingArea:setFontCompoundName( "8.Arial" )
aNewPos[2] := 20
FOR i := 1 TO aSize[1] STEP 100
IF i = 1
aNewPos[1] := 0
cText := "0"
ELSE
aNewPos[1] := i -12
cText := LTRIM(STR(i-1))
ENDIF
// Pixel
oXbp := XbpStatic():new( drawingArea, , aNewPos, {30,12}, { { XBP_PP_COMPOUNDNAME, "8.MS Sans Serif" } } )
oXbp:caption := cText
oXbp:clipSiblings := .T.
oXbp:options := XBPSTATIC_TEXT_VCENTER+XBPSTATIC_TEXT_LEFT
oXbp:create()
NEXT
oPS := XbpPresSpace():new()
oPS:create( oDlg:drawingArea:winDevice() )
oDlg:drawingArea:paint := {|| DrawGraphic( oPS, aSize, nDPi ) }
IF lIsW98Run
oDlg:show()
ELSE
SetWindowLayered(hWnd,.T.) // Stil setzen
SetWindowTransparency(hWnd,100) // unsichtbar machen
oDlg:show()
SetWindowTransparency(hWnd,100,15) // sichtbar machen
ENDIF
SetAppFocus( oDlg )
nEvent := xbe_None
DO WHILE nEvent <> xbeP_Close
nEvent := AppEvent( @mp1, @mp2, @oXbp )
DO CASE
CASE nEvent == xbeM_LbDown .AND. oXbp:isDerivedFrom("XbpIWindow")
oDlg:drawingArea:setPointer(, XBPSTATIC_SYSICON_WAIT, XBPWINDOW_POINTERTYPE_SYSPOINTER )
aDragArea := GetCursorPos()
aPos := oDlg:currentpos()
nX := aDragArea[ 1 ] - aPos[ 1 ]
nY := aDragArea[ 2 ] - aPos[ 2 ]
aDragArea[ 1 ] -= nX
aDragArea[ 2 ] -= nY
//
// set to Cursor Position
//
oDlg:setPos( aDragArea )
oDlg:drawingArea:setPointer(, XBPSTATIC_SYSICON_MOVE, XBPWINDOW_POINTERTYPE_SYSPOINTER )
oDlg:drawingArea:captureMouse( .T. )
lMove := .T.
CASE nEvent == xbeM_Motion .AND. oXbp:isDerivedFrom("XbpIWindow")
IF lMove = .T.
aDragArea := GetCursorPos()
aDragArea[ 1 ] -= nX
aDragArea[ 2 ] -= nY
oDlg:setPos( aDragArea )
ENDIF
CASE nEvent == xbeM_LbUp .AND. oXbp:isDerivedFrom("XbpIWindow")
//
//
//
aDragArea := GetCursorPos()
aDragArea[ 1 ] -= nX
aDragArea[ 2 ] -= nY
oDlg:setPos( aDragArea )
SETAPPFOCUS( oDlg )
oDlg:drawingArea:setpointer(, XBPSTATIC_SYSICON_ARROW, XBPWINDOW_POINTERTYPE_SYSPOINTER )
oDlg:drawingArea:captureMouse( .F. )
lMove := .F.
OTHERWISE
oXbp:handleEvent( nEvent, mp1, mp2 )
ENDCASE
ENDDO
RETURN
PROCEDURE DrawGraphic( oPS, aSize, nDPI )
LOCAL aAttr[ GRA_AA_COUNT], i
LOCAL n
aAttr[GRA_AA_COLOR] := GRA_CLR_BLACK
GraSetAttrLine(oPS, aAttr)
for i = 0 to aSize[1] step 10
graline( oPs, {i, 0}, {i, if(i % 100 = 0, 20, if(i % 50 = 0, 16, 12))})
next
aAttr[GRA_AL_COLOR] := GRA_CLR_BLUE
GraSetAttrLine(oPS, aAttr)
for i = 5 to aSize[1]-5 step 10
graline( oPs, {i, 0}, {i, 8})
next
* ------------------------------------------------- *
*
* add Zoll/cm on upper site
*
* ------------------------------------------------- *
FOR i = 0 to aSize[1] step 1
IF (i % ROUND(nDPI/25.4*10/2,0) = 0) // 0.5 cm
aAttr[GRA_AL_COLOR] := GRA_CLR_BLUE
GraSetAttrLine(oPS, aAttr)
Graline( oPs, {i, 60}, {i,72})
ENDIF
IF (i % ROUND(nDPI/25.4*10,0) = 0) // 1 cm
aAttr[GRA_AL_COLOR] := GRA_CLR_RED
GraSetAttrLine(oPS, aAttr)
Graline( oPs, {i, 55}, {i,72})
ENDIF
IF (i % nDPI = 0) // 1 Zoll
aAttr[GRA_AL_COLOR] := GRA_CLR_CYAN
GraSetAttrLine(oPS, aAttr)
Graline( oPs, {i, 40}, {i,72})
ENDIF
NEXT
RETURN
*
* eof
*