Jump to content

Button questions on encoding, align left, and bitmap


Recommended Posts

First time I'm diving a little deeper into buttons, and mainly frustrated by the encoding problem. The rabbit hole is deep... ūüėõ

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

$text = "[book] Esm√©e S√Ľrnom√† - Cars_ Planes, Boats, & Rockets! (great) Until the line doubles if there are spaces or a .bmp in front."

$hGUI = GUICreate("", 600, 300)

GUICtrlCreateButton("  " & $text, 10, 10, 580, 40, BitOR($BS_LEFT,$BS_MULTILINE))
GUICtrlSetFont(-1, 11, 600)

GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
    EndSwitch
WEnd

(1) I'm loading filenames with _FileListToArrayRec() and my impression is this gets all or most "special" characters. However, I can't find how to have some correctly go on a button... In the example it's only the '&' that is getting lost, but there may be more...

My .au3 file gets saved in UTF-8 with BOM and I'm already pretty dirty from the rabbit hole... ūüėú

(2)  Is there a more professional way to Left Align besides the $BS_LEFT I'm using?

I mean, when a line goes double (like in my example) or you have a bitmap in front, the spaces I'm now using to create some margin lead to big problems.
If I don't have the spaces, things stick to the edge...

h8a8DM2.jpg

 

(3) I've been making some bitmaps to go on the buttons and for a few of them the image colors change. Does this ring a bell about what might be wrong? (tried saving them in different ways, and like the ones that are working).

Thanks for any pointers, esp. #1 ūü§ó

Edited by Guy_
Link to post
Share on other sites
  • Moderators

Guy_,

1. Buttons always loose a single "&" character as Windows interprets that as setting the next character as the accelerator key for firing the control - you need to double the "&" using StringReplace.

2. You can add the same spacing to the beginning of each line to create a standard margin like this:

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>

$sText = "This is line #1" & @CRLF & "This is line #2"
_AddMargin($sText)

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton($sText, 10, 10, 580, 40, BitOR($BS_LEFT,$BS_MULTILINE))
GUICtrlSetFont(-1, 11, 600)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

WEnd

Func _AddMargin(ByRef $sText)
    $sText = "    " & StringReplace($sText, @CRLF, @CRLF & "    ")
EndFunc

3. Never seen bitmap colours change as you describe.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

(1) Phew! Thanks so much! :)

(2) Thanks! I think this can be handy one day but because I have no Returns in the titles, it's really doing the same thing as I did but with four spaces instead of two. The mishaps are still the same...

(3) I'll try if I can make a small reproducer somewhere tomorrow. I've had it with at least four .bmp's. They are not changing in front of my eyes but display differently than I designed them. For example ...
fiG3vyE.jpg

This is my code minus some lengthy vars:

_AddMargin($s_Title)

$a_hBtn[$i][0] = GUICtrlCreateButton($s_Title, 10, , , , BitOR($BS_LEFT,$BS_MULTILINE))

GUICtrlSetFont(-1, 11, 600)

If StringInStr("pdfx", $_ext) Then
    GUICtrlSetImage(-1, @ScriptDir & "\label\acro.bmp", "", $BS_BITMAP)         ; Adobe Acrobat (pdf)
ElseIf StringInStr("djvu", $_ext) Then
    GUICtrlSetImage(-1, @ScriptDir & "\label\djvu.bmp", "", $BS_BITMAP)         ; DjVu
ElseIf StringInStr("epub", $_ext) Then
    GUICtrlSetImage(-1, @ScriptDir & "\label\epub.bmp", "", $BS_BITMAP)         ; EPUB
ElseIf StringInStr("azw3azw4kdpkpfmobi", $_ext) Then
    GUICtrlSetImage(-1, @ScriptDir & "\label\kindle.bmp", "", $BS_BITMAP)       ; Amazon Kindle (mobi azw azw3 azw4 kdp kpf)
ElseIf StringInStr("docx", $_ext) Then
    GUICtrlSetImage(-1, @ScriptDir & "\label\word.bmp", "", $BS_BITMAP)         ; MS WORD (doc docx)
ElseIf StringInStr("rtf", $_ext) Then
    GUICtrlSetImage(-1, @ScriptDir & "\label\wordpad.bmp", "", $BS_BITMAP)      ; WordPad (rtf)
ElseIf StringInStr("odt", $_ext) Then
    GUICtrlSetImage(-1, @ScriptDir & "\label\odt.bmp", "", $BS_BITMAP)          ; LibreOffice (odt)
Else
    GUICtrlSetImage(-1, @ScriptDir & "\label\generic.bmp", "", $BS_BITMAP)
EndIf

P.S. Enjoying your great scrollbars for the first time too! ūü§©

Edited by Guy_
Link to post
Share on other sites
  • Moderators

Guy_,

Use my StringSize UDF (the link is in my sig) to break up the strings to the width you require - the UDF adds @CRLFs where necessary so solving your problem.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...