Thread overview
Win32api: How to send a Struct in DialogBox?
Oct 13
Marcone
Oct 13
Marcone
Oct 14
Marcone
Oct 14
Marcone
October 13
struct Teste {
    string nome = "Paul";
    int idade = 33;
}

extern(Windows):
BOOL DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) nothrow
{
    // I want to be able to use the struct object here.
    // writeln(test.nome);
    return false;
}

void chamaJanela(){
    Test test; // How to send this object to the DlgMain function?
    DialogBox(null, MAKEINTRESOURCE(IDD_DIALOG1), null, &DlgMain);
}
October 13
On Tuesday, 13 October 2020 at 22:26:35 UTC, Marcone wrote:
> struct Teste {
>     string nome = "Paul";
>     int idade = 33;
> }
>
> extern(Windows):
> BOOL DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) nothrow
> {
>     // I want to be able to use the struct object here.
>     // writeln(test.nome);
>     return false;
> }
>
> void chamaJanela(){
>     Test test; // How to send this object to the DlgMain function?
>     DialogBox(null, MAKEINTRESOURCE(IDD_DIALOG1), null, &DlgMain);
> }

Instead of calling DialogBox, you might try DialogBoxParam[A|W].

>Before displaying the dialog box, the function passes an application-defined
>value to the dialog box procedure as the lParam parameter of the WM_INITDIALOG
>message. An application can use this value to initialize dialog box controls.

- https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-dialogboxparamw


October 13
On Tuesday, 13 October 2020 at 22:46:36 UTC, starcanopy wrote:
> On Tuesday, 13 October 2020 at 22:26:35 UTC, Marcone wrote:
>> [...]
>
> Instead of calling DialogBox, you might try DialogBoxParam[A|W].
>
>>[...]
>
> - https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-dialogboxparamw

Can you make a example with my code?
October 14
DialogBoxParam receive need "int". How convert struct object reference to int and cast to struct type after?

I will cast using:

Teste * params = cast(Teste*) LOWORD(lParam);

writeln(params.nome);
writeln(params.idade);


But here, how can send struct?

DialogBoxParam(null, MAKEINTRESOURCE(IDD_DIALOG1), null, &DlgMain, &test); // Error, need "int" but I am sending Test*





October 14
Solved:

Teste * params = cast(Teste*) lParam;

writeln(params.nome);
writeln(params.idade);


But here, how can send struct?

DialogBoxParam(null, MAKEINTRESOURCE(IDD_DIALOG1), null, &DlgMain, cast(int) &test); // Error, need "int" but I am sending Test*
October 14
On Wednesday, 14 October 2020 at 00:07:10 UTC, Marcone wrote:
> Solved:
>
> Teste * params = cast(Teste*) lParam;
>
> writeln(params.nome);
> writeln(params.idade);
>
>
> But here, how can send struct?
>
> DialogBoxParam(null, MAKEINTRESOURCE(IDD_DIALOG1), null, &DlgMain, cast(int) &test); // Error, need "int" but I am sending Test*

Sorry, I was going to create an example for you, but something came up. Thankfully, it looks like you've solved it in your own way (You might want to cast &test to LPARAM instead of int.), but if you have any more D/WinApi questions, you might want to check here: https://github.com/AndrejMitrovic/DWinProgramming.