Bonnes fêtes de fin d'année !
Une petite application qui affiche une règle pour mesurer sur l'écran (en cm, en inch et en pixels).
S'adapte à la résolution de l'écran.
C'est en pb 4.40.
J'ai testé sous XP et vista.
La fenêtre est redimensionnable.
Code : Tout sélectionner
;///////////////////////////////
; Mesure 1.2 : 29/12/2009 - by Z@ph0d
; PB 4.40
;///////////////////////////////
EnableExplicit
;{- Enumerations / DataSections
;{ Windows
Enumeration
#Window_0
EndEnumeration
;}
;{ Gadgets
Enumeration
#Button_0
#text_1
#text_2
#combo_1
; #option_2
; #option_3
; #option_4
#trackbar_0
#checkbox_0
EndEnumeration
;}
;
;}
;
Procedure.i gettpp(f.i)
Protected hdc.i,r.i
;
hdc=GetDC_(GetDesktopWindow_())
If f=0
r= 1440/GetDeviceCaps_(hdc,#LOGPIXELSX)
Else
r= 1440/GetDeviceCaps_(hdc,#LOGPIXELSY)
EndIf
ReleaseDC_(GetDesktopWindow_(),hdc)
;
ProcedureReturn r
EndProcedure
Procedure ruler()
Protected px.i,py.i,i.i,x.i,w.i,f.i
;
UpdateWindow_(WindowID(#window_0))
; SendMessage_(WindowID(#window_0), #WM_SETREDRAW, #True, 0)
;
f=GetGadgetState(#combo_1)
Select f
Case 0
w=1440/2.54+1
Case 1
w=1440
EndSelect
;
px= (w/gettpp(0))/10
py= (w/gettpp(1))/10
;
x=0
;
StartDrawing(WindowOutput(#window_0))
DrawingFont(FontID(1))
;
If f<>2
For i=0 To WindowWidth(#window_0)
If i%10=0
Line(x,0,1,10)
DrawText(x-2,12,Str(i/10),#Black,#White)
Line(x,WindowHeight(#window_0)-1,1,-10)
DrawText(x-2,WindowHeight(#window_0)-20,Str(i/10),#Black,#White)
ElseIf i%5=0
Line (x,0,1,5)
Line(x,WindowHeight(#window_0)-1,1,-5)
Else
Line(x,0,1,2)
Line (x,WindowHeight(#window_0)-1,1,-2)
EndIf
;
x+px
Next
Else
For i=0 To WindowWidth(#window_0)
If i%20=0
Line(x,0,1,10)
DrawText(x-2,12,Str(x),#Black,#White)
Line(x,WindowHeight(#window_0)-1,1,-10)
DrawText(x-2,WindowHeight(#window_0)-20,Str(x),#Black,#White)
ElseIf i%10=0
Line (x,0,1,5)
Line(x,WindowHeight(#window_0)-1,1,-5)
Else
;Line(x,0,1,2)
;Line (x,WindowHeight(#window_0)-1,1,-2)
EndIf
;
x+1
Next
EndIf
;
x=30
If f<>2
For i=0 To WindowHeight(#window_0)
If i%10=0
Line(1,x,10,1)
DrawText(15,x-5,Str(i/10),#Black,#White)
Line(WindowWidth(#window_0)-1,x,-10,1)
DrawText(WindowWidth(#window_0)-20,x-5,Str(i/10),#Black,#White)
ElseIf i%5=0
Line (1,x,5,1)
Line(WindowWidth(#window_0)-1,x,-5,1)
Else
Line(1,x,2,1)
Line (WindowWidth(#window_0)-1,x,-2,1)
EndIf
;
x+py
If x>WindowHeight(#window_0)-30
Break
EndIf
Next
Else
For i=0 To WindowHeight(#window_0)
If i%20=0
Line(1,x,10,1)
DrawText(15,x-5,Str(x-30),#Black,#White)
Line(WindowWidth(#window_0)-1,x,-10,1)
DrawText(WindowWidth(#window_0)-20,x-5,Str(x-30),#Black,#White)
ElseIf i%10=0
Line (1,x,5,1)
Line(WindowWidth(#window_0)-1,x,-5,1)
Else
;Line(1,x,2,1)
;Line (WindowWidth(#window_0)-1,x,-2,1)
EndIf
;
x+1
If x>WindowHeight(#window_0)-30
Break
EndIf
Next
EndIf
;
StopDrawing()
EndProcedure
Procedure OpenWindow_Window_0()
If OpenWindow(#Window_0, 450, 200, 400, 100, "Règle - by Z@ph0d - 2009", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
;transparence:
SetWindowLong_(WindowID(#window_0), #GWL_EXSTYLE, GetWindowLong_(WindowID(#window_0), #GWL_EXSTYLE) | #WS_EX_LAYERED)
SetLayeredWindowAttributes_(WindowID(#window_0), 0, 200, #LWA_ALPHA)
TextGadget(#Text_1, 30, 30, 70, 20, "Transparence", #PB_Text_Border)
TrackBarGadget(#TrackBar_0, 20, 45, 150, 30, 150, 255);, #PB_TrackBar_Ticks)
SetGadgetState(#trackbar_0,230)
ComboBoxGadget(#Combo_1, 150, 30, 70, 20)
AddGadgetItem(#combo_1, -1,"cm")
AddGadgetItem(#combo_1, -1,"inch")
AddGadgetItem(#combo_1, -1,"pixel")
;OptionGadget(#Option_2, 110, 30, 30, 15, "cm")
SetGadgetState(#combo_1,0)
;OptionGadget(#Option_3, 150, 30, 40, 15, "inch")
;OptionGadget(#Option_4, 190, 30, 40, 15, "pixel")
ButtonGadget(#Button_0, 320, 30, 50, 20, "Quitter")
;TextGadget(#Text_2, 200, 60, 120, 20, "by Z@ph0d-2009", #PB_Text_Center|#PB_Text_Border)
CheckBoxGadget(#CheckBox_0, 240, 32, 80, 15, "Premier plan")
;
;WindowBounds(#window_0,400,100,#PB_Ignore,#PB_Ignore)
;
LoadFont(1, "small font", 6)
ruler()
EndIf
EndProcedure
;////////////////////////////////////////
;
OpenWindow_Window_0()
SmartWindowRefresh(#window_0,1)
Define t.i
;
;{- Event loop
Repeat
Select WaitWindowEvent()
; ///////////////////
Case #PB_Event_Gadget
Select EventGadget()
Case #Button_0
CloseWindow(#window_0)
Break
Case #trackbar_0
SetLayeredWindowAttributes_(WindowID(#window_0), 0, GetGadgetState(#trackbar_0), #LWA_ALPHA)
;Case #option_2,#option_3,#option_4
Case #combo_1
If EventType()=#CBN_SELCHANGE
InvalidateRect_(WindowID(#Window_0), 0, 1)
ruler()
EndIf
Case #checkbox_0
If GetGadgetState(#checkbox_0)
StickyWindow(#window_0,1)
Else
StickyWindow(#window_0,0)
EndIf
;
EndSelect
; ////////////////////////
Case #WM_KEYDOWN
If GetAsyncKeyState_(#VK_SHIFT)
t=10
Else
t=1
EndIf
;
Select EventwParam()
Case #VK_UP
ResizeWindow(#window_0,#PB_Ignore,WindowY(#window_0)-t,#PB_Ignore,#PB_Ignore)
Case #VK_DOWN
ResizeWindow(#window_0,#PB_Ignore,WindowY(#window_0)+t,#PB_Ignore,#PB_Ignore)
Case #VK_LEFT
ResizeWindow(#window_0,WindowX(#window_0)-t,#PB_Ignore,#PB_Ignore,#PB_Ignore)
Case #VK_RIGHT
ResizeWindow(#window_0,WindowX(#window_0)+t,#PB_Ignore,#PB_Ignore,#PB_Ignore)
EndSelect
Case #WM_SIZE
InvalidateRect_(WindowID(#Window_0), 0, 1)
ruler()
SetWindowTitle(#window_0,"Règle : W:"+Str(WindowWidth(#window_0))+"/H:"+Str(WindowHeight(#window_0)))
Case #WM_LBUTTONDOWN
SendMessage_(WindowID(#window_0), #WM_NCLBUTTONDOWN, #HTCAPTION, 0)
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Window_0
CloseWindow(#Window_0)
Break
EndSelect
EndSelect
ForEver
;
;}
Code mis à jour le 29/12/09 pour bouger la fenêtre au clavier (touches de direction +/-shift)