From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5feb723c26279aee X-Google-Attributes: gid103376,public From: "Jerry van Dijk" Subject: Re: Win32 dialogs/resource grief (longish) Date: 2000/03/02 Message-ID: <38bdb710_1@news2.prserv.net> X-Deja-AN: 592008452 References: <38BC8428.901597BD@brighton.ac.uk> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Complaints-To: abuse@prserv.net X-Trace: 2 Mar 2000 00:34:24 GMT, 139.92.232.207 Organization: * JerryWare * X-MSMail-Priority: Normal Reply-To: "Jerry van Dijk" Newsgroups: comp.lang.ada Date: 2000-03-02T00:00:00+00:00 List-Id: > I have two simple dialogs: one with a label, combo box and OK/Cancel > buttons, another with a label and Yes/No/Cancel buttons. They work > fine individually, but not together. I've tried putting the dialogs > in the same resource file and in separate files; it makes no difference. Basically, the problem is that passing around data within the Win32 environment takes more care. Explaining it all would take more then a posting, but hopefully the code below will point in the right direction. Compile with: rcl -i yesnodlg.rc yesnodlg.o gnatmake test_dialogs -- test_dialogs.adb ---------------- with YesNo_Dialog; procedure Test_Dialogs is begin YesNo_Dialog.Do_Dialog; end Test_Dialogs; -- yesno_dialog.ads ---------------- package YesNo_Dialog is procedure Do_Dialog; -- execute dialog end YesNo_Dialog; -- yesno_dialog.adb ---------------- with Ada.Text_IO; use Ada.Text_IO; with Ada.Unchecked_Conversion; with Win32; use Win32; with Win32.Windef; use Win32.Windef; with Win32.Winuser; use Win32.Winuser; with Win32.Windowsx; use Win32.Windowsx; with Resources; use Resources; package body YesNo_Dialog is ------------------------- -- Generic subprograms -- ------------------------- type Integer_Access is access all Integer; function To_LPARAM is new Ada.Unchecked_Conversion (Integer_Access, LPARAM); function To_Access is new Ada.Unchecked_Conversion (LPARAM, Integer_Access); -- for moving an integer pointer around ------------------------- -- Private subprograms -- ------------------------- function YesNo_DlgProc (Dlg_Handle : HWND; Dlg_Message : UINT; Dlg_wParam : WPARAM; Dlg_lParam : LPARAM) return BOOL; pragma Convention (StdCall, YesNo_DlgProc); -- Dialog procedure function On_Init (Dlg_Handle : HWND; Dlg_Focus : HWND; Dlg_lParam : LPARAM) return Win32.BOOL; -- handle dialog initialization procedure On_Command (Dlg_Handle : HWND; Control_Id : INT; Control_Handle : HWND; Notification_Code : UINT); -- handle dialog commands -------------------- -- Execute Dialog -- -------------------- procedure Do_Dialog is Result : INT; Button : aliased Integer; begin Put_Line ("--- Yes/no dialog test ---"); Result := DialogBoxParam (GetWindowInstance (Desktop_Handle), LPCSTR (MAKEINTRESOURCE (YesNo_Dlg)), Desktop_Handle, YesNo_DlgProc'Access, To_LPARAM (Button'Unchecked_Access)); Put_Line ("Dialog result code:" & Result'Img); Put ("Button pressed: "); case Button is when IDYES => Put_Line ("Yes"); when IDNO => Put_Line ("No"); when IDCANCEL => Put_Line ("Cancel"); when others => Put_Line ("Unknown"); end case; end Do_Dialog; ---------------------- -- Dialog procedure -- ---------------------- function YesNo_DlgProc (Dlg_Handle : HWND; Dlg_Message : UINT; Dlg_wParam : WPARAM; Dlg_lParam : LPARAM) return BOOL is begin case Dlg_Message is when WM_INITDIALOG => return BOOL (HANDLE_WM_INITDIALOG (Dlg_Handle, Dlg_wParam, Dlg_lParam, On_Init'Access)); when WM_COMMAND => return BOOL (HANDLE_WM_COMMAND (Dlg_Handle, Dlg_wParam, Dlg_lParam, On_Command'Access)); when others => return Win32.FALSE; end case; end YesNo_DlgProc; ---------------------------------- -- Handle dialog initialization -- ---------------------------------- function On_Init (Dlg_Handle : HWND; Dlg_Focus : HWND; Dlg_lParam : LPARAM) return Win32.BOOL is Result : LONG; begin Result := SetWindowLong (Dlg_Handle, GWL_USERDATA, Dlg_lParam); return Win32.TRUE; end On_Init; ---------------------------- -- Handle dialog commands -- ---------------------------- procedure On_Command (Dlg_Handle : HWND; Control_Id : INT; Control_Handle : HWND; Notification_Code : UINT) is Result : BOOL; Button : Integer_Access; begin Button := To_Access (GetWindowLong (Dlg_Handle, GWL_USERDATA)); case Control_Id is when IDNO => Button.all := IDNO; Result := EndDialog (Dlg_Handle, Win32.TRUE); when IDYES => Button.all := IDYES; Result := EndDialog (Dlg_Handle, Win32.TRUE); when IDCANCEL => Button.all := IDCANCEL; Result := EndDialog (Dlg_Handle, Win32.TRUE); when others => null; end case; end On_Command; end YesNo_Dialog; -- resources.ads ---------------- with System; use System; with Win32.Windef; use Win32.Windef; package Resources is pragma Linker_Options ("yesnodlg.o"); -- link the dialog resources Desktop_Handle : constant HWND := Null_Address; -- Handle to the desktop 'window' YesNo_Dlg : constant := 1000; -- dialog resource identifiers end Resources; /* -- yesnodlg.rc --------------- */ #include 1000 DIALOG 6, 15, 166, 39 STYLE DS_3DLOOK | DS_CENTER | 0x200L | WS_POPUP | WS_VISIBLE | WS_CAPTION CAPTION "Yes/no dialog" FONT 9, "Arial" BEGIN LTEXT "Press a button:", 1004, 8, 4, 131, 12 DEFPUSHBUTTON "Yes", IDYES, 12, 20, 42, 13 PUSHBUTTON "No", IDNO, 64, 20, 42, 13 PUSHBUTTON "Cancel", IDCANCEL, 116, 20, 42, 13 END