Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

API Win32: CreateDialog échoue

5 réponses
Avatar
Mickaël Savafi
Bonjour,
J'ai créé ma boite de dialogue avec Visual Studio 2008, j'ai bien mon
"ressource.h" et mon "dialog.rc"
sauf que quand je veux créer une instance de la boite de dialogue, j'ai un
pointeur NULL.
GetLastError() me renvoie pourtant 0 ; il n'y a donc pas d'erreur
normalement
voici le WinMain():

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hDlg;
hDlg=CreateDialog(hInstance,(LPCTSTR)IDD_DIALOG1,NULL,(DLGPROC)MainProc);
// hDlg=CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOG1)
,NULL,(DLGPROC)MainProc);
int err = GetLastError();
if (!hDlg)
{
MessageBox(hDlg, L"Cannot create window", L"Error", MB_ICONERROR | MB_OK);
return 0;
}
ShowWindow(hDlg,SW_SHOW);
MSG msg;
while(GetMessage(&msg,NULL,0,0)==TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}

mon pointeur hDlg est NULL.
Sauriez-vous d'où cela peu venir?
Merci d'avance.

5 réponses

Avatar
Christian ASTOR
On 26 sep, 14:31, Mickaël Savafi wrote:

J'ai créé ma boite de dialogue avec Visual Studio 2008, j'ai bien mon
"ressource.h" et mon "dialog.rc"
sauf que quand je veux créer une instance de la boite de dialogue, j'ai un
pointeur NULL.
GetLastError() me renvoie pourtant 0 ; il n'y a donc pas d'erreur
normalement



Qu'y a-til dans la Dlg ?
Si C. Controls, appeler InitCommonControlsEx() auparavant.
Avatar
Mickaël Savafi
"Christian ASTOR" a écrit dans le message de
news:
On 26 sep, 14:31, Mickaël Savafi wrote:

Qu'y a-til dans la Dlg ?
Si C. Controls, appeler InitCommonControlsEx() auparavant.



Non, il n'y a pas de Common Controls. Meme en mettant
InitCommonControlsEx(), (au cas où), cela ne change pas
si cela peut aider, voici les defines utilisés dans le resource.h :
#define IDD_DIALOG1 101
#define ID_GT_GDI 1001
#define ID_GT_SDL 1002
#define ID_GT_SFML 1003
#define ID_GT_SILVERLIGHT 1004
#define ID_SKIN_NAME 1005
#define ID_MAIL_LINK 1006
#define ID_RESET 1007
#define ID_SET_COLOR_1 1011
#define ID_SET_COLOR_2 1012

que l'on retrouve dans le .rc: (dans la partie // Dialog)
BEGIN
PUSHBUTTON "Exit",IDCANCEL,6,108,51,14
GROUPBOX "Graphic type",IDC_STATIC,7,15,288,31
CONTROL "GDI",ID_GT_GDI,"Button",BS_AUTORADIOBUTTON,24,26,28,10
CONTROL "SDL",ID_GT_SDL,"Button",BS_AUTORADIOBUTTON,87,26,28,10
CONTROL
"SFML",ID_GT_SFML,"Button",BS_AUTORADIOBUTTON,171,26,33,10
CONTROL "Silverlight
(C#)",ID_GT_SILVERLIGHT,"Button",BS_AUTORADIOBUTTON |
WS_DISABLED,232,26,64,10
LTEXT "Skin name",IDC_STATIC,7,53,49,11
EDITTEXT ID_SKIN_NAME,53,49,173,14,ES_AUTOHSCROLL
LTEXT ".skin",IDC_STATIC,232,50,16,9
CONTROL "by
<a>mickaelsavafi</a>",ID_MAIL_LINK,"SysLink",WS_TABSTOP,204,7,92,11
PUSHBUTTON "Reset",ID_RESET,68,108,51,14
COMBOBOX ID_SET_COLOR_1,84,71,48,14,CBS_DROPDOWNLIST |
CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP
LTEXT "Player 1 pieces color",IDC_STATIC,6,73,67,9
LTEXT "Player 2 pieces color",IDC_STATIC,6,90,67,9
COMBOBOX ID_SET_COLOR_2,84,89,48,14,CBS_DROPDOWNLIST |
CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP
DEFPUSHBUTTON "Generate !",IDOK,246,108,50,14
END
Avatar
Christian ASTOR
On 26 sep, 15:16, Mickaël Savafi wrote:

    CONTROL         "by
<a>mickaelsavafi</a>",ID_MAIL_LINK,"SysLink",WS_TABSTOP,204,7,92,11



Ben si, le SysLink, c'est un C. Control.
Il faut à la fois InitCommonControlsEx() & ICC_LINK_CLASS
et surtout activer la v.6 des C. Controls, notamment en utilisant un
Manifest.
Avatar
Mickaël Savafi
"Christian ASTOR" a écrit dans le message de
news:
On 26 sep, 15:16, Mickaël Savafi wrote:

Ben si, le SysLink, c'est un C. Control.
Il faut à la fois InitCommonControlsEx() & ICC_LINK_CLASS
et surtout activer la v.6 des C. Controls, notamment en utilisant un
Manifest.



j'ai donc rajouté ceci avant le CreateDialog():

INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_LINK_CLASS;
if (!InitCommonControlsEx(&icex))
{
MessageBox(NULL, L"Cannot Initialise C. Controls", L"Error", MB_ICONERROR
| MB_OK);
return 0;
}

et j'ai une erreur.
Par contre, je n'ai pas bien compris ce que vous voulez dire par "activer la
v6 des Common Controls" (Propriété de Configuration / Editeur de liens /
Fichier Manifeste / Activer le Contrôle de compte utilisateur ?)

Merci beaucoup
Avatar
Christian ASTOR
Mickaël Savafi wrote:

j'ai donc rajouté ceci avant le CreateDialog():
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_LINK_CLASS;
if (!InitCommonControlsEx(&icex))
{
MessageBox(NULL, L"Cannot Initialise C. Controls", L"Error",
MB_ICONERROR | MB_OK);
return 0;
}
et j'ai une erreur.



Quelle erreur ?

Par contre, je n'ai pas bien compris ce que vous voulez dire par
"activer la v6 des Common Controls"



Ajouter un Manifest :
http://msdn.microsoft.com/en-us/library/ms997646.aspx