IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Discussion :

[Dev-C++] Subclassing dans une classe


Sujet :

Windows

  1. #1
    sas
    sas est déconnecté
    Membre éprouvé

    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 54
    Points : 1 257
    Points
    1 257
    Par défaut [Dev-C++] Subclassing dans une classe
    je ne comprends pas pourquoi le compilo me retourne cette erreur :

    src/Gfx.cpp: In member function `void CGfx::SubClass()':
    src/Gfx.cpp:90: error: aggregate value used where an integer was expected
    src/Gfx.cpp:90: error: invalid conversion from `LONG' to `LRESULT (*)(HWND__*,
    unsigned int, unsigned int, long int)'

    quand dans une classe je déclare ça:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    LRESULT CALLBACK SubClassPictureBoxProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
    void SubClass(void);    
    WNDPROC	pSubClassPictureBoxProc;
    qqn pourrait-il m'expliquer??

    et j'appelle SetWindowLong avec :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    void
    CGfx::SubClass(void)
    {
            pSubClassPictureBoxProc = SetWindowLong(m_hWndCtrl, GWL_WNDPROC, (LONG)SubClassPictureBoxProc);
    }

  2. #2
    Expert éminent sénior

    Homme Profil pro
    pdg
    Inscrit en
    Juin 2003
    Messages
    5 750
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : pdg

    Informations forums :
    Inscription : Juin 2003
    Messages : 5 750
    Points : 10 669
    Points
    10 669
    Billets dans le blog
    3
    Par défaut
    Est-ce que SubClassPictureBoxProc est static ?

  3. #3
    sas
    sas est déconnecté
    Membre éprouvé

    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 54
    Points : 1 257
    Points
    1 257
    Par défaut
    ha ben non j'ai pas mis en static, il le faut?
    c'est comme pour les procédure de boite de dialogues ?

    je les déclare comme ça dans les classes

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    static BOOL CALLBACK DlgFunc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
    et j'utilise SetProp dans la fonction
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    const char pMyDialogClass[]  = "DialogDlgClass";
    
    BOOL CALLBACK
    CMyDialogDlg::DlgFunc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch (msg) 
        {
        	case WM_INITDIALOG:
        	{
        		CMyDialogDlg *phWnd = (CMyDialogDlg *)lParam;
        		SetProp(hDlg, pMyDialogClass, phWnd);
        	   return phWnd->OnInit(hDlg);
        	}
        	break;   
                   
        	case WM_COMMAND:
        	{
        	    CMyDialogDlg *phWnd = (CMyDialogDlg *)GetProp(hDlg, pMyDialogClass);
               return phWnd->OnCommand(hDlg, wParam, lParam);
        	}
         	break;
         			
            case WM_DESTROY:
            {
                CMyDialogDlg *phWnd = (CMyDialogDlg *)GetProp(hDlg, pMyDialogClass);
                RemoveProp(hDlg, pMyDialogClass);
            }
            break;
    	}
    	
    	return FALSE;
    }

  4. #4
    Expert éminent sénior

    Homme Profil pro
    pdg
    Inscrit en
    Juin 2003
    Messages
    5 750
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : pdg

    Informations forums :
    Inscription : Juin 2003
    Messages : 5 750
    Points : 10 669
    Points
    10 669
    Billets dans le blog
    3
    Par défaut
    Oui, sinon un paramètre supplémentaire this est créé.
    http://c.developpez.com/faq/cpp/?pag...onction_membre

  5. #5
    sas
    sas est déconnecté
    Membre éprouvé

    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 54
    Points : 1 257
    Points
    1 257
    Par défaut
    oki avais pas fait le rapprochement


  6. #6
    sas
    sas est déconnecté
    Membre éprouvé

    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 54
    Points : 1 257
    Points
    1 257
    Par défaut
    je croyais que j'allais facilement m'en sortir avec le tutorial que tu m'as filé mais en fait non

    j'essaye de construire une classe qui va faire du subclassing sur des contrôles, afin d'appliquer les couleurs, les fontes, les images automatiquement....

    le problème c'est que dans les fonctions membres de subclassing je ne peux pas accèder à mes variables le compilo me sort des erreurs du type :

    In static member function `static LRESULT
    CGfx:ictureBoxProc(HWND__*, unsigned int, unsigned int, long int)':
    error: invalid use of member `CGfx::pPictureBoxProc' in static member function

    et ça pour toutes les variables utilisées dans les fonctions de subclassing

    voici le header :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    
    #ifndef _GFX_
    #define _GFX_
    
    #include "OlePicture.h"
    
    #define COLOR_BACKGROUND_DIALOG 0x404040
    #define COLOR_RED 0xC0
    #define COLOR_WHITE 0xFFFFFF
    #define COLOR_ORANGE 0xAEE8FB
    #define COLOR_GRIS 0x808080
    #define COLOR_YELLOW 0xC0FFFF
    #define COLOR_BLACK 0x0
    #define COLOR_BLUE 0xFF8080
    
    class CGfx
    {
    public:
        
        CGfx(HWND hDlg, int idCtrl);
        ~CGfx();
       
        void Destroy(void);
        
    private :
        
        static LRESULT CALLBACK StaticProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
        static LRESULT CALLBACK EditBoxProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
        static LRESULT CALLBACK PictureBoxProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
        
        WNDPROC	pStaticProc;
        WNDPROC	pEditBoxProc;
        WNDPROC	pPictureBoxProc;
        
        void SubClass(void);
        
        IPicture *m_pIPicture;
        
        long m_BackColor;
        long m_TextColor;
        int m_BkMode;
        
        HWND m_hWndCtrl;
        HWND m_hWndDlg;
        int m_idCtrl;
        int m_typeCtrl;
        int m_colorCtrl;
    };    
    
    #endif
    et le source :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    #include <windows.h>
    #include <commctrl.h>
    #include <ocidl.h>
    
    #include "Gfx.h"
    
    ///////////////////////////////////////////
    // Les id des Contrôles pour la classe Gfx
    //
    // 10xxx &#58; Static
    // 11xxx &#58; Image
    // 12xxx &#58; Edit Box
    // 13xxx &#58; Button
    // 14xxx &#58; Combo Box
    // 15xxx &#58; Check Box
    // 16xxx &#58; Radio Button
    // 17xxx &#58; Group Box
    // 18xxx &#58; Listview
    // 19xxx &#58; Treeview
    //
    // 1x0xx &#58; Défaut
    // 1x1xx &#58; COLOR_RED COLOR_WHITE TRANSPARENT
    // 1x2xx &#58; COLOR_ORANGE COLOR_GRIS TRANSPARENT
    // 1x3xx &#58; COLOR_ORANGE COLOR_BLACK TRANSPARENT
    // 1x4xx &#58; COLOR_YELLOW COLOR_BLACK TRANSPARENT
    // 1x5xx &#58; COLOR_ORANGE COLOR_BLUE TRANSPARENT
    // 1x6xx &#58; COLOR_YELLOW COLOR_BLACK OPAQUE
    // 1x7xx &#58; COLOR_WHITE COLOR_BLACK OPAQUE
    // 1x8xx &#58; COLOR_BACKGROUND_DIALOG COLOR_GRIS TRANSPARENT
    
    CGfx&#58;&#58;CGfx&#40;HWND hDlg, int idCtrl&#41;
    &#123;
        int iGroupCtrl;
        char buf&#91;100&#93;;
        
        m_hWndDlg = hDlg;
        m_idCtrl = idCtrl;
        m_hWndCtrl = GetDlgItem&#40;m_hWndDlg, m_idCtrl&#41;;
        
        m_typeCtrl = &#40;m_idCtrl - 10000&#41; / 1000;
        m_colorCtrl = &#40;m_idCtrl - &#40;m_typeCtrl * 1000 + 10000&#41;&#41; / 100;
    
        switch &#40;m_colorCtrl&#41;
        &#123;
            case 1&#58;
            &#123;
                m_BackColor = COLOR_RED;
                m_TextColor = COLOR_WHITE;
            &#125;    
            break;
            case 2&#58;
            &#123;
                m_BackColor = COLOR_ORANGE;
                m_TextColor = COLOR_GRIS;
            &#125;    
            break;
            case 3&#58;
            &#123;
                m_BackColor = COLOR_ORANGE;
                m_TextColor = COLOR_BLACK;
            &#125;    
            break;
            case 4&#58;
            &#123;
                m_BackColor = COLOR_YELLOW;
                m_TextColor = COLOR_BLACK;
            &#125;    
            break;
            case 5&#58;
            &#123;
                m_BackColor = COLOR_ORANGE;
                m_TextColor = COLOR_BLUE;           
            &#125;    
            break;
            case 6&#58;
            &#123;
                m_BackColor = COLOR_YELLOW;
                m_TextColor = COLOR_BLACK;
            &#125;    
            break;
            case 7&#58;
            &#123;
                m_BackColor = COLOR_WHITE;
                m_TextColor = COLOR_BLACK;
            &#125;    
            break;
            case 8&#58;
            &#123;
                m_BackColor = COLOR_BACKGROUND_DIALOG;
                m_TextColor = COLOR_GRIS;
            &#125;    
            break;
        &#125;
        
        if &#40;m_typeCtrl == 1&#41; m_BkMode = OPAQUE;
        else m_BkMode = TRANSPARENT;
        
        m_pIPicture = NULL;
        
        pStaticProc = NULL;
        pEditBoxProc = NULL;
        pPictureBoxProc = NULL;
            
        SubClass&#40;&#41;;    
    &#125;
    
    CGfx&#58;&#58;~CGfx&#40;&#41;
    &#123;
    &#125;
    
    void
    CGfx&#58;&#58;SubClass&#40;void&#41;
    &#123;
        if &#40;m_typeCtrl == 0&#41;
        &#123;
            pStaticProc = &#40;WNDPROC&#41;&#58;&#58;SetWindowLong&#40;m_hWndCtrl, GWL_WNDPROC, reinterpret_cast<long>&#40;StaticProc&#41;&#41;;
        &#125;
        if &#40;m_typeCtrl == 1&#41;
        &#123;
            pPictureBoxProc = &#40;WNDPROC&#41;&#58;&#58;SetWindowLong&#40;m_hWndCtrl, GWL_WNDPROC, reinterpret_cast<long>&#40;PictureBoxProc&#41;&#41;;
        &#125;
        if &#40;m_typeCtrl == 2&#41;
        &#123;
            pEditBoxProc = &#40;WNDPROC&#41;&#58;&#58;SetWindowLong&#40;m_hWndCtrl, GWL_WNDPROC, reinterpret_cast<long>&#40;EditBoxProc&#41;&#41;;
        &#125;
        
    &#125;
    
    LRESULT CALLBACK
    CGfx&#58;&#58;StaticProc&#40;HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam&#41;
    &#123;
    	switch &#40;msg&#41;
    	&#123;
        	case WM_CTLCOLORSTATIC &#58;
            &#123;   
               HBRUSH hbrush = CreateSolidBrush&#40;m_BackColor&#41;;
            
               SelectObject&#40;&#40;HDC&#41;wParam, hbrush&#41;;
               SetBkMode&#40;&#40;HDC&#41;wParam, m_BkMode&#41;;
               SetBkColor&#40;&#40;HDC&#41;wParam, m_BackColor&#41;;
               SetTextColor&#40;&#40;HDC&#41;wParam, m_TextColor&#41;;
    		    
    		   return &#40;LRESULT&#41;hbrush;
            &#125;
            break;
        
        	default&#58;
        		return CallWindowProc&#40;pStaticProc, hwnd, msg, wParam, lParam&#41; ;
    	&#125;
    &#125;
    
    LRESULT CALLBACK
    CGfx&#58;&#58;EditBoxProc&#40;HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam&#41;
    &#123;
    	switch &#40;msg&#41;
    	&#123;
        	case WM_CTLCOLOREDIT&#58;
            &#123;
               HBRUSH hbrush = CreateSolidBrush&#40;m_BackColor&#41;;
            
               SelectObject&#40;&#40;HDC&#41;wParam, hbrush&#41;;
               SetBkMode&#40;&#40;HDC&#41;wParam, m_BkMode&#41;;
               SetBkColor&#40;&#40;HDC&#41;wParam, m_BackColor&#41;;
               SetTextColor&#40;&#40;HDC&#41;wParam, m_TextColor&#41;;
    		    
    		   return &#40;LRESULT&#41;hbrush;
            &#125;
            break;
        
        	default&#58;
        		return CallWindowProc&#40;pEditBoxProc, hwnd, msg, wParam, lParam&#41; ;
    	&#125;
    &#125;
    
    LRESULT CALLBACK
    CGfx&#58;&#58;PictureBoxProc&#40;HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam&#41;
    &#123;
    	PAINTSTRUCT ps;
    	RECT rc;
    
    	switch &#40;msg&#41;
    	&#123;
        	case WM_ERASEBKGND&#58;
        		GetClientRect&#40;hwnd, &rc&#41;;
        		FillRect&#40;&#40;HDC&#41;wParam, &rc, CreateSolidBrush&#40;COLOR_BACKGROUND_DIALOG&#41;&#41;;
        		return 1;
        
        	case WM_PAINT&#58;    
        		BeginPaint&#40;hwnd, &ps&#41;;
        		GetClientRect&#40;hwnd, &rc&#41;;
        		FillRect&#40;ps.hdc, &rc, CreateSolidBrush&#40;COLOR_BACKGROUND_DIALOG&#41;&#41;;
        		if&#40;m_pIPicture&#41;
        		&#123;
        			OlePicRender&#40;m_pIPicture, ps.hdc, &rc, TRUE&#41;;
        		&#125;
        		EndPaint&#40;hwnd, &ps&#41;;
        		return 0;
        
        	default&#58;
        		return CallWindowProc&#40;pPictureBoxProc, hwnd, msg, wParam, lParam&#41; ;
    	&#125;
    &#125;
    
    void
    CGfx&#58;&#58;Destroy&#40;void&#41;
    &#123;
        if &#40;m_typeCtrl == 0&#41; SetWindowLong&#40;m_hWndCtrl, GWL_WNDPROC, &#40;DWORD&#41;StaticProc&#41;;
        if &#40;m_typeCtrl == 1&#41; SetWindowLong&#40;m_hWndCtrl, GWL_WNDPROC, &#40;DWORD&#41;pPictureBoxProc&#41;;
        if &#40;m_typeCtrl == 2&#41; SetWindowLong&#40;m_hWndCtrl, GWL_WNDPROC, &#40;DWORD&#41;pEditBoxProc&#41;;
    &#125;
    je suis un peu perdu pour coder cette classe.....

  7. #7
    Expert éminent sénior

    Homme Profil pro
    pdg
    Inscrit en
    Juin 2003
    Messages
    5 750
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : pdg

    Informations forums :
    Inscription : Juin 2003
    Messages : 5 750
    Points : 10 669
    Points
    10 669
    Billets dans le blog
    3
    Par défaut
    C'est un problème classique. On ne peut pas associer une fonction membre et une instance de classe comme cela. Car tu as 2 données à associer:
    - l'adresse de la fonction
    - l'adresse de l'instance de classe
    Il te faut associer une fonction statique comme WndProc, et associer ton instance C++ à ta HWND, via SetProp ou GWL_USERDATA par exemple.
    Y'a pas mal de littérature là dessus.
    http://www.relisoft.com/win32/generic.html

  8. #8
    sas
    sas est déconnecté
    Membre éprouvé

    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 54
    Points : 1 257
    Points
    1 257
    Par défaut
    j'ai regardé le site et c'est pas simple de tout comprendre
    quelle syntaxe dois-je utiliser pour faire l'association ??

    j'ai tenté ce code, ça compile mais à l'éxécution ça crash!!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    const char pStaticProcClass&#91;&#93;  = "StaticProcClass";
    const char pEditBoxProcClass&#91;&#93;  = "EditBoxProcClass";
    const char pPictureBoxProcClass&#91;&#93;  = "PictureBoxProcClass";
    
    CGfx&#58;&#58;CGfx&#40;HWND hDlg, int idCtrl&#41;
    &#123;   '
         '
         '   rien à changer au dessus
         '
         '
        SubClass&#40;this&#41;;    
    &#125;
    
    CGfx&#58;&#58;~CGfx&#40;&#41;
    &#123;
        if &#40;m_typeCtrl == 0&#41; SetWindowLong&#40;m_hWndCtrl, GWL_WNDPROC, &#40;DWORD&#41;StaticProc&#41;;
        if &#40;m_typeCtrl == 1&#41; SetWindowLong&#40;m_hWndCtrl, GWL_WNDPROC, &#40;DWORD&#41;pPictureBoxProc&#41;;
        if &#40;m_typeCtrl == 2&#41; SetWindowLong&#40;m_hWndCtrl, GWL_WNDPROC, &#40;DWORD&#41;pEditBoxProc&#41;;
    &#125;
    
    void
    CGfx&#58;&#58;SubClass&#40;CGfx *pgfx&#41;
    &#123;
        if &#40;m_typeCtrl == 0&#41;
        &#123;
            SetWindowLong&#40;pgfx->m_hWndCtrl, GWL_USERDATA, &#40;DWORD&#41;pgfx&#41;;
            pgfx->pStaticProc = &#40;WNDPROC&#41;&#58;&#58;SetWindowLong&#40;pgfx->m_hWndCtrl, GWL_WNDPROC, &#40;LONG&#41;pgfx->StaticProc&#41;;
        &#125;
        if &#40;m_typeCtrl == 1&#41;
        &#123;
            SetWindowLong&#40;pgfx->m_hWndCtrl, GWL_USERDATA, &#40;DWORD&#41;pgfx&#41;;
            pgfx->pPictureBoxProc = &#40;WNDPROC&#41;&#58;&#58;SetWindowLong&#40;pgfx->m_hWndCtrl, GWL_WNDPROC, &#40;LONG&#41;pgfx->PictureBoxProc&#41;;
        &#125;
        if &#40;m_typeCtrl == 2&#41;
        &#123;
           SetWindowLong&#40;pgfx->m_hWndCtrl, GWL_USERDATA, &#40;DWORD&#41;pgfx&#41;;
           pgfx->pEditBoxProc = &#40;WNDPROC&#41;&#58;&#58;SetWindowLong&#40;pgfx->m_hWndCtrl, GWL_WNDPROC, &#40;LONG&#41;pgfx->EditBoxProc&#41;;
        &#125;
        
    &#125;
    
    LRESULT CALLBACK
    CGfx&#58;&#58;StaticProc&#40;HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam&#41;
    &#123;
    	switch &#40;msg&#41;
    	&#123;
    	    case WM_CREATE&#58;
    	    &#123;
    	        CGfx *phWnd = &#40;CGfx *&#41;lParam;
        		SetProp&#40;hwnd, pStaticProcClass, phWnd&#41;;
    	    &#125;
            break;
                 
        	case WM_CTLCOLORSTATIC &#58;
            &#123;  
               CGfx *phWnd = &#40;CGfx*&#41;GetProp&#40;hwnd, pStaticProcClass&#41;;
                 
               HBRUSH hbrush = CreateSolidBrush&#40;phWnd->m_BackColor&#41;;
            
               SelectObject&#40;&#40;HDC&#41;wParam, hbrush&#41;;
               SetBkMode&#40;&#40;HDC&#41;wParam, phWnd->m_BkMode&#41;;
               SetBkColor&#40;&#40;HDC&#41;wParam, phWnd->m_BackColor&#41;;
               SetTextColor&#40;&#40;HDC&#41;wParam, phWnd->m_TextColor&#41;;
    		    
    		   return &#40;LRESULT&#41;hbrush;
            &#125;
            break;
            
            case WM_DESTROY&#58;
            &#123;
                RemoveProp&#40;hwnd, pStaticProcClass&#41;;
            &#125;
            break;
        
        	default&#58;
        	&#123;
        	    CGfx *phWnd = &#40;CGfx*&#41;GetProp&#40;hwnd, pStaticProcClass&#41;;
        		return CallWindowProc&#40;phWnd->pStaticProc, hwnd, msg, wParam, lParam&#41; ;
          	&#125;  		
    	&#125;
    &#125;

  9. #9
    Expert éminent sénior

    Homme Profil pro
    pdg
    Inscrit en
    Juin 2003
    Messages
    5 750
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : pdg

    Informations forums :
    Inscription : Juin 2003
    Messages : 5 750
    Points : 10 669
    Points
    10 669
    Billets dans le blog
    3
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
           case WM_CREATE&#58; 
           &#123; 
               CGfx *phWnd = &#40;CGfx *&#41;lParam; 
              SetProp&#40;hwnd, pStaticProcClass, phWnd&#41;; 
           &#125; 
            break;
    Tu t'es bien débrouillé pour passer une instance via lParam lors du CreateWindow ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
           default&#58; 
           &#123; 
               CGfx *phWnd = &#40;CGfx*&#41;GetProp&#40;hwnd, pStaticProcClass&#41;; 
              return CallWindowProc&#40;phWnd->pStaticProc, hwnd, msg, wParam, lParam&#41; ; 
             &#125;
    là c'est le DefWindowProc classique.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
           case WM_CTLCOLORSTATIC &#58; 
            &#123;  
               CGfx *phWnd = &#40;CGfx*&#41;GetProp&#40;hwnd, pStaticProcClass&#41;; 
                  
               HBRUSH hbrush = CreateSolidBrush&#40;phWnd->m_BackColor&#41;; 
            
               SelectObject&#40;&#40;HDC&#41;wParam, hbrush&#41;; 
               SetBkMode&#40;&#40;HDC&#41;wParam, phWnd->m_BkMode&#41;; 
               SetBkColor&#40;&#40;HDC&#41;wParam, phWnd->m_BackColor&#41;; 
               SetTextColor&#40;&#40;HDC&#41;wParam, phWnd->m_TextColor&#41;; 
              
             return &#40;LRESULT&#41;hbrush; 
            &#125; 
            break;
    c'est pas comme ça, plutot dans le genre:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
           case WM_CTLCOLORSTATIC &#58; 
            &#123;  
               CGfx *phWnd = &#40;CGfx*&#41;GetProp&#40;hwnd, pStaticProcClass&#41;; 
               return phWnd->OnCtlColorStatic&#40; &#40;HDC&#41;wParam &#41;;
            &#125; 
            break; 
    
    // ...
    
    LRESULT CGfx&#58;&#58;OnCtlColorStatic&#40; HDC hDC &#41;
    &#123;
        HBRUSH hbrush = CreateSolidBrush&#40; this->m_BackColor&#41;; 
    
        SelectObject&#40; hDC, hbrush&#41;; 
        SetBkMode&#40; hDC, this->m_BkMode&#41;; 
        SetBkColor&#40; hDC, this->m_BackColor&#41;; 
        SetTextColor&#40; hDC, this->m_TextColor&#41;; 
              
        return &#40;LRESULT&#41;hbrush; 
    &#125;

  10. #10
    sas
    sas est déconnecté
    Membre éprouvé

    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 54
    Points : 1 257
    Points
    1 257
    Par défaut
    bon j'ai repris mon code et je l'ai modifié suivant tes conseils

    ça donne ça :

    pour la mise en place des proc de sous classement :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
            pPictureBoxProc = &#40;WNDPROC&#41;SetWindowLong&#40;m_hWndCtrl, GWL_WNDPROC, &#40;LONG&#41;PictureBoxProc&#41;;
            SetWindowLong&#40;m_hWndCtrl, GWL_USERDATA, &#40;DWORD&#41;this&#41;;
    je ne pouvais pas utiliser SetProp puisque mes contrôle sont définit dans un fichier ressource

    pour le proc du picturebox :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    LRESULT CALLBACK
    CGfx&#58;&#58;PictureBoxProc&#40;HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam&#41;
    &#123;
    	PAINTSTRUCT ps;
    	RECT rc;
    
    	CGfx *phWnd = &#40;CGfx*&#41;GetWindowLong&#40;hwnd, GWL_USERDATA&#41;;
    	
    	switch &#40;msg&#41;
    	&#123;
    		
        	case WM_ERASEBKGND&#58;
    	    &#123;
        		GetClientRect&#40;hwnd, &rc&#41;;
        		FillRect&#40;&#40;HDC&#41;wParam, &rc, CreateSolidBrush&#40;COLOR_BACKGROUND_DIALOG&#41;&#41;;
        		return 1;
       		&#125;
       		break;
       		
        	case WM_PAINT&#58;
            &#123;              
        		BeginPaint&#40;hwnd, &ps&#41;;
        		phWnd->OnPaintPictureBox&#40;ps.hdc&#41;;
        		EndPaint&#40;hwnd, &ps&#41;;
        		return 0;
       		&#125;
       		break;
       		
       		case WM_DESTROY&#58;
            &#123;            
                if&#40;phWnd->m_pIPicture&#41; OleReleasePic&#40;phWnd->m_pIPicture&#41;; 
            &#125;
            break;
       		
        	default&#58;
    	    &#123;
        		return CallWindowProc&#40;phWnd->pPictureBoxProc, hwnd, msg, wParam, lParam&#41; ;
       		&#125;  		
    	&#125;
    &#125;
    et l'affichage d'une image :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    void
    CGfx&#58;&#58;OnPaintPictureBox&#40;HDC hdc&#41;
    &#123;
        RECT rc;
        
        GetClientRect&#40;m_hWndCtrl, &rc&#41;;
        if&#40;m_pIPicture&#41;
        &#123;
        	OlePicRender&#40;m_pIPicture, hdc, &rc, TRUE&#41;;
        &#125;
    &#125;
    ça tourne nikel
    il me suffit d'appeler ma classe comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    g_MyCtrl = new CGfx&#40;hDlg, IDC_STATIC&#41;;   	
    g_MyCtrl->LoadPicture&#40;"G&#58;\\Pochettes\\une image.jpg"&#41;;
    par contre et là faudrais que je vois ça en détail c que pour les contrôles du type static et edit le message WM_CTLCOLORSTATIC et WM_CTLCOLOREDIT (et d'autre message...) ne sont pas interceptés, peut- être est-ce dû à un style manquant lors de la création du contrôle ? (genre
    ils manquent le flag Notify)

    sinon je crois qu'avec tout ça je vais pouvoir développer une librairie de contrôles personnalisés, un grand merci monsieur!

    ha pour finir 2 questions :

    1) je ne capte pas trop bien quand utilisé le :: pour appeler des api en c++ pourrais-tu m'expliquer davantage ?

    2) si je construit mes contrôles à partir de sous classement et sachant que j'en ai beaucoup dans mes dialog (environ 20 sur 4 dialogues constament chargée) il n'y a pas un risque de blocage de l'appli ou de crash ?

    et encore un grand

  11. #11
    Expert éminent sénior

    Homme Profil pro
    pdg
    Inscrit en
    Juin 2003
    Messages
    5 750
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : pdg

    Informations forums :
    Inscription : Juin 2003
    Messages : 5 750
    Points : 10 669
    Points
    10 669
    Billets dans le blog
    3
    Par défaut
    Oui c'est à peu près ça sauf qu'idéalement aucun code aurte que le formattage des paramètres ne devrait être présent dans la WndProc (appeler OnDestroy() par exemple au lieu de faire le OleReleasePic). Ca permet de bien séparer le code, et surtout de créer une WndProc que tu pourras facilement réutiliser dans un autre programme.
    Par contre je sais pas où tu delete le CGfx * associé à via GWL_USERDATA ?
    Personnelement je crée et associe l'instance lors de WM_CREATE (new) et la libère lors de WM_DESTROY (delete).

    Citation Envoyé par sas
    par contre et là faudrais que je vois ça en détail c que pour les contrôles du type static et edit le message WM_CTLCOLORSTATIC et WM_CTLCOLOREDIT (et d'autre message...) ne sont pas interceptés, peut- être est-ce dû à un style manquant lors de la création du contrôle ? (genre
    ils manquent le flag Notify)
    Faut voir. Certains contrôles comme le boutons nécessitent d'être owner drawed pour faire certains trucs (BS_OWNERDRAW). Mais normalement pas besoin...

    Citation Envoyé par sas
    sinon je crois qu'avec tout ça je vais pouvoir développer une librairie de contrôles personnalisés, un grand merci monsieur!
    Oui c'est amusant à faire. Y'a d'autre techniques plus balaises aussi (thunking).

    Citation Envoyé par sas
    ha pour finir 2 questions :

    1) je ne capte pas trop bien quand utilisé le :: pour appeler des api en c++ pourrais-tu m'expliquer davantage ?

    2) si je construit mes contrôles à partir de sous classement et sachant que j'en ai beaucoup dans mes dialog (environ 20 sur 4 dialogues constament chargée) il n'y a pas un risque de blocage de l'appli ou de crash ?

    et encore un grand
    1) c'est du C++ ça. Ca indique juste que ça fait partie du namespace global, autrement dit d'aucun namespace. Normalement il fautdrait l'utiliser. D'autres font aussi ç:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    namespace win32
    &#123;
        #include <windows.h>
    &#125;
    
    win32&#58;&#58;MessageBox&#40; 0, "coucou", "", 0 &#41;;
    sans namespace, tout est défini dans le namespace global, qu'on accède via ::.

    2) A priori non. En faisant du subclassing, tu crées une nouvelle classe. Je sais pas si les objets USER sont limités comme les objets GDI sous Windows9x. A priori non. En tous cas pas de pblm pour 20 classes.
    La VCL (Delphi, BCB) sous classe chaque composant Windows, et ça marche très bien.
    Et en isolant bien la wndproc comme expliqué plus haut tu devrait pouvoir factoriser et réduire le nombre de sous classes.

  12. #12
    sas
    sas est déconnecté
    Membre éprouvé

    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    54
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 54
    Points : 1 257
    Points
    1 257
    Par défaut
    oki tout est noté et merci encore

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 8
    Dernier message: 09/07/2005, 23h10
  2. classe dans une classe ?
    Par tut dans le forum UML
    Réponses: 23
    Dernier message: 25/06/2004, 15h00
  3. [Thread] Erreur dans une classe interne
    Par totof2308 dans le forum Général Java
    Réponses: 5
    Dernier message: 03/06/2004, 08h15
  4. Thread dans une classe ?
    Par Sephi dans le forum Threads & Processus
    Réponses: 7
    Dernier message: 07/03/2004, 18h16
  5. Fonction callback dans une classe
    Par julian_ross dans le forum MFC
    Réponses: 8
    Dernier message: 02/03/2004, 11h42

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo