While learning the ropes One more
Posted: Tue Apr 03, 2007 9:50 pm
Code updated for 5.20+
While learning .....
Quick Color values in Hex and Dec.
;It was easy even for a beginner
gebe
addition
Hi,
While learning to handle LCCwin32 ,I discovered the clock record of the microprocessor.
I am sure it is not new to some chaps but it might have been forgotten ...
gebe
gebe 
While learning .....
Quick Color values in Hex and Dec.
Code: Select all
; PureBasic Visual Designer v3.95 build 1485 (PB4Code)
;- Window Constants
;No need for Help ;
Enumeration
#Window_0
EndEnumeration
;- Gadget Constants
;
Enumeration
#TrRed
#TxtRED
#TrGreen
#TxGreen
#TrBlue
#TxBlue
#Tcolor
#TvalDEC
#TvalHEX
#TLabelDEC
#TLabelHex
EndEnumeration
;------------------------------------------------------------------------------------
Procedure Open_Window_0()
If OpenWindow(#Window_0, 615, 2, 400, 300, "Pure Basic Colors Settings Values Hex and Dec", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
TrackBarGadget(#TrRed , 10, 70, 130, 20, 0, 255, #PB_TrackBar_Ticks)
TrackBarGadget(#TrGreen, 10, 120, 130, 20, 0, 255, #PB_TrackBar_Ticks)
TrackBarGadget(#TrBlue , 10, 170, 130, 20, 0, 255, #PB_TrackBar_Ticks)
TextGadget(#TxtRED , 145, 70, 70, 20, "RED", #PB_Text_Center | #PB_Text_Border)
TextGadget(#TxGreen, 145, 120, 70, 20, "GREEN", #PB_Text_Center | #PB_Text_Border)
TextGadget(#TxBlue , 145, 170, 70, 20, "BLUE", #PB_Text_Center | #PB_Text_Border)
TextGadget(#Tcolor, 250, 65, 100, 130, "-", #PB_Text_Center | #PB_Text_Border)
TextGadget(#TLabelDEC, 110, 210, 110, 20, "Decimal Value", #PB_Text_Center | #PB_Text_Border)
TextGadget(#TvalDEC, 250, 210, 100, 20, "-", #PB_Text_Center | #PB_Text_Border)
TextGadget(#TLabelHex, 110, 240, 110, 20, "HexaDecimal Value", #PB_Text_Center | #PB_Text_Border)
TextGadget(#TvalHEX, 250, 240, 100, 20, "-", #PB_Text_Center | #PB_Text_Border)
EndIf
EndProcedure
;--------------------------------------------------------------------------------------
#GrMult=256
#BlMult=256*256
Open_Window_0()
Rouge.l=0
Vert.l=0
Bleu.l=0
Couleur.l=0
SetGadgetColor(#TxtRED,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#Txgreen,#PB_Gadget_FrontColor,#White)
SetGadgetColor(#Txblue,#PB_Gadget_FrontColor,#White)
Repeat ; Start of the event loop
Event = WaitWindowEvent() ; This line waits until an event is received from Windows
WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
GadgetID = EventGadget() ; Is it a gadget event?
EventType = EventType() ; The event type
;You can place code here, and use the result as parameters for the procedures
If Event = #PB_Event_Gadget
If GadgetID = #TrRed
Rouge = GetGadgetState(#TrRed)
SetGadgetText(#TxtRED,Str(rouge))
couleur=rouge+vert*#grmult+bleu*#BlMult
SetGadgetColor(#Tcolor,#PB_Gadget_BackColor,couleur)
SetGadgetText(#tvaldec,Str(couleur))
SetGadgetText(#tvalhex,Hex(couleur))
SetGadgetColor(#TxtRED,#PB_Gadget_BackColor,ROUGE)
ElseIf GadgetID = #TrGreen
vert = GetGadgetState(#TrGreen)
SetGadgetText(#TxGreen,Str(Vert))
couleur=rouge+vert*#grmult+bleu*#BlMult
SetGadgetColor(#Tcolor,#PB_Gadget_BackColor,couleur)
SetGadgetText(#tvaldec,Str(couleur))
SetGadgetText(#tvalhex,Hex(couleur))
SetGadgetColor(#Txgreen,#PB_Gadget_BackColor,vert*#grmult)
ElseIf GadgetID = #TrBlue
bleu = GetGadgetState(#TrBlue)
SetGadgetText(#Txblue,Str(bleu))
couleur=rouge+vert*#grmult+bleu*#BlMult
SetGadgetColor(#Tcolor,#PB_Gadget_BackColor,couleur)
SetGadgetText(#tvaldec,Str(couleur))
SetGadgetText(#tvalhex,Hex(couleur))
SetGadgetColor(#Txblue,#PB_Gadget_BackColor,bleu*#blmult)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
End
gebe

addition
Hi,
While learning to handle LCCwin32 ,I discovered the clock record of the microprocessor.
I am sure it is not new to some chaps but it might have been forgotten ...
gebe
Code: Select all
Procedure.q Mcycles()
EnableASM
RDTSC
;my XP "64"bits Win32 machine does not like the following 2 codes
;I had to cancell those 2 lines in order for it to work
MOV [ecx+4],edx ;XP shy************
MOV [ecx],eax ;XP shy ***********
ProcedureReturn ;edx,eax
DisableASM
EndProcedure
a.f=0
OpenConsole()
For j=100 To 1001 Step 100
Print (Str(1000000*j)+" loops")
Print (Chr(10))
tt0=GetTickCount_()
t0.q=Mcycles()
For i.l=0 To 1000000*j
a=Sqr(i);a+2*4/345 Do something ...
Next i
t1.q=Mcycles()
ttt=GetTickCount_()-tt0
tc.q=t1-t0
Print ("Count Start : "+Str(t0))
Print(Chr(10))
Print ("Count Stop : "+Str(t1))
Print(Chr(10))
Print("Number of Clocks : "+ Str(tc))
Print(Chr(10))
Print("Time : "+Str(ttt)+" milliseconds")
Print(Chr(10))
Print("Freq = ")
Print( Str(tc/ttt/1000))
Print(" Mhz")
Print (Chr(10))
Next j
Print(Chr(10))
Print(Chr(10))
Print ("TEST Ended Press Any key To EXIT")
Repeat
Delay(10)
Until Inkey()=" "
