Constantes MessageRequester

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Avatar de l’utilisateur
JohnJohnsonSHERMAN
Messages : 648
Inscription : dim. 13/déc./2015 11:05
Localisation : Allez, cherche...
Contact :

Constantes MessageRequester

Message par JohnJohnsonSHERMAN »

Salut à tous !

Voilà, des petites constantes a mettre dans les Flags d'un MessageRequester pour personnaliser les boutons... C'est juste un petit truc découvert tout a fait par hasard :?

Dans PB, on connait déja #PB_MessageRequester_Ok, pour afficher un bouton "Ok", #PB_MessageRequester_YesNo pour les boutons "oui" et "non", et #PB_MessageRequester_YesNoCancel pour les boutons "Oui", "Non, et "Annuler".
Je vous présente aussi #PB_MessageRequester_OkCancel, #PB_MessageRequester_AbandonRetryContinue, #PB_MessageRequester_RetryCancel, et #PB_MessageRequester_CancelRetryContinue... A vous de tester ;)

Un petit code pour illustrer cela :

Code : Tout sélectionner


; ### Constantes MessageRequester pour personnaliser ses boites de dialogue. Par JohnJohnsonSHERMAN. ###




Enumeration MsgReq
  #PB_MessageRequester_Ok =0
  #PB_MessageRequester_OkCancel=1
  #PB_MessageRequester_AbandonRetryContinue=2
  #PB_MessageRequester_YesNoCancel=3
  #PB_MessageRequester_YesNo=4
  #PB_MessageRequester_RetryCancel=5
  #PB_MessageRequester_CancelRetryContinue=6
EndEnumeration

MessageRequester("Test","Ceci est un message requester Ok",#PB_MessageRequester_Ok)
MessageRequester("Test","Ceci est un message requester Ok et Annuler",#PB_MessageRequester_OkCancel)
MessageRequester("Test","Ceci est un message requester Abandonner,Recommencer,Continuer",#PB_MessageRequester_AbandonRetryContinue)
MessageRequester("Test","Ceci est un message requester Oui,Non,Annuler",#PB_MessageRequester_YesNoCancel)
MessageRequester("Test","Ceci est un message requester Oui, Non",#PB_MessageRequester_YesNo)
MessageRequester("Test","Ceci est un message requester Recommencer,Annuler",#PB_MessageRequester_RetryCancel)
MessageRequester("Test","Ceci est un message requester Annuler, Recommencer, Continuer",#PB_MessageRequester_CancelRetryContinue)
Voila,j'ai trouvé ca ce matin par hasard en essayant d'obtenir des MessageRequester avec une icone "erreur" dessus (cf Droopy lib ,#MB_ICONERROR), le probléme étant que je ne connait pas la valeur de #MB_ICONERROR. J'ai testé plusieurs valeurs et j'ai trouvé ca... comme je ne l'ait pas déjà vu sur le forum, je vous le partage.. 8)
"Le bug se situe entre la chaise et le clavier"
Votre expert national en bogage et segfaults.

CPU : AMD A8 Quad core - RAM 8Gb - HDD 2To
  • Windows 10 x64 - PB 5.61 x64
  • Linux Ubuntu 16.04 LTS x64 (dual boot) - PB pas encore réinstallé
Marc56
Messages : 2147
Inscription : sam. 08/févr./2014 15:19

Re: Constantes MessageRequester

Message par Marc56 »

Menu Outils > Visualiseur de Structures > Onglet Constantes :wink:

Ou si tu as besoin de savoir rapidement la valeur: Debug

Code : Tout sélectionner

Debug #MB_ICONERROR
= 16

PS. Comme ces numéros sont aussi liés aux API ils sont constants quelque soit le langage, donc quand on en manipule plusieurs, on utilise (enfin moi) les numéros plutôt que les noms à coucher dehors :mrgreen:

Ex: les MsgBox (MessagesRequester en PB) avec 64, ça donne OK + Point d’exclamation. :)
Avatar de l’utilisateur
JohnJohnsonSHERMAN
Messages : 648
Inscription : dim. 13/déc./2015 11:05
Localisation : Allez, cherche...
Contact :

Re: Constantes MessageRequester

Message par JohnJohnsonSHERMAN »

Il y a une erreur dans le précédent post : le MeesageRequester avec #PB_MessageRequester_CancelRetryContinue n'affiche pas de bouton "continuer", mais un bouton "Ignorer", qui a une valeur de retour différente. Juste pour l'ergonomie, je la corrige.

Sinon, voici les constantes renvoyées par le MessageRequester quand on clique sur les boutons :

Code : Tout sélectionner

Enumeration MsgRegClic
  #PB_MessageRequesterEvent_Ok=1
  #PB_MessageRequesterEvent_Cancel=2
  #PB_MessageRequesterEvent_Abandon=3
  #PB_MessageRequesterEvent_Retry=4     ;Deux valeurs peuvent être retournées dans le cas d'un clic sur Recommencer : 4 lorqu'il est issu d'un MessageRequester Abandonner, Recommencer,Ignorer
  ;                                      ou 11 lorsqu'issue d'un MessageReqester Annuler, Recommencer, Continuer.
  #PB_MessageRequesterEvent_Ignore=5
  #PB_MessageRequesterEvent_Yes=6
  #PB_MessageRequesterEvent_No=7
  #PB_MessageRequesterEvent_Retry2=10
  #PB_MessageRequesterEvent_Continue=11
EndEnumeration

"Le bug se situe entre la chaise et le clavier"
Votre expert national en bogage et segfaults.

CPU : AMD A8 Quad core - RAM 8Gb - HDD 2To
  • Windows 10 x64 - PB 5.61 x64
  • Linux Ubuntu 16.04 LTS x64 (dual boot) - PB pas encore réinstallé
Avatar de l’utilisateur
JohnJohnsonSHERMAN
Messages : 648
Inscription : dim. 13/déc./2015 11:05
Localisation : Allez, cherche...
Contact :

Re: Constantes MessageRequester

Message par JohnJohnsonSHERMAN »

Double post, désolé j'ai pas vu la réponse de Marc.

Vu que j'ait pas les API, je ne pouvait pas savoir... merci!
En tout cas j'ai trouvé un truc tout seul :lol: Je suis content.. ;)
"Le bug se situe entre la chaise et le clavier"
Votre expert national en bogage et segfaults.

CPU : AMD A8 Quad core - RAM 8Gb - HDD 2To
  • Windows 10 x64 - PB 5.61 x64
  • Linux Ubuntu 16.04 LTS x64 (dual boot) - PB pas encore réinstallé
Marc56
Messages : 2147
Inscription : sam. 08/févr./2014 15:19

Re: Constantes MessageRequester

Message par Marc56 »

Voila toutes les valeurs de MessageRequester

https://msdn.microsoft.com/fr-fr/librar ... 90%29.aspx

Il suffit d'additionner les valeurs pour composer la boite:
Ex: Message Oui+Non+Annuler + « ? » en PB

Code : Tout sélectionner

MessageRequester("Test Box", " Oui+Non+Annuler + ? ", 67)   ; 67 = 0 + 3 + 64
Ce sont les mêmes valeurs que celles utilisées pour MsgBox en VB, VBA, puisque cela encapsule la même API. On fini par connaitre ces numéros par cœur et ça va bien plus vite.
(Il existe une petite application (en langage AutoIt, je crois) pour générer le code des messages requester. Je crois qu'elle a été portée en PB, sinon, c'est le genre d'exercice rapide à réaliser. Chercher MessageBox Generator dans google image pour des exemples)

:wink:
Avatar de l’utilisateur
JohnJohnsonSHERMAN
Messages : 648
Inscription : dim. 13/déc./2015 11:05
Localisation : Allez, cherche...
Contact :

Re: Constantes MessageRequester

Message par JohnJohnsonSHERMAN »

Trés intéressant Marc, merci de l'info !
J'avait testé avec une boucle jusqu'a 100 les "premiers" looks de MessageRequesters, mais là, c'est bien expliqué et trés clair... les boutons par défaut, etc... et tout ca marche avec PB aussi! Ne reste plus qu'a l'appliquer a nos codes si ce n'est déjà fait..

Merci pour tout :)

Edit : Allez, juste pour le fun, voila les valeurs que vous pourrez utiliser dans vos MessageRequester (a combiner dans le paramétre 'Flags' avec "|", comme d'hab :) )

Code : Tout sélectionner

; ### Constantes MessageRequester pour personnaliser ses boites de dialogue. Par JohnJohnsonSHERMAN. ###




Enumeration MsgReqButtons
  #PB_MessageRequester_Ok =0
  #PB_MessageRequester_OkCancel=1
  #PB_MessageRequester_AbortRetryIgnore=2
  #PB_MessageRequester_YesNoCancel=3
  #PB_MessageRequester_YesNo=4
  #PB_MessageRequester_RetryCancel=5
  #PB_MessageRequester_CancelRetryContinue=6
EndEnumeration

Enumeration MsgReqStyle
  #PB_MessageRequester_Error = 16
  #PB_MessageRequester_Question= 32
  #PB_MessageRequester_Warning = 48
  #PB_MessageRequester_Info = 64
  #PB_MessageRequester_Other = 0
EndEnumeration

Enumeration MsgReqDefaultButton
  #PB_MessageRequester_FirstButton = 0
  #PB_MessageRequester_SecondButton = 256
  #PB_MessageRequester_ThirdButton = 512
EndEnumeration


Enumeration MsgRegClic
  #PB_MessageRequesterEvent_Ok=1
  #PB_MessageRequesterEvent_Cancel=2
  #PB_MessageRequesterEvent_Abandon=3
  #PB_MessageRequesterEvent_Retry=4     ;Deux valeurs peuvent être retournées dans le cas d'un clic sur Recommencer : 4 lorqu'il est issu d'un MessageRequester Abandonner, Recommencer,Ignorer
  ;                                      ou 11 lorsqu'issue d'un MessageReqester Annuler, Recommencer, Continuer.
  #PB_MessageRequesterEvent_Ignore=5
  #PB_MessageRequesterEvent_Yes=6
  #PB_MessageRequesterEvent_No=7
  #PB_MessageRequesterEvent_Retry2=10
  #PB_MessageRequesterEvent_Continue=11
EndEnumeration
Amusez vous bien ;)
Dernière modification par JohnJohnsonSHERMAN le dim. 20/mars/2016 15:17, modifié 1 fois.
"Le bug se situe entre la chaise et le clavier"
Votre expert national en bogage et segfaults.

CPU : AMD A8 Quad core - RAM 8Gb - HDD 2To
  • Windows 10 x64 - PB 5.61 x64
  • Linux Ubuntu 16.04 LTS x64 (dual boot) - PB pas encore réinstallé
Avatar de l’utilisateur
blendman
Messages : 2017
Inscription : sam. 19/févr./2011 12:46

Re: Constantes MessageRequester

Message par blendman »

Après, pour faire encore plus simple et pour choper les constantes qui t'intéressent :

Code : Tout sélectionner

For i = 0 To 200
    MessageRequester("Test","Pour tester les constantes et voir celles qui t'intéressent : "+Str(i),i)
Next
Tu pourras avoir plein d 'icones et tout :)
Avatar de l’utilisateur
JohnJohnsonSHERMAN
Messages : 648
Inscription : dim. 13/déc./2015 11:05
Localisation : Allez, cherche...
Contact :

Re: Constantes MessageRequester

Message par JohnJohnsonSHERMAN »

C'est bien ce que j'ai fait ce matin... Sinon, vas voir le lien de Marc, ou encore mieux, utilise mes constantes ;), dans mon précedent post (que je viens d'éditer). Tu peux te faire un include, et tu y mets toutes tes constantes, tes macros, c'est trés pratique !
Petit exemple :

Code : Tout sélectionner

MessageRequester("Sherman","Le Sherman dit... c'est un warning avec des boutons Abandonner, Recommencer, Ignorer et le bouton Recommencer est sélectionné par défaut ! Waouh, trop génial ;)",#PB_MessageRequester_AbortRetryIgnore | #PB_MessageRequester_Warning | #PB_MessageRequester_SecondButton)
"Le bug se situe entre la chaise et le clavier"
Votre expert national en bogage et segfaults.

CPU : AMD A8 Quad core - RAM 8Gb - HDD 2To
  • Windows 10 x64 - PB 5.61 x64
  • Linux Ubuntu 16.04 LTS x64 (dual boot) - PB pas encore réinstallé
Avatar de l’utilisateur
Micoute
Messages : 2522
Inscription : dim. 02/oct./2011 16:17
Localisation : 35520 La Mézière

Re: Constantes MessageRequester

Message par Micoute »

On peut aussi en faire des personnalisés.

Code : Tout sélectionner

; Type  | Boutons qui apparaissent avec résultat
;  0      OK = 1
;  1      OK = 1, Annuler = 2
;  2      Abandon = 3, Réessayer = 4, Ignorer = 5
;  3      Oui = 6, Non = 7, Annuler = 2
;  4      Oui = 6, Non = 7
;  5      Réessayer = 4, Annuler = 2
; 10      Choisir = 10, Annuler = 2
; 11      Valider = 11, Annuler = 2
; 12      Quitter = 12, Annuler = 2
; 13      Sauvegarder = 13, Annuler = 2
; 14      Ascendant = 141, Descendant = 142, Annuler = 2
; 15      Analyser = 15, Annuler = 2
; 16      Formater = 16, Annuler = 2
; 17      Rechercher = 17, Annuler = 2

; Icone | Description de l'icône
;  0      Rien          : pas d'icône
;  1      Interdit      : rond rouge avec une croix blanche
;  2      Aide          : bulle avec un ?
;  3      Danger        : triangle jaune avec un !
;  4      Information   : bulle avec un I
;  5      Idée          : ampoule
;  6      Refus         : cercle barré
;  7      Cadenas       : cadenas
;  8      HDD           : disque dur
;  9      Trier         : flèche + traits décroissants
; 10      Analyser      : graphique
; 11      Rechercher    : loupe

Enumeration Icones
  #Image_1
  #Image_2
  #Image_3
  #Image_4
  #Image_5
  #Image_6
  #Image_7
  #Image_8
  #Image_9
  #Image_10
  #Image_11
  #Icone
EndEnumeration

Procedure InitImage()
  UsePNGImageDecoder()
  
  Global Interdit = CatchImage(#Image_1, ?Interdit); Icone Interdit
  Global Aide = CatchImage(#Image_2, ?Aide); Icone Aide
  Global Danger = CatchImage(#Image_3, ?Danger); Icone Danger
  Global Information = CatchImage(#Image_4, ?Information); Icone Information
  Global Idee = CatchImage(#Image_5, ?Idee); Icone Idée
  Global Refus = CatchImage(#Image_6, ?Refus); Icone Refus
  Global Cadenas = CatchImage(#Image_7, ?Cadenas); Icone Cadenas
  Global Trier = CatchImage(#Image_10, ?Trier) ; Icone fleche + traits décroissants
  Global HDD = CatchImage(#Image_8, ?HDD)      ; Icone Disque dur
  Global Analyser
  Global Rechercher = CatchImage(#Image_9, ?Loupe) ; Icone loupe
  
  DataSection
    Interdit:
    IncludeBinary "icones\Interdit.png"
    Aide:
    IncludeBinary "icones\Aide.png"
    Danger:
    IncludeBinary "icones\Danger.png"
    Information:
    IncludeBinary "icones\Information.png"
    Idee:
    IncludeBinary "icones\Idee.png"
    Refus:
    IncludeBinary "icones\Refus.png"
    Cadenas:
    IncludeBinary "icones\Cadenas.png"
    HDD:
    IncludeBinary "icones\HDD.png"
    Trier:
    IncludeBinary "icones\Trier.png"
    Loupe:
    IncludeBinary "icones\Rechercher.png"
  EndDataSection
EndProcedure

Procedure MessageRequester2(Titre$, Message$, Type.i, Icone.i)
  Protected.i Texte = 0, Bouton1 = 1, Bouton2 = 2, Bouton3 = 3, ValRet1, ValRet2, ValRet3
  
  OpenWindow(0, 0, 0, 420, 150, Titre$,#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  
  TextGadget(Texte, 60, 66, 250, 128, Message$)
  
  Select Icone
    Case 0 ;pas d'icône
    Case 1
      ImageGadget(#Icone, 5, 5, 40, 40,Interdit)
    Case 2
      ImageGadget(#Icone, 5, 5, 40, 40,Aide)
    Case 3
      ImageGadget(#Icone, 5, 5, 40, 40,Danger)
    Case 4
      ImageGadget(#Icone, 5, 5, 40, 40,Information)
    Case 5
      ImageGadget(#Icone, 5, 5, 40, 40, Idee)
    Case 6
      ImageGadget(#Icone, 5, 5, 40, 40, Refus)
    Case 7
      ImageGadget(#Icone, 5, 5, 40, 40, Cadenas)
    Case 8
      ImageGadget(#Icone, 5, 5, 40, 40, HDD)
    Case 9
      ImageGadget(#Icone, 5, 5, 40, 40, Trier)
    Case 10
      ImageGadget(#Icone, 5, 5, 40, 40, Rechercher)
  EndSelect  
  
  Select Type
    Case 0 ;Bouton OK 1
      ButtonGadget(Bouton1, 330, 99, 60, 20, "Ok")
      ValRet1 = 1
    Case 1 ; Ok 1, Annuler 2
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Ok")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Annuler")
      ValRet1 = 1
      ValRet2 = 2
    Case 2 ; Abandon 3, Réessayer 4, Ignorer 5
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Abandon")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Réessayer")
      ButtonGadget(Bouton3, 330, 99, 60, 20, "Ignorer")
      ValRet1 = 3
      ValRet2 = 4
      ValRet3 = 5
    Case 3 ; Oui 6, Non 7, Annuler 2
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Oui")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Non")
      ButtonGadget(Bouton3, 330, 99, 60, 20, "Annuler")
      ValRet1 = 6
      ValRet2 = 7
      ValRet3 = 2
    Case 4 ; Oui 6, Non 7
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Oui")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Non")
      ValRet1 = 6
      ValRet2 = 7
    Case 5 ; Réessayer 4, Annuler 2
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Réessayer")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Annuler")
      ValRet1 = 4
      ValRet2 = 2
    Case 10; Choisir
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Choisir")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Annuler")
      ValRet1 = 10
      ValRet2 = 2
    Case 11; Valider
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Valider")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Annuler")
      ValRet1 = 11
      ValRet2 = 2      
    Case 12; Quitter
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Quitter")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Annuler")
      ValRet1 = 12
      ValRet2 = 2
    Case 13; Sauvegarder
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Sauvegarder")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Annuler")
      ValRet1 = 13
      ValRet2 = 2
    Case 14; Trier
      ButtonGadget(Bouton1, 330, 33, 70, 20, "Ascendant")
      ButtonGadget(Bouton2, 330, 66, 70, 20, "Descendant")
      ButtonGadget(Bouton3, 330, 99, 70, 20, "Annuler")
      ValRet1 = 141
      ValRet2 = 142
      ValRet3 = 2
    Case 15; Analyser
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Analyser")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Annuler")
      ValRet1 = 15
      ValRet2 = 2
    Case 16; Formater
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Formater")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Annuler")
      ValRet1 = 16
      ValRet2 = 2
    Case 17; Rechercher
      ButtonGadget(Bouton1, 330, 33, 60, 20, "Rechercher")
      ButtonGadget(Bouton2, 330, 66, 60, 20, "Annuler")
      ValRet1 = 17
      ValRet2 = 2
      
  EndSelect
  
  Repeat
    Select WaitWindowEvent()
      Case #PB_Event_Gadget
        Select EventGadget()
          Case Bouton1
            ProcedureReturn ValRet1
          Case Bouton2
            ProcedureReturn ValRet2
          Case Bouton3
            ProcedureReturn ValRet3
        EndSelect
      Case #PB_Event_CloseWindow
        Select EventWindow()
          Case 0
            CloseWindow(0)
            Break
        EndSelect
    EndSelect
  ForEver
EndProcedure

Procedure Message(Titre.s, Msg.s, Type.i, Icone.i)
  
  If Type >= 0 And Type <= 16 And Icone >= 0 And Icone <= 10
    ProcedureReturn MessageRequester2(Titre.s, Msg.s, Type.i, Icone.i)
  Else
    ProcedureReturn 0
  EndIf
  
EndProcedure

InitImage()

CompilerIf #PB_Compiler_IsMainFile
  Debug Message("TRI", "Dans quel sens voulez-vous trier ?", 14, 2)
  Debug Message("ATTENTION","Souhaitez-vous vraiment formater votre disque dur ?", 16, 8)
CompilerEndIf  
Imageimagik Imageimagik Imageimagik Imageimagik Imageimagik Imageimagik Imageimagik Imageimagik Imageimagik Imageimagik Imageimagik Imageimagik
Microsoft Windows 10 Famille 64 bits : Carte mère : ASRock 970 Extreme3 R2.0 : Carte Graphique NVIDIA GeForce RTX 3080 : Processeur AMD FX 6300 6 cœurs 12 threads 3,50 GHz PB 5.73 PB 6.00 LTS (x64)
Un homme doit être poli, mais il doit aussi être libre !
Avatar de l’utilisateur
JohnJohnsonSHERMAN
Messages : 648
Inscription : dim. 13/déc./2015 11:05
Localisation : Allez, cherche...
Contact :

Re: Constantes MessageRequester

Message par JohnJohnsonSHERMAN »

Oui bien sur, vu comme ca les possibilités sont infinies... mais qui a envie de trimer une demie-heure sur un vulgaire message d'erreur ? (a part ce cher Micoute :mrgreen: ) C'est sur que si on veux personnaliser le texte ou la disposition des éléments, ajouter une barre de progression, etc... faut le faire "soi même", mais d'un autre coté, c'est quand même trés pratique d'avoir ces Requesters sous la main... merci PB (honnêtement, montrez moi un ide plus simple et évolué que PB et je vous montrerai un mensonge ;) ) :lol:

Bon je prends ton code Micoute et je le garde pour les "grandes occasions"...

:arrow: :idea: Vous pouvez toujours reprendre ces petits codes que je vous ait offert ce matin quelques posts au dessus :!: :P 8)

Non mais franchement pour une fois que je fais quelque chose de constructif sur ce forum (même si ce n'est qu'une toute petite astuce...) :roll:

Edit : Tu les as faites toi-même les icônes micoute ? Elles sont pas mal du tout je trouve...
"Le bug se situe entre la chaise et le clavier"
Votre expert national en bogage et segfaults.

CPU : AMD A8 Quad core - RAM 8Gb - HDD 2To
  • Windows 10 x64 - PB 5.61 x64
  • Linux Ubuntu 16.04 LTS x64 (dual boot) - PB pas encore réinstallé
Shadow
Messages : 1373
Inscription : mer. 04/nov./2015 17:39

Re: Constantes MessageRequester

Message par Shadow »

Salut,

En simple tu as ça mais ya des bug que j'ai pas corriger si tu insert
des guillemet dans le titre ou le message.

Code : Tout sélectionner

; Crée par Monsieur dieppedalle david

Enumeration
  #Assistance_cration_de_boite_de_dialogue
EndEnumeration

;- Gadget Constants
;
Enumeration
  #Titre_boite
  #Message_boite
  #Text_0
  #Text_1
  #Button_valider
  #Button_apercue
  #Button_annuler
  #Combo_type_boite
  #Combo_bouton_boite
  #Text_3
EndEnumeration

Procedure.l CodeBoite(TypeBoite$, BoutonBoite$)
  
  If LCase(TypeBoite$) = "standard"
    
    If LCase(BoutonBoite$) = "ok"
      CodeBoite = 0
    ElseIf LCase(BoutonBoite$) = "ok, annuler"
      CodeBoite = 1
    ElseIf LCase(BoutonBoite$) = "oui, non"
      CodeBoite = 4
    ElseIf LCase(BoutonBoite$) = "oui, non, annuler"
      CodeBoite = 3
    ElseIf LCase(BoutonBoite$) = "recommencer, annuler"
      CodeBoite = 5
    ElseIf LCase(BoutonBoite$) = "annuler, recommencer, continuer"
      CodeBoite = 6
    ElseIf LCase(BoutonBoite$) = "abandonner, recommencer, igniorer"
      CodeBoite = 2
    Else
      CodeBoite = 0
    EndIf
    
  ElseIf LCase(TypeBoite$) = "information"
    
    If LCase(BoutonBoite$) = "ok"
      CodeBoite = 64
    ElseIf LCase(BoutonBoite$) = "ok, annuler"
      CodeBoite = 65
    ElseIf LCase(BoutonBoite$) = "oui, non"
      CodeBoite = 68
    ElseIf LCase(BoutonBoite$) = "oui, non, annuler"
      CodeBoite = 67
    ElseIf LCase(BoutonBoite$) = "recommencer, annuler"
      CodeBoite = 69
    ElseIf LCase(BoutonBoite$) = "annuler, recommencer, continuer"
      CodeBoite = 70
    ElseIf LCase(BoutonBoite$) = "abandonner, recommencer, igniorer"
      CodeBoite = 66
    Else
      CodeBoite = 0
    EndIf
    
  ElseIf LCase(TypeBoite$) = "question"
    
    If LCase(BoutonBoite$) = "ok"
      CodeBoite = 32
    ElseIf LCase(BoutonBoite$) = "ok, annuler"
      CodeBoite = 33
    ElseIf LCase(BoutonBoite$) = "oui, non"
      CodeBoite = 36
    ElseIf LCase(BoutonBoite$) = "oui, non, annuler"
      CodeBoite = 35
    ElseIf LCase(BoutonBoite$) = "recommencer, annuler"
      CodeBoite = 37
    ElseIf LCase(BoutonBoite$) = "annuler, recommencer, continuer"
      CodeBoite = 38
    ElseIf LCase(BoutonBoite$) = "abandonner, recommencer, igniorer"
      CodeBoite = 34
    Else
      CodeBoite = 0
    EndIf
    
  ElseIf LCase(TypeBoite$) = "avertissement"
    
    If LCase(BoutonBoite$) = "ok"
      CodeBoite = 48
    ElseIf LCase(BoutonBoite$) = "ok, annuler"
      CodeBoite = 49
    ElseIf LCase(BoutonBoite$) = "oui, non"
      CodeBoite = 52
    ElseIf LCase(BoutonBoite$) = "oui, non, annuler"
      CodeBoite = 51
    ElseIf LCase(BoutonBoite$) = "recommencer, annuler"
      CodeBoite = 53
    ElseIf LCase(BoutonBoite$) = "annuler, recommencer, continuer"
      CodeBoite = 54
    ElseIf LCase(BoutonBoite$) = "abandonner, recommencer, igniorer"
      CodeBoite = 50
    Else
      CodeBoite = 0
    EndIf
    
  ElseIf LCase(TypeBoite$) = "erreur"
    
    If LCase(BoutonBoite$) = "ok"
      CodeBoite = 16
    ElseIf LCase(BoutonBoite$) = "ok, annuler"
      CodeBoite = 17
    ElseIf LCase(BoutonBoite$) = "oui, non"
      CodeBoite = 20
    ElseIf LCase(BoutonBoite$) = "oui, non, annuler"
      CodeBoite = 19
    ElseIf LCase(BoutonBoite$) = "recommencer, annuler"
      CodeBoite = 21
    ElseIf LCase(BoutonBoite$) = "annuler, recommencer, continuer"
      CodeBoite = 22
    ElseIf LCase(BoutonBoite$) = "abandonner, recommencer, igniorer"
      CodeBoite = 18
    Else
      CodeBoite = 0
    EndIf
    
  Else
    ProcedureReturn 0
  EndIf
  
  ProcedureReturn CodeBoite
EndProcedure

Procedure Open_Assistance_cration_de_boite_de_dialogue()
  If OpenWindow(#Assistance_cration_de_boite_de_dialogue, 532, 301, 448, 366, "Assistance création de boîte de dialogue...",  #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
    StringGadget(#Titre_boite, 9, 30, 430, 20, "", #ES_MULTILINE | #ESB_DISABLE_LEFT | #ESB_DISABLE_RIGHT)
    StringGadget(#Message_boite, 7, 80, 433, 160, "", #ES_MULTILINE | #ESB_DISABLE_LEFT | #ESB_DISABLE_RIGHT | #ES_AUTOVSCROLL)
      TextGadget(#Text_0, 10, 10, 430, 15, "Titre de la boîte:", #PB_Text_Center)
      TextGadget(#Text_1, 15, 60, 425, 15, "Message de la boîte:", #PB_Text_Center)
      ButtonGadget(#Button_valider, 190, 325, 75, 25, "Valider")
      ButtonGadget(#Button_apercue, 110, 325, 75, 25, "Aperçue")
      ButtonGadget(#Button_annuler, 270, 325, 75, 25, "Annuler")
      ComboBoxGadget(#Combo_type_boite, 50, 280, 125, 20)
      AddGadgetItem(#Combo_type_boite, -1, "Standard")
      AddGadgetItem(#Combo_type_boite, -1, "Information")
      AddGadgetItem(#Combo_type_boite, -1, "Question")
      AddGadgetItem(#Combo_type_boite, -1, "Avertissement")
      AddGadgetItem(#Combo_type_boite, -1, "Erreur")
      SetGadgetState(#Combo_type_boite, 0)
      ComboBoxGadget(#Combo_bouton_boite, 185, 280, 215, 20)
      AddGadgetItem(#Combo_bouton_boite, -1, "Ok")
      AddGadgetItem(#Combo_bouton_boite, -1, "Ok, Annuler")      
      AddGadgetItem(#Combo_bouton_boite, -1, "Oui, Non")
      AddGadgetItem(#Combo_bouton_boite, -1, "Oui, Non, Annuler")
      AddGadgetItem(#Combo_bouton_boite, -1, "Recommencer, Annuler")
      AddGadgetItem(#Combo_bouton_boite, -1, "Annuler, Recommencer, Continuer")
      AddGadgetItem(#Combo_bouton_boite, -1, "Abandonner, Recommencer, Igniorer")
      SetGadgetState(#Combo_bouton_boite, 0)
      TextGadget(#Text_3, 10, 260, 430, 15, "                       Type de boîte:                                 Bouton de la boîte:")
      
  EndIf
  
  Repeat ; Start of the event loop
  
  Event = WaitWindowEvent() ; This line waits until an event is received from Windows
  
  WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
  
  GadgetID = EventGadget() ; Is it a gadget event?
  
  EventType = EventType() ; The event type
  
  TitreBoite$ = GetGadgetText(#Titre_boite)
  MessageBoite$ = GetGadgetText(#Message_boite)
  TypeBoite$ = GetGadgetItemText(#Combo_type_boite, GetGadgetState(#Combo_type_boite))
  BoutonBoite$ = GetGadgetItemText(#Combo_bouton_boite, GetGadgetState(#Combo_bouton_boite))
  
  If Event = #PB_Event_Gadget
    
    If GadgetID = #Titre_boite
      
    ElseIf GadgetID = #Message_boite
      
    ElseIf GadgetID = #Button_valider
      SetClipboardText("MessageRequester(" + Chr(34) + TitreBoite$ + Chr(34) + ", " + Chr(34) + MessageBoite$ + Chr(34) + ", " + Str(CodeBoite(TypeBoite$, BoutonBoite$)) + ")")
      MessageRequester("Information", "      Le code a été copier dans le presse papier !", 64)
      
    ElseIf GadgetID = #Button_apercue
      MessageRequester(TitreBoite$, MessageBoite$, CodeBoite(TypeBoite$, BoutonBoite$))
      
    ElseIf GadgetID = #Button_annuler
      End
      
    ElseIf GadgetID = #Combo_type_boite
      
      If GetGadgetState(#Combo_type_boite) = 0
        ResizeGadget(#Message_boite, 7, 80, 433, 160)
      Else
        ResizeGadget(#Message_boite, 31, 80, 384, 160)
      EndIf
      
    ElseIf GadgetID = #Combo_bouton_boite
      
    EndIf
    
  EndIf
  
Until Event = #PB_Event_CloseWindow ; End of the event loop

EndProcedure

Open_Assistance_cration_de_boite_de_dialogue()
Sinon j'avais fais ça, je sais pas si c'est à jour par contre:
http://www.aht.li/1923179/Assistant_cre ... ialogue.7z
http://www.aht.li/1911772/Assistant_cre ... logue_2.7z

Autre truc sympa que j'avais créer aussi, c'est pour la console.
Je ne sais pas si c'est la dernière version:
http://www.aht.li/2141436/Message_Conso ... complet.7z
Processeur: Intel Core I7-4790 - 4 Cœurs - 8 Thread: 3.60 Ghz.
Ram: 32 GB.
Disque: C: SDD 250 GB, D: 3 TB.
Vidéo: NVIDIA GeForce GTX 960: 2 GB DDR5.
Écran: Asus VX248 24 Pouces: 1920 x 1080.
Système: Windows 7 64 Bits.

PureBasic: 5.60 x64 Bits.
Avatar de l’utilisateur
Ar-S
Messages : 9475
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: Constantes MessageRequester

Message par Ar-S »

Il vaut mieux que tu remplaces tes if/endif par des select/case.
Comme son nom l'indique, if else endif teste toutes les combinaisons jusqu'à trouver la bonne.
Le Select Case est plus approprié lorsque tu as beaucoup de else.

Ta boucle donne ça.

Code : Tout sélectionner

Repeat ; Start of the event loop
 
  event = WaitWindowEvent() ; This line waits until an event is received from Windows
 
  WindowID = EventWindow() ; The Window where the event is generated, can be used in the gadget procedures
 
  GadgetID = EventGadget() ; Is it a gadget event?
 
  EventType = EventType() ; The event type
 
  TitreBoite$ = GetGadgetText(#Titre_boite)
  MessageBoite$ = GetGadgetText(#Message_boite)
  TypeBoite$ = GetGadgetItemText(#Combo_type_boite, GetGadgetState(#Combo_type_boite))
  BoutonBoite$ = GetGadgetItemText(#Combo_bouton_boite, GetGadgetState(#Combo_bouton_boite))
  
  
  Select Event
    Case #PB_Event_Gadget
      Select GadgetID
        Case #Titre_boite
          
        Case #Message_boite
          
        Case #Button_valider
          SetClipboardText("MessageRequester(" + Chr(34) + TitreBoite$ + Chr(34) + ", " + Chr(34) + MessageBoite$ + Chr(34) + ", " + Str(CodeBoite(TypeBoite$, BoutonBoite$)) + ")")
          MessageRequester("Information", "      Le code a été copier dans le presse papier !", 64)
          
        Case #Button_apercue
          MessageRequester(TitreBoite$, MessageBoite$, CodeBoite(TypeBoite$, BoutonBoite$))
          
        Case #Button_annuler
          End
          
        Case #Combo_type_boite
          
          If GetGadgetState(#Combo_type_boite) = 0
            ResizeGadget(#Message_boite, 7, 80, 433, 160)
          Else
            ResizeGadget(#Message_boite, 31, 80, 384, 160)
          EndIf
          
        Case #Combo_bouton_boite
          
      EndSelect
  EndSelect

Until Event = #PB_Event_CloseWindow ; End of the event loop
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Mesa
Messages : 1097
Inscription : mer. 14/sept./2011 16:59

Re: Constantes MessageRequester

Message par Mesa »

Sur le forum, traîne mon générateur de code de requester pour windows.
Voici la version 5.xx

Code : Tout sélectionner

; **************************************************
; **************************************************
; * Win MessageBox                                 *
; *                                                *
; * Code Mesaliko                                  *
; *      LSI                                       *
; * PB 4.5x remplacer FrameGadget par Frame3DGadget*
; *                                                *
; * Décembre 2011                                  *
; * Bug corrigé longueur de texte Janvier 2012     *
; * PB 5.xx Mars 2016                              *
; **************************************************

;{- Enumerations / DataSections
;{ Windows
Enumeration
  #Window_0
  #Window_1
EndEnumeration
;}
;{ Gadgets
Enumeration
  #Frame3D_0
  #Option_1
  #Option_2
  #Option_3
  #Option_4
  #Option_5
  #Option_6
  #Option_7
  #Text_8
  #Frame3D_9
  #Option_10
  #Option_11
  #Option_12
  #Option_13
  #Option_14
  #Frame3D_15
  #Option_16
  #Option_17
  #Option_18
  #Option_19
  #Frame3D_20
  #Option_21
  #Option_22
  #Option_23
  #Frame3D_24
  #Option_25
  #Option_26
  #Option_27
  #Option_28
  #Option_29
  #Option_30
  
  #Button_0
  
  #String_0
  #String_1
  
  #CheckBox_0
  
  #TextGadget_1_0
  
EndEnumeration

Global True=1
Global False=0
Global h_frame

Global code.s

;}
; Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;}
Procedure Callback(hWin,msg,wParam,lParam)
  Select msg
    Case #WM_HELP
      *hlp.HELPINFO = lParam
      Select *hlp\iContextType
        Case #HELPINFO_WINDOW
          ;Debug "Help Window - CtrlId:"+Str(*hlp\iCtrlId)+" - ItemHandle:"+Str(*hlp\hItemHandle)+" - ContextId:"+Str(*hlp\dwContextId)+" - Mouse:"+Str(*hlp\MousePos\x)+"/"+Str(*hlp\MousePos\y)
          MessageRequester("Aide","Vous avez demandé de l'aide ?",36);16384
                                                                     ;Case #HELPINFO_MENUITEM
                                                                     ;Debug "Help Menu - CtrlId:"+Str(*hlp\iCtrlId)+" - ItemHandle:"+Str(*hlp\hItemHandle)+" - ContextId:"+Str(*hlp\dwContextId)+" - Mouse:"+Str(*hlp\MousePos\x)+"/"+Str(*hlp\MousePos\y)
      EndSelect
  EndSelect
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure

Procedure.l GetTextWidthPix(numb, espace=1)
  ;espace : null-terminated + pour la checkbox par exemple, il faut ajouter la largeur d'un espace au texte 
  hDC = GetDC_(GadgetID(numb))
  hFont = SendMessage_(GadgetID(numb),#WM_GETFONT,0,0)
  If hFont And hDC
    SelectObject_(hDC,hFont)
  EndIf
  GetTextExtentPoint32_(hDC, GetGadgetText(numb), Len(GetGadgetText(numb)) + espace, lpSize.SIZE)
  result=lpSize\cx
  ReleaseDC_(#Window_0, hDC)
  ProcedureReturn result
EndProcedure

Procedure.l GetTextHeightPix(numb, espace=8)
  ; pourquoi 8 ????? 
  hDC = GetDC_(GadgetID(numb))
  hFont = SendMessage_(GadgetID(numb),#WM_GETFONT,0,0)
  If hFont And hDC
    SelectObject_(hDC,hFont)
  EndIf
  GetTextExtentPoint32_(hDC, GetGadgetText(numb), Len(GetGadgetText(numb)), lpSize.SIZE)
  result=lpSize\cy + espace
  ReleaseDC_(#Window_0, hDC)
  ProcedureReturn result
EndProcedure

; Procedure.l LoadWindowFont(Bold = -1, Italic = -1, UnderLine = -1, Size.f = -1)
;    Protected ncm.NONCLIENTMETRICS
;    ncm\cbSize = SizeOf(NONCLIENTMETRICS)
;    SystemParametersInfo_(#SPI_GETNONCLIENTMETRICS, SizeOf(NONCLIENTMETRICS), @ncm, 0)
;    If Bold = 0
;       ncm\lfMessageFont\lfWeight = 0
;    ElseIf Bold = 1
;       ncm\lfMessageFont\lfWeight = 700
;    EndIf
;    If Italic = 0
;       ncm\lfMessageFont\lfItalic = 0
;    ElseIf Italic = 1
;       ncm\lfMessageFont\lfItalic = 1
;    EndIf
;    If UnderLine = 0
;       ncm\lfMessageFont\lfUnderline = 0
;    ElseIf UnderLine = 1
;       ncm\lfMessageFont\lfUnderline = 1
;    EndIf
;    If Size > 0
;       ncm\lfMessageFont\lfheight * Size
;    EndIf
;    
; ;    Debug PeekS(@ncm\lfMessageFont\lfFaceName, 32)
; ;    CompilerIf #PB_Compiler_Debugger
; ;    DC = GetDC_(0)
; ;    Debug Round(Abs(ncm\lfMessageFont\lfheight) * 72 / GetDeviceCaps_(DC, #LOGPIXELSY), #PB_Round_Nearest)
; ;    ReleaseDC_(0, DC)
; ;    CompilerEndIf
; ;    
;    ProcedureReturn CreateFontIndirect_(@ncm\lfMessageFont)
; EndProcedure

Procedure OpenWindow_Window_0()
  
  x_frame = 8 ; marge gauche du cadre
  x_option = 16 ; marge gauche bouton radio
  
  
  ;    FontID = LoadWindowFont()
  ;    If FontID
  ;       If CreateImage(0, 300, 200)
  ;          If StartDrawing(ImageOutput(0))
  ;                DrawingFont(FontID)
  ;                h_frame = TextHeight("M") ; unité de hauteur
  ;                l_frame = TextWidth("ANNULER(2)  RECOMMENCER(10)  CONTINUER(11)  ") + h_frame ; longueur max des cadres
  ;             StopDrawing()
  ;          EndIf
  ;          FreeImage(0)
  ;       EndIf
  ;       DeleteObject_(FontID)
  ;    EndIf
  
  
  ;    l_option = l_frame ; longueur bouton radio
  ;    h_option = h_frame ; hauteur bouton radio
  ;    l_frame + 2 * x_option + 2 * x_frame
  
  If OpenWindow(#Window_0, 0, 0, 0, 0, "Créateur de Win MessageBox ", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
    LoadFont(1, "Arial", 9)
    SetGadgetFont(#PB_Default, FontID(1))
    ;FontID = LoadWindowFont()
    ;SetGadgetFont(#PB_Default, FontID)
    OptionGadget(1000,0,0,10,10,"ANNULER(2)  RECOMMENCER(10)  CONTINUER(11)")
    l_frame =GetTextWidthPix(1000,2)
    h_frame =GetTextHeightPix(1000)
    ResizeGadget(1000,#PB_Ignore ,#PB_Ignore ,l_frame,h_frame)
    l_frame = GadgetWidth(1000)
    h_frame = GadgetHeight(1000)
    FreeGadget(1000)
    
    l_option = l_frame ; longueur bouton radio
    h_option = h_frame ; hauteur bouton radio
    l_frame + 2 * x_option + 2 * x_frame
    
    delta_y = -4 ; espace entre les boutons radio
    
    y = -delta_y
    FrameGadget(#Frame3D_0, x_frame, y, l_frame, h_frame * 1.5 + delta_y + (h_option + delta_y) * 7, "Type de Bouton (Retour bouton)")
    y + h_frame + delta_y
    OptionGadget(#Option_1, x_frame + x_option, y, l_option, h_option, "OK(1)")
    SetGadgetState(#Option_1, 1)
    y + h_option + delta_y
    OptionGadget(#Option_2, x_frame + x_option, y, l_option, h_option, "OK(1)  ANNULER(2)")
    y + h_option + delta_y
    OptionGadget(#Option_3, x_frame + x_option, y, l_option, h_option, "ABANDONNER(3)  RECOMMENCER(4)  IGNORER(5)")
    y + h_option + delta_y
    OptionGadget(#Option_4, x_frame + x_option, y, l_option, h_option, "OUI(6)  NON(7)  ABANDONNER(3)")
    y + h_option + delta_y
    OptionGadget(#Option_5, x_frame + x_option, y, l_option, h_option, "OUI(6)  NON(7)")
    y + h_option + delta_y
    OptionGadget(#Option_6, x_frame + x_option, y, l_option, h_option, "RECOMMENCER(4)  ANNULER(2)")
    y + h_option + delta_y
    OptionGadget(#Option_7, x_frame + x_option, y, l_option, h_option, "ANNULER(2)  RECOMMENCER(10)  CONTINUER(11)")
    y + h_option + delta_y
    y + h_frame * 0.5
    
    y - delta_y
    
    y0 = y
    FrameGadget(#Frame3D_9, x_frame, y, l_frame / 2, h_frame * 1.5 + delta_y + (h_option + delta_y) * 5, "Icône ")
    y + h_frame + delta_y
    OptionGadget(#Option_10, x_frame + x_option, y, l_option / 2 - x_option, h_option, "Pas d'icône")
    SetGadgetState(#Option_10, 1)
    y + h_option + delta_y
    OptionGadget(#Option_11, x_frame + x_option, y, l_option / 2 - x_option, h_option, "Stop")
    y + h_option + delta_y
    OptionGadget(#Option_12, x_frame + x_option, y, l_option / 2 - x_option, h_option, "?")
    y + h_option + delta_y
    OptionGadget(#Option_13, x_frame + x_option, y, l_option / 2 - x_option, h_option, "!")
    y + h_option + delta_y
    OptionGadget(#Option_14, x_frame + x_option, y, l_option / 2 - x_option, h_option, "i")
    y + h_option + delta_y
    y + h_frame * 0.5
    
    y - delta_y
    
    y = y0
    FrameGadget(#Frame3D_15, x_frame + l_frame / 2, y, l_frame / 2, h_frame * 1.5 + delta_y + (h_option + delta_y) * 5, "Bouton par défaut ")
    y + h_frame + delta_y
    OptionGadget(#Option_16, x_frame + l_frame / 2 + x_option, y, l_option / 2 - delta_x, h_option, "Premier")
    SetGadgetState(#Option_16, 1)
    y + h_option + delta_y
    OptionGadget(#Option_17, x_frame + l_frame / 2 + x_option, y, l_option / 2 - delta_x, h_option, "Second")
    y + h_option + delta_y
    OptionGadget(#Option_18, x_frame + l_frame / 2 + x_option, y, l_option / 2 - delta_x, h_option, "Troisième")
    y + h_option + delta_y
    OptionGadget(#Option_19, x_frame + l_frame / 2 + x_option, y, l_option / 2 - delta_x, h_option, "Quatrième")
    y + h_option + delta_y
    CheckBoxGadget(#CheckBox_0, x_frame + l_frame / 2 + x_option, y, l_option / 2 - delta_x, h_option, "Ajouter Bouton Aide")
    y + h_option + delta_y
    y + h_frame * 0.5
    
    y - delta_y
    
    FrameGadget(#Frame3D_20, x_frame, y, l_frame, h_frame * 1.5 + delta_y + (h_option + delta_y) * 3, "Modalité ")
    y + h_frame + delta_y
    OptionGadget(#Option_21, x_frame + x_option, y, l_option, h_option, "Modal-Par défaut")
    SetGadgetState(#Option_21, 1)
    y + h_option + delta_y
    OptionGadget(#Option_22, x_frame + x_option, y, l_option, h_option, "Système")
    y + h_option + delta_y
    OptionGadget(#Option_23, x_frame + x_option, y, l_option, h_option, "Tâche")
    y + h_option + delta_y
    y + h_frame * 0.5
    
    y - delta_y
    
    FrameGadget(#Frame3D_24, x_frame, y, l_frame, h_frame * 1.5 + delta_y + (h_option + delta_y) * 6, "Divers ")
    y + h_frame + delta_y
    OptionGadget(#Option_25, x_frame + x_option, y, l_option, h_option, "Par défaut")
    SetGadgetState(#Option_25, 1)
    y + h_option + delta_y
    OptionGadget(#Option_26, x_frame + x_option, y, l_option, h_option, "Sur le bureau par défaut uniquement")
    y + h_option + delta_y
    OptionGadget(#Option_27, x_frame + x_option, y, l_option, h_option, "Texte aligné à droite")
    y + h_option + delta_y
    OptionGadget(#Option_28, x_frame + x_option, y, l_option, h_option, "En avant-plan")
    y + h_option + delta_y
    OptionGadget(#Option_29, x_frame + x_option, y, l_option, h_option, "Top-most attribut")
    y + h_option + delta_y
    OptionGadget(#Option_30, x_frame + x_option, y, l_option, h_option, "Notification service")
    y + h_option + delta_y
    y + h_frame * 0.5
    
    y - delta_y
    
    StringGadget(#String_0, x_frame, y, l_frame, h_option + 8, "Entrez le Titre du WinMessageBox")
    y + h_option + 8 - delta_y
    StringGadget(#String_1, x_frame, y, l_frame, h_option + 8, "Entrez le Texte du WinMessageBox")
    y + h_option + 8 - delta_y
    ButtonGadget(#Button_0, x_frame, y, l_frame, h_option * 2, "Code PureBasic dans le Presse-Papier")
    y + h_option * 2
    
    ; y - delta_y
    
    ResizeWindow(#Window_0, #PB_Ignore, 8, l_frame + x_frame * 2, y)
    
  EndIf
EndProcedure

Procedure OpenWindow_Window_Code() ; fenêtre fille qui affiche le code final
  
  x0=  WindowX(#Window_0) ; distance jusqu'au bord de la fenêtre principale
  
  If OpenWindow(#Window_1,0, 0,x0-6,100,"Ce Code à copier est déjà dans le Presse-Papier", #PB_Window_Tool, WindowID(#Window_0))
    ;TextGadget(#TextGadget_1_0,0,0,290,90,code,#PB_Text_Border)
    EditorGadget(#TextGadget_1_0, 0, 0, x0-10, 30)
    SetGadgetItemText(#TextGadget_1_0, -1, code)
    h_editor = h_frame*(CountGadgetItems(#TextGadget_1_0)  + 2) ; hauteur de l'editor
    ResizeGadget(#TextGadget_1_0, #PB_Ignore, #PB_Ignore, #PB_Ignore, h_editor)
    ResizeWindow(#Window_1, #PB_Ignore, #PB_Ignore, #PB_Ignore, h_editor+30)
  EndIf
  
EndProcedure


OpenWindow_Window_0()
SetWindowCallback(@Callback()) ; gestion de l'aide

;{- Event loop
Repeat
  Event = WaitWindowEvent()
  
  Select Event
      ; ///////////////////
    Case #PB_Event_Gadget
      EventGadget = EventGadget()
      EventType = EventType()
      ;{-
      ; If EventGadget = #Frame3D_0
      ; ElseIf EventGadget = #Option_1
      ; ElseIf EventGadget = #Option_2
      ; ElseIf EventGadget = #Option_3
      ; ElseIf EventGadget = #Option_4
      ; ElseIf EventGadget = #Option_5
      ; ElseIf EventGadget = #Option_6
      ; ElseIf EventGadget = #Option_7
      ; ElseIf EventGadget = #Text_8
      ; ElseIf EventGadget = #Frame3D_9
      ; ElseIf EventGadget = #Option_10
      ; ElseIf EventGadget = #Option_11
      ; ElseIf EventGadget = #Option_12
      ; ElseIf EventGadget = #Option_13
      ; ElseIf EventGadget = #Option_14
      ; ElseIf EventGadget = #Frame3D_15
      ; ElseIf EventGadget = #Option_16
      ; ElseIf EventGadget = #Option_17
      ; ElseIf EventGadget = #Option_18
      ; ElseIf EventGadget = #Frame3D_19
      ; ElseIf EventGadget = #Option_20
      ; ElseIf EventGadget = #Option_21
      ; ElseIf EventGadget = #Option_22
      ; ElseIf EventGadget = #Option_23
      ; ElseIf EventGadget = #Option_24
      ; ElseIf EventGadget = #Option_25
      ; ElseIf
      ;}
      
      
      If EventGadget = #Button_0
        
        ; option1 Type de Box
        Compteur = 0
        For i = #Option_1 To #Option_1 + 6
          ; Debug GetGadgetState(i)
          If GetGadgetState(i) = 1
            option1 = Compteur
          EndIf
          Compteur = Compteur + 1
        Next i
        
        ; option2 Icône
        Compteur = 0
        For i = #Option_10 To #Option_10 + 4
          ; Debug GetGadgetState(i)
          If GetGadgetState(i) = 1
            option2 = Compteur * 16
          EndIf
          Compteur = Compteur + 1
        Next i
        
        ; option3 Bouton par dédaut
        Compteur = 0
        For i = #Option_16 To #Option_16 + 3
          ; Debug GetGadgetState(i)
          If GetGadgetState(i) = 1
            option3 = Compteur * 256
          EndIf
          Compteur = Compteur + 1
        Next i
        
        ; option4 Modalité
        Compteur = 0
        For i = #Option_21 To #Option_21 + 2
          ; Debug GetGadgetState(i)
          If GetGadgetState(i) = 1
            option4 = Compteur * 4096
          EndIf
          Compteur = Compteur + 1
        Next i
        
        ; option5 Divers
        If GetGadgetState(#Option_25) = 1 : option5 = 0 * 65536 : EndIf
        If GetGadgetState(#Option_26) = 1 : option5 = 2 * 65536 : EndIf
        If GetGadgetState(#Option_27) = 1 : option5 = 8 * 65536 : EndIf
        If GetGadgetState(#Option_28) = 1 : option5 = 1 * 65536 : EndIf
        If GetGadgetState(#Option_29) = 1 : option5 = 4 * 65536 : EndIf
        If GetGadgetState(#Option_30) = 1 : option5 = 1 * 1046876 : EndIf
        ; Debug option5
        
        options = option1 + option2 + option3 + option4 + option5
        ; Debug options
        
        
        ; Code sous forme de texte dans le presse-papier
        code = "Retour=MessageRequester(" + Chr(34) + GetGadgetText(#String_0) + Chr(34) + ", " + Chr(34) + GetGadgetText(#String_1) + Chr(34) + ", " + Str(options) + ")"
        
        If GetGadgetState(#CheckBox_0) = 1 ; Si Ajout du bouton Aide
          options = options + 4 * 4096
          
          code = code + Chr(13)+Chr(10)
          code = code + Chr(13)+Chr(10) + "Pour gérer l'aide, Ajouter cette procédure avant le openwindow()"
          code = code + Chr(13)+Chr(10) + "Procedure Callback(hWin,msg,wParam,lParam)"
          code = code + Chr(13)+Chr(10) + "Select msg"
          code = code + Chr(13)+Chr(10) + "Case #WM_HELP"
          code = code + Chr(13)+Chr(10) + "*hlp.HELPINFO = lParam"
          code = code + Chr(13)+Chr(10) + "Select *hlp\iContextType"
          code = code + Chr(13)+Chr(10) + "Case #HELPINFO_WINDOW"
          code = code + Chr(13)+Chr(10) + ";Debug " + Chr(34) + "Help Window - CtrlId: "+ Chr(34) + "+Str(*hlp\iCtrlId)+ "+ Chr(34) +  "- ItemHandle: "+ Chr(34) + "+Str(*hlp\hItemHandle)+ "+ Chr(34) +  "- ContextId: "+ Chr(34) + "+Str(*hlp\dwContextId)+ "+ Chr(34) +  "- Mouse: "+ Chr(34) + "+Str(*hlp\MousePos\x)+"+ Chr(34) + "/"+ Chr(34) + "+Str(*hlp\MousePos\y)"
          code = code + Chr(13)+Chr(10) + ";MessageRequester(" + Chr(34) + "Aide" + Chr(34) + "," + Chr(34) + "Vous avez demandé de l'aide ?" + Chr(34) + ",36)"
          code = code + Chr(13)+Chr(10) + ";Case #HELPINFO_MENUITEM"
          code = code + Chr(13)+Chr(10) + ";Debug " + Chr(34) + "Help Menu - CtrlId:" + Chr(34) + "+Str(*hlp\iCtrlId)+" + Chr(34) + " - ItemHandle:" + Chr(34) + "+Str(*hlp\hItemHandle)+" + Chr(34) + " - ContextId:" + Chr(34) + "+Str(*hlp\dwContextId)+" + Chr(34) + " - Mouse:" + Chr(34) + "+Str(*hlp\MousePos\x)+" + Chr(34) + "/" + Chr(34) + "+Str(*hlp\MousePos\y)"
          code = code + Chr(13)+Chr(10) + "EndSelect"
          code = code + Chr(13)+Chr(10) + "EndSelect"
          code = code + Chr(13)+Chr(10) + "ProcedureReturn #PB_ProcessPureBasicEvents"
          code = code + Chr(13)+Chr(10) + "EndProcedure"
          code = code + Chr(13)+Chr(10)
          code = code + Chr(13)+Chr(10) + "Et ajouter cette ligne après le openwindow()"
          code = code + Chr(13)+Chr(10) + "SetWindowCallback(@Callback())"
          code = code + Chr(13)+Chr(10)
          code = code + Chr(13)+Chr(10) + "La touche F1 devrait fonctionner"
          
        EndIf
        
        
        ;Debug code
        
        ClearClipboard()
        SetClipboardText(code)
        
        OpenWindow_Window_Code()
        
        ; On voit ce que ça donne
        Retour = MessageRequester(GetGadgetText(#String_0), GetGadgetText(#String_1), options)
        
        Debug Retour
        
      EndIf
      
      ; ////////////////////////
    Case #PB_Event_CloseWindow
      EventWindow = EventWindow()
      If EventWindow = #Window_0
        CloseWindow(#Window_0)
        Break
      EndIf
  EndSelect
ForEver
;}

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; Pour avoir une fenêtre avec un "?" dans la barre de titre

;   OpenWindow(0, 100, 100, 200, 200, "ContextHelp Example", #PB_Window_SystemMenu); And CreateGadgetList(WindowID(0))
;   SetWindowLong_(WindowID(0), #GWL_EXSTYLE, GetWindowLong_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_CONTEXTHELP)
;   SetWindowPos_(WindowID(0), 0, -1 , -1, -1, -1, #SWP_NOSIZE | #SWP_NOMOVE | #SWP_NOZORDER  | #SWP_FRAMECHANGED | #SWP_SHOWWINDOW)

; --------------------------------------------------------------------------------
;
;
; Button Pressed Return Value 
; OK  1
; CANCEL  2
; ABORT  3
; RETRY  4
; IGNORE  5
; YES  6
; NO  7
; TRY AGAIN ** 10
; Continue ** 11
;
; 
;
; Remarks
;
; The flag parameter can be a combination of the following values:
;
; decimal flag Button-related Result hexadecimal flag
; 0 OK button 0x0
; 1 OK And Cancel 0x1
; 2 Abort, Retry, And Ignore 0x2
; 3 Yes, No, And Cancel 0x3
; 4 Yes And No 0x4
; 5 Retry And Cancel 0x5
; 6 ** Cancel, Try Again, Continue 0x6


; decimal flag Icon-related Result hexadecimal flag
; 0 (No icon) 0x0
; 16 Stop-sign icon 0x10
; 32 Question-mark icon 0x20
; 48 Exclamation-point icon 0x30
; 64 Information-sign icon consisting of an 'i' in a circle 0x40

; decimal flag Default-related Result hexadecimal flag
; 0 First button is Default button 0x0
; 256 Second button is Default button 0x100
; 512 Third button is Default button 0x200
;(0x00000300L le 4 ieme bouton)

; decimal flag Modality-related Result hexadecimal flag
; 0 Application  0x0
; 4096 System modal (dialog has an icon) 0x1000
; 8192 Task modal 0x2000

; decimal flag Miscellaneous-related Result hexadecimal flag
; 0 (nothing Else special) 0x0
;(0x20000 MB_DEFAULT_DESKTOP_ONLY
; 262144 MsgBox has top-most attribute set 0x40000
; 524288 title And text are right-justified 0x80000

;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

; Displays a modal dialog box that contains a system icon, a set of buttons, And a brief application-specific message, such As status Or error information. The message box returns an integer value that indicates which button the user clicked.
; Syntax
;
; int WINAPI MessageBox(
;   __in_opt  HWND hWnd,
;   __in_opt  LPCTSTR lpText,
;   __in_opt  LPCTSTR lpCaption,
;   __in      UINT uType
; );
;
; Parameters
;
; hWnd [in, optional]
;
;     Type: HWND
;
;     A handle To the owner window of the message box To be created. If this parameter is NULL, the message box has no owner window.
; lpText [in, optional]
;
;     Type: LPCTSTR
;
;     The message To be displayed. If the string consists of more than one line, you can separate the lines using a carriage Return And/Or linefeed character between each line.
; lpCaption [in, optional]
;
;     Type: LPCTSTR
;
;     The dialog box title. If this parameter is NULL, the Default title is Error.
; uType [in]
;
;     Type: UINT
;
;     The contents And behavior of the dialog box. This parameter can be a combination of flags from the following groups of flags.
;
;     To indicate the buttons displayed in the message box, specify one of the following values.
;     Value   Meaning
;
;     MB_ABORTRETRYIGNORE
;     0x00000002L
;
;        
;
;     The message box contains three push buttons: Abort, Retry, And Ignore.
;
;     MB_CANCELTRYCONTINUE
;     0x00000006L
;
;        
;
;     The message box contains three push buttons: Cancel, Try Again, Continue. Use this message box type instead of MB_ABORTRETRYIGNORE.
;
;     MB_HELP
;     0x00004000L
;
;        
;
;     Adds a Help button To the message box. When the user clicks the Help button Or presses F1, the system sends a WM_HELP message To the owner.
;
;     MB_OK
;     0x00000000L
;
;        
;
;     The message box contains one push button: OK. This is the Default.
;
;     MB_OKCANCEL
;     0x00000001L
;
;        
;
;     The message box contains two push buttons: OK And Cancel.
;
;     MB_RETRYCANCEL
;     0x00000005L
;
;        
;
;     The message box contains two push buttons: Retry And Cancel.
;
;     MB_YESNO
;     0x00000004L
;
;        
;
;     The message box contains two push buttons: Yes And No.
;
;     MB_YESNOCANCEL
;     0x00000003L
;
;        
;
;     The message box contains three push buttons: Yes, No, And Cancel.
;
;     
;
;     To display an icon in the message box, specify one of the following values.
;     Value   Meaning
;
;     MB_ICONEXCLAMATION
;     0x00000030L
;
;        
;
;     An exclamation-point icon appears in the message box.
;
;     MB_ICONWARNING
;     0x00000030L
;
;        
;
;     An exclamation-point icon appears in the message box.
;
;     MB_ICONINFORMATION
;     0x00000040L
;
;        
;
;     An icon consisting of a lowercase letter i in a circle appears in the message box.
;
;     MB_ICONASTERISK
;     0x00000040L
;
;        
;
;     An icon consisting of a lowercase letter i in a circle appears in the message box.
;
;     MB_ICONQUESTION
;     0x00000020L
;
;        
;
;     A question-mark icon appears in the message box. The question-mark message icon is no longer recommended because it does Not clearly represent a specific type of message And because the phrasing of a message As a question could apply To any message type. In addition, users can confuse the message symbol question mark With Help information. Therefore, do Not use this question mark message symbol in your message boxes. The system continues To support its inclusion only For backward compatibility.
;
;     MB_ICONSTOP
;     0x00000010L
;
;        
;
;     A stop-sign icon appears in the message box.
;
;     MB_ICONERROR
;     0x00000010L
;
;        
;
;     A stop-sign icon appears in the message box.
;
;     MB_ICONHAND
;     0x00000010L
;
;        
;
;     A stop-sign icon appears in the message box.
;
;     
;
;     To indicate the Default button, specify one of the following values.
;     Value   Meaning
;
;     MB_DEFBUTTON1
;     0x00000000L
;
;        
;
;     The first button is the Default button.
;
;     MB_DEFBUTTON1 is the Default unless MB_DEFBUTTON2, MB_DEFBUTTON3, Or MB_DEFBUTTON4 is specified.
;
;     MB_DEFBUTTON2
;     0x00000100L
;
;        
;
;     The second button is the Default button.
;
;     MB_DEFBUTTON3
;     0x00000200L
;
;        
;
;     The third button is the Default button.
;
;     MB_DEFBUTTON4
;     0x00000300L
;
;        
;
;     The fourth button is the Default button.
;
;     
;
;     To indicate the modality of the dialog box, specify one of the following values.
;     Value   Meaning
;
;     MB_APPLMODAL
;     0x00000000L
;
;        
;
;     The user must respond To the message box before continuing work in the window identified by the hWnd parameter. However, the user can move To the windows of other threads And work in those windows.
;
;     Depending on the hierarchy of windows in the application, the user may be able To move To other windows within the thread. All child windows of the parent of the message box are automatically disabled, but pop-up windows are Not.
;
;     MB_APPLMODAL is the Default If neither MB_SYSTEMMODAL nor MB_TASKMODAL is specified.
;
;     MB_SYSTEMMODAL
;     0x00001000L
;
;        
;
;     Same As MB_APPLMODAL except that the message box has the WS_EX_TOPMOST style. Use system-modal message boxes To notify the user of serious, potentially damaging errors that require immediate attention (For example, running out of memory). This flag has no effect on the user's ability to interact with windows other than those associated with hWnd.
;
;     MB_TASKMODAL
;     0x00002000L
;
;        
;
;     Same As MB_APPLMODAL except that all the top-level windows belonging To the current thread are disabled If the hWnd parameter is NULL. Use this flag when the calling application Or library does Not have a window handle available but still needs To prevent input To other windows in the calling thread without suspending other threads.
;
;     
;
;     To specify other options, use one Or more of the following values.
;     Value   Meaning
;
;     MB_DEFAULT_DESKTOP_ONLY
;     0x00020000L
;
;        
;
;     Same As desktop of the interactive window station. For more information, see Window Stations.
;
;     If the current input desktop is Not the Default desktop, MessageBox does Not Return Until the user switches To the Default desktop.
;
;     MB_RIGHT
;     0x00080000L
;
;        
;
;     The text is right-justified.
;
;     MB_RTLREADING
;     0x00100000L
;
;        
;
;     Displays message And caption text using right-To-left reading order on Hebrew And Arabic systems.
;
;     MB_SETFOREGROUND
;     0x00010000L
;
;        
;
;     The message box becomes the foreground window. Internally, the system calls the SetForegroundWindow function For the message box.
;
;     MB_TOPMOST
;     0x00040000L
;
;        
;
;     The message box is created With the WS_EX_TOPMOST window style.
;
;     MB_SERVICE_NOTIFICATION
;     0x00200000L
;
;        
;
;     The caller is a service notifying the user of an event. The function displays a message box on the current active desktop, even If there is no user logged on To the computer.
;
;     Terminal Services: If the calling thread has an impersonation token, the function directs the message box To the session specified in the impersonation token.
;
;     If this flag is set, the hWnd parameter must be NULL. This is so that the message box can appear on a desktop other than the desktop corresponding To the hWnd.
;
;     For information on security considerations in regard To using this flag, see Interactive Services. In particular, be aware that this flag can produce interactive content on a locked desktop And should therefore be used For only a very limited set of scenarios, such As resource exhaustion.
;
;     
;
; Return value
;
; Type: int
;
; If a message box has a Cancel button, the function returns the IDCANCEL value If either the ESC key is pressed Or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect.
;
; If the function fails, the Return value is zero. To get extended error information, call GetLastError.
;
; If the function succeeds, the Return value is one of the following menu-item values.
; Return code/value   Description
;
; IDABORT
; 3
;
;    
;
; The Abort button was selected.
;
; IDCANCEL
; 2
;
;    
;
; The Cancel button was selected.
;
; IDCONTINUE
; 11
;
;    
;
; The Continue button was selected.
;
; IDIGNORE
; 5
;
;    
;
; The Ignore button was selected.
;
; IDNO
; 7
;
;    
;
; The No button was selected.
;
; IDOK
; 1
;
;    
;
; The OK button was selected.
;
; IDRETRY
; 4
;
;    
;
; The Retry button was selected.
;
; IDTRYAGAIN
; 10
;
;    
;
; The Try Again button was selected.
;
; IDYES
; 6
;
;    
;
; The Yes button was selected.
;
; 
; Remarks
;
; The following system icons can be used in a message box by setting the uType parameter To the corresponding flag value.
; Icon   Flag values
; Icon For MB_ICONHAND, MB_ICONSTOP, And MB_ICONERROR   MB_ICONHAND, MB_ICONSTOP, Or MB_ICONERROR
; Icon For MB_ICONQUESTION   MB_ICONQUESTION
; Icon For MB_ICONEXCLAMATION And MB_ICONWARNING   MB_ICONEXCLAMATION Or MB_ICONWARNING
; Icon For MB_ICONASTERISK And MB_ICONINFORMATION   MB_ICONASTERISK Or MB_ICONINFORMATION
;
; 
;
; Adding two right-To-left marks (RLMs), represented by Unicode formatting character U+200F, in the beginning of a MessageBox display string is interpreted by the MessageBox rendering engine so As To cause the reading order of the MessageBox To be rendered As right-To-Left (RTL).
;
; When you use a system-modal message box To indicate that the system is low on memory, the strings pointed To by the lpText And lpCaption parameters should Not be taken from a resource file because an attempt To load the resource may fail.
;
; If you create a message box While a dialog box is present, use a handle To the dialog box As the hWnd parameter. The hWnd parameter should Not identify a child window, such As a control in a dialog box.
;}
M.
Répondre