home *** CD-ROM | disk | FTP | other *** search
/ Computerworld 1996 March / Computerworld_1996-03_cd.bin / idg_cd3 / aplikace / komunika / odywin2 / ody2wevj.lzh / TESTDLG.SCR < prev    next >
Encoding:
Text File  |  1995-02-03  |  6.7 KB  |  162 lines

  1.  
  2. SCRIPT TestDlg;
  3.  
  4. #include "windows.inc"
  5.  
  6. VAR hWndClient:Number;
  7.     hRes,hToolBar,hMenu:Number;
  8.  
  9. (*................................................*)
  10.  
  11. FUNC TestDialog():Number;
  12.  
  13.  CONST IDD_TEXT0     = 200;  (* IDs you assigned to dialog controls *)
  14.        IDD_MYBUTTON  = 201;
  15.  
  16.        IDD_TBFIRST   = 250;  (* IDs you assigned to toolbar buttons *)
  17.        IDD_TBLAST    = 253;
  18.        IDD_TBHELP    = 253;
  19.  
  20.        IDM_MENUFIRST = 1000; (* you MUST use this ID range for menu items *)
  21.        IDM_MENULAST  = 1199;
  22.  
  23.        IDM_ARRANGEICONS = 1033; (* A menu item we'll actually do something with *)
  24.  
  25.  VAR hDlg,iMsg,wParam,hStatus:Number;
  26.      lParam:Long;
  27.      myText:String[30];
  28.      NumStr:String[10];
  29.  
  30. BEGIN
  31.      wParam := -1;
  32.      myText := "A string to edit";
  33.  
  34.      (* Load the dialog template by name from the resource DLL (hRes) *)
  35.      hDlg := LoadDialog(hRes, "TESTDLG",-1,-1);
  36.      IF hDlg=0 THEN
  37.          Write('Unable to find dialog template "TESTDLG".|');
  38.        ELSE
  39.          (* The dialog is automatically displayed, so now we are ready to
  40.           * enter our message loop for this dialog.
  41.           *)
  42.          WHILE GetDialogMessage(hDlg,iMsg,wParam,lParam) DO
  43.              CASE iMsg OF (* check message type *)
  44.                | WM_INITDIALOG:
  45.                    (* This is the first msg every dialog gets. It tells us
  46.                     * to fill in all the text controls, highlight the
  47.                     * appropriate radio buttons etc.
  48.                     *)
  49.                    SetDlgItemText(hDlg,IDD_TEXT0,myText);
  50.                    hStatus := AssignStatus(hDlg, "[20]TESTDLG.SCR[0]Demonstration Status Line");
  51.                    AssignMenu(hDlg, hMenu, 3);
  52.                    AssignToolBar(hDlg, hToolBar);
  53.  
  54.                | WM_COMMAND:
  55.                    (* You get a WM_COMMAND message every time the user clicks
  56.                     * a menu item, toolbar button or a button in the dialog,
  57.                     * in which case wParam identifies the item. You also
  58.                     * get WM_COMMANDs which are actually notification messages
  59.                     * from listbox controls and the like.
  60.                     *)
  61.                     IF ((wParam>=IDM_MENUFIRST) AND (wParam<=IDM_MENULAST)) THEN
  62.                        IntToStr(wParam, NumStr);
  63.                        SetStatusField(hStatus, 1, "Menu command ("+NumStr+") selected.");
  64.                        IF wParam=IDM_ARRANGEICONS THEN
  65.                            WinPostMessage(hWndClient,WM_MDIICONARRANGE,0,0);
  66.                        END;
  67.                      ELSIF ((wParam>=IDD_TBFIRST) AND (wParam<=IDD_TBLAST)) THEN
  68.                        IntToStr(wParam-IDD_TBFIRST, NumStr);
  69.                        SetStatusField(hStatus, 1, "ToolBar button("+NumStr+") clicked.");
  70.                        IF wParam=IDD_TBHELP THEN
  71.                            WinPostMessage(hDlg,WM_COMMAND,IDHELP,0);
  72.                        END;
  73.                      ELSE
  74.                        CASE wParam OF
  75.                          | IDD_MYBUTTON:
  76.                              SetDlgItemText(hDlg, IDD_TEXT0, "Button clicked!");
  77.                              SetStatusField(hStatus, 1, "Button clicked!");
  78.                          | IDHELP:
  79.                              MessageBox(GetFocus(),
  80.                                  "Sorry, this demo doesn't provide any help!",
  81.                                  "Help!",
  82.                                  MB_ICONSTOP+MB_OK);
  83.                          | IDOK:
  84.                              (* OK button clicked - read out the final values
  85.                               * of the dialog fields, then close the dialog.
  86.                               *)
  87.                              GetDlgItemText(hDlg, IDD_TEXT0, myText);
  88.                              EndDialog(hDlg, 1);
  89.                          | IDCANCEL:
  90.                              (* Cancel button clicked - discard any changes
  91.                               * made to dialog fields, then close the dialog.
  92.                               *)
  93.                              EndDialog(hDlg, 0);
  94.                        END;
  95.                    END;
  96.              END;
  97.          END;
  98.      END;
  99.      Write("Dialog has ended, result=",wParam,".|");
  100.      Write('   string was "',myText,'".|');
  101.      return wParam;
  102. END;
  103.  
  104. (*................................................*)
  105.  
  106. BEGIN
  107.      (* This next line shows a trick you can use to obtain the handle of
  108.       * Odyssey's MDI client window. This is a standard windows which all
  109.       * genuine MDI applications have. The Windows Programmers Reference
  110.       * books documents messages you can send to Windows of this type. For
  111.       * the purpose of this demo we will only be sending a WM_MDIICONARRANGE
  112.       * message to it.
  113.       *)
  114.      hWndClient := GetDlgItem(GetOdyWindow(), 0);
  115.  
  116.      (* We need a handle to the library (DLL) where our resources
  117.       * are stored (ie. menu and dialog templates, toolbar bitmaps, etc.
  118.       *)
  119.      hRes := LoadResourceLibrary("demodlg.dll");
  120.  
  121.      IF (hRes>=32) THEN (* make sure the resource DLL handle is valid *)
  122.          (* Extract a menu template by name from the resource library *)
  123.          hMenu := LoadMenu(hRes, "TEST_MENU");
  124.  
  125.          IF hMenu<>0 THEN (* if that worked, then... *)
  126.              (* Tell Odyssey to extract a toolbar bitmap from the resource
  127.               * DLL, and turn it into an actual toolbar.
  128.               *)
  129.              hToolBar := CreateToolBar(hRes,"TEST_TOOLS",4,
  130.                 "250[Button help0],251[Button help1],252[Button help2],253[Button help3]");
  131.  
  132.              (* Note that by this point the menu and toolbar objects are
  133.               * loaded, but so far they are neither visible nor active. That
  134.               * is because they are only displayed when the associated
  135.               * modeless dialog is active, and we haven't even created that
  136.               * dialog next - the following local function both creates (loads)
  137.               * and animates the dialog.
  138.               *)
  139.              TestDialog();
  140.  
  141.              (* If we've finished animating the dialog then we are finished
  142.               * altogether, which means that now we might as well free the
  143.               * resources we allocated above.
  144.               *)
  145.              DestroyToolBar(hToolBar);
  146.              DestroyMenu(hMenu);
  147.              (* Note that the hToolBar and hMenu handles are invalid from
  148.               * this point onwards.
  149.               *)
  150.          END;
  151.  
  152.          (* Finally, we tell Windows to discard the resource DLL *)
  153.          FreeResourceLibrary(hRes);
  154.  
  155.          (* Fini. *)
  156.        ELSE
  157.          (* Well, that didn't get very far, did it! *)
  158.          Write('Unable to open resource library "DEMODLG.DLL".|');
  159.      END;
  160. END;
  161.  
  162.