digitalmars.D.learn - Win32 with D: Using RegisterClassExA instead of RegisterClass
- BeschBesch (83/83) Jan 28 2014 So, I wanted to try out D as a better alternative to C/C++ and
- John Chapman (3/20) Jan 28 2014 You need to fill in the cbSize field like so:
- BeschBesch (1/3) Jan 29 2014 Ungh. How embarassing. Now it works, thank you.
So, I wanted to try out D as a better alternative to C/C++ and now I bump into some minor problems. Basically, it seems the WinAPI is limited to D. My problem: Using WNDCLASS and RegisterClass works out fine but when I try the Ex-versions (RegisterClassExA/WNDCLASSEX) windows returns a INVALID_PARAMETER error, though I did not change anything besides adding "Ex". Where is the mistake or is my approach totally wrong? module winmain; import core.runtime; import std.conv; import std.utf; import core.sys.windows.windows; public import myWindows.d; // for extended WinAPI stuff...still empty pragma(lib, "gdi32.lib"); pragma (lib,"user32.lib"); extern (Windows) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { int result; try { Runtime.initialize(); result = myWinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow); Runtime.terminate(); } catch (Throwable o) // catch any uncaught exceptions { MsgBox(o.toString(),"Runtime error"); result = 0; // failed } return result; } int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND wnd; MSG msg; WNDCLASSEXA wce; wce.cbClsExtra = 0; wce.cbWndExtra = 0; wce.hbrBackground = cast(HBRUSH)GetStockObject(WHITE_BRUSH); wce.hCursor = LoadCursorA(null,IDC_ARROW); wce.hIcon = LoadIconA(null, IDI_APPLICATION); wce.hIconSm = LoadIconA(null, IDI_APPLICATION); wce.hInstance = hInstance; wce.lpszClassName = cast(char*)("VolumeControl_Main"); wce.style = 0; wce.lpszMenuName = null; wce.lpfnWndProc = &WinProc; if (!RegisterClassExA(&wce)) { MessageBoxA(null,cast(char*)"RegisterClass failed!", cast(char*) "Init-Error",0); return 0; } wnd = CreateWindowExA(0,wce.lpszClassName,"TestBox",WS_OVERLAPPEDWINDOW, 250,250,250,250,null,null,hInstance,null); ShowWindow(wnd, SW_SHOWNORMAL); UpdateWindow(wnd); while (GetMessageA(&msg,null,0,0)) { TranslateMessage(&msg); DispatchMessageA(&msg); } return 0; } extern(Windows) LRESULT WinProc(HWND wnd, UINT msg, WPARAM W, LPARAM L) nothrow { switch (msg) { case WM_DESTROY: PostQuitMessage(0); return 0; default: } return DefWindowProcA(wnd, msg, W, L); }
Jan 28 2014
On Tuesday, 28 January 2014 at 21:17:18 UTC, BeschBesch wrote:My problem: Using WNDCLASS and RegisterClass works out fine but when I try the Ex-versions (RegisterClassExA/WNDCLASSEX) windows returns a INVALID_PARAMETER error, though I did not change anything besides adding "Ex". Where is the mistake or is my approach totally wrong?WNDCLASSEXA wce;You need to fill in the cbSize field like so: wce.cbSize = WNDCLASSEXA.sizeof;wce.cbClsExtra = 0; wce.cbWndExtra = 0; wce.hbrBackground = cast(HBRUSH)GetStockObject(WHITE_BRUSH); wce.hCursor = LoadCursorA(null,IDC_ARROW); wce.hIcon = LoadIconA(null, IDI_APPLICATION); wce.hIconSm = LoadIconA(null, IDI_APPLICATION); wce.hInstance = hInstance; wce.lpszClassName = cast(char*)("VolumeControl_Main"); wce.style = 0; wce.lpszMenuName = null; wce.lpfnWndProc = &WinProc;
Jan 28 2014
You need to fill in the cbSize field like so: wce.cbSize = WNDCLASSEXA.sizeof;Ungh. How embarassing. Now it works, thank you.
Jan 29 2014