it's a bit ugly but hey, it works and with a little fooling around it can be turned into a supersimple app that quickly shows you the constants... but i guess this has been done a thousand times, yet it was fun (sort of) to build another one...
first the easy small version, intended for expansion and beginner learning:
Code: Select all
Procedure.l x_constants_info(nr)
Protected m.s
Global x_constants_nr.l, x_constants_n.l, x_retval_text.s, x_retval.l
;
; *** converts an event number to plain text
;
; this procedure is mostly for educational and reference purposes, it returns the name of a constant
;
; in: nr - event or value
; retval: #True - found
; #False - not found
; out: x_retval - #True found #False not found
; x_retval_text - line of text returned
;
; the returned string has the following format:
;
; - #whatever - a known constant in pb
; - #pb_whatever - a known pb constant
; - #wm_whatever - a known windows constant
; - whatever - in uppercase: the windows name of a known windows message that was not defined in pb
; - whatever - in lowercase: something else, comments, whatever
;
; this procedure only returns what is encoded inside it, which allows for some more details on, for
; example, window messages, but is harder to maintain and update... the function x_constants_more()
; takes information from one or more external files but needs the x_lib to work
;
; we'll do it in a few steps...
;
; 1. match it against predefined and decoded pb constants
; 2. match it against predefined and decoded win constants
; 3. match it against known but not (yet) predefined win constants
; 4. match it against known numeric values (that yet have to be encoded, if ever)
; 5. report dec, hex and bin value for unknown ones
; 6. you can use x_constants_more() To go through external files
;
;
; 1. predefined pb constants
;
Select nr
Case #PB_Event_Menu
m = "#PB_Event_Menu"
Case #PB_Event_CloseWindow
m = "#PB_Event_CloseWindow"
Case #PB_Event_Gadget
m = "#PB_Event_Gadget"
;
; a gadget has been pushed
;
Case #PB_Event_Repaint
m = "#PB_Event_Repaint"
Case #PB_Event_MoveWindow
m = "#PB_Event_MoveWindow"
;
; the window has been moved
;
EndSelect
;
;
; 2. predefined constants for windows messages
;
Select nr
Case #WM_KEYDOWN
m = m + " #WM_KEYDOWN"
Case #WM_MOUSEMOVE
m = m + " #WM_MOUSEMOVE"
Case #WM_LBUTTONDOWN
m = m + " #WM_LBBUTTONDOWN"
Case #WM_LBUTTONUP
m = m + " #WM_LBBUTTONUP"
Case #WM_MOVE
m = m + " #WM_MOVE"
EndSelect
;
;
; 3. missing constants for windows messages
;
#WM_MOUSELEAVE = $2A3
;
Select nr
Case #WM_MOUSELEAVE
;
; mouse left window (after a trackmouseevent was used)"
; only generated after calling TrackMouseEvent_()
;
m = m + " WM_MOUSELEAVE"
EndSelect
;
;
; 4. numeric ones (stuff we haven't found a proper var for yet)
;
Select nr
Case 0
m = m + " none"
Case 5
m = m + " resize?"
Case 160
m = m + " mouse_over_dragbar?"
Case 161
m = m + " window_has_moved?"
Case 275
m = m + " focus_or_activation?"
Case 516
m = m + " rmb_down?"
Case 517
m = m + " rmb_up?"
Case 519
m = m + " mmb_down?"
Case 520
m = m + " mmb_up?"
Case 522
;
; scrollwheel
; read event_parameter for the direction
;
event_parameter = EventwParam()
If event_parameter>0
m = m + " scrollwheel_up"
Else
m = m + " scrollwheel_down"
EndIf
Case 674
Debug " unknown"
EndSelect
;
; 5. add some info if we don't know what it was
;
m = m+" "
If Left(m,1) <> "#"
m = m+" "+Str(nr)+" $"+Hex(nr)+" %"+Bin(nr)
x_retval = #False
Else
x_retval = #True
EndIf
x_retval_text = Trim(m)
x_constants_nr = nr
x_constants_more = 0
;
ProcedureReturn x_retval
EndProcedure
Code: Select all
OpenWindow(0,100,100,300,200,"Message numbers to text",#PB_Window_SystemMenu|#PB_Window_SizeGadget)
lv_h = ListViewGadget(1,2,2,296,176)
;
Repeat
event = WaitWindowEvent()
x_constants_info(event)
;
; gadgets and the debugger can seriously screw up expected results :-)
; (that doesn't mean the results are wrong, they are just... different than one would expect)
; so comment out what you don't want
;
Debug x_retval_text
AddGadgetItem(1,-1,x_retval_text)
SendMessage_(lv_h,#LB_SETCARETINDEX,999999,0)
TextGadget(2,2,184,296,18,x_retval_text,#PB_Text_Center)
;
Until event = #PB_Event_CloseWindow
second part is a little smarter, it reads in all files you specify, then dumps all constants in an array, sorts it, and shows you quickly the value of something and where it found it
first the procedures:
Code: Select all
Procedure x_constants_read(file.s)
Protected file_nr.l, n.l, s.s
Global x_constants_nr.l, x_constants_n.l, x_retval_text.s, x_constants_more.l, x_retval.l
;
; *** read constants from a file
;
; info is first stored in a single string for sorting, afterwards i retrieve the values and store
; them into longs for quicker processing
;
If x_constants_n = 0
Dim x_constants_nr.l(#x_constants_max)
Dim x_constants_text.s(#x_constants_max)
EndIf
;
If x_not(x_exist(file)) And (x_parse(file,"*",0) Or x_parse(file,"?",0))
x_dir(GetPathPart(file),GetFilePart(file),2,0,0,0)
n=0
While n < x_dir_n
n = n+1
x_constants_read(x_dir_list(n))
Wend
EndIf
;
file_nr = OpenFile(#PB_Any,file)
If file_nr > 0
n = 0
While Eof(file_nr) = 0 And x_constants_n < #x_constants_max
s = Trim(ReadString())
n = n+1
If Left(s,1)="#"
x_parse(s,"#",0)
x_parse(s,"=",0)
s = x_strex(x_val(x_parse),"###########")+" "+s
If Len(s) > 100
s = Left(s,95)+"..."
EndIf
s = Left(s+Space(100),100)
s = s+file+" ("+Str(n)+")"
x_constants_text(x_constants_n) = s
x_constants_n = x_constants_n+1
EndIf
Wend
CloseFile(file_nr)
EndIf
x_constants_more = 0
EndProcedure
Procedure x_constants_more()
Protected n.l, p1.l, p2.l, p.l
Global x_constants_nr.l, x_constants_n.l, x_retval_text.s
;
; *** return info on a constant retrieved form an external file
;
; in: - none
; retval: #True - yeah, found more
; #False - nothing more
; x_constants_text - the text found defining the constant
;
x_retval = #False
If x_constants_more = 0
;
; first attempt to find
;
If x_constants_sort <> x_constants_n ; no or new data so we can sort
SortArray(x_constants_text(),0,0,x_constants_n)
n = 0
While n < x_constants_n
x_constants_nr(n) = Val(x_constants_text(n))
n = n+1
Wend
EndIf
;
; binary search
;
p1 = 1
p2 = x_constants_n
;
Repeat
p = (p1+p2)/2
If x_constants_nr(p) > x_constants_nr
p2 = p
ElseIf x_constants_nr(p) = x_constants_nr
p1 = p
p2 = p
Else
p1 = p
EndIf
Until p1 = p2
If p > 0
While x_constants_nr(p-1) = x_constants_nr
p = p-1
Wend
EndIf
;
If x_constants_nr(p) = x_constants_nr
x_retval = #True
x_retval_text = x_constants_text(p)
x_constants_more = p
EndIf
;
Else
;
x_constants_more = x_constants_more+1
If x_constants_nr(x_constants_more) = x_constants_nr
x_retval_text = x_constants_text(x_constants_more)
x_retval = #True
EndIf
EndIf
;
ProcedureReturn x_retval
EndProcedure
calling it is easy, for example i want to know all constants defined as '4':
Code: Select all
IncludeFile "x_lib.pb"
x_init()
;
; first read any pb code you wanna include (wildcards allowed)
; the two files with all residents are good candidates :-)
;
x_constants_read("c:\software\purebasic\_docs_tools\*.pb")
x_constants_read("c:\software\purebasic\_projects\x_lib.pb")
;
; look for info on '4' and display what's found
;
x_constants_info(#x_eol)
Repeat
Debug ">"+x_retval_text
Until x_constants_more() = #False