Page 1 sur 2

Vraimant le C, c pas pour moi...

Publié : jeu. 28/juil./2005 15:39
par gansta93
Bonjour,

D'après ce qu'explique cette url, quelqu'un pourait-il me faire un exemple d'un applet du panneau de config ?

Merci d'avance.

Publié : jeu. 28/juil./2005 18:39
par Droopy
Tu peux accéder aux panneau de config sans connaitre le C

Code : Tout sélectionner

; Panneau de config
RunProgram("control.exe","","")

; Imprimantes
RunProgram("control.exe","Printers","")

; Propriétés système
RunProgram("rundll32.exe","shell32.dll,Control_RunDLL sysdm.cpl","")

; Propriété réseau XP
RunProgram("control.exe","netconnections","")

; Propriété réseau 98
RunProgram("rundll32.exe","shell32.dll,Control_RunDLL netcpl.cpl","")

Publié : jeu. 28/juil./2005 18:51
par gansta93
Je sais, mais ce n'est pas ce que je veux. Ce que je veux moi, c'est créer mon élément du panneau de configuration. Et là, tout ce que je sais, c'est qu'il faut créer un fichier dll qui contient au moins la fonction CPLApplet et c'est là que se pause le problème parce que je ne comprand pas les paramètre qui sont requis pour cette fonction. J'ai aussi un exemple en delphy, qui est un langage dont mon expérience est quasi nule. Donc si quelqu'un pouvait m'aider, ça serait cool.

Merci d'avance.

Publié : jeu. 28/juil./2005 19:04
par Dr. Dri
vachement intéressant comme truc, je jette un coup d'oeil ^^

Dri

Publié : jeu. 28/juil./2005 19:29
par KarLKoX

Code : Tout sélectionner

; http://www.codeproject.com/shell/cpl.asp
; 
;  CONTROL.EXE will answer this message And launch an applet
; 
;  WM_CPL_LAUNCH
; 
;       wParam      - window handle of calling app
;       lParam      - LPTSTR of name of applet To launch
; 
;  WM_CPL_LAUNCHED
; 
;       wParam      - TRUE/FALSE If applet was launched
;       lParam      - NULL
; 
;  CONTROL.EXE will post this message To the caller when the applet returns
;  (ie., when wParam is a valid window handle)
; 
; 
#WM_CPL_LAUNCH    = #WM_USER + 1000
#WM_CPL_LAUNCHED  = #WM_USER + 1001

Structure CPLINFO
  idIcon.l                  ; icon resource id, provided by CPlApplet()
  idName.l                  ; name string res. id, provided by CPlApplet()
  idInfo.l                  ; info string res. id, provided by CPlApplet()
  lData.l                   ; user defined data
EndStructure

Structure NEWCPLINFO
  dwSize.l                  ; similar to the commdlg
  dwFlags.l
  dwHelpContext.l           ; help context to use
  lData.l                   ; user defined data
  hIcon.l                   ; icon to use, this is owned by CONTROL.EXE (may be deleted)
  szName.s[32]              ; short name
  szInfo.s[64]              ; long name (status line)
  szHelpFile.s[128]         ; path to help file to use
EndStructure

; The messages CPlApplet() must handle: 

#CPL_DYNAMIC_RES = 0
#CPL_INIT        = 1
;  This message is sent To indicate CPlApplet() was found.
;  lParam1 And lParam2 are not defined.
;  Return TRUE Or FALSE indicating whether the control panel should proceed.

#CPL_GETCOUNT    = 2
;  This message is sent To determine the number of applets To be displayed.
;  lParam1 And lParam2 are not defined.
;  Return the number of applets you wish To display in the control
;  panel window.

#CPL_INQUIRE     = 3
;  This message is sent For information about each applet.
;
;  A CPL SHOULD HANDLE BOTH THE CPL_INQUIRE And CPL_NEWINQUIRE MESSAGES.
;  The developer must not make any assumptions about the order Or dependance
;  of CPL inquiries.
;
;  lParam1 is the applet number To register, a value from 0 To
;  (CPL_GETCOUNT - 1).  lParam2 is a far ptr To a CPLINFO Structure.
;  Fill in CPLINFO's idIcon, idName, idInfo and lData fields with
;  the resource id For an icon To display, name And description string ids,
;  And a long Data item associated with applet #lParam1.  This information
;  may be cached by the caller at runtime And/Or across sessions.
;  To prevent caching, see CPL_DYNAMIC_RES, above.

#CPL_SELECT      = 4
;  The CPL_SELECT message has been deleted.

#CPL_DBLCLK      = 5
;  This message is sent when the applet's icon has been double-clicked
;  upon.  lParam1 is the applet number which was selected.  lParam2 is the
;  applet's lData value.
;  This message should initiate the applet's dialog box. 

#CPL_STOP        = 6
;  This message is sent For each applet when the control panel is exiting.
;  lParam1 is the applet number.  lParam2 is the applet's lData  value.
;  Do applet specific cleaning up here.

#CPL_EXIT        = 7
;  This message is sent just before the control panel calls FreeLibrary.
;  lParam1 And lParam2 are not defined.
;  Do non-applet specific cleaning up here.

#CPL_NEWINQUIRE  = 8
; Same as CPL_INQUIRE execpt lParam2 is a pointer To a NEWCPLINFO struct.
;
;  A CPL SHOULD HANDLE BOTH THE CPL_INQUIRE And CPL_NEWINQUIRE MESSAGES.
;  The developer must not make any assumptions about the order Or dependance
;  of CPL inquiries.

#CPL_STARTWPARMSA= 9
#CPL_STARTWPARMSW= 10
; this message parallels CPL_DBLCLK in that the applet should initiate
; its dialog box.  where it differs is that this invocation is coming
; out of RUNDLL, And there may be some extra directions For execution.
; lParam1: the applet number.
; lParam2: an LPSTR To any extra directions that might exist.
; returns: TRUE If the message was handled; FALSE if not.

; This message is internal To the Control Panel And MAIN applets.
; It is only sent when an applet is invoked from the Command line
; during system installation.
#CPL_SETUP       = 200

Declare Handle_CPL_INIT(lParam1, lParam2)
Declare Handle_CPL_GETCOUNT(lParam1, lParam2)
Declare Handle_CPL_INQUIRE(lParam1, lParam2)
Declare Handle_CPL_SELECT(lParam1, lParam2)
Declare Handle_CPL_DBLCLK(lParam1, lParam2)
Declare Handle_CPL_STOP(lParam1, lParam2)
Declare Handle_CPL_EXIT(lParam1, lParam2)
Declare Handle_CPL_NEWINQUIRE(lParam1, lParam2)
Declare Handle_CPL_STARTWPARMSA(lParam1, lParam2)
Declare Handle_CPL_STARTWPARMSW(lParam1, lParam2)
Declare Handle_CPL_SETUP(lParam1, lParam2)

Declare MyWindow()
Dim ptrFunc.l(10)

; The CPL_INIT message is sent To a Control Panel application To prompt it To perform Global initialization, 
; especially memory allocation.
; Return Values: If initialization succeeds, a Control Panel application should Return nonzero. 
; Otherwise, it should Return zero. If the application returns zero, the controlling application ends communication 
; And releases the DLL containing the Control Panel application.
;
; Remarks: Because this is the only way a Control Panel application can signal an error condition, 
; the application should allocate memory in response To this message. This message is sent immediately after the DLL containing the application is loaded via LoadLibrary().
Procedure Handle_CPL_INIT(lParam1, lParam2)

  ptrFunc(#CPL_INIT)        = @Handle_CPL_INIT()
  ptrFunc(#CPL_GETCOUNT)    = @Handle_CPL_GETCOUNT()
  ptrFunc(#CPL_INQUIRE)     = @Handle_CPL_INQUIRE()
  ptrFunc(#CPL_SELECT)      = @Handle_CPL_SELECT()
  ptrFunc(#CPL_DBLCLK)      = @Handle_CPL_DBLCLK()
  ptrFunc(#CPL_STOP)        = @Handle_CPL_STOP()
  ptrFunc(#CPL_EXIT)        = @Handle_CPL_EXIT()
  ptrFunc(#CPL_NEWINQUIRE)  = @Handle_CPL_NEWINQUIRE()
  ptrFunc(#CPL_STARTWPARMSA)= @Handle_CPL_STARTWPARMSA()
  ptrFunc(#CPL_STARTWPARMSW)= @Handle_CPL_STARTWPARMSW()
  ptrFunc(#CPL_SETUP)       = @Handle_CPL_SETUP()
  
  MyWindow()
  MessageRequester("Info", "Handle_CPL_INIT")
  
  ProcedureReturn 1
EndProcedure

; The The CPL_GETCOUNT message is sent To a Control Panel application To retrieve the number of dialog boxes 
; supported by the application.
; Return Values: A Control Panel application should Return the number of dialog boxes it supports.
; 
; Remarks: This message is sent immediately after the CPL_INIT message.
Procedure Handle_CPL_GETCOUNT(lParam1, lParam2)

  MessageRequester("Info", "Handle_CPL_GETCOUNT")
  
  ProcedureReturn 1
EndProcedure

Procedure Handle_CPL_INQUIRE(lParam1, lParam2)

  MessageRequester("Info", "Handle_CPL_INQUIRE")
  
  ProcedureReturn 0
  
EndProcedure

Procedure Handle_CPL_SELECT(lParam1, lParam2)

  MessageRequester("Info", "Handle_CPL_SELECT")
  
  ProcedureReturn 0
EndProcedure

; The CPL_DBLCLK message is sent To a Control Panel application when the user double-clicks the icon of a dialog box 
; supported by the application.
; 
; Parameters: Value of aLParam1_in. Specifies the dialog box number. Value of lParam2 Specifies the value that 
; the Control Panel application loaded into the lData member of the CPLINFO Or NEWCPLINFO Structure 
; For the dialog box. The application loads lData member in response To the CPL_INQUIRE Or CPL_NEWINQUIRE message.
; Return Values: If a Control Panel application processes this message successfully, it should Return zero.
; 
; Remarks: In response To this message, a Control Panel application must display the corresponding dialog box. 
Procedure Handle_CPL_DBLCLK(lParam1, lParam2)

  MessageRequester("Info", "Handle_CPL_DBLCLK")
  
  ProcedureReturn 0
  
EndProcedure

; The CPL_STOP message is sent once For each dialog box when the application controlling the Control Panel 
; application closes.
; Parameters: Value of aLParam1_in. Specifies the dialog box number. Value of lParam Specifies the value 
; that the Control Panel application loaded into the lData member of the CPLINFO Or NEWCPLINFO Structure For 
; the dialog box. The application loads lData member in response To the CPL_INQUIRE Or CPL_NEWINQUIRE message.
; Return Values: A Control Panel application should Return the number of dialog boxes it supports.
; 
; Remarks: In response To this message, a Control Panel application must perform cleanup For the given dialog box. 
Procedure Handle_CPL_STOP(lParam1, lParam2)

  MessageRequester("Info", "Handle_CPL_STOP")
  
  ProcedureReturn 1
  
EndProcedure

; The  CPL_EXIT message is sent once To a Control Panel application before the controlling application releases 
; the DLL containing the application.
; Return Values: A Control Panel application should Return the number of dialog boxes it supports.
; 
; Remarks: This message is sent after the last CPL_STOP message is sent. In response To this message, a Control 
; Panel application must free any memory that it has allocated And perform Global-level cleanup. 
Procedure Handle_CPL_EXIT(lParam1, lParam2)

  MessageRequester("Info", "Handle_CPL_EXIT")
  
  ProcedureReturn 1
  
EndProcedure

; The  CPL_NEWINQUIRE message is sent To a Control Panel application To request information about a dialog box 
; that the application supports.
; Parameters: Value of aLParam1_in. Specifies the dialog box number. Value of lParam2 Specifies the address 
; of a NEWCPLINFO Structure. The Control Panel application should fill this Structure with information about 
; the dialog box.
; Return Values: If a Control Panel application processes this message successfully, it should Return zero.
; 
; Remarks: This message is sent once For each dialog box supported by the application. 
; It is sent immediately after the CPL_GETCOUNT message. Upon receiving this message, 
; the application can initialize the dialog box. If the application must allocate memory, 
; it should do so in response To the CPL_INIT message. 
Procedure Handle_CPL_NEWINQUIRE(lParam1, lParam2)

  MessageRequester("Info", "Handle_CPL_NEWINQUIRE")
  
  ProcedureReturn 0
  
EndProcedure

Procedure Handle_CPL_STARTWPARMSA(lParam1, lParam2)

  MessageRequester("Info", "Handle_CPL_STARTWPARMSA")
  
EndProcedure

Procedure Handle_CPL_STARTWPARMSW(lParam1, lParam2)

  MessageRequester("Info", "Handle_CPL_STARTWPARMSW")
  
EndProcedure

; The  CPL_SELECT message is sent To a Control Panel application when the user selects the icon of a dialog box 
; supported by the application. Value of aLParam1_in. Specifies the dialog box number. Value of lParam2 Specifies 
; the value that the Control Panel application loaded into the  lData member of the  CPLINFO Or  NEWCPLINFO 
; Structure For the dialog box. The application loads the  lData member in response To the  CPL_INQUIRE Or  
; CPL_NEWINQUIRE message.
; 
; Return Values: If a Control Panel application processes this message successfully, it should Return zero. 
Procedure Handle_CPL_SETUP(lParam1, lParam2)

  MessageRequester("Info", "Handle_CPL_SETUP")
  
EndProcedure

Procedure MyWindow()
  
  If OpenWindow(0, 100, 200, 195, 260, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget, "PureBasic Applet")
    Repeat
      EventID = WaitWindowEvent()
      If EventID = #PB_Event_CloseWindow
        Quit = 1
      EndIf
    Until Quit = 1
  EndIf
 End
EndProcedure

ProcedureDLL CPlApplet(hwndCPl, msg, lParam1, lParam2)

  ; Il n'y a rien qui se passe ... comprend pas (ProcedureCDLL donne la même chose
  MessageRequester(Str(msg), "info")
;   If msg = #CPL_INIT
;     MessageRequester("CPL_INIT", "Info")
;     ProcedureReturn Handle_CPL_Init(lParam1, lParam2)
;   Else
;     CallFunctionFast(ptrFunc(msg), lParam1, lParam2)
;   EndIf
  
  ProcedureReturn 0
  
EndProcedure
Je l'ai fait vite fait mais ça ne marche pas, le point d'entré est bon et en cdecl ca ne change rien.
A voir ...

Publié : jeu. 28/juil./2005 19:47
par gansta93
Merci, au moins ça me prouve que ça n'est pas impossible. :-D Je vais voir ça tout de suite en compilant ce que ça donne.

Encore merci.

Publié : jeu. 28/juil./2005 19:49
par Dr. Dri
essaye le CPLApplet avec un CPL majuscule, il me smble que les dll sont sensibles à la casse

Dri

Publié : jeu. 28/juil./2005 19:56
par Dr. Dri
la doc de la page que tu nous a filée ne semble pas aussi complète que ce qu'on trouve dans le code de karlkox... néanmoins j'ai pris le temps de te coder ca... un genre de ptit squelette...

Code : Tout sélectionner

Enumeration 1
  #CPL_Init
  #CPL_GetCount
  #CPL_Inquire
  #CPL_Select
  #CPL_DblClk
  #CPL_Stop
  #CPL_Exit
  #CPL_NewInquire
EndEnumeration

Structure CPL_Info
 	hIcon.l
  pszName.s
  pszInfo.s
  lData.l ;je n'ai pas compris à quoi il sert
EndStructure

Structure NewCPL_Info
  dwSize.l
  dwFlags.l
  dwHelpContext.l
  lData.l
  hIcon.l
  szName.b[32]
  szInfo.b[64]
  szHelpFile.b[128]
EndStructure

;------------------------------------------------------------

#NB_Applets = 1
Dim    CPL_Infos.   CPL_Info(#NB_Applets-1)
Dim NewCPL_Infos.NewCPL_Info(#NB_Applets-1)
                                       ;-1 parce qu'on démarre à zéro

ProcedureDLL.l CPLApplet(hwndCPL.l, Msg.l, wParam.l, lParam.l)
  Protected ReturnValue.l
  
  Select Msg
    Case #CPL_Init
      ;ici tu initialise tout
      ;par exemple tu remplis le tableau CPL_Infos
      ReturnValue = #True
    Case #CPL_GetCount
      ReturnValue = #NB_Applets;nombre d'applets, à toi de gérer
                               ;si t'as deux applets à gérer par exemple,
                               ;ca va générer deux icônes dans le panneau de configs
    Case #CPL_Inquire
      ;si jamais t'as rempli le tableau ca peut donner
      i = wParam
      CopyMemory(CPL_Infos(i), lParam, SizeOf(CPL_Info))
    Case #CPL_Select
      ;ici je n'ai pas compris à quoi ca sert
    Case #CPL_DblClk
      ;ici j'imagine que tu ouvres tes fenetres de config par exemple
    Case #CPL_Stop
      ;ici l'utilisateur a fermé le panneau de configs
      ;les cpl windows ne se ferment pas (à ce que j'ai pu constater)
      ;libre à toi de l'ignorer
    Case #CPL_Exit
      ;fermeture de windows, donc du panneau (définitivement)
      ;ici, libère toute la mémoire allouée
      ;(mémoire, fenetres, gadgets etc)
    Case #CPL_NewInquire
      ;même principe que l'inquire
      i = wParam
      CopyMemory(NewCPL_Infos(i), lParam, SizeOf(NewCPL_Info))
  EndSelect
  
  ProcedureReturn ReturnValue
EndProcedure
Dri ;)

PS. pas testé

Publié : jeu. 28/juil./2005 20:09
par gansta93
Merci Dri, je vais tester ça. En revanche, j'ai cru comprendre que les applets avaient besoin des resources. Hors on dirait que PB ignore toutes les resources (Tèmes XP, informations de version, et autres resources choisies dans l'onglet resources). Cela pause donc problème. Pourquoi Pure ignore-t-il les resources pour les DLLs ?

Publié : jeu. 28/juil./2005 21:38
par Dr. Dri
regarde les options de compilation avec la 3.94

Dri

Publié : jeu. 28/juil./2005 21:51
par gansta93
Oui, j'ai tout définit, mais tout est ignoré lorsque je compile. Si ct un exécutable, ça aurait marché mais là c une dll alors ça marche pas. Je ne comprand pas pourquoi.

Publié : jeu. 28/juil./2005 22:29
par Dr. Dri
oké je vois... donc à signaler...
bug, oubli ou prévu, faut faire savoir qu'on en a besoin ^^

Dri

POUF !!! :-P

Publié : mar. 09/août/2005 17:34
par gansta93
Salut à tous,

CT trop simple, dans CodeArchiv. Le seul problème est que je ne comprand pas l'allemand, donc si quelqu'un peut traduir svp... j'ai peur du résultat de la traduction d'un traducteur automatique. ;-)

Code : Tout sélectionner

; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=2318&highlight=
; Author: Andreas
; Date: 18. September 2003


; Frage:
;   Welche Vorraussetzungen sind nötig, damit ein Programm in der Systemsteuerung angezeigt wird ?
; Antwort:
;   In der Systemsteuerung werden die CPL-Dateien die sich im Systemordner befinden angezeigt.
;   CPL-Dateien sind nichts anderes als DLL's mit einer exportierten Funktion. Die Funktion
;   heisst CPIApplet und niemals anders. 
;   Was Du also machen musst ist folgendes:
;   In PB die Dll erstellen, umbenennen in CPL und in die Windows-System-Ordner kopieren. 

;   Beispiel : 

;###################### 
;CPIApplet-Grundgerüst 
;###################### 
;Author : Andreas 
;###################### 
;Compiler-Option: DLL 
;nach Erstellen in CPL umbenennen und in 
;den Windows System-Ordner kopieren 
;Danach erscheint das icon in der Systemsteuerung 
;###################### 
;Das Beispiel öffnet lediglich Notepad und zeigt die 
;Autoexec.bat an. 
;###################### 


ProcedureDLL.l CPlApplet(hwndCPI.l,uMsg.l,lParam1.l,lParam2.l) 
  Shared Name.s,Info.s 
  
  #CPL_DBLCLK  = 5 
  #CPL_EXIT = 7 
  #CPL_GETCOUNT = 2 
  #CPL_INIT = 1 
  #CPL_INQUIRE = 3 
  #CPL_STOP = 6 
  #CPL_NEWINQUIRE = 8 
  
  Structure NEWCPLINFO 
    dwSize.l 
    dwFlags.l 
    dwHelpContext.l 
    lData.l 
    hIcon.l 
    szName.b[32] 
    szInfo.b[64] 
    szHelpFile.b[128] 
  EndStructure 
  
  Select uMsg 
    Case #CPL_INIT 
      ;beim Initieren die Variablen füllen 
      Name = "Das ist der Name";Name der unter dem Icon erscheint (max. 32) 
      Info = "Das ist die Info";Info die in der Statusbar erscheint (max. 64) 
      result = 1 
    Case #CPL_GETCOUNT 
      result = 1 ;1 Icon 
    Case #CPL_NEWINQUIRE 
      ;Informationen setzen 
      *cp.NEWCPLINFO = lParam2 
      *cp\dwSize = SizeOf(NEWCPLINFO) 
      *cp\hIcon = ExtractIcon_(0,"Notepad.exe",0) 
      PokeS(@*cp\szName[0], Name) 
      PokeS(@*cp\szInfo[0], Info) 
      result = 0 
    Case  #CPL_DBLCLK 
      ;hier passiert alles was beim Doppelklick auf das Icon passieren soll 
      ;in diesem Fall wird Notepad gestartet 
      RunProgram("Notepad.exe","c:\autoexec.bat", "c:\", 0) 
      result = 0 
    Case #CPL_STOP 
      result = 0 
    Case #CPL_EXIT 
      result = 0 
  EndSelect 
  ProcedureReturn result 
EndProcedure  
Nouveau sujet : Vraiment la simplicité, c pas pour moi ! :-P

Publié : mar. 09/août/2005 18:36
par nico
Tu l'utilise comment cette procédure?

:?:

Publié : mar. 09/août/2005 18:41
par gansta93
En fait comme dis au début c'est une procedureDll donc il faut créer une DLL puis changer son extension en .cpl puis la placer dans le répertoir Windows\System ou Winnt\System32. En suite quand on ouvre le paneau de config, l'icône devrait apparaître, j'admet ne pas avoir essayé le code. :oops: Je voulais d'abord voir la traduction.