digitalmars.D.learn - Win32api: How to send a Struct in DialogBox?
- Marcone (16/16) Oct 13 2020 struct Teste {
- starcanopy (4/28) Oct 13 2020 -
- Marcone (2/8) Oct 13 2020 Can you make a example with my code?
- Marcone (9/9) Oct 13 2020 DialogBoxParam receive need "int". How convert struct object
- Marcone (8/8) Oct 13 2020 Solved:
- starcanopy (6/14) Oct 13 2020 Sorry, I was going to create an example for you, but something
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); }
Oct 13 2020
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
Oct 13 2020
On Tuesday, 13 October 2020 at 22:46:36 UTC, starcanopy wrote:On Tuesday, 13 October 2020 at 22:26:35 UTC, Marcone wrote:Can you make a example with my code?[...]Instead of calling DialogBox, you might try DialogBoxParam[A|W].[...]- https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-dialogboxparamw
Oct 13 2020
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*
Oct 13 2020
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*
Oct 13 2020
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.
Oct 13 2020