& Character problem
#1
using the & character is a problem when typing in text box and displaying it, is thee a fix

type A&B
screen show AB
xprint show A&B

type A&&B
screen show A&B
xprint show A&&B
Reply
#2
unable to duplicate problem with: 
Code:
#compile exe
#dim all
%UNICODE = 1

function pbmain () as long
  local W, RtoL as wstring
  local R as string
  local hDlg as dword
  W = chr$$(&h1D08)
  RtoL = chr$$(&h21D0)  'F4)
  dialog default font "Consolas", 10, 0, 1
  dialog new 0, W, , , 150, 50, %ws_overlappedwindow, %ws_ex_left or _
     %ws_ex_ltrreading to hDlg
  control add textbox, hDlg, 1000, "", 5, 5, 40, 12
 
  dialog show modal hDlg

end function           

and typing into textbox as stated using PBWin 10 on Windows 10

Cheers,
Reply
#3
FORMATTING NOT SHOWING CORRECT ON POST

type A&B
screen show AB <-- SHOULD BE B UNDERLINE
xprint show A&B

type A&&B
screen show A&B
xprint show A&&B

Here is sample code that show problem

'CODE FOR PROBLEM

#COMPILE EXE
#DIM ALL
%UNICODE = 1

GLOBAL hDlg AS DWORD, A AS STRING

CALLBACK FUNCTION XPRINTT()
XPRINT ATTACH CHOOSE
XPRINT A
XPRINT CLOSE
END FUNCTION

CALLBACK FUNCTION TEXTT()
CONTROL GET TEXT hDlg, 1000 TO A
CONTROL SET TEXT hDlg, 1002, A
END FUNCTION

FUNCTION PBMAIN () AS LONG
LOCAL W, RtoL AS WSTRING
LOCAL R AS STRING

W = CHR$$(&h1D08)
RtoL = CHR$$(&h21D0) 'F4)
DIALOG DEFAULT FONT "Consolas", 10, 0, 1
DIALOG NEW 0, W, , , 150, 50, %WS_OVERLAPPEDWINDOW, %WS_EX_LEFT OR _
%WS_EX_LTRREADING TO hDlg
CONTROL ADD TEXTBOX, hDlg, 1000, "", 5, 5, 40, 12
CONTROL ADD BUTTON ,hDlg,1001, "DONE", 50,5,40,12, CALL TEXTT
CONTROL ADD LABEL ,hDlg,1002, "XX", 50,25,40,12, '
CONTROL ADD BUTTON ,hDlg,1003, "PRINT", 100, 5,40,12, CALL XPRINTT


DIALOG SHOW MODAL hDlg

END FUNCTION

doing xprint better to print to file than waste paper
Reply
#4
"screen show AB <-- SHOULD BE B UNDERLINE"

I get AB with B underlined in label here after clicking DONE. No idea why you don't.

For A&&B I get A&B as said.

The pdf after PRINT shows content of textbox for A&B and A&&B. "&&" tries to hotkey the second "&", it can't so just shows one.

Post 1 did not mention display in label, so I was not surprised when the textbox when B was not underlined.

All the help I have, bye from this.

Cheers,
Reply
#5
(01.10.2025, 12:38 AM)Robert Alvarez Wrote: FORMATTING NOT SHOWING CORRECT ON POST

type A&B
screen show AB  <-- SHOULD BE B UNDERLINE
xprint show A&B



doing xprint better to print to file than waste paper


Known behaviour of recent versions of  Windows.  

By default, you need to hit Alt key to show keyboard shortcuts in menus and labels (and button text).
"&&" shows the character "&" in such controls and it is NOT a  shortcut.

To demonstrate more clearly, try "&DONE" as the button label Smile

Demonstration of what is actually stored:
Code:
#COMPILE EXE
#DIM ALL
%UNICODE = 1

GLOBAL hDlg AS DWORD, A AS STRING

CALLBACK FUNCTION DisplayIt
LOCAL s AS STRING
CONTROL GET TEXT CB.HNDL, 1002 TO s
? s & $LF & A
END FUNCTION

CALLBACK FUNCTION TEXTT()
CONTROL GET TEXT hDlg, 1000 TO A
CONTROL SET TEXT hDlg, 1002, A
END FUNCTION

FUNCTION PBMAIN () AS LONG
LOCAL W, RtoL AS WSTRING
LOCAL R AS STRING

W = CHR$$(&h1D08)
RtoL = CHR$$(&h21D0) 'F4)
DIALOG DEFAULT FONT "Consolas", 10, 0, 1
DIALOG NEW 0, W, , , 150, 50, %WS_OVERLAPPEDWINDOW, %WS_EX_LEFT OR _
%WS_EX_LTRREADING TO hDlg
CONTROL ADD TEXTBOX, hDlg, 1000, "", 5, 5, 40, 12
CONTROL ADD BUTTON ,hDlg,1001, "&DONE", 50,5,40,12, CALL TEXTT
CONTROL ADD LABEL ,hDlg,1002, "XX", 50,25,40,12, '
CONTROL ADD BUTTON ,hDlg,1003, "Display", 100, 5,40,12, CALL Displayit


DIALOG SHOW MODAL hDlg

END FUNCTION
             

You can control this behaviour with: 
Control Panel > Ease of Access Center > Make the keyboard easier to use > Enable "Underline keyboard shortcuts and access keys".

   
--
New PowerBASIC User Community Forum:
https://pbusers.org/forum
Reply
#6
To always show & in static (label) control, add %SS_NOPREFIX style to it.
MS explains: "Prevents interpretation of any ampersand (&) characters in the control's text as accelerator prefix characters. These are displayed with the ampersand removed and the next character in the string underlined. This static control style may be included with any of the defined static controls.
An application can combine SS_NOPREFIX with other styles by using the bitwise OR (|) operator. This can be useful when filenames or other strings that may contain an ampersand (&) must be displayed in a static control in a dialog box."

Code:
'======================================================================
#COMPILE EXE
#DIM ALL
'--------------------------------------------------------------------
%UNICODE = 1
#INCLUDE "WIN32API.INC"
'--------------------------------------------------------------------
%IDC_LABEL1         = 501
%IDC_TEXTFIELD1     = 541

'======================================================================
FUNCTION PBMAIN () AS LONG
  LOCAL hDlg AS DWORD

  DIALOG NEW 0, "Dialog1",,, 111, 39, %WS_CAPTION OR %WS_SYSMENU OR _
                                      %WS_MINIMIZEBOX, 0 TO hDlg
  '------------------------------------------------------------------
  CONTROL ADD TEXTBOX, hDlg, %IDC_TEXTFIELD1, "TextBox - X&Y", 5, 5, 100, 13
  CONTROL ADD LABEL, hDlg, %IDC_LABEL1, "Label - X&Y", 5, 20, 100, 13, %SS_NOPREFIX

  '-------------------------------------------------------------------
  DIALOG SHOW MODELESS hDlg, CALL DlgProc
  DO
    DIALOG DOEVENTS
  LOOP WHILE ISWIN(hDlg)

END FUNCTION

'======================================================================
CALLBACK FUNCTION DlgProc() AS LONG
  SELECT CASE CB.MSG
  CASE %WM_INITDIALOG

  CASE %WM_COMMAND
      SELECT CASE CB.CTL
      CASE %IDCANCEL
          IF CB.CTLMSG = %BN_CLICKED OR CB.CTLMSG = 1 THEN
              DIALOG END CB.HNDL, 0
          END IF
      END SELECT

  END SELECT

END FUNCTION
Reply
#7
I think he did not want to see the &, he wanted the hot-key. The & was not showing, correct, but not getting the underline indicating the hot-key took affect.
Reply
#8
(01.10.2025, 02:29 PM)Borje Hagsten Wrote: To always show & in static (label) control, add %SS_NOPREFIX style to it.
MS explains: "Prevents interpretation of any ampersand (&) characters in the control's text as accelerator prefix characters. These are displayed with the ampersand removed and the next character in the string underlined. This static control style may be included with any of the defined static controls.
An application can combine SS_NOPREFIX with other styles by using the bitwise OR (|) operator. This can be useful when filenames or other strings that may contain an ampersand (&) must be displayed in a static control in a dialog box."

N.B. Applies to Labels but not to Buttons. (for a button, you have to use "&&")
--
New PowerBASIC User Community Forum:
https://pbusers.org/forum
Reply
#9
%SS_NOPREFIX Fixed the problem

thanks Borje and everyone for your help and comments
Reply
#10
For buttons, use ownerdrawn and DrawText with %DT_NOPREFIX format.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)