bonjour
je teste le code suivant sur visual studi c++ 2008 qui permet d'effectuer une liste deroulante par API
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
#include "stdafx.h
#include <windows.h>
#include <stdio.h>
 
HINSTANCE instance;
 
#define ID_COMBOBOX_1       110
#define ID_BUTTON_1         111
#define ID_BUTTON_2         112
#define ID_EDIT_1           113
 
HWND hComboBox1;
HWND hEdit1;
 
VOID RemplieFenetrePrincipale(HWND fenetrePrincipale)
{
    hComboBox1=CreateWindow(
        "COMBOBOX",
        "",
        WS_CHILD|WS_VISIBLE|CBS_DISABLENOSCROLL|CBS_DROPDOWNLIST,
        10,10,
        180,150,
        fenetrePrincipale,
        (HMENU)ID_COMBOBOX_1,
        instance,
        NULL);
 
     hEdit1=CreateWindow(
 "EDIT",
        "Entrez le texte à ajouter",
        WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL|WS_BORDER,
        10,40,
        180,20,
        fenetrePrincipale,
        (HMENU)ID_EDIT_1,
        instance,
        NULL);
 
    CreateWindow(
        "BUTTON",
        "Ajouter",
        WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
        10,70,
        70,20,
        fenetrePrincipale,
        (HMENU)ID_BUTTON_1,
        instance,
        NULL);
 
    CreateWindow(
        "BUTTON",
        "Supprimer",
        WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
        90,70,
        70,20,
        fenetrePrincipale,
        (HMENU)ID_BUTTON_2,
        instance,
        NULL);
}
 
VOID NotificationControle(HWND fenetrePrincipale,UINT message,WPARAM wParam, LPARAM lParam)
{
    UINT iId=LOWORD(wParam);
    UINT iCode=HIWORD(wParam);
    HWND hCtl=(HWND)lParam;
 
   if(iId==ID_COMBOBOX_1)
   {
 
   }
   else if(iId==ID_BUTTON_1)
   {
        CHAR lpText[256];
        GetWindowText(hEdit1,lpText,256);
 
        SendMessage(hComboBox1,CB_ADDSTRING,0,(LPARAM)lpText);
   }
   else if(iId==ID_BUTTON_2)
   {
       LRESULT lRes=SendMessage(hComboBox1,CB_GETCURSEL,0,0);
       if(lRes==CB_ERR)
       {
           MessageBox(fenetrePrincipale,"Aucun élément sélectionné","Action annulée",MB_OK);
           return ;
       }
 
       SendMessage(hComboBox1,CB_DELETESTRING,(WPARAM)lRes,0);
   }
}
 
LRESULT CALLBACK procedureFenetrePrincipale(HWND fenetrePrincipale, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HWND boutons[2] = {NULL};
 
    switch (message)
    {
        case WM_CREATE:
            RemplieFenetrePrincipale(fenetrePrincipale);
            return 0;
        case WM_COMMAND:
            NotificationControle(fenetrePrincipale,message,wParam,lParam);
            return 0;
        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;
        default:
            return DefWindowProc(fenetrePrincipale,message,wParam,lParam);
    }
}
 
 
int APIENTRY WinMain (HINSTANCE cetteInstance, HINSTANCE precedenteInstance,
             LPSTR lignesDeCommande, int modeDAffichage)
{
    HWND fenetrePrincipale;
    MSG message;
    WNDCLASS classeFenetre;
 
    instance = cetteInstance;
 
    classeFenetre.style = CS_DBLCLKS;// pour attraper les double-clics
    classeFenetre.lpfnWndProc = procedureFenetrePrincipale;
    classeFenetre.cbClsExtra = 0;
    classeFenetre.cbWndExtra = 0;
    classeFenetre.hInstance = NULL;
    classeFenetre.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    classeFenetre.hCursor = LoadCursor(NULL, IDC_ARROW);
    classeFenetre.hbrBackground = (HBRUSH)(1 + COLOR_BTNFACE);
    classeFenetre.lpszMenuName = NULL;
    classeFenetre.lpszClassName = "classeF";
 
// On prévoit quand même le cas où ça échoue
    if(!RegisterClass(&classeFenetre))
        return FALSE;
 
    fenetrePrincipale=CreateWindow(
        "classeF",
        "Ma premiere fenetre winAPI !",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT,CW_USEDEFAULT,
        210,140,
        NULL,
        NULL,
        cetteInstance,
        NULL);
 
    if (!fenetrePrincipale)
        return FALSE;
 
    ShowWindow(fenetrePrincipale,modeDAffichage);
    UpdateWindow(fenetrePrincipale);
 
 
    while(GetMessage(&message,NULL,0,0))
    {
        TranslateMessage(&message);
        DispatchMessage(&message);
    }
 
    return message.wParam;
}
mais je les erreurs suivant
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
1>------ Build started: Project: interface liste, Configuration: Debug Win32 ------
1>Compiling...
1>interface liste.cpp
1>c:\users\dell\desktop\interface liste\interface liste\interface liste.cpp(4) : error C2001: newline in constant
1>c:\users\dell\desktop\interface liste\interface liste\interface liste.cpp(29) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [9]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\dell\desktop\interface liste\interface liste\interface liste.cpp(40) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [5]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\dell\desktop\interface liste\interface liste\interface liste.cpp(51) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\dell\desktop\interface liste\interface liste\interface liste.cpp(62) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\dell\desktop\interface liste\interface liste\interface liste.cpp(78) : error C2664: 'GetWindowTextW' : cannot convert parameter 2 from 'CHAR [256]' to 'LPWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\dell\desktop\interface liste\interface liste\interface liste.cpp(87) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [26]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\dell\desktop\interface liste\interface liste\interface liste.cpp(134) : error C2440: '=' : cannot convert from 'const char [8]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\dell\desktop\interface liste\interface liste\interface liste.cpp(149) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [8]' to 'LPCWSTR'
1>        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>Build log was saved at "file://c:\Users\DELL\Desktop\interface liste\interface liste\Debug\BuildLog.htm"
1>interface liste - 9 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
pouvez vous m'aider car c'est tres urgent pour mon PFE
et merci d'avance