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

C++ Discussion :

probleme de cast


Sujet :

C++

  1. #1
    Membre régulier
    Inscrit en
    Juillet 2003
    Messages
    140
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 140
    Points : 76
    Points
    76
    Par défaut probleme de cast
    voila j'ai un probleme de cast avec la fonction SendMessage.

    voila le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
           LVCOLUMN lvc; 
    	lvc.mask=LVCF_WIDTH|LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT;
    	lvc.cx=column_width;
    	lvc.fmt=LVCFMT_LEFT;
    	lvc.pszText=column_nam;
    	lvc.cchTextMax=strlen(column_name);
    	lvc.iSubItem=((listview_ID-300)*10+300)+column_number+1;
    	hcolumn=SendMessage(hliste, LVM_INSERTCOLUMN, column_number,(long) &lvc);
    et voila ce que me dit le compilo :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    cannot convert from 'long' to 'struct HWND__ *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    j'ai essayé ca :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    hcolumn=SendMessage(hliste, LVM_INSERTCOLUMN, column_number,(HWND)(long) &lvc);
    mais la il me dit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    cannot convert from 'struct HWND__ *' to 'long'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    voila.... [/code]

  2. #2
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    Salut

    A mon avis la première erreur porte sur le premier paramètre et non sur le quatrième (&lvc est un LVCOLUMN*, pas un HWND). En l'occurence, le cast en long (LPARAM pour être rigoureux) passe très bien.

    Par contre, est-ce que hliste est bien un HWND ?

  3. #3
    Membre régulier
    Inscrit en
    Juillet 2003
    Messages
    140
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 140
    Points : 76
    Points
    76
    Par défaut
    hliste est bien un HWND, donc le probleme vient pas de la....
    j'ai fait comme ca :

    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
     
    HWND hliste;
     
    ............
     
     
    ............
     
    	char *column_nam;
    	column_nam=column_name;
    	LVCOLUMN lvc; 
    	lvc.mask=LVCF_WIDTH|LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT;
    	lvc.cx=column_width;
    	lvc.fmt=LVCFMT_LEFT;
    	lvc.pszText=column_nam;
    	lvc.cchTextMax=strlen(column_name);
    	lvc.iSubItem=((listview_ID-300)*10+300)+column_number+1;
    	hcolumn=SendMessage(hliste, LVM_INSERTCOLUMN, column_number,(LPARAM)&lvc);
    et ca marche pas mieux, il me redonne la meme erreur....

  4. #4
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    Ce code compile parfaitement chez moi (VC7). Essaie de poster un code complet minimal qui reproduit le problème, il doit y avoir une feinte quelque part.

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 77
    Points : 83
    Points
    83
    Par défaut
    hcolumns, c'est défini comme quoi ?

  6. #6
    Membre régulier
    Inscrit en
    Juillet 2003
    Messages
    140
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 140
    Points : 76
    Points
    76
    Par défaut
    hcolumn est defini comme HWND, voila le code complet :
    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
    #include <stdlib.h>
    #include <stdio.h>
    #include <windows.h> //ajouter les commandes pour le compilateur Dev-C++ 4&#58; -mwindows -lwsock32
    #include <winsock.h> //
    #include <commctrl.h>
    // Global Variables&#58; 
    HINSTANCE hInst;                        // current instance 
                            // The title bar text 
     
    // Foward declarations of functions included in this code module&#58; 
    ATOM            MyRegisterClass&#40;HINSTANCE hInstance&#41;; 
    BOOL            InitInstance&#40;HINSTANCE, int&#41;; 
    LRESULT CALLBACK   WndProc&#40;HWND, UINT, WPARAM, LPARAM&#41;; 
    void addcolumn&#40;int, int, char column_name&#91;16&#93;, int&#41;;
     
    const HMENU ID_BUTTON_OK = &#40;HMENU&#41;1; 
    const HMENU ID_LIST = &#40;HMENU&#41;2; 
    const HMENU ID_EDIT = &#40;HMENU&#41;3; 
     
    HWND hbouton; 
    HWND hedit; 
    HWND hliste; 
    HWND hcolumn; 
     
     
     
    int APIENTRY WinMain&#40;HINSTANCE hInstance, 
                         HINSTANCE hPrevInstance, 
                         LPSTR     lpCmdLine, 
                         int       nCmdShow&#41; 
    &#123; 
        // TODO&#58; Place code here. 
       MSG msg; 
       HACCEL hAccelTable; 
     
     
       MyRegisterClass&#40;hInstance&#41;; 
     
       // Perform application initialization&#58; 
       if &#40;!InitInstance &#40;hInstance, nCmdShow&#41;&#41; 
       &#123; 
          return FALSE; 
       &#125; 
     
     
       // Main message loop&#58; 
       while &#40;GetMessage&#40;&msg, NULL, 0, 0&#41;&#41; 
       &#123; 
          if &#40;!TranslateAccelerator&#40;msg.hwnd, hAccelTable, &msg&#41;&#41; 
          &#123; 
             TranslateMessage&#40;&msg&#41;; 
             DispatchMessage&#40;&msg&#41;; 
          &#125; 
       &#125; 
     
       return msg.wParam; 
    &#125; 
     
     
    ATOM MyRegisterClass&#40;HINSTANCE hInstance&#41; 
    &#123; 
       WNDCLASSEX wcex; 
     
       wcex.cbSize = sizeof&#40;WNDCLASSEX&#41;; 
     
       wcex.style         = CS_HREDRAW | CS_VREDRAW; 
       wcex.lpfnWndProc   = &#40;WNDPROC&#41;WndProc; 
       wcex.cbClsExtra      = 0; 
       wcex.cbWndExtra      = 0; 
       wcex.hInstance      = hInstance; 
       wcex.hIcon         = 0; 
       wcex.hCursor      = LoadCursor&#40;NULL, IDC_ARROW&#41;; 
       //wcex.hbrBackground   = &#40;HBRUSH&#41;&#40;COLOR_WINDOW&#41;; 
        wcex.hbrBackground = static_cast<HBRUSH> &#40;GetStockObject&#40;LTGRAY_BRUSH&#41;&#41;; 
       wcex.lpszMenuName   = 0; 
       wcex.lpszClassName   = "ma fenetre"; 
       wcex.hIconSm      = 0; 
     
       return RegisterClassEx&#40;&wcex&#41;; 
    &#125; 
     
     
     
    BOOL InitInstance&#40;HINSTANCE hInstance, int nCmdShow&#41; 
    &#123; 
       HWND hWnd; 
     
       hInst = hInstance; // Store instance handle in our global variable 
     
       hWnd = CreateWindow&#40;"ma fenetre", "Mon titre", WS_OVERLAPPEDWINDOW, 
          CW_USEDEFAULT, 0, 300, 600, NULL, NULL, hInstance, NULL&#41;; 
     
       if &#40;!hWnd&#41; 
       &#123; 
          return FALSE; 
       &#125; 
     
    ShowWindow&#40;hWnd, nCmdShow&#41;; 
     
     
     
       UpdateWindow&#40;hWnd&#41;; 
     
       return TRUE; 
    &#125; 
     
    LRESULT CALLBACK WndProc&#40;HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam&#41; 
    &#123; 
       int wmId, wmEvent; 
        int static xbutton, ybutton; 
       switch &#40;message&#41; 
       &#123; 
          case WM_CREATE&#58; 
                 xbutton = LOWORD&#40;GetDialogBaseUnits&#40;&#41;&#41;;    // Abscisse de la fenêtre principale // 
                 ybutton = HIWORD&#40;GetDialogBaseUnits&#40;&#41;&#41;;    // Ordonnée de la fenêtre principale // 
     
             hbouton = CreateWindow&#40;"BUTTON", "OK", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 
             20 +xbutton, 435 + ybutton, 50, 25, hWnd, ID_BUTTON_OK, hInst, NULL&#41;; 
    RECT rcl;  
    INITCOMMONCONTROLSEX icex; 
     
    // Ensure that the common control DLL is loaded. 
    icex.dwSize = sizeof&#40;INITCOMMONCONTROLSEX&#41;; 
    icex.dwICC  = ICC_LISTVIEW_CLASSES; 
    InitCommonControlsEx&#40;&icex&#41;; 
     
    // Create the list-view window in report view with label 
    // editing enabled. 
    GetClientRect &#40;hWnd, &rcl&#41;; 
    hliste = CreateWindow &#40;WC_LISTVIEW, "", 
            WS_VISIBLE |WS_CHILD | LVS_REPORT | LVS_EDITLABELS, 
            10, 10, 80, 80, 
            hWnd, &#40;HMENU&#41; 301, hInst, NULL&#41;; 
    if &#40;hliste == NULL&#41; 
            return NULL; 
    addcolumn&#40;301,1,"prem col",30&#41;;
     
             hedit = CreateWindow&#40;"EDIT", "", WS_VISIBLE | WS_CHILD |WS_BORDER , 
             20+xbutton, 500 +ybutton, 300, 25, hWnd, ID_EDIT, hInst, NULL&#41;; 
             SetFocus&#40;hedit&#41;; 
     
     
     
             break; 
          case WM_COMMAND&#58; 
             wmId    = LOWORD&#40;wParam&#41;; 
             wmEvent = HIWORD&#40;wParam&#41;; 
             // Parse the menu selections&#58; 
             switch &#40;wmId&#41; 
             &#123; 
                case ID_BUTTON_OK&#58; 
                   char text&#91;200&#93;; 
                   GetWindowText&#40; hedit, text, 200 &#41;; 
                   SendMessage&#40;  hliste, LB_ADDSTRING, 0,  &#40;long&#41;&text&#41;;
                   SetWindowText&#40; hedit, "" &#41;; 
                   SetFocus&#40;hedit&#41;; 
     
     
                   break; 
                default&#58; 
                   return DefWindowProc&#40;hWnd, message, wParam, lParam&#41;; 
             &#125; 
             break; 
          case WM_DESTROY&#58; 
             PostQuitMessage&#40;0&#41;; 
             break; 
          default&#58; 
             return DefWindowProc&#40;hWnd, message, wParam, lParam&#41;; 
       &#125; 
       return 0; 
    &#125; 
     
    void addcolumn&#40;int listview_ID, int column_number, char column_name&#91;16&#93;, int column_width&#41;
    &#123;
    	char *column_nam;
    	column_nam=column_name;
    	LVCOLUMN lvc; 
    	lvc.mask=LVCF_WIDTH|LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT;
    	lvc.cx=column_width;
    	lvc.fmt=LVCFMT_LEFT;
    	lvc.pszText=column_nam;
    	lvc.cchTextMax=strlen&#40;column_name&#41;;
    	lvc.iSubItem=&#40;&#40;listview_ID-300&#41;*10+300&#41;+column_number+1;
    	hcolumn=SendMessage&#40;hliste, LVM_INSERTCOLUMN, column_number,&#40;LPARAM&#41;&lvc&#41;;
    &#125;

  7. #7
    Rédacteur
    Avatar de Laurent Gomila
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2003
    Messages
    10 651
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2003
    Messages : 10 651
    Points : 15 920
    Points
    15 920
    Par défaut
    (un code minimal c'est mieux quand même...)

    SendMessage renvoie un LRESULT, pas un HWND.

  8. #8
    Membre régulier
    Profil pro
    Inscrit en
    Juillet 2004
    Messages
    77
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2004
    Messages : 77
    Points : 83
    Points
    83
    Par défaut
    je suis d'accord.......

    le cast doit être fait sur la valeur de retours....

  9. #9
    Membre régulier
    Inscrit en
    Juillet 2003
    Messages
    140
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 140
    Points : 76
    Points
    76
    Par défaut
    ok merci bien de vos reponses

  10. #10
    Membre régulier
    Inscrit en
    Juillet 2003
    Messages
    140
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 140
    Points : 76
    Points
    76
    Par défaut
    j'ai creer une deux colonne dans ma listview, mais le probleme c'est que je n'arrive pas a afficher un texte dans les deux colonnes, voila ma fonction d'ajout d'item dans les colonnnes :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    void additem&#40;char item_name&#91;16&#93;&#41;
    &#123;
    	char *item_nam;
    	item_nam=item_name;
    	LVITEM lvi;
    	lvi.mask = LVIF_TEXT | LVIF_STATE; 
    	lvi.state = 0; 
    	lvi.stateMask = 0; 
    	lvi.iItem = 1;
    	lvi.iSubItem = 0;
    	lvi.pszText = item_nam; 
    	ListView_InsertItem&#40;hliste, &lvi&#41;;
    &#125;
    et voila comment j'appele la fonction :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    additem&#40;"salut"&#41;;
    additem&#40;"ca va?"&#41;;
    le probleme est donc que ca ecrit le premier et le deuxieme texte dans la meme colonne et donc sur deux lignes au lieu d'afficher le premier texte dans la premiere colonne et le second dans la seconde et le tout donc sur une ligne.

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

Discussions similaires

  1. [VB.NET] Deploiement / Probleme de Cast
    Par XnoTonio dans le forum Windows Forms
    Réponses: 3
    Dernier message: 02/06/2006, 15h09
  2. Probleme de cast de string en int
    Par Oberown dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 26/04/2006, 12h48
  3. Réponses: 12
    Dernier message: 25/07/2005, 15h49
  4. [VB.NET][dataset][datagrid] probleme de Cast
    Par graphicsxp dans le forum Windows Forms
    Réponses: 3
    Dernier message: 05/05/2005, 15h18
  5. Probleme de cast de parametres
    Par John Fullspeed dans le forum Langage
    Réponses: 3
    Dernier message: 14/10/2004, 09h43

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