Thread overview
How to make Create Window Work?
Dec 09, 2020
Ruby The Roobster
Dec 09, 2020
Adam D. Ruppe
Dec 09, 2020
Ruby The Roobster
Dec 09, 2020
Adam D. Ruppe
Dec 09, 2020
Ruby The Roobster
Dec 09, 2020
Ruby The Roobster
Dec 09, 2020
Adam D. Ruppe
Dec 09, 2020
Ruby The Roobster
December 09, 2020
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?
December 09, 2020
On Wednesday, 9 December 2020 at 17:25:10 UTC, Ruby The Roobster wrote:
>              CreateWindow("BUTTON".toUTF16z,      // window class name

fyi for a string literal like this you can just do

"BUTTON"w.ptr // note the w

> This gives an error saying: Cannot pas argument of type 'int' to argument of type 'void*'. How is this fixed?

Use lowercase `null` instead.
December 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:
>>              CreateWindow("BUTTON".toUTF16z,      // window class name
>
> fyi for a string literal like this you can just do
>
> "BUTTON"w.ptr // note the w
>
>> This gives an error saying: Cannot pas argument of type 'int' to argument of type 'void*'. How is this fixed?
>
> Use lowercase `null` instead.

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.
December 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.

December 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:
>> 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.

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);
}
December 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`|
December 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.
December 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.