Macro et constante

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Cls
Messages : 620
Inscription : mer. 22/juin/2005 8:51
Localisation : Nantes

Macro et constante

Message par Cls »

Bonjour à tous,

Je souhaite faire une macro de ce type :

Code : Tout sélectionner

Macro #PB_String_Numeric
  #PB_String_Numeric|#PB_Text_Right
EndMacro
Ce code bug, n'étant pas spécialiste des macros, voyez - vous une solution fonctionnelle ?

Merci d'avance,
Cls
tmyke
Messages : 1554
Inscription : lun. 24/juil./2006 6:44
Localisation : vosges (France) 47°54'39.06"N 6°20'06.39"E

Message par tmyke »

Certains caracteres sont dévolues à des fonctions bien précise au sein du langage.
Comme en particulier le caractère '#' dévolue aux constantes. Vouloir définir une macro
avec me parait impossible. A la rigueur tu peux ecrire ceci:

Code : Tout sélectionner

Macro PB_String_Numeric
  #PB_String_Numeric|#PB_Text_Right
EndMacro

Debug #PB_String_Numeric|#PB_Text_Right
Debug PB_String_Numeric
cela fonctionne, mais tu perds dans ce cas la syntaxe 'constante' et la coloration syntaxique qui
va avec.

tu peux par contre ecrire quelque chose comme cela:

Code : Tout sélectionner

#PB_String_Numeric_ = #PB_String_Numeric|#PB_Text_Right
Debug #PB_String_Numeric_
;)
Force et sagesse...
Anonyme2
Messages : 3518
Inscription : jeu. 22/janv./2004 14:31
Localisation : Sourans

Message par Anonyme2 »

Une macro a un nom et ce nom ne peut pas être une constante et de plus une constante ne peut pas changer de valeur (ça a été possible il y a quelques années)

J'ai juste enlevé le # du nom

Code : Tout sélectionner

Macro PB_String_Numeric
  #PB_String_Numeric|#PB_Text_Right
EndMacro

Debug #PB_String_Numeric
Debug #PB_Text_Right
Debug PB_String_Numeric
Debug #PB_String_Numeric|#PB_Text_Right

a.l = PB_String_Numeric

Debug a
Cls
Messages : 620
Inscription : mer. 22/juin/2005 8:51
Localisation : Nantes

Message par Cls »

Merci pour vos réponses.

Je vais rentrer un peu plus dans les détails. J'ai une application relativement importante (environ 15000 lignes) contenant pratiquement 250 StringGadgets de type Numeric. Mon client me demande d'aligner ces StringGadgets à droite (format monétaire). Le soucy est que je ne souhaite pas toucher aux codes sources de l'interface (dès que je fais une modif sur les écrans, je passe par Visual Designer, ca permet de générer l'interface sans avoir à retoucher le fichier source pour intégrer les anciennes modifs).

J'aimerais donc que l'ajout du PB_Text_Right se fasse automatiquement à la compilation... est - ce possible ?


Une autre solution serait de lancer une procédure à l'ouverture des écrans qui détecterait les Gadget de type String contenant l'attribut #PB_String_Numeric (ou autre selon l'API Windows). D'où une nouvelle question : peut - on connaitre le type d'un gadget sous windows, et si oui ses différents attributs ?
Avatar de l’utilisateur
Chris
Messages : 3731
Inscription : sam. 24/janv./2004 14:54
Contact :

Message par Chris »

Pour connaître le type de gadget, tu as la fonction GadgetType(#Gadget)

Pour connaître les attributs d'un gadget, tu peux toujours essayer GetWindowLong_(GadgetId(#Gadget), #GWL_STYLE)

Code : Tout sélectionner

Style = GetWindowLong_(GadgetId(#Gadget), #GWL_STYLE)

If Style & #Pb_String_Numeric
  Debug "Numérique"
Endif
Sinon, pour les attributs des StringGadgets version Windows,(appelés "Edit"), les constantes de style sont là.
ES_AUTOHSCROLL
Automatically scrolls text to the right by 10 characters when the user types a character at the end of the line. When the user presses the ENTER key, the control scrolls all text back to position zero.

ES_AUTOVSCROLL
Automatically scrolls text up one page when the user presses the ENTER key on the last line.

ES_CENTER
Windows 98/Me, Windows 2000/XP: Centers text in a single-line or multiline edit control.
Windows 95, Windows NT 4.0 and earlier: Centers text in a multiline edit control.


ES_LEFT
Left aligns text.

ES_LOWERCASE
Converts all characters to lowercase as they are typed into the edit control.
To change this style after the control has been created, use SetWindowLong.


ES_MULTILINE
Designates a multiline edit control. The default is single-line edit control.
When the multiline edit control is in a dialog box, the default response to pressing the ENTER key is to activate the default button. To use the ENTER key as a carriage return, use the ES_WANTRETURN style.

When the multiline edit control is not in a dialog box and the ES_AUTOVSCROLL style is specified, the edit control shows as many lines as possible and scrolls vertically when the user presses the ENTER key. If you do not specify ES_AUTOVSCROLL, the edit control shows as many lines as possible and beeps if the user presses the ENTER key when no more lines can be displayed.

If you specify the ES_AUTOHSCROLL style, the multiline edit control automatically scrolls horizontally when the caret goes past the right edge of the control. To start a new line, the user must press the ENTER key. If you do not specify ES_AUTOHSCROLL, the control automatically wraps words to the beginning of the next line when necessary. A new line is also started if the user presses the ENTER key. The window size determines the position of the Wordwrap. If the window size changes, the Wordwrapping position changes and the text is redisplayed.

Multiline edit controls can have scroll bars. An edit control with scroll bars processes its own scroll bar messages. Note that edit controls without scroll bars scroll as described in the previous paragraphs and process any scroll messages sent by the parent window.


ES_NOHIDESEL
Negates the default behavior for an edit control. The default behavior hides the selection when the control loses the input focus and inverts the selection when the control receives the input focus. If you specify ES_NOHIDESEL, the selected text is inverted, even if the control does not have the focus.

ES_NUMBER
Allows only digits to be entered into the edit control. Note that, even with this set, it is still possible to paste non-digits into the edit control.
To change this style after the control has been created, use SetWindowLong.


ES_OEMCONVERT
Converts text entered in the edit control. The text is converted from the Windows character set to the OEM character set and then back to the Windows character set. This ensures proper character conversion when the application calls the CharToOem function to convert a Windows string in the edit control to OEM characters. This style is most useful for edit controls that contain file names that will be used on file systems that do not support Unicode.
To change this style after the control has been created, use SetWindowLong.


ES_PASSWORD
Displays an asterisk (*) for each character typed into the edit control. This style is valid only for single-line edit controls.
Windows XP: If the edit control is from user32.dll, the default password character is an asterisk. However, if the edit control is from comctl32.dll version 6, the default character is a black circle.

To change the characters that is displayed, or set or clear this style, use the EM_SETPASSWORDCHAR message.

Note Comctl32.dll version 6 is not redistributable but it is included in Microsoft Windows XP or later. To use Comctl32.dll version 6, specify it in a manifest. For more information on manifests, see Using Windows XP Visual Styles.

ES_READONLY
Prevents the user from typing or editing text in the edit control.
To change this style after the control has been created, use the EM_SETREADONLY message.


ES_RIGHT
Windows 98/Me, Windows 2000/XP: Right aligns text in a single-line or multiline edit control. Windows 95, Windows NT 4.0 and earlier: Right aligns text in a multiline edit control.

ES_UPPERCASE
Converts all characters to uppercase as they are typed into the edit control.
To change this style after the control has been created, use SetWindowLong.


ES_WANTRETURN
Specifies that a carriage return be inserted when the user presses the ENTER key while entering text into a multiline edit control in a dialog box. If you do not specify this style, pressing the ENTER key has the same effect as pressing the dialog box's default push button. This style has no effect on a single-line edit control.
To change this style after the control has been created, use SetWindowLong.
Cls
Messages : 620
Inscription : mer. 22/juin/2005 8:51
Localisation : Nantes

Message par Cls »

Merci Chris.

C'est idiot de ma part de n'avoir pas regardé plus attentivement que ça les fonctions de la librairie Gadget ! (Je m'attendais à une fonction GetGadgetType() : 5 lignes au dessus de GadgetType() dans l'aide !)

Effectivement GetWindowLong renvoie les infos désirées. Décidement la fin de semaine est difficile ! Je commence à être fatigué :)

En tout cas merci beaucoup pour ton aide.

Cordialement,
Cls
Répondre