DialogBox() failed mit 0x582 - class already exists
-
Moin moin,
folgendes:
Ich habe einen Dialog mit ein paar Controls und 2 ComboBox controls.
Wenn ich den Dialog mit DialogBoxParam() erstellen will, bekomme ich -1 zurück und GetLastError() sagt 0x582 - class already exists.Mit meinem Lieblingsdebugger Olly hab ich herausgefunden das der Fehler intern anscheinend beim Erstellen der EDIT-Box von der zweiten ComboBox auftritt.
Die ComboBoxen ind dabei im ressource-file wie folgt deklariert:
CONTROL "",IDC_FP_EXPIRES,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|CBS_HASSTRINGS|CBS_DROPDOWNLIST,112,185,95,90 CONTROL "",IDC_FP_FORMAT,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|CBS_HASSTRINGS|CBS_SORT|CBS_DROPDOWNLIST,112,205,95,73
die zugehörigen IDs:
#define IDC_FP_EXPIRES 1017 #define IDC_FP_FORMAT 1016
Das seltsame an der Sache ist das ein zweiter Dialog den ich getrennt aufrufe, der aber auch 2 comboboxen hat, funktioniert.
Also InitCommonControls() und so hab ich
Der kaputte Dialog ging auch schon einmal.. keine Ahnung was ich da geändert hab o.OHoffe hier kann mir jemand helfen, Google ist nicht sehr aussagekräftig zu dem Thema
Gruß
livinskull
-
hm... ich kannte zwar das "CONTROL" resource statement nicht aber das scheint alles richtig zu sein. Dachte nur eigentlich dass der classname "COMBOBOX" ist und nich "ComboBox" aber wenn du sagst dass das woanders funktioniert...
Nur zur Sicherheit kannst du ja mal das "COMBOBOX" resource statement testen:
http://msdn.microsoft.com/en-us/library/aa380889(v=VS.85).aspxBin mir aber sicher dass der Fehler nicht mit denen von dir geposteten zeilen zu tun hat. Poste mal mehr von deinem Resource script bzw. allgemein mehr code...
-
"Class already exists" ist aber eigentümlich. Klassen werden normalerweise nicht registriert wenn DialogBoxParam aufgerufen wird, sondern ebne nur Controls erzeugt.
Bist Du sicher?
Hast Du evtl. Klassen verändert? (SetClassLong)
-
Das Resource File hat mir mein Resource Editor so gebaut (ResEd).
Klassen habe ich (absichtlich) sicher keine geändert.Werde heute abend wenn ich wieder zu Hause bin mal mehr vom Code posten.
-
So, jetzt mal ein bisschen mehr Code.
Das Snippet in dem der Fehler auftritt (die Parameter für Dialogbox() sind übrigens alle in Ordnung):
case IDM_CONFIG: if (!IsWindow(g_hConfigWindow)) { if (DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_CONFIG), hwnd, ConfigDlgProc) == -1) { GetLastError(); /* for debugging purposes */ /* dieses GetLastError() gibt 0x582 zurück */ } /* update hotkey */ UnregisterHotKey(hwnd, ID_PASTE_HOTKEY); if (g_uiHotkey) { if (!RegisterHotKey(hwnd, ID_PASTE_HOTKEY, HIBYTE(LOWORD(g_uiHotkey)), LOBYTE(LOWORD(g_uiHotkey)))) MessageBox(hwnd, TEXT("Unable to register hotkey, maybe its already registered with another application.\nPlease select another hotkey."), TEXT("Error"), MB_OK | MB_ICONERROR | MB_SETFOREGROUND | MB_TOPMOST); } } break;
Die (sinnvoll gekürzte) DialogProc zu dem fehlerhaften Dialog:
INT_PTR CALLBACK ConfigDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch(uMsg) { case WM_CLOSE: EndDialog(hwndDlg, 0); break; case WM_DESTROY: g_hConfigWindow = NULL; break; case WM_INITDIALOG: g_hConfigWindow = hwndDlg; /* init controls with values from settings */ ReadSettings(); if (g_uiHotkey) SendDlgItemMessage(hwndDlg, IDC_HOTKEY, HKM_SETHOTKEY, (WPARAM) g_uiHotkey, 0); SendDlgItemMessage(hwndDlg, IDC_AP_OPENINBROWSER, BM_SETCHECK, (WPARAM) ((g_dwAfterPasting & AP_FLAG_OPEN) ? BST_CHECKED : BST_UNCHECKED), 0); SendDlgItemMessage(hwndDlg, IDC_AP_COPYLINK, BM_SETCHECK, (WPARAM) ((g_dwAfterPasting & AP_FLAG_COPY) ? BST_CHECKED : BST_UNCHECKED), 0); SendDlgItemMessage(hwndDlg, IDC_AP_SHOWLINK, BM_SETCHECK, (WPARAM) ((g_dwAfterPasting & AP_FLAG_SHOW) ? BST_CHECKED : BST_UNCHECKED), 0); SendDlgItemMessage(hwndDlg, IDC_FP_ENABLED, BM_SETCHECK, (WPARAM) (g_bFastPasting?BST_CHECKED:BST_UNCHECKED), 0); SetWindowText(GetDlgItem(hwndDlg, IDC_FP_NAME), g_szPasteName); SetWindowText(GetDlgItem(hwndDlg, IDC_FP_EMAIL), g_szPasteEmail); SetWindowText(GetDlgItem(hwndDlg, IDC_FP_SUBDOMAIN), g_szPasteSubdomain); SendDlgItemMessage(hwndDlg, IDC_FP_PRIVATE, BM_SETCHECK, (WPARAM) (g_bPastePrivate?BST_CHECKED:BST_UNCHECKED), 0); FillComboBoxes(hwndDlg, IDC_FP_EXPIRES, IDC_FP_FORMAT); EnableWindow(GetDlgItem(hwndDlg, IDC_FP_NAME), g_bFastPasting); EnableWindow(GetDlgItem(hwndDlg, IDC_FP_EMAIL), g_bFastPasting); EnableWindow(GetDlgItem(hwndDlg, IDC_FP_SUBDOMAIN), g_bFastPasting); EnableWindow(GetDlgItem(hwndDlg, IDC_FP_EXPIRES), g_bFastPasting); EnableWindow(GetDlgItem(hwndDlg, IDC_FP_FORMAT), g_bFastPasting); EnableWindow(GetDlgItem(hwndDlg, IDC_FP_PRIVATE), g_bFastPasting); return FALSE; case WM_COMMAND: switch (HIWORD(wParam)) { case BN_CLICKED: switch(LOWORD(wParam)) { case IDC_FP_ENABLED: /* enable/disable controls with fp_enable checkbox */ break; case IDOK: /* read settings from controls and save them */ /* ... */ //break; // fall through to IDCANCEL to close the window case IDCANCEL: SendMessage(hwndDlg, WM_CLOSE, 0, 0); break; } break; } break; default: return FALSE; } return TRUE; }
Das Resourceskript:
#include <windows.h> #include <commctrl.h> #include <richedit.h> #include "resource.h" IDD_CONFIG DIALOGEX 0,0,222,276 CAPTION "Configuration" FONT 8,"Ms Shell Dlg",0,0,0 STYLE WS_POPUP|WS_VISIBLE|WS_CAPTION|WS_SYSMENU|DS_CENTER|DS_SETFOREGROUND|DS_MODALFRAME|DS_SHELLFONT|DS_3DLOOK BEGIN CONTROL "OK",IDOK,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|BS_DEFPUSHBUTTON,47,256,50,14 CONTROL "Cancel",IDCANCEL,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP,111,256,50,14 CONTROL "",IDC_HOTKEY,"HOTKEY_CLASS",WS_VISIBLE|WS_TABSTOP,114,12,92,12 CONTROL "Hotkey for pasting",IDC_STATIC,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_GROUP,11,14,58,11 CONTROL "Enable fast pasting",IDC_FP_ENABLED,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,14,115,76,8 CONTROL "Open paste in browser",IDC_AP_OPENINBROWSER,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,47,87,8 CONTROL "Fast pasting",IDC_STATIC,"Button",WS_CHILDWINDOW|WS_VISIBLE|BS_GROUPBOX,7,102,207,148 CONTROL "Paste name (optional)",IDC_STATIC,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_GROUP,33,130,69,8 CONTROL "Copy link to clipboard",IDC_AP_COPYLINK,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,12,62,83,8 CONTROL "After pasting",IDC_STATIC,"Button",WS_CHILDWINDOW|WS_VISIBLE|BS_GROUPBOX,7,32,207,62 CONTROL "Show link",IDC_AP_SHOWLINK,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,11,77,47,8 CONTROL "Email (optional)",IDC_STATIC,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_GROUP,33,148,48,8 CONTROL "Subdomain (optional)",IDC_STATIC,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_GROUP,33,167,67,8 CONTROL "private paste",IDC_FP_PRIVATE,"Button",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|BS_AUTOCHECKBOX,33,227,57,8 CONTROL "",IDC_FP_EXPIRES,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|CBS_HASSTRINGS|CBS_DROPDOWNLIST,112,185,95,90 CONTROL "Expires in",IDC_STATIC,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_GROUP,33,187,31,8 CONTROL "Format",IDC_STATIC,"Static",WS_CHILDWINDOW|WS_VISIBLE|WS_GROUP,33,207,22,8 CONTROL "",IDC_FP_FORMAT,"ComboBox",WS_CHILDWINDOW|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP|CBS_HASSTRINGS|CBS_SORT|CBS_DROPDOWNLIST,112,205,95,73 CONTROL "",IDC_FP_NAME,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|ES_AUTOHSCROLL,112,127,95,14,WS_EX_CLIENTEDGE CONTROL "",IDC_FP_EMAIL,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|ES_AUTOHSCROLL,112,146,95,14,WS_EX_CLIENTEDGE CONTROL "",IDC_FP_SUBDOMAIN,"Edit",WS_CHILDWINDOW|WS_VISIBLE|WS_TABSTOP|ES_AUTOHSCROLL,112,165,95,14,WS_EX_CLIENTEDGE END
Und zu guter letzt die resource.h:
#define IDC_STATIC -1 #define MANIFEST 24 #define IDD_CONFIG 104 #define IDC_HOTKEY 1013 #define IDC_FP_ENABLED 1014 #define IDC_AP_OPENINBROWSER 1010 #define IDC_AP_COPYLINK 1011 #define IDC_AP_SHOWLINK 1012 #define IDC_FP_PRIVATE 1015 #define IDC_FP_EXPIRES 1017 #define IDC_FP_FORMAT 1016 #define IDC_FP_NAME 1000 #define IDC_FP_EMAIL 1021 #define IDC_FP_SUBDOMAIN 1022 #define IDD_PASTE 106 #define IDC_PASTE_NAME 1030 #define IDC_PASTE_EMAIL 1025 #define IDC_PASTE_SUBDOMAIN 1024 #define IDC_PASTE_EXPIRES 1026 #define IDC_PASTE_FORMAT 1027 #define IDC_PASTE_TEXT 1002 #define IDC_PASTE_PRIVATE 1028 #define IDD_SHOWLINK 108 #define IDC_LINK 1023 #define IDI_ICON1 102
Hoffe ich hab nichts vergessen...
-
InitCommonControls ausgeführt?
http://msdn.microsoft.com/en-us/library/bb775695(v=vs.85).aspx
-
Jup, steht im ersten Post schon, außerdem geht der zweite Dialog mit Combobox und der hier ging auch schonmal (inkl Combobox und hotkey-control)