Au moins, là, on la voit bien la lettre qui est sous le curseur!

[Edit]
Ajouté.
- Copie directe dans jaPBe à la position du curseur. (Désactivable)
- Fenêtre toujours au premier plan. (Désactivable)
- Ajout de la commande "Chr()". (Désactivable)
Corrigé.
- Un bug qui empêchait le caractère "&" d'apparaître
Modifié.
- Mode de détection de l'index du gadget contenant le caractère à afficher dans l'image.
[Edit2]
Ajouté.
- Les caractères de commande (de 0 à 32)
- Sauvegarde de la dernière police utilisée, et des règlages
Code : Tout sélectionner
;{- Constantes
Enumeration
#Win_Main
EndEnumeration
Enumeration
#Cmb_Fonts
#Img_Preview
#Txt_Result
#TxtCopie
#Chk_Japbe
#Chk_InsertChr
#Chk_Sticky
#Btn_CopyAsString
#Btn_CopyAsChar
#Btn_CopyAsHex
#Btn_CopyAsBin
#Btn_CopyAsDec
#Btn_CopyAsCar
#Btn_Erase
EndEnumeration
#STN_CLICKED = 0
#WMCD_InsertText = 2
;}
;{- Variables, Listes tableaux
Global NewList Fontes.s()
Global NewList Texts.l()
Global CurPos.POINT
Global Dim CommanChars.s(32)
;}
;{- Déclarations
Declare Create_Image(Lettre.s)
Declare EnumFontProc(*lpelf.ENUMLOGFONT, *lpntm.NEWTEXTMETRIC, FontType, lParam)
Declare GetFont_Info()
Declare Hi_Word(Long)
Declare Open_Window_0()
Declare WinCallback(Hwn, Msge, wParam, lParam)
Declare UpdateTexts()
;}
;{- Image vide
CreateImage(10, 255, 250)
StartDrawing(ImageOutput(10))
Box(0, 0, 255, 250, $FFFFFF)
StopDrawing()
;}
;{- Procédures
Procedure Open_Window_0()
x_Text = 270 : y_Text = 5 : IdTxt = 1000
If OpenWindow(#Win_Main, 5, 5, 655, 385, "Table des caractères", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar )
If CreateGadgetList(WindowID(#Win_Main))
ImageGadget(#Img_Preview, 5, 30, 255, 250, ImageID(10), #PB_Image_Border)
ComboBoxGadget(#Cmb_Fonts, 5, 5, 260, 200)
TextGadget(#Txt_Result, 5, 290, 645, 25, "", #PB_Text_Center | #PB_Text_Border | #SS_NOPREFIX)
SetGadgetFont(#Txt_Result, FontID(2))
TextGadget(#TxtCopie, 5, 320, 100, 25, "", #PB_Text_Center | #PB_Text_Border | #SS_NOPREFIX)
SetGadgetFont(#TxtCopie, FontID(2))
CheckBoxGadget(#Chk_Sticky, 330, 320, 100, 25, "Toujours devant")
CheckBoxGadget(#Chk_InsertChr, 435, 320, 100, 25, "Ajouter le ''Chr()''")
CheckBoxGadget(#Chk_Japbe, 540, 320, 150, 25, "Copier dans JaPBe")
ButtonGadget(#Btn_CopyAsDec, 5, 355, 80, 25, "Décimal")
ButtonGadget(#Btn_CopyAsChar, 85, 355, 80, 25, "Char")
ButtonGadget(#Btn_CopyAsBin, 165, 355, 80, 25, "Binaire")
ButtonGadget(#Btn_CopyAsHex, 245, 355, 80, 25, "Hexadécimal")
ButtonGadget(#Btn_CopyAsString, 325, 355, 80, 25, "Chaine")
; ButtonGadget(#Btn_CopyAsCar, 405, 355, 80, 25, "Caractère")
ButtonGadget(#Btn_Erase, 560, 355, 80, 25, "Effacer")
For i = 0 To 255
AddElement(Texts())
TextGadget(IdTxt, x_Text, y_Text, 20, 20, "", #PB_Text_Center | #PB_Text_Border | #SS_NOTIFY | #SS_NOPREFIX)
Texts() = IdTxt : IdTxt + 1
x_Text + 20 : If x_Text > 640 : x_Text = 270 : y_Text + 20 : EndIf
SetGadgetFont(Texts(), FontID(0))
Next
EndIf
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
Procedure EnumFontProc(*lpelf.ENUMLOGFONT, *lpntm.NEWTEXTMETRIC, FontType, lParam)
FnN$ = PeekS(@*lpelf\elfLogFont\lfFaceName[0])
AddElement(Fontes())
Fontes() = FnN$
ProcedureReturn #True
EndProcedure
Procedure GetFont_Info()
hdc = GetDC_(GetDesktopWindow_())
EnumFontFamilies_(hdc, 0, @EnumFontProc(),0)
ReleaseDC_ (GetDesktopWindow_(), hdc)
EndProcedure
Procedure UpdateTexts()
ForEach Texts()
i = ListIndex(Texts())
SetGadgetFont(Texts(), FontID(0))
SetGadgetText(Texts(), Chr(i))
Next
EndProcedure
Procedure Hi_Word(Long)
ProcedureReturn (Long >>16) & $FFFF
EndProcedure
Procedure WinCallback(Hwn, Msge, wParam, lParam)
Result = #PB_ProcessPureBasicEvents
Select Msge
Case #WM_COMMAND
If Hi_Word(wParam) = #STN_CLICKED
ForEach Texts()
If GadgetID(Texts()) = lParam
SetGadgetText(#TxtCopie, GetGadgetText(Texts()))
If Texts() >= 1000 And Texts() <= 1031
DisableGadget(#Btn_CopyAsChar, 1)
Else
DisableGadget(#Btn_CopyAsChar, 0)
EndIf
EndIf
Next
EndIf
EndSelect
ProcedureReturn Result
EndProcedure
Procedure Create_Image(Lettre.s)
If CreateImage(0, 255, 250)
StartDrawing(ImageOutput(0))
DrawingMode(1) : DrawingFont(FontID(1))
W_Lettre = TextWidth(Lettre) : H_Lettre = TextHeight(Lettre)
Box(0, 0, 255, 250, $FFFFFF)
DrawText(128 - W_Lettre/2, 128 - H_Lettre / 2, Lettre)
StopDrawing()
SetGadgetState(#Img_Preview, ImageID(0))
EndIf
EndProcedure
Procedure SendDatasToEditor(MainWin, Datas$, Mode.l)
RunOneWin = FindWindow_(@"WindowClass_0",@"jaPBe-RunOneWindow")
If RunOneWin
If Datas$
cd.COPYDATASTRUCT
cd\dwData = Mode
cd\cbData = Len(Datas$)+1
cd\lpData = @Datas$
SendMessage_(RunOneWin, #WM_COPYDATA, MainWin, cd)
EndIf
EndIf
EndProcedure
;}
;{- Initialisation
GetFont_Info() : SortList(Fontes(), 2)
OpenPreferences("CharMap.pref")
CmbState = ReadPreferenceLong("IdFont", 19)
StickyState = ReadPreferenceLong("OnTop", 1)
ChrState = ReadPreferenceLong("AddChr", 0)
JapbeState = ReadPreferenceLong("Japbe", 1)
ClosePreferences()
SelectElement(Fontes(), CmbState) : LoadFont(0, Fontes(), 9) : LoadFont(1, Fontes(), 140) : LoadFont(2, "Courier New", 10, #PB_Font_Bold)
Restore CommandChar
For i = 0 To 32
Read CommanChars(i)
Next
If Open_Window_0()
ForEach Fontes()
AddGadgetItem(#Cmb_Fonts, -1, Fontes())
Next
SetGadgetState(#Cmb_Fonts, CmbState)
SetGadgetState(#Chk_Sticky, StickyState)
SetGadgetState(#Chk_InsertChr, ChrState)
SetGadgetState(#Chk_Japbe, JapbeState)
StickyWindow(#Win_Main, GetGadgetState(#Chk_Sticky))
SetWindowCallback(@WinCallback())
Else
End
EndIf
UpdateTexts()
If FindWindow_("WindowClass_7", "jaPBe V3")
DisableGadget(#Chk_Japbe, 0)
Else
DisableGadget(#Chk_Japbe, 1)
SetGadgetState(#Chk_Japbe, 0)
EndIf
;}
;{- Boucle
Repeat;{
GetCursorPos_(CurPos)
HObjet = WindowFromPoint_(CurPos\x, CurPos\y) : IDWindow = GetWindowLong_(HObjet, #GWL_ID)
If IDWindow >= 1000
If IDWindow >= 1000 And IDWindow <=1032
c = IDWindow - 1000
Ms1$ = CommanChars(IDWindow - 1000) + " "
Ms2$ = "Ascii = " + RSet(Str(c), 3, "0") + " "
Ms3$ = "Hex = $" + RSet(Hex(c), 2, "0") + " "
Ms4$ = "Bin = %" + RSet(Bin(c), 8, "0")
SetGadgetText(#Txt_Result, Ms1$ + Ms2$ + Ms3$ + Ms4$)
SetGadgetState(#Img_Preview, ImageID(10))
Else
SelectElement(Texts(), IDWindow - 1000)
C$ = GetGadgetText(Texts()) : c = Asc(C$)
Ms1$ = "Car. = " + RSet(C$, 1, " ") + " "
Ms2$ = "Ascii = " + RSet(Str(c), 3, "0") + " "
Ms3$ = "Hex = $" + RSet(Hex(c), 2, "0") + " "
Ms4$ = "Bin = %" + RSet(Bin(c), 8, "0")
SetGadgetText(#Txt_Result, Ms1$ + Ms2$ + Ms3$ + Ms4$)
Create_Image(GetGadgetText(Texts()))
EndIf
EndIf
Select WaitWindowEvent();{
Case #PB_Event_Gadget
Select EventGadget();{
Case #Cmb_Fonts;{
If EventType() = #CBN_SELCHANGE
SelectElement(Fontes(), GetGadgetState(#Cmb_Fonts))
LoadFont(0, Fontes(), 9) : LoadFont(1, Fontes(), 140)
UpdateTexts()
SetGadgetState(#Img_Preview, ImageID(10))
EndIf;}
Case #Btn_CopyAsBin;{
c = Asc(GetGadgetText(#TxtCopie))
If GetGadgetState(#Chk_InsertChr) = 1
Res$ = "chr(%" + Bin(c) + ")"
Else
Res$ = "%" + Bin(c)
EndIf
If GetGadgetState(#Chk_Japbe) = 0
SetClipboardText(Res$)
Else
SendDatasToEditor(WindowID(#Win_Main), Res$, #WMCD_InsertText)
EndIf;}
Case #Btn_CopyAsChar;{
If GetGadgetState(#Chk_InsertChr) = 1
Res$ = "Chr('"+ GetGadgetText(#TxtCopie) + "')"
Else
Res$ = "'"+GetGadgetText(#TxtCopie)+"'"
EndIf
If GetGadgetState(#Chk_Japbe) = 0
SetClipboardText(Res$)
Else
SendDatasToEditor(WindowID(#Win_Main), Res$, #WMCD_InsertText)
EndIf;}
Case #Btn_CopyAsDec;{
c = Asc(GetGadgetText(#TxtCopie))
If GetGadgetState(#Chk_InsertChr) = 1
Res$ = "chr("+Str(c)+")"
Else
Res$ =Str(c)
EndIf
If GetGadgetState(#Chk_Japbe) = 0
SetClipboardText(Res$)
Else
SendDatasToEditor(WindowID(#Win_Main), Res$, #WMCD_InsertText)
EndIf;}
Case #Btn_CopyAsHex;{
c = Asc(GetGadgetText(#TxtCopie))
If GetGadgetState(#Chk_InsertChr) = 1
Res$ = "chr($"+Hex(c)+")"
Else
Res$ = "$"+Hex(c)
EndIf
If GetGadgetState(#Chk_Japbe) = 0
SetClipboardText(Res$)
Else
SendDatasToEditor(WindowID(#Win_Main), Res$, #WMCD_InsertText)
EndIf;}
Case #Btn_CopyAsString;{
Res$ = Chr(34) + GetGadgetText(#TxtCopie) + Chr(34)
If GetGadgetState(#Chk_Japbe) = 0
SetClipboardText(Res$)
Else
SendDatasToEditor(WindowID(#Win_Main), Res$, #WMCD_InsertText)
EndIf;}
Case #Btn_CopyAsCar;{
Res$ = GetGadgetText(#TxtCopie)
If GetGadgetState(#Chk_Japbe) = 0
SetClipboardText(Res$)
Else
SendDatasToEditor(WindowID(#Win_Main), Res$, #WMCD_InsertText)
EndIf;}
Case #Btn_Erase;{
SetGadgetText(#TxtCopie, "");}
Case #Chk_Sticky;{
StickyWindow(#Win_Main, GetGadgetState(#Chk_Sticky));}
EndSelect;}
Case #PB_Event_CloseWindow;{
CreatePreferences("CharMap.pref")
WritePreferenceLong("IdFont", GetGadgetState(#Cmb_Fonts))
WritePreferenceLong("OnTop", GetGadgetState(#Chk_Sticky))
WritePreferenceLong("AddChr", GetGadgetState(#Chk_InsertChr))
WritePreferenceLong("Japbe", GetGadgetState(#Chk_Japbe))
ClosePreferences()
Quit =#True;}
EndSelect;}
Until Quit;}
End;}
;{- Datas
DataSection
CommandChar:
Data.s "NUL - Null","SOH - Start Of Header", "STX - Start Of Text", "ETX - End Of Text", "EOT - End Of Transmission", "ENQ - Enquiry", "ACK - Acknowledge", "BEL - Bell"
Data.s "BS - BackSpace", "HT - Horizontal Tab", "LF - Line Feed", "VT - Vertical Tab", "FF - Form Feed", "CR - Carriage Return", "SO - Shift Out", "SI - Shift In", "DLE - Data Link Escape"
Data.s "DC1 - (XON) Device Control 1", "DC2 - Device Control 2", "DC3 - (XOFF) Device Control 3", "DC4 - Device Control 4", "NAK - Negative Acknowledge", "SYN - Synchronous IDLE"
Data.s "ETB - End of Trans. Block", "CAN - Cancel", "EM - End of Medium", "SUB - Substitute", "ESC - Escape", "FS - File Separator", "GS - Group Separator"
Data.s "RS - Request to Send", "US - Unit Separator", "SP - Space"
EndDataSection;}
; IDE Options = PureBasic Visual Designer v4.0 Alpha 15 build 651
; VD_UsePB_Any = 0
; VD_IncludeBinaryBitmaps = 1
; VD_IncludeXPskins = 0