home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1991 / 05 / grdlagen / dialog1.c next >
Encoding:
C/C++ Source or Header  |  1991-02-20  |  8.3 KB  |  233 lines

  1. /*--------------------------------------------------------*/
  2. /*                    DIALOG1.C                           */
  3. /*      Dialogboxen für den OS/2-Presentation Manager     */
  4. /*         (c) 1991 Jürgen Heid & TOOLBOX                 */
  5. /*--------------------------------------------------------*/
  6. #include <stdio.h>
  7. #include "dialog1.h"                   // Symbol. Konstanten
  8. #define INCL_WIN
  9. #include <os2.h>                       //  PM-Include-Datei
  10.  
  11. typedef struct INFO
  12.  { USHORT  usDialogType; USHORT  idActColor; }
  13. INFO;
  14. /*-------------- Funktions-Prototypen --------------------*/
  15. int cdecl        main(VOID);
  16. BOOL             WndCreate(VOID);
  17. MRESULT EXPENTRY ClientWindowProc(HWND   hwnd, USHORT msg,
  18.                                   MPARAM mp1,  MPARAM mp2);
  19. MRESULT EXPENTRY FarbenDlgProc(   HWND   hwnd, USHORT msg,
  20.                                   MPARAM mp1,  MPARAM mp2);
  21. void             PaintClient(HWND hwnd, USHORT idB);
  22. /*-------------- globale Variablen -----------------------*/
  23. HAB  hab_g;                 // Programmanker
  24. HWND hwndFrame_g;           // Handle für das Frame-Fenster
  25. HWND hwndClient_g;          // Handle für den Client-Bereich
  26. CHAR  szText_g[]  =  " Hello World by PM ";
  27. /*-------------- Tabelle der Farben ----------------------*/
  28. COLOR aColors_g[]={CLR_BLACK,     CLR_BLUE,    CLR_RED,
  29.                    CLR_PINK,      CLR_GREEN,   CLR_CYAN,
  30.                    CLR_YELLOW,    CLR_WHITE,   CLR_DARKGRAY,
  31.                    CLR_DARKBLUE,  CLR_DARKRED, CLR_DARKPINK,
  32.                    CLR_DARKGREEN, CLR_DARKCYAN,
  33.                    CLR_BROWN,     CLR_PALEGRAY};
  34.  
  35. int cdecl main()
  36. {
  37.   HMQ   hmq;                // Handle fuer die Message-Queue
  38.   QMSG  qmsg;               // Message in der Message-Queue
  39.   hab_g = WinInitialize(0);          //Initialisiere PM
  40.   hmq = WinCreateMsgQueue(hab_g, 0); //Erzeuge Message-Queue
  41.   if (hmq != (HMQ)NULL)
  42.   {
  43.     if (WndCreate() == TRUE)
  44.     {
  45.       while(WinGetMsg(hab_g,(PQMSG)&qmsg, (HWND)NULL, 0, 0))
  46.         WinDispatchMsg(hab_g, (PQMSG)&qmsg);
  47.       WinDestroyWindow(hwndFrame_g);
  48.     }
  49.     WinDestroyMsgQueue(hmq);
  50.   }
  51.   WinTerminate(hab_g);
  52.   return 0;
  53. }
  54.  
  55. BOOL WndCreate(VOID)
  56. {
  57.  
  58.   CHAR szClientClass[] = "KlasseDialog1"; // Name Fensterkl.
  59.   ULONG flCreateFrame;  // Flags für die Erzeugung d. Contr.
  60.   BOOL  fRc;            // Hilfsvariable zur Prüfung des
  61.                         // Rückgabewertes von API-Funktionen
  62.   fRc = WinRegisterClass(
  63.           hab_g,             // Programmanker
  64.           szClientClass,     // Name der Fensterklasse
  65.           ClientWindowProc,  // Adr. der Fensterprozedur
  66.           CS_SIZEREDRAW,     // Klassen-Style
  67.           0);                // keine Extra-Bytes reservier.
  68.   if (fRc == FALSE) return (FALSE);
  69.   flCreateFrame = FCF_STANDARD & ~FCF_ICON;
  70.   hwndFrame_g = WinCreateStdWindow(
  71.            HWND_DESKTOP,      // Handle des Vaterfensters
  72.            WS_VISIBLE,        // Style des Frame-Fensters
  73.            (PULONG)&flCreateFrame,
  74.            szClientClass,     // Client-Fenster-Klasse
  75.            "",                // Kein expliziter Titel
  76.            0L,                // Style des Client-Fensters
  77.            (HMODULE)NULL,     // Resourcen sind in EXE-Datei
  78.            ID_RESOURCE,       // Bezeichner für Resources
  79.            (PHWND)&hwndClient_g);
  80.   if (hwndFrame_g == (HWND)NULL) return (FALSE);
  81.   return (TRUE);
  82. }
  83.  
  84. MRESULT EXPENTRY ClientWindowProc(HWND hwnd, USHORT msg,
  85.                                   MPARAM mp1, MPARAM mp2)
  86. {                      // ID der aktuell angezeigten Farbe !
  87.   static  USHORT  idColorBClient_s  =  ID_BRED;
  88.                // ID der ClientFarbe vordem Aufklappen der
  89.                // Dialogbox vom Typ 2. Wichtig bei "CANCEL"!
  90.   static  USHORT  idColorBClientOld_s;
  91.   USHORT  usRc;
  92.   BOOL    fRc;
  93.  
  94.   switch(msg)
  95.   {
  96.     case WM_PAINT:
  97.       PaintClient (hwnd, idColorBClient_s); return 0;
  98.     case WM_USER:
  99.     {
  100.       USHORT idRadioButton;
  101.       idRadioButton = SHORT1FROMMP(mp1);
  102.       if (idRadioButton != idColorBClient_s  &&
  103.           idRadioButton >= ID_BBLACK         &&
  104.           idRadioButton <= ID_BPGRAY)
  105.       {
  106.        idColorBClient_s = idRadioButton; DosBeep(1200, 100);
  107.        fRc = WinInvalidateRect (hwnd, NULL, FALSE) ;
  108.       }
  109.       return 0;                 // Message wurde verarbeitet
  110.     }
  111.     case WM_COMMAND:
  112.     {
  113.       USHORT command; INFO info;
  114.       command = COMMANDMSG(&msg)->cmd; switch (command)
  115.       {
  116.         case IDM_EXITPROG:
  117.           WinPostMsg(hwnd, WM_CLOSE, 0L, 0L); break;
  118.         case IDM_BCOLOR1:
  119.           info.usDialogType = IDM_BCOLOR1;
  120.           info.idActColor   = idColorBClient_s;
  121.           usRc = WinDlgBox (HWND_DESKTOP, hwnd,
  122.                             FarbenDlgProc, (HMODULE) NULL,
  123.                             IDD_BCOLOR12, (PVOID)&info);
  124.           if (usRc != DID_CANCEL && usRc != DID_ERROR)
  125.           {
  126.             if (idColorBClient_s != usRc)
  127.             {
  128.               idColorBClient_s = usRc; DosBeep(1200, 100);
  129.               fRc = WinInvalidateRect(hwnd,NULL,FALSE);
  130.             }
  131.           }
  132.           return 0;
  133.         case IDM_BCOLOR2:
  134.           idColorBClientOld_s = idColorBClient_s;
  135.           info.usDialogType = IDM_BCOLOR2;
  136.           info.idActColor   = idColorBClient_s;
  137.           usRc = WinDlgBox (HWND_DESKTOP, hwnd,
  138.                             FarbenDlgProc, (HMODULE) NULL,
  139.                             IDD_BCOLOR12, (PVOID)&info);
  140.           if (usRc == DID_CANCEL &&
  141.               idColorBClient_s != idColorBClientOld_s )
  142.           {
  143.             idColorBClient_s  =  idColorBClientOld_s;
  144.             DosBeep(1200, 100);
  145.             fRc = WinInvalidateRect(hwnd,NULL,FALSE);
  146.           }
  147.           return 0 ;
  148.         case IDM_RESUME:
  149.           break;
  150.         default:              // default für switch(command)
  151.           return WinDefWindowProc(hwnd,msg,mp1,mp2);
  152.       }
  153.     }
  154.     default:                  // default für switch(msg)
  155.       return WinDefWindowProc(hwnd, msg, mp1, mp2);
  156.   }
  157.   return FALSE;
  158. }
  159.  
  160. void PaintClient(HWND hwnd, USHORT idB)
  161. {
  162.   HPS    hps;               // Presentation-Space-Handle
  163.   RECTL  rectl;             // Struktur Rechteck-Koordinaten
  164.   BOOL   fRc;
  165.   int    rc;
  166.   char   szTmp[255];
  167.   COLOR  colorBClient;
  168.   hps  = WinBeginPaint(hwnd, NULL, NULL);
  169.   sprintf(szTmp, "%s (idColorBClient = %d)", szText_g, idB);
  170.   colorBClient = aColors_g[idB-ID_BBLACK];
  171.   fRc = WinQueryWindowRect(hwnd, &rectl);
  172.   rc = WinDrawText(hps, -1, szTmp, &rectl, CLR_WHITE,
  173.        colorBClient, DT_CENTER | DT_VCENTER | DT_ERASERECT);
  174.   fRc = WinEndPaint(hps);              // Paint ist erledigt
  175. }
  176.  
  177. MRESULT EXPENTRY FarbenDlgProc(HWND hwnd,  USHORT msg,
  178.                                MPARAM mp1, MPARAM mp2)
  179. {
  180.   static USHORT  idRadioButton_s;
  181.   static USHORT  usDialogType_s;
  182.   BOOL           fRc;
  183.   switch (msg)
  184.   {
  185.     case WM_INITDLG:
  186.     {
  187.       INFO FAR *pinfo;
  188.       pinfo = (INFO FAR *) PVOIDFROMMP(mp2);
  189.       idRadioButton_s = pinfo->idActColor;
  190.       usDialogType_s  = pinfo->usDialogType;
  191.       WinSendDlgItemMsg(hwnd, idRadioButton_s,
  192.                         BM_SETCHECK, MPFROM2SHORT (TRUE, 0),
  193.                         NULL);
  194.       return (MRESULT)FALSE;
  195.     }
  196.     case WM_CONTROL:
  197.     {
  198.       USHORT  id = SHORT1FROMMP (mp1);
  199.       if (id >= ID_BBLACK && id <= ID_BPGRAY)
  200.       {
  201.         idRadioButton_s = id;         // gilt für Typ 1 + 2!
  202.         if (usDialogType_s == IDM_BCOLOR2  &&
  203.             SHORT2FROMMP(mp1) == BN_CLICKED)
  204.         {
  205.           fRc = WinPostMsg(hwndClient_g, WM_USER,
  206.                            MPFROMSHORT(idRadioButton_s),0L);
  207.         }
  208.       }
  209.       return 0 ;
  210.     }
  211.     case WM_COMMAND:
  212.     {
  213.       USHORT  command;
  214.       if (usDialogType_s == IDM_BCOLOR1)
  215.       {
  216.         command = COMMANDMSG(&msg)->cmd;
  217.         if (command == DID_CANCEL)
  218.           return WinDefDlgProc (hwnd, msg, mp1, mp2);
  219.         else
  220.         {                            // fRc muss TRUE sein!
  221.           fRc = WinDismissDlg (hwnd, idRadioButton_s );
  222.           return NULL;
  223.         }
  224.       }
  225.       else return WinDefDlgProc (hwnd, msg, mp1, mp2);
  226.     }
  227.     default:
  228.       return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
  229.   }
  230. }
  231. /*--------------------------------------------------------*/
  232. /*                Ende von DIALOG1.C                      */
  233.