[Windows] Boites de dialogue avec icône

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

[Windows] Boites de dialogue avec icône

Message par Mesa »

Voici une petite application que j'ai appelé Créateur de Win MessageBox qui vous permet d'utiliser les boîtes de dialogues de Windows.

Image
By mesarc at 2011-12-19
Image
By mesarc at 2011-12-16

La fenêtre du debugger vous renvoie le numéro du bouton qui a été cliqué et le presse papier contient le code PureBasic à utiliser pour la Boite de dialogue correspondante.

Pour faire fonctionner le bouton aide dans votre application, ajouter cette procédure :

Code : Tout sélectionner

; **********************************************
; **********************************************
; * Win MessageBox                             *
; *                                            *
; * Code Mesaliko                              *
; *      LSI                                   *
; * PB 4.5x 4.60                               *
; *                                            *
; * Décembre 2011                              *
; * Bug corrigé longueur de texte Janvier 2012 *
; **********************************************

;{- 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", 8)
     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
      Frame3DGadget(#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
      Frame3DGadget(#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
      Frame3DGadget(#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
     
      Frame3DGadget(#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
     
      Frame3DGadget(#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.
;}

Mesa.
Dernière modification par Mesa le mer. 18/janv./2012 18:52, modifié 3 fois.
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: [Windows] Boites de dialogue avec icône

Message par Le Soldat Inconnu »

Salut,

Pourquoi ne pas retourner un code sous la forme

Code : Tout sélectionner

MessageRequester("Entrez le Texte du WinMessageBox", "Entrez le Titre du WinMessageBox", 82214)
Cela supprimerait les propriétés de la fenêtre mère mais bon ...

++
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: [Windows] Boites de dialogue avec icône

Message par Mesa »

Résolu.
Dernière modification par Mesa le lun. 19/déc./2011 18:19, modifié 1 fois.
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Re: [Windows] Boites de dialogue avec icône

Message par Le Soldat Inconnu »

Les gadgets sont décalés sous Win7, en fait, les frame3D sont trop petit

voici la correction de ton code

J'ai changé le principe de calcul de la hauteur et largeur des textes : Je charge la police de window par défaut pour être plus précis (tu ne chargeais pas de police)
Et j'ai corrigé le positionnement de tous les gadgets

Il manque encore la gestion du bouton aide

Code : Tout sélectionner

; *******************
; * Win MessageBox
; *
; * Code Mesaliko
; *
; * PB 4.5x 4.60
; *
; * Décembre 2011
; *******************

;{- Enumerations / DataSections
;{ Windows
Enumeration
	#Window_0
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
	
EndEnumeration
;} 
; Define.l Event, EventWindow, EventGadget, EventType, EventMenu
;} 

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
	delta_y = 4 ; espace entre les boutons 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, l_frame + x_frame * 2, 614, "Créateur de Win MessageBox ", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
		
		y = delta_y
		Frame3DGadget(#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
		Frame3DGadget(#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
		Frame3DGadget(#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
		
		Frame3DGadget(#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
		
		Frame3DGadget(#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, 32, #PB_Ignore, y)
		
	EndIf
EndProcedure

OpenWindow_Window_0()

;{- 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
				
				If GetGadgetState(#CheckBox_0) = 1 ; Si Ajout du bouton Aide
					options = options + 4 * 4096
				EndIf
				
				; Code sous forme de texte dans le presse-papier
				code.s = "Retour=MessageRequester(" + Chr(34) + GetGadgetText(#String_1) + Chr(34) + ", " + Chr(34) + GetGadgetText(#String_0) + Chr(34) + ", " + Str(options) + ")"
				
				Debug code
				
				ClearClipboard()
				SetClipboardText(code)
				
				; On voit ce que ça donne
				Retour = MessageRequester(GetGadgetText(#String_1), GetGadgetText(#String_0), options)
				
				Debug Retour
				
			EndIf
			
			; ////////////////////////
		Case #PB_Event_CloseWindow
			EventWindow = EventWindow()
			If EventWindow = #Window_0
				CloseWindow(#Window_0)
				Break
			EndIf
	EndSelect
ForEver

;} 

;{ 
;- -------------------------------------------------------------------------------


; 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.
;}  
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: [Windows] Boites de dialogue avec icône

Message par Mesa »

ça marche impeccablement sous XP, j'ai corrigé un petit bug, le texte de la boîte était inversé avec le titre.

Quelqu'un a essayé sous Vista ?
Dernière modification par Mesa le lun. 19/déc./2011 18:20, modifié 1 fois.
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: [Windows] Boites de dialogue avec icône

Message par Mesa »

Le bouton aide fonctionne maintenant.

Le post n°1 contient le code corrigé.
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: [Windows] Boites de dialogue avec icône

Message par Kwai chang caine »

Quelqu'un a essayé sous Vista ?
J'en profite que j'ai un VISTA sous les doigts pour te repondre :wink:
J'ai pas testé toutes les options, mais ça marche niquel.

Merci beaucoup de ce partage 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: [Windows] Boites de dialogue avec icône

Message par Mesa »

Bonne nouvelle :D

J'ai ajouté une petite fenêtre qui affiche le code, la mise à jour est déjà faite dans le premier post.

Pour ma part, j'ai créé un .exe dans le dossier purebasic et j'ai ajouté une entrée dans l’éditeur Purebasic (outils\outils personnalisés...).

Comme ça, je l'ai sous la main à tout instant.

Mesa.
Avatar de l’utilisateur
Kwai chang caine
Messages : 6989
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: [Windows] Boites de dialogue avec icône

Message par Kwai chang caine »

Pour etre bien sur, j'ai compilé sous vista, car la derniere fois j'avais juste essayé avec l'IDE :oops:
Je persiste et signe, ça "chemar" sous VISTA :mrgreen:

Bonne idée le coup de la "popup" avec le texte dedans :D
Remarque, t'aurais aussi pu le mettre dans un StringGadget sur le panneau principal, ça aurait évité de gerer deux fenetres :wink:
Autrement ça aurait été cool, de laisser la croix sur le popup, car c'est un peu frustrant de ne pas pouvoir la fermer :(

Bon travail 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: [Windows] Boites de dialogue avec icône

Message par Mesa »

Correction d'un bug d'affichage, j'espère que tout est bon maintenant.
Voir le post n°1.

Mesa.
Avatar de l’utilisateur
kernadec
Messages : 1606
Inscription : ven. 25/avr./2008 11:14

Re: [Windows] Boites de dialogue avec icône

Message par kernadec »

bonsoir et merci, Mesa

c'est OK pour moi aussi avec XP SP2

Cordialement
Répondre