Un programme pour réaliser des QCM [Avec Cryptage]

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
brossden
Messages : 833
Inscription : lun. 26/janv./2004 14:37

Un programme pour réaliser des QCM [Avec Cryptage]

Message par brossden »

Le projet complet comporte une fichier exemple. Faire un copier coller dans un ficheir que vous vouderz bien nommer "Exemple.qcm"
Questionnaire Exemple
Quelle est la couleur du cheval blanc d'Henri IV ?
A - Gris
B - Blanc
C - Noir
D - Baie
B
La réponse est dans la question !!
Quelle est la vitesse de la lumière ?
A - 10 000 Km/s
B - 150 000 Kms
C - 300 000 Km/s
D - 500 000 Km/s
C
La Bonne réponse est 300 000 Kilomètres par seconde
Quelle infraction occasionne un retrait de point ?
A - Dépassement vitesse limite
B - Téléphoner au Volant
C - Oubli de la ceinture de sécurité
D - Taux d'alcoolémie > 0.5 g/l
ABCD
Toutes ces infractions sont passibles d'un retrait de point(s) !!
Quelle est la couleur du cheval gris d'Henri IV
A - Gris
B - Blanc
C - Noir
D - Baie
A
La réponse est Toujours dans la question !!
Le projet comporte un Editeru de QCM qui permet de créer modifier un Fichier QCM

Code : Tout sélectionner

Structure Champs
  CQuestion.s : CPropA.s : CPropB.s : CPropC.s : CPropD.s : CReponse.s : CSolution.s
EndStructure

Global Question ,Reponse, FTitre.s, Window
Global ChoixA,ChoixB,ChoixC,ChoixD
Global Titre, ProposA, ProposB, ProposC, ProposD
Global Charge, Sauve, Ajoute, Supprime, Valide
Global Scroll
Global NewList Quest.Champs(), FTitre.s, Nbr, File.s
Procedure Sauve()
  File = SaveFileRequester("Sauvegarde du questionnaire",File,"Questionnaire|*.qcm",0)
  If UCase(GetExtensionPart(File))<>"QCM"
    File+".qcm"
  EndIf
  OpenFile(1,File)
  WriteStringN(1,GetGadgetText(Titre))
  ForEach Quest()
    WriteStringN(1,Quest()\CQuestion)
    WriteStringN(1,Quest()\CPropA)
    WriteStringN(1,Quest()\CPropB)
    WriteStringN(1,Quest()\CPropC)
    WriteStringN(1,Quest()\CPropD)
    WriteStringN(1,Quest()\CSolution)
    WriteStringN(1,Quest()\CReponse)
  Next
  CloseFile(1)
EndProcedure

Procedure Disable(Char,Sauv,Ajou,Vali,Supp,Scro)
  DisableGadget(Charge, Char)
  DisableGadget(Sauve, Sauv)
  DisableGadget(Ajoute, Ajou)
  DisableGadget(Valide, Vali)
  DisableGadget(Supprime, Supp) 
  DisableGadget(Scroll, Scro)
EndProcedure

Procedure Charge()
  ClearList(Quest())
  Nbr=0
  File = OpenFileRequester("Selection du Questionnaire à éditer","*.qcm","Questionnaire|*.qcm",0)
  OpenFile(1,File)
  FTitre=ReadString(1)
  Repeat
    AddElement(Quest())
    Quest()\CQuestion= ReadString(1)
    Quest()\CPropA   = ReadString(1)
    Quest()\CPropB   = ReadString(1)
    Quest()\CPropC   = ReadString(1)
    Quest()\CPropD   = ReadString(1)
    Quest()\CSolution =ReadString(1)
    Quest()\CReponse = ReadString(1)
    Nbr+1
  Until Eof(1)
  CloseFile(1)
  SetGadgetAttribute(Scroll,#PB_ScrollBar_Maximum,Nbr)
  SetGadgetState(Scroll,1)
EndProcedure

Procedure Valide()
  Rep.s=""
  If GetGadgetState(ChoixA) : Rep+"A" :EndIf
  If GetGadgetState(ChoixB) : Rep+"B" :EndIf
  If GetGadgetState(ChoixC) : Rep+"C" :EndIf
  If GetGadgetState(ChoixD) : Rep+"D" :EndIf
  Quest()\CQuestion= GetGadgetText(Question)
  Quest()\CPropA   = GetGadgetText(ProposA)
  Quest()\CPropB   = GetGadgetText(ProposB)
  Quest()\CPropC   = GetGadgetText(ProposC)
  Quest()\CPropD   = GetGadgetText(ProposD)
  Quest()\CSolution= Rep
  Quest()\CReponse = GetGadgetText(Reponse)

EndProcedure

Procedure Affiche()
  SetWindowTitle(Window,"Editeur de Q.C.M   Question : "+ Str(GetGadgetState(Scroll))+" / "+Str(Nbr))
  SetGadgetText(Titre,FTitre)
  SetGadgetText(Question,Quest()\CQuestion)
  SetGadgetText(Reponse,Quest()\CReponse)
  SetGadgetText(ProposA,Quest()\CPropA)
  SetGadgetText(ProposB,Quest()\CPropB)
  SetGadgetText(ProposC,Quest()\CPropC)
  SetGadgetText(ProposD,Quest()\CPropD)
  Rep.s=Quest()\CSolution
  If FindString(Rep,"A",1) : SetGadgetState(ChoixA,1): Else : SetGadgetState(ChoixA,0) : EndIf
  If FindString(Rep,"B",1) : SetGadgetState(ChoixB,1): Else : SetGadgetState(ChoixB,0) : EndIf
  If FindString(Rep,"C",1) : SetGadgetState(ChoixC,1): Else : SetGadgetState(ChoixC,0) : EndIf
  If FindString(Rep,"D",1) : SetGadgetState(ChoixD,1): Else : SetGadgetState(ChoixD,0) : EndIf
EndProcedure

Procedure Open_Window()
  Window = OpenWindow(#PB_Any, 281, -1, 514, 420, "",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
  If Window
    If CreateGadgetList(WindowID(Window))
      frame = Frame3DGadget(#PB_Any, 20, 60, 440, 80, "Question")
      frame = Frame3DGadget(#PB_Any, 20, 150, 440, 140, "Propositions")
      frame = Frame3DGadget(#PB_Any, 20, 300, 440, 80, "Réponse")
      frame = Frame3DGadget(#PB_Any, 20, 10, 440, 40, "Titre de La Fenêtre")
      Question = EditorGadget(#PB_Any, 40, 80, 400, 50)
      Reponse = EditorGadget(#PB_Any, 40, 320, 400, 50)
      ChoixA  = CheckBoxGadget(#PB_Any, 40, 170, 35, 20, "A - ")
      ChoixB  = CheckBoxGadget(#PB_Any, 40, 200, 35, 20, "B -")
      ChoixC  = CheckBoxGadget(#PB_Any, 40, 230, 35, 20, "C -")
      ChoixD  = CheckBoxGadget(#PB_Any, 40, 260, 35, 20, "D -")
      Titre  = StringGadget(#PB_Any, 40, 25, 400, 20, FTitre)
      ProposA = StringGadget(#PB_Any, 80, 170, 360, 20, "")
      ProposB = StringGadget(#PB_Any, 80, 200, 360, 20, "")
      ProposC = StringGadget(#PB_Any, 80, 230, 360, 20, "")
      ProposD = StringGadget(#PB_Any, 80, 260, 360, 20, "")
      Charge  = ButtonGadget(#PB_Any, 20, 390, 80, 23, "Charger")
      Sauve   = ButtonGadget(#PB_Any, 110, 390, 80, 23, "Sauver")
      Ajoute  = ButtonGadget(#PB_Any, 200, 390, 80, 23, "Ajouter")
      Valide  = ButtonGadget(#PB_Any, 290, 390, 80, 23, "Valider")
      Supprime= ButtonGadget(#PB_Any, 380, 390, 80, 23, "Suppimer")
      Scroll  = ScrollBarGadget(#PB_Any, 480, 20, 10, 350, 1, 1, 1, #PB_ScrollBar_Vertical)
    EndIf
  EndIf
EndProcedure

Open_Window()
Disable(0,1,0,1,1,1)
SetActiveGadget(Titre)
Repeat
  Event = WaitWindowEvent()
  GadgetID = EventGadget()
  If Event = #PB_Event_Gadget

    If GadgetID = Valide
      Valide()
      Disable(0,0,0,0,1,0)
      
    ElseIf GadgetID = Charge
      Charge()
      FirstElement(Quest())
      Affiche()
      Disable(0,0,0,0,0,0)
      
    ElseIf GadgetID = Sauve
      Sauve()
      Disable(0,0,0,0,0,0)
      
      ElseIf GadgetID = Supprime
      DeleteElement(Quest())
      SetGadgetAttribute(Scroll,#PB_ScrollBar_Maximum,GetGadgetAttribute(Scroll,#PB_ScrollBar_Maximum)-1)
      SelectElement(Quest(),GetGadgetState(Scroll))
      Nbr-1
      Affiche()
      Disable(0,0,0,0,0,0)
      
    ElseIf GadgetID = Ajoute
      AddElement(Quest())
      SetGadgetAttribute(Scroll,#PB_ScrollBar_Maximum,GetGadgetAttribute(Scroll,#PB_ScrollBar_Maximum)+1)
      Nbr+1
      SetGadgetState(Scroll,GetGadgetState(Scroll)+1)
      Affiche()
      Disable(1,1,1,0,0,0)
      
      SetActiveGadget(Question)
    ElseIf GadgetID = Scroll
      SelectElement(Quest(), GetGadgetState(Scroll)-1)
      Affiche()
    EndIf
  EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
End
Et pour finir un programme pour lancer le questionnaire :

Code : Tout sélectionner

InitSound(); on initialise l'environnement son
UseJPEGImageDecoder()
;-----------Message d'introduction----------------------
Intro1$ = "Bienvenue sur QCM ."
Intro2$ = "Cliquer sur le boutton Lancer QCM pour commencer le test."
;-----------Fin Message d'introduction------------------

;-----------Questions / Réponses-------------------------
Structure Champs
  Libel.s : PropA.s : PropB.s : PropC.s : PropD.s : Reponse.s : Solution.s
EndStructure
;- Globals
Global FontID1= LoadFont(1, "Georgia", 8) ,FontID2 = LoadFont(2, "Georgia", 10)
Global FontID3 = LoadFont(3, "Georgia", 12, #PB_Font_Bold) ,FontID4 = LoadFont(4, "Georgia", 12, #PB_Font_Underline)
Global FontID5 = LoadFont(5, "Georgia", 24) ,Image0, Image1, Th, Note, Nbr, NewList Quest.Champs(), File.s, Titre.s, Nb


;-----------Création questionnaire---------------------------
ClearList(Quest())
Nbr=0
File = OpenFileRequester("Selection du Questionnaire à éditer","*.qcm","Questionnaire|*.qcm",0)
OpenFile(1,File)
Titre.s=ReadString(1)
Repeat
  AddElement(Quest())
  Nb+1
  Quest()\Libel= ReadString(1)
  Quest()\PropA   = ReadString(1)
  Quest()\PropB   = ReadString(1)
  Quest()\PropC   = ReadString(1)
  Quest()\PropD   = ReadString(1)
  Quest()\Reponse = ReadString(1)
  Quest()\Solution =ReadString(1)
Until Eof(1)
CloseFile(1)

;- Repère dela fin du questinnaire !!
AddElement(Quest())
Quest()\Libel = "Fin"

;-----------Fin du Questionnaire---------------------------

;- Constantes

Enumeration
  #Window_1 : #MenuBar_2 : #MENU_4 : #MENU_5 : #Image_0 : #ProgressBar_0 : #Frame3D_0
  #Editor_0 : #Frame3D_1 : #CheckBox_0 : #CheckBox_1 : #CheckBox_2 : #CheckBox_3 : #Frame3D_2
  #Editor_1 : #Button_0 : #Frame3D_3 : #String_0 : #Text_0 : #Button_2 : #String_1 : #ListIcon_0
  #Button_3 : #Image_2 : #Text_1 : #Text_2 : #Editor_3 : #Button_4 : #ProgressBar_1 : #SOn : #StatusBar_0
EndEnumeration

;- Catch Images
Image0 = CatchImage(0, ?Image0) : Image1 = CatchImage(1, ?Image1)

;- Images
DataSection
Image0:
;IncludeBinary "D:\Divers\Sources Logiciel InfoProject\QCM\logo.bmp"
Image1:
;IncludeBinary "D:\Divers\Sources Logiciel InfoProject\QCM\sst.jpg"
EndDataSection

Procedure Questionne()
  SetGadgetState(#CheckBox_0,0) : SetGadgetState(#CheckBox_1,0)
  SetGadgetState(#CheckBox_2,0) : SetGadgetState(#CheckBox_3,0)
  ClearGadgetItemList(#Editor_0) : ClearGadgetItemList(#Editor_1)
  AddGadgetItem(#Editor_0,-1,Quest()\Libel)
  AddGadgetItem(#Editor_0,-1,"")
  AddGadgetItem(#Editor_0,-1,Quest()\PropA) : AddGadgetItem(#Editor_0,-1,Quest()\PropB)
  AddGadgetItem(#Editor_0,-1,Quest()\PropC) : AddGadgetItem(#Editor_0,-1,Quest()\PropD)
EndProcedure

Procedure Reponse()
  Rep.s=""
  Nbr+1
  If GetGadgetState(#CheckBox_0) : Rep.s+"A" :EndIf
  If GetGadgetState(#CheckBox_1) : Rep.s+"B" :EndIf
  If GetGadgetState(#CheckBox_2) : Rep.s+"C" :EndIf
  If GetGadgetState(#CheckBox_3) : Rep.s+"D" :EndIf
  ClearGadgetItemList(#Editor_1)
  If Rep=Quest()\Reponse
    AddGadgetItem(#Editor_1,-1,"BRAVO ! Bonne réponse")
    Note+1
  Else
    AddGadgetItem(#Editor_1,-1,"FAUX!")
    AddGadgetItem(#Editor_1,-1,"Soyez plus attentif :")
    AddGadgetItem(#Editor_1,-1,"")
    AddGadgetItem(#Editor_1,-1,Quest()\Solution)
  EndIf
  StatusBarText(#StatusBar_0,1,Str(Note)+ "/" +Str(Nbr));,#PB_StatusBar_Raised)
NextElement(Quest.Champs())
EndProcedure

Procedure Laps(Param)
  Repeat
    SetGadgetState(#ProgressBar_1,GetGadgetState(#ProgressBar_1)+10)
    Delay(100)
    If LoadSound(#SOn, "c:\WINDOWS\system32\oobe\images\clickerx.wav") ; on va chercher le son
      PlaySound(#SOn , 0); on joue le son
    EndIf
    If GetGadgetState(#ProgressBar_1)=500
      Reponse()
      MessageRequester("Questionaire","Temps écoulé")
      SetGadgetState(#ProgressBar_1,0)
      SetGadgetText(#Button_0,"Question Suivante" )
      PauseThread(Th)
    EndIf
  ForEver
EndProcedure

Procedure Open_Window_1()
  If OpenWindow(#Window_1, 871, 293, 563, 456, Titre,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_BorderLess | #PB_Window_ScreenCentered | #PB_Window_WindowCentered )
    If CreateMenu(#MenuBar_2, WindowID(#Window_1))
      MenuTitle("Fichier")
      MenuItem(#MENU_4, "Quitter")
    EndIf
    If CreateStatusBar(#StatusBar_0, WindowID(#Window_1))
      AddStatusBarField(50)
      StatusBarText(#StatusBar_0,0," Points :",#PB_StatusBar_Raised)
      AddStatusBarField(50)
      StatusBarText(#StatusBar_0,1,"")
      AddStatusBarField(900)
    EndIf
    If CreateGadgetList(WindowID(#Window_1))
      Frame3DGadget(#Frame3D_0, 5, 5, 550, 180, "Question :")
      SetGadgetFont(#Frame3D_0, FontID1)
      EditorGadget(#Editor_0, 15, 25, 530, 145 ,#PB_Editor_ReadOnly)
      Frame3DGadget(#Frame3D_1, 5, 195, 550, 70, "Réponse :")
      SetGadgetFont(#Frame3D_1, FontID1)
      CheckBoxGadget(#CheckBox_0, 25, 225, 90, 15, "Réponse A", #PB_CheckBox_Right | #PB_CheckBox_Center)
      SetGadgetFont(#CheckBox_0, FontID2)
      CheckBoxGadget(#CheckBox_1, 160, 225, 85, 15, "Réponse B", #PB_CheckBox_Right | #PB_CheckBox_Center)
      SetGadgetFont(#CheckBox_1, FontID2)
      CheckBoxGadget(#CheckBox_2, 300, 225, 85, 15, "Réponse C", #PB_CheckBox_Right | #PB_CheckBox_Center)
      SetGadgetFont(#CheckBox_2, FontID2)
      CheckBoxGadget(#CheckBox_3, 450, 225, 85, 15, "Réponse D", #PB_CheckBox_Right | #PB_CheckBox_Center)
      SetGadgetFont(#CheckBox_3, FontID2)
      Frame3DGadget(#Frame3D_2, 5, 290, 550, 110, "Correction :")
      SetGadgetFont(#Frame3D_2, FontID1)
      EditorGadget(#Editor_1, 10, 310, 540, 80 ,#PB_Editor_ReadOnly)
      ButtonGadget(#Button_0, 440, 270, 115, 20, "Lancer le QCM")
      SetGadgetFont(#Button_0, FontID1)
      ProgressBarGadget(#ProgressBar_1, 102, 418, 460, 18, 0, 500)
    EndIf
  EndIf
EndProcedure

Open_Window_1()
AddGadgetItem(#Editor_0, -1,Intro1$)
AddGadgetItem(#Editor_0, -1,Intro2$)
FirstElement(Quest())
Th = CreateThread(@Laps(),0)
PauseThread(Th)

Repeat ; Start of the event loop
  Event = WaitWindowEvent() ; This line waits until an event is received from Windows
  GadgetID = EventGadget() ; Is it a gadget event?
  If Event = #PB_Event_Menu
    MenuID = EventMenu()
    If MenuID = #MENU_4
      Debug "GadgetID: #MENU_4"
      End
    EndIf
  EndIf
  If Event = #PB_Event_Gadget
    If GadgetID = #Button_0
      If Quest()\Libel="Fin"
        MessageRequester("Note", "Votre Note est de :"+Str(Note)+" / "+Str(Nb)+"  soit : "+StrF(Note*20/Nb,2)+" sur 20" )
        End
      EndIf
      If GetGadgetText(#Button_0)<>"Valider"
        SetGadgetText(#Button_0,"Valider" )
        ResumeThread(Th)
        n+1
        Questionne()
      Else
        If GetGadgetState(#ProgressBar_1)=500
          ResumeThread(Th)
        Else
          PauseThread(Th)
          SetGadgetText(#Button_0,"Détail Réponse" )
          SetGadgetState(#ProgressBar_1,0)
          SetGadgetText(#Button_0,"Question Suivante" )
          Reponse()
        EndIf
      EndIf
    EndIf
  EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
End
J'ai ecris ce programme pour MetalOS pour lui donner un exemple de soft dont il semble qu'il avait besoin.

Il est certain qu'un codage du fichier qcm serait idéal pour eviter aux petits malins de lire les bonnes réponses mais je pense que ce n'est pas trés difficile à ajouter !

80
Dernière modification par brossden le lun. 04/juin/2007 19:52, modifié 3 fois.
Denis

Bonne Jounée à tous
Avatar de l’utilisateur
Ar-S
Messages : 9540
Inscription : dim. 09/oct./2005 16:51
Contact :

Message par Ar-S »

Merci pour ce script trés interressant !
Avatar de l’utilisateur
MetalOS
Messages : 1510
Inscription : mar. 20/juin/2006 22:17
Localisation : Lorraine
Contact :

Message par MetalOS »

Alors la tu vient de me faire tomber le ... au sol. tu veut pas me faire des soft et que je le vende à mon nom :lol: . Merci pour ta source, tien tu peut aller dans le poste Hors sujet pour prendre une petite pause tu le mérite bien et tu prend une bière sur mon compte. Ha oui, tu dira au barmen Mr Dobro qu'il mette ca sur ma note, c un ami. :lol: :lol: :lol: :lol: . Encore merci à toi.
brossden
Messages : 833
Inscription : lun. 26/janv./2004 14:37

Message par brossden »

@ MetalOS

De rien, je me suis amusé comme b'hab et si cela peut te rendre service ... pas de problème !
Je vais modifier mon soft pour coder les données !
Denis

Bonne Jounée à tous
brossden
Messages : 833
Inscription : lun. 26/janv./2004 14:37

Message par brossden »

Voila les codes modifiés pour crypter les fichiers questionnaires :

Editeur :

Code : Tout sélectionner


Structure Champs
  CQuestion.s : CPropA.s : CPropB.s : CPropC.s : CPropD.s : CReponse.s : CSolution.s
EndStructure

Global Question ,Reponse, FTitre.s, Window
Global ChoixA,ChoixB,ChoixC,ChoixD
Global Titre, ProposA, ProposB, ProposC, ProposD
Global Charge, Sauve, Ajoute, Supprime, Valide
Global Scroll
Global NewList Quest.Champs(), FTitre.s, Nbr, File.s

Procedure EnCode(File.s)
  OpenFile(1,File)
  Lg=Lof(1)
  *Fil=AllocateMemory(Lg+8)
  ReadData(1,*Fil,Lg)
  Clef.q=$4A5FC89D2A45B45D 
  For n=0 To Lg-7 Step 8
    PokeQ(*Fil+n,PeekQ(*Fil+n)!Clef)
  Next
  CloseFile(1)
  CreateFile(2,File)
  WriteData(2,*Fil,Lg)
EndProcedure

Procedure DeCode(File.s)
  OpenFile(1,File)
  Lg=Lof(1)
  *Fil=AllocateMemory(Lg+8)
  ReadData(1,*Fil,Lg)
  Clef.q=$4A5FC89D2A45B45D 
  For n=0 To Lg-7 Step 8
    PokeQ(*Fil+n,PeekQ(*Fil+n)!Clef)
  Next
  CloseFile(1)
  CreateFile(2,"c:\Temp.tmp")
  WriteData(2,*Fil,Lg)
  CloseFile(2)
EndProcedure


Procedure Sauve()
  File = SaveFileRequester("Sauvegarde du questionnaire",File,"Questionnaire|*.qcm",0)
  If UCase(GetExtensionPart(File))<>"QCM"
    File+".qcm"
  EndIf
  CreateFile(1,File)
  WriteStringN(1,GetGadgetText(Titre))
  ForEach Quest()
    WriteStringN(1,Quest()\CQuestion)
    WriteStringN(1,Quest()\CPropA)
    WriteStringN(1,Quest()\CPropB)
    WriteStringN(1,Quest()\CPropC)
    WriteStringN(1,Quest()\CPropD)
    WriteStringN(1,Quest()\CSolution)
    WriteStringN(1,Quest()\CReponse)
  Next
  CloseFile(1)
EnCode(File)
EndProcedure

Procedure Disable(Char,Sauv,Ajou,Vali,Supp,Scro)
  DisableGadget(Charge, Char)
  DisableGadget(Sauve, Sauv)
  DisableGadget(Ajoute, Ajou)
  DisableGadget(Valide, Vali)
  DisableGadget(Supprime, Supp)
  DisableGadget(Scroll, Scro)
EndProcedure

Procedure Charge()
  ClearList(Quest())
  Nbr=0
  File = OpenFileRequester("Selection du Questionnaire à éditer","*.qcm","Questionnaire|*.qcm",0)
  DeCode(File)
  OpenFile(1,"c:\Temp.tmp")
  FTitre=ReadString(1)
  Repeat
    AddElement(Quest())
    Quest()\CQuestion= ReadString(1)
    Quest()\CPropA   = ReadString(1)
    Quest()\CPropB   = ReadString(1)
    Quest()\CPropC   = ReadString(1)
    Quest()\CPropD   = ReadString(1)
    Quest()\CSolution =ReadString(1)
    Quest()\CReponse = ReadString(1)
    Nbr+1
  Until Eof(1)
  CloseFile(1)

  SetGadgetAttribute(Scroll,#PB_ScrollBar_Maximum,Nbr)
  SetGadgetState(Scroll,1)
  Delay(100)
  DeleteFile("Temp.tmp")
EndProcedure

Procedure Valide()
  Rep.s=""
  If GetGadgetState(ChoixA) : Rep+"A" :EndIf
  If GetGadgetState(ChoixB) : Rep+"B" :EndIf
  If GetGadgetState(ChoixC) : Rep+"C" :EndIf
  If GetGadgetState(ChoixD) : Rep+"D" :EndIf
  Quest()\CQuestion= GetGadgetText(Question)
  Quest()\CPropA   = GetGadgetText(ProposA)
  Quest()\CPropB   = GetGadgetText(ProposB)
  Quest()\CPropC   = GetGadgetText(ProposC)
  Quest()\CPropD   = GetGadgetText(ProposD)
  Quest()\CSolution= Rep
  Quest()\CReponse = GetGadgetText(Reponse)
  
EndProcedure

Procedure Affiche()
  SetWindowTitle(Window,"Editeur de Q.C.M   Question : "+ Str(GetGadgetState(Scroll))+" / "+Str(Nbr))
  SetGadgetText(Titre,FTitre)
  SetGadgetText(Question,Quest()\CQuestion)
  SetGadgetText(Reponse,Quest()\CReponse)
  SetGadgetText(ProposA,Quest()\CPropA)
  SetGadgetText(ProposB,Quest()\CPropB)
  SetGadgetText(ProposC,Quest()\CPropC)
  SetGadgetText(ProposD,Quest()\CPropD)
  Rep.s=Quest()\CSolution
  If FindString(Rep,"A",1) : SetGadgetState(ChoixA,1): Else : SetGadgetState(ChoixA,0) : EndIf
  If FindString(Rep,"B",1) : SetGadgetState(ChoixB,1): Else : SetGadgetState(ChoixB,0) : EndIf
  If FindString(Rep,"C",1) : SetGadgetState(ChoixC,1): Else : SetGadgetState(ChoixC,0) : EndIf
  If FindString(Rep,"D",1) : SetGadgetState(ChoixD,1): Else : SetGadgetState(ChoixD,0) : EndIf
EndProcedure

Procedure Open_Window()
  Window = OpenWindow(#PB_Any, 281, -1, 514, 420, "",  #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar )
  If Window
    If CreateGadgetList(WindowID(Window))
      frame = Frame3DGadget(#PB_Any, 20, 60, 440, 80, "Question")
      frame = Frame3DGadget(#PB_Any, 20, 150, 440, 140, "Propositions")
      frame = Frame3DGadget(#PB_Any, 20, 300, 440, 80, "Réponse")
      frame = Frame3DGadget(#PB_Any, 20, 10, 440, 40, "Titre de La Fenêtre")
      Question = EditorGadget(#PB_Any, 40, 80, 400, 50)
      Reponse = EditorGadget(#PB_Any, 40, 320, 400, 50)
      ChoixA  = CheckBoxGadget(#PB_Any, 40, 170, 35, 20, "A - ")
      ChoixB  = CheckBoxGadget(#PB_Any, 40, 200, 35, 20, "B -")
      ChoixC  = CheckBoxGadget(#PB_Any, 40, 230, 35, 20, "C -")
      ChoixD  = CheckBoxGadget(#PB_Any, 40, 260, 35, 20, "D -")
      Titre  = StringGadget(#PB_Any, 40, 25, 400, 20, FTitre)
      ProposA = StringGadget(#PB_Any, 80, 170, 360, 20, "")
      ProposB = StringGadget(#PB_Any, 80, 200, 360, 20, "")
      ProposC = StringGadget(#PB_Any, 80, 230, 360, 20, "")
      ProposD = StringGadget(#PB_Any, 80, 260, 360, 20, "")
      Charge  = ButtonGadget(#PB_Any, 20, 390, 80, 23, "Charger")
      Sauve   = ButtonGadget(#PB_Any, 110, 390, 80, 23, "Sauver")
      Ajoute  = ButtonGadget(#PB_Any, 200, 390, 80, 23, "Ajouter")
      Valide  = ButtonGadget(#PB_Any, 290, 390, 80, 23, "Valider")
      Supprime= ButtonGadget(#PB_Any, 380, 390, 80, 23, "Suppimer")
      Scroll  = ScrollBarGadget(#PB_Any, 480, 20, 10, 350, 1, 1, 1, #PB_ScrollBar_Vertical)
    EndIf
  EndIf
EndProcedure

Open_Window()
Disable(0,1,0,1,1,1)
SetActiveGadget(Titre)
Repeat
  Event = WaitWindowEvent()
  GadgetID = EventGadget()
  If Event = #PB_Event_Gadget
    
    If GadgetID = Valide
      Valide()
      Disable(0,0,0,0,1,0)
      
    ElseIf GadgetID = Charge
      Charge()
      FirstElement(Quest())
      Affiche()
      Disable(0,0,0,0,0,0)
      Debug @Quest()
      For n= 0 To 10
        Debug PeekC(@Quest()+n)
      Next
      
    ElseIf GadgetID = Sauve
      Sauve()
      Disable(0,0,0,0,0,0)
      
    ElseIf GadgetID = Supprime
      DeleteElement(Quest())
      SetGadgetAttribute(Scroll,#PB_ScrollBar_Maximum,GetGadgetAttribute(Scroll,#PB_ScrollBar_Maximum)-1)
      SelectElement(Quest(),GetGadgetState(Scroll))
      Nbr-1
      Affiche()
      Disable(0,0,0,0,0,0)
      
    ElseIf GadgetID = Ajoute
      AddElement(Quest())
      SetGadgetAttribute(Scroll,#PB_ScrollBar_Maximum,GetGadgetAttribute(Scroll,#PB_ScrollBar_Maximum)+1)
      Nbr+1
      SetGadgetState(Scroll,GetGadgetState(Scroll)+1)
      Affiche()
      Disable(1,1,1,0,0,0)
      
      SetActiveGadget(Question)
    ElseIf GadgetID = Scroll
      SelectElement(Quest(), GetGadgetState(Scroll)-1)
      Affiche()
    EndIf
  EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
End 


Lanceur de questionnaire :

Code : Tout sélectionner



InitSound(); on initialise l'environnement son
UseJPEGImageDecoder()
;-----------Message d'introduction----------------------
Intro1$ = "Bienvenue sur QCM ."
Intro2$ = "Cliquer sur le boutton Lancer QCM pour commencer le test."
;-----------Fin Message d'introduction------------------

;-----------Questions / Réponses-------------------------
Structure Champs
  Libel.s : PropA.s : PropB.s : PropC.s : PropD.s : Reponse.s : Solution.s
EndStructure
;- Globals
Global FontID1= LoadFont(1, "Georgia", 8) ,FontID2 = LoadFont(2, "Georgia", 10)
Global FontID3 = LoadFont(3, "Georgia", 12, #PB_Font_Bold) ,FontID4 = LoadFont(4, "Georgia", 12, #PB_Font_Underline)
Global FontID5 = LoadFont(5, "Georgia", 24) ,Image0, Image1, Th, Note, Nbr, NewList Quest.Champs(), File.s, Titre.s, Nb
Declare DeCode(File.s)

;-----------Création questionnaire---------------------------
ClearList(Quest())
Nbr=0
File = OpenFileRequester("Selection du Questionnaire à éditer","*.qcm","Questionnaire|*.qcm",0)

DeCode(File.s)
OpenFile(1,"c:\Temp.tmp")
Titre.s=ReadString(1)
Repeat
  AddElement(Quest())
  Nb+1
  Quest()\Libel= ReadString(1)
  Quest()\PropA   = ReadString(1)
  Quest()\PropB   = ReadString(1)
  Quest()\PropC   = ReadString(1)
  Quest()\PropD   = ReadString(1)
  Quest()\Reponse = ReadString(1)
  Quest()\Solution =ReadString(1)
Until Eof(1)
CloseFile(1)

;- Repère dela fin du questinnaire !!
AddElement(Quest())
Quest()\Libel = "Fin"

;-----------Fin du Questionnaire---------------------------

;- Constantes

Enumeration
  #Window_1 : #MenuBar_2 : #MENU_4 : #MENU_5 : #Image_0 : #ProgressBar_0 : #Frame3D_0
  #Editor_0 : #Frame3D_1 : #CheckBox_0 : #CheckBox_1 : #CheckBox_2 : #CheckBox_3 : #Frame3D_2
  #Editor_1 : #Button_0 : #Frame3D_3 : #String_0 : #Text_0 : #Button_2 : #String_1 : #ListIcon_0
  #Button_3 : #Image_2 : #Text_1 : #Text_2 : #Editor_3 : #Button_4 : #ProgressBar_1 : #SOn : #StatusBar_0
EndEnumeration

;- Catch Images
Image0 = CatchImage(0, ?Image0) : Image1 = CatchImage(1, ?Image1)

;- Images
DataSection
Image0:
;IncludeBinary "D:\Divers\Sources Logiciel InfoProject\QCM\logo.bmp"
Image1:
;IncludeBinary "D:\Divers\Sources Logiciel InfoProject\QCM\sst.jpg"
EndDataSection

Procedure DeCode(File.s)
  OpenFile(1,File)
  Lg=Lof(1)
  *Fil=AllocateMemory(Lg+8)
  ReadData(1,*Fil,Lg)
  Clef.q=$4A5FC89D2A45B45D 
  For n=0 To Lg-7 Step 8
    PokeQ(*Fil+n,PeekQ(*Fil+n)!Clef)
  Next
  CloseFile(1)
  CreateFile(2,"c:\Temp.tmp")
  WriteData(2,*Fil,Lg)
  CloseFile(2)
EndProcedure

Procedure Questionne()
  SetGadgetState(#CheckBox_0,0) : SetGadgetState(#CheckBox_1,0)
  SetGadgetState(#CheckBox_2,0) : SetGadgetState(#CheckBox_3,0)
  ClearGadgetItemList(#Editor_0) : ClearGadgetItemList(#Editor_1)
  AddGadgetItem(#Editor_0,-1,Quest()\Libel)
  AddGadgetItem(#Editor_0,-1,"")
  AddGadgetItem(#Editor_0,-1,Quest()\PropA) : AddGadgetItem(#Editor_0,-1,Quest()\PropB)
  AddGadgetItem(#Editor_0,-1,Quest()\PropC) : AddGadgetItem(#Editor_0,-1,Quest()\PropD)
EndProcedure

Procedure Reponse()
  Rep.s=""
  Nbr+1
  If GetGadgetState(#CheckBox_0) : Rep.s+"A" :EndIf
  If GetGadgetState(#CheckBox_1) : Rep.s+"B" :EndIf
  If GetGadgetState(#CheckBox_2) : Rep.s+"C" :EndIf
  If GetGadgetState(#CheckBox_3) : Rep.s+"D" :EndIf
  ClearGadgetItemList(#Editor_1)
  If Rep=Quest()\Reponse
    AddGadgetItem(#Editor_1,-1,"BRAVO ! Bonne réponse")
    Note+1
  Else
    AddGadgetItem(#Editor_1,-1,"FAUX!")
    AddGadgetItem(#Editor_1,-1,"Soyez plus attentif :")
    AddGadgetItem(#Editor_1,-1,"")
    AddGadgetItem(#Editor_1,-1,Quest()\Solution)
  EndIf
  StatusBarText(#StatusBar_0,1,Str(Note)+ "/" +Str(Nbr));,#PB_StatusBar_Raised)
  NextElement(Quest.Champs())
EndProcedure

Procedure Laps(Param)
  Repeat
    SetGadgetState(#ProgressBar_1,GetGadgetState(#ProgressBar_1)+10)
    Delay(100)
    If LoadSound(#SOn, "c:\WINDOWS\system32\oobe\images\clickerx.wav") ; on va chercher le son
      PlaySound(#SOn , 0); on joue le son
    EndIf
    If GetGadgetState(#ProgressBar_1)=500
      Reponse()
      MessageRequester("Questionaire","Temps écoulé")
      SetGadgetState(#ProgressBar_1,0)
      SetGadgetText(#Button_0,"Question Suivante" )
      PauseThread(Th)
    EndIf
  ForEver
EndProcedure

Procedure Open_Window_1()
  If OpenWindow(#Window_1, 871, 293, 563, 456, Titre,  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_BorderLess | #PB_Window_ScreenCentered | #PB_Window_WindowCentered )
    If CreateMenu(#MenuBar_2, WindowID(#Window_1))
      MenuTitle("Fichier")
      MenuItem(#MENU_4, "Quitter")
    EndIf
    If CreateStatusBar(#StatusBar_0, WindowID(#Window_1))
      AddStatusBarField(50)
      StatusBarText(#StatusBar_0,0," Points :",#PB_StatusBar_Raised)
      AddStatusBarField(50)
      StatusBarText(#StatusBar_0,1,"")
      AddStatusBarField(900)
    EndIf
    If CreateGadgetList(WindowID(#Window_1))
      Frame3DGadget(#Frame3D_0, 5, 5, 550, 180, "Question :")
      SetGadgetFont(#Frame3D_0, FontID1)
      EditorGadget(#Editor_0, 15, 25, 530, 145 ,#PB_Editor_ReadOnly)
      Frame3DGadget(#Frame3D_1, 5, 195, 550, 70, "Réponse :")
      SetGadgetFont(#Frame3D_1, FontID1)
      CheckBoxGadget(#CheckBox_0, 25, 225, 90, 15, "Réponse A", #PB_CheckBox_Right | #PB_CheckBox_Center)
      SetGadgetFont(#CheckBox_0, FontID2)
      CheckBoxGadget(#CheckBox_1, 160, 225, 85, 15, "Réponse B", #PB_CheckBox_Right | #PB_CheckBox_Center)
      SetGadgetFont(#CheckBox_1, FontID2)
      CheckBoxGadget(#CheckBox_2, 300, 225, 85, 15, "Réponse C", #PB_CheckBox_Right | #PB_CheckBox_Center)
      SetGadgetFont(#CheckBox_2, FontID2)
      CheckBoxGadget(#CheckBox_3, 450, 225, 85, 15, "Réponse D", #PB_CheckBox_Right | #PB_CheckBox_Center)
      SetGadgetFont(#CheckBox_3, FontID2)
      Frame3DGadget(#Frame3D_2, 5, 290, 550, 110, "Correction :")
      SetGadgetFont(#Frame3D_2, FontID1)
      EditorGadget(#Editor_1, 10, 310, 540, 80 ,#PB_Editor_ReadOnly)
      ButtonGadget(#Button_0, 440, 270, 115, 20, "Lancer le QCM")
      SetGadgetFont(#Button_0, FontID1)
      ProgressBarGadget(#ProgressBar_1, 102, 418, 460, 18, 0, 500)
    EndIf
  EndIf
EndProcedure

Open_Window_1()
AddGadgetItem(#Editor_0, -1,Intro1$)
AddGadgetItem(#Editor_0, -1,Intro2$)
FirstElement(Quest())
Th = CreateThread(@Laps(),0)
PauseThread(Th)

Repeat ; Start of the event loop
  Event = WaitWindowEvent() ; This line waits until an event is received from Windows
  GadgetID = EventGadget() ; Is it a gadget event?
  If Event = #PB_Event_Menu
    MenuID = EventMenu()
    If MenuID = #MENU_4
      Debug "GadgetID: #MENU_4"
      End
    EndIf
  EndIf
  If Event = #PB_Event_Gadget
    If GadgetID = #Button_0
      If Quest()\Libel="Fin"
        MessageRequester("Note", "Votre Note est de :"+Str(Note)+" / "+Str(Nb)+"  soit : "+StrF(Note*20/Nb,2)+" sur 20" )
        End
      EndIf
      If GetGadgetText(#Button_0)<>"Valider"
        SetGadgetText(#Button_0,"Valider" )
        ResumeThread(Th)
        n+1
        Questionne()
      Else
        If GetGadgetState(#ProgressBar_1)=500
          ResumeThread(Th)
        Else
          PauseThread(Th)
          SetGadgetText(#Button_0,"Détail Réponse" )
          SetGadgetState(#ProgressBar_1,0)
          SetGadgetText(#Button_0,"Question Suivante" )
          Reponse()
        EndIf
      EndIf
    EndIf
  EndIf
Until Event = #PB_Event_CloseWindow ; End of the event loop
End


Denis

Bonne Jounée à tous
Répondre