digitalmars.D.learn - How to make Create Window Work?
- Ruby The Roobster (39/39) Dec 09 2020 Here is the code im using:
- Adam D. Ruppe (5/9) Dec 09 2020 fyi for a string literal like this you can just do
- Ruby The Roobster (6/15) Dec 09 2020 It's not the 'NULL' that's the error. It doesn't compile because
- Adam D. Ruppe (4/8) Dec 09 2020 I know.
- Ruby The Roobster (38/46) Dec 09 2020 I did. Still gives an error:
- Ruby The Roobster (3/3) Dec 09 2020 Also, here is the error in full: E:\Users\User\Desktop\tet.d|100|
- Adam D. Ruppe (15/16) Dec 09 2020 here, that's the only int you do and I'm pretty sure that's
- Ruby The Roobster (3/8) Dec 09 2020 Thank you. Now it works.
Here is the code im using:
extern(Windows)
LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam) nothrow
{
scope (failure) assert(0);
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
switch (message)
{
case WM_CREATE:
CreateWindow("BUTTON".toUTF16z, // window class
name
"The Hello Program", // window caption
WS_CHILD | WS_VISIBLE, // window style
CW_USEDEFAULT, // initial x
position
CW_USEDEFAULT, // initial y
position
250, // initial x size
250, // initial y size
hwnd, // parent window
handle
0, // window menu handle
NULL, // program instance
handle
NULL);
return 0;
case WM_COMMAND:
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
This gives an error saying: Cannot pas argument of type 'int' to
argument of type 'void*'. How is this fixed?
Dec 09 2020
On Wednesday, 9 December 2020 at 17:25:10 UTC, Ruby The Roobster wrote:CreateWindow("BUTTON".toUTF16z, // window class namefyi for a string literal like this you can just do "BUTTON"w.ptr // note the wThis gives an error saying: Cannot pas argument of type 'int' to argument of type 'void*'. How is this fixed?Use lowercase `null` instead.
Dec 09 2020
On Wednesday, 9 December 2020 at 17:32:57 UTC, Adam D. Ruppe wrote:On Wednesday, 9 December 2020 at 17:25:10 UTC, Ruby The Roobster wrote:It's not the 'NULL' that's the error. It doesn't compile because of the '0' . That is what I need to fix, since I want to make a WM_COMMAND for that button.CreateWindow("BUTTON".toUTF16z, // window class namefyi for a string literal like this you can just do "BUTTON"w.ptr // note the wThis gives an error saying: Cannot pas argument of type 'int' to argument of type 'void*'. How is this fixed?Use lowercase `null` instead.
Dec 09 2020
On Wednesday, 9 December 2020 at 17:37:16 UTC, Ruby The Roobster wrote:It's not the 'NULL' that's the error.I know.It doesn't compile because of the '0' . That is what I need to fix, since I want to make a WM_COMMAND for that button.Use lowercase `null` instead.
Dec 09 2020
On Wednesday, 9 December 2020 at 17:42:50 UTC, Adam D. Ruppe wrote:On Wednesday, 9 December 2020 at 17:37:16 UTC, Ruby The Roobster wrote:I did. Still gives an error: LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) nothrow { scope (failure) assert(0); HDC hdc; PAINTSTRUCT ps; RECT rect; switch (message) { case WM_CREATE: CreateWindow("BUTTON".toUTF16z, // window class name "The Hello Program", // window caption WS_CHILD | WS_VISIBLE, // window style CW_USEDEFAULT, // initial x position CW_USEDEFAULT, // initial y position 250, // initial x size 250, // initial y size hwnd, // parent window handle 0, // window menu handle null, // program instance handle null); return 0; case WM_COMMAND: case WM_DESTROY: PostQuitMessage(0); return 0; default: } return DefWindowProc(hwnd, message, wParam, lParam); }It's not the 'NULL' that's the error.I know.It doesn't compile because of the '0' . That is what I need to fix, since I want to make a WM_COMMAND for that button.Use lowercase `null` instead.
Dec 09 2020
Also, here is the error in full: E:\Users\User\Desktop\tet.d|100|
cannot pass argument `0` of type `int` to parameter `void*
i`|
Dec 09 2020
On Wednesday, 9 December 2020 at 17:45:18 UTC, Ruby The Roobster
wrote:
0, // window menu
here, that's the only int you do and I'm pretty sure that's
supposed a be a HMENU which is a HANDLE, which is a void* rather
than an int.
C will cast 0 to null implicitly, D will not. If there's ever a
case where you need to pass a number as a handle (like some
HBRUSHe among others), you then explicitly cast it like
`cast(HANDLE) -1`. (HANDLE is an alias to void* too so that would
also work)
But for 0 you almost certainly just want to get in the habit of
using the built in `null` instead 0.
re NULL vs null, both are OK here, but since NULL can actually be
overridden by other libs (it is just a library constant) you're
better off consistently using `null` for those too.
Dec 09 2020
On Wednesday, 9 December 2020 at 17:57:49 UTC, Adam D. Ruppe wrote:C will cast 0 to null implicitly, D will not. If there's ever a case where you need to pass a number as a handle (like some HBRUSHe among others), you then explicitly cast it like `cast(HANDLE) -1`. (HANDLE is an alias to void* too so that would also work)Thank you. Now it works.
Dec 09 2020









Ruby The Roobster <michaeleverestc79 gmail.com> 