home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------*/
- /* DIALOG2.C */
- /* (C) 1991 J. Heid & toolbox */
- /* für OS/2 1.2 oder höher */
- /*--------------------------------------------------------*/
-
- #include <stdio.h>
- #include "dialog2.h" // Symbol. Konstanten für
- // dialog2.c und dialog2.rc
- #define INCL_WIN
- #include <os2.h> // PM-Include-Datei
- #define MAXITEMLEN 80 // max. Länge des Farbtextes
- #define ANZAHLFARBEN 16
- typedef struct INFO // Initialisierungsinfo für
- { // die Dialogbox:
- USHORT idActColor; // zu checkender Radiobutton,
- USHORT usType; // Typ und
- CHAR *szTitel; // Titel
- } INFO;
-
- int cdecl main(int argc, char **argv);
- BOOL WndCreate(VOID);
- MRESULT EXPENTRY ClientWindowProc(HWND hwnd, USHORT msg,
- MPARAM mp1, MPARAM mp2);
- MRESULT EXPENTRY FarbenDlgProc (HWND hwnd, USHORT msg,
- MPARAM mp1, MPARAM mp2);
- BOOL EnableFarbMenüEintraege(BOOL fEnable);
- void PaintClient(HWND hwnd, USHORT idB);
- HAB hab_g; // Programmanker
- HWND hwndFrame_g; // Handle für das Frame-Fenster
- HWND hwndClient_g; // Handle für den Client-Bereich
- // des Fensters
- HWND hwndMenu_g; // Handle für den Actionbar
- CHAR szText_g[] = " Hello World by PM ";
- CHAR *aszTitel_g[] = { "Applikationsmodale Dialogbox",
- "Systemmodale Dialogbox",
- "Nichtmodale Dialogbox" };
- // Tabelle der Farben
- COLOR aColors_g[] = { CLR_BLACK, CLR_BLUE,
- CLR_RED, CLR_PINK,
- CLR_GREEN, CLR_CYAN,
- CLR_YELLOW, CLR_WHITE,
- CLR_DARKGRAY, CLR_DARKBLUE,
- CLR_DARKRED, CLR_DARKPINK,
- CLR_DARKGREEN, CLR_DARKCYAN,
- CLR_BROWN, CLR_PALEGRAY };
- // Text neben den Radiobuttons in der Dialogbox
- CHAR aszRadioButtonText_g[ANZAHLFARBEN][MAXITEMLEN+1];
- BOOL fMehrereDlgBoxen_g = FALSE;
-
- int cdecl main(int argc, char **argv)
- {
- HMQ hmq; // Handle für die Message-Queue
- QMSG qmsg; // Message in der Message-Queue
- if (argc == 2)
- {
- if ((argv[1][0] == '-' || argv[1][0] == '/') &&
- (argv[1][1] == 'm'))
- fMehrereDlgBoxen_g = TRUE;
- }
- hab_g = WinInitialize(0); // Initialisiere PM
- // Erzeuge Message-Queue
- hmq = WinCreateMsgQueue(hab_g, 0);
- if (hmq != (HMQ)NULL)
- {
- if (WndCreate() == TRUE)
- {
- while(WinGetMsg(hab_g, (PQMSG)&qmsg, (HWND)NULL, 0,0))
- WinDispatchMsg(hab_g, (PQMSG)&qmsg);
- WinDestroyWindow(hwndFrame_g);
- }
- WinDestroyMsgQueue(hmq);
- }
- WinTerminate(hab_g);
- return 0;
- }
-
- BOOL WndCreate(VOID)
- {
- // Name der Fensterklasse
- CHAR szClientClass[] = "KlasseDialog2";
- ULONG flCreateFrame; // Flaggen für die Erzeugung
- // der Controls
- BOOL fRc; // Hilfsvariable zum Abprüfen
- // des Rückgabewertes von
- // API-Funktionen
- // Ordne die ClientWndProc einer Klasse zu
- fRc = WinRegisterClass(
- hab_g, // Programmanker
- szClientClass, // Name der Fensterklasse
- ClientWindowProc, // Adr. der Fensterprozedur
- CS_SIZEREDRAW, // Klassen-Style
- 0); // keine Extra-Bytes reservieren
- // wenn WinRegisterClass schiefgeht
- if (fRc == FALSE) return (FALSE);
- // Standardfenster mit Actionbar und
- // Akzeleratortabelle als Resource
- flCreateFrame = FCF_STANDARD & ~FCF_ICON;
- // Erzeugen eines Standardfensters
- hwndFrame_g = WinCreateStdWindow(
- HWND_DESKTOP, // Handle des Vaterfensters
- WS_VISIBLE, // Style des Frame-Fensters
- (PULONG)&flCreateFrame,
- szClientClass, // Client-Fenster-Klasse
- // expliziten Titel anhängen
- " - Demonstration der Dialogbox-Modalitäten",
- 0L, // Style des Client-Fensters
- (HMODULE)NULL, // Resourcen sind in EXE-Datei
- ID_RESOURCE, // Bezeichner für Resourcen
- (PHWND)&hwndClient_g); // Zeiger auf den Handle
- // des Client-Fensters
- // WinCreateStdWindow nicht erfolgreich
- if (hwndFrame_g == (HWND)NULL) return (FALSE);
- return (TRUE);
- }
-
- MRESULT EXPENTRY ClientWindowProc(HWND hwnd, USHORT msg,
- MPARAM mp1, MPARAM mp2)
- {
- static BOOL fDlgBoxActive_s = FALSE;
- static USHORT idColorBClient_s = ID_BRED;
- static USHORT idColorBClientOld_s;
- USHORT usRc;
- BOOL fRc;
- switch(msg)
- {
- case WM_CREATE:
- {
- HWND hwndDlg;
- INFO info;
- USHORT usItemLen;
- int i;
- info.idActColor = idColorBClient_s;
- hwndDlg = WinLoadDlg(HWND_DESKTOP, hwnd,
- FarbenDlgProc, (HMODULE) NULL,
- IDD_BCOLOR, (PVOID)&info);
- if (hwndDlg == NULL) return ((MRESULT)TRUE);
- for (i = 0; i <= ID_BPGRAY-ID_BBLACK; i++)
- {
- usItemLen = WinQueryDlgItemText(
- hwndDlg, ID_BBLACK+i, MAXITEMLEN,
- aszRadioButtonText_g[i]);
- }
- fRc = WinDestroyWindow(hwndDlg);
- if (fRc != TRUE) return ((MRESULT)TRUE);
- hwndFrame_g = WinQueryWindow(hwnd, QW_PARENT, FALSE);
- hwndMenu_g = WinWindowFromID(hwndFrame_g, FID_MENU);
- if (hwndFrame_g == NULL || hwndMenu_g == NULL)
- return ((MRESULT)TRUE);
- return ((MRESULT)FALSE);
- }
- case WM_PAINT:
- PaintClient (hwnd, idColorBClient_s);
- return 0;
- case WM_USER:
- {
- USHORT idRadioButton;
- idRadioButton = SHORT1FROMMP(mp1);
- if (idRadioButton != idColorBClient_s &&
- idRadioButton >= ID_BBLACK &&
- idRadioButton <= ID_BPGRAY)
- {
- idColorBClient_s = idRadioButton;
- DosBeep(1200, 100);
- fRc = WinInvalidateRect (hwnd, NULL, FALSE) ;
- }
- return 0 ; // Message wurde verarbeitet
- }
- case WM_COMMAND:
- {
- USHORT command;
- INFO info;
- command = COMMANDMSG(&msg)->cmd;
- switch (command)
- {
- case IDM_EXITPROG:
- WinPostMsg(hwnd, WM_CLOSE, 0L, 0L);
- break;
- case IDM_APPMODAL:
- case IDM_SYSMODAL:
- case IDM_NONMODAL:
- {
- HWND hwndDlgBoxOwner;
- idColorBClientOld_s = idColorBClient_s;
- info.idActColor = idColorBClient_s;
- if (command == IDM_APPMODAL)
- {
- info.usType = IDM_APPMODAL;
- info.szTitel = aszTitel_g[0];
- hwndDlgBoxOwner = hwnd;
- }
- else if (command == IDM_SYSMODAL)
- {
- info.usType = IDM_SYSMODAL;
- info.szTitel = aszTitel_g[1];
- hwndDlgBoxOwner = hwnd;
- }
- else if (command == IDM_NONMODAL)
- {
- info.usType = IDM_NONMODAL;
- info.szTitel = aszTitel_g[2];
- hwndDlgBoxOwner = HWND_DESKTOP;
- }
- // Aufbau einer Dialogbox
- if (fMehrereDlgBoxen_g == TRUE ||
- (fMehrereDlgBoxen_g == FALSE &&
- fDlgBoxActive_s == FALSE))
- {
- fDlgBoxActive_s = TRUE;
- // Farb-Menüeinträge disablen
- if (command == IDM_NONMODAL &&
- fMehrereDlgBoxen_g == FALSE)
- { fRc = EnableFarbMenueEinträge(FALSE); }
- usRc = WinDlgBox (HWND_DESKTOP, hwndDlgBoxOwner,
- FarbenDlgProc, (HMODULE) NULL,
- IDD_BCOLOR, (PVOID)&info);
- // Farb-Menüeinträge wieder enablen
- if (command == IDM_NONMODAL &&
- fMehrereDlgBoxen_g == FALSE)
- { fRc = EnableFarbMenueEintraege(TRUE); }
- fDlgBoxActive_s = FALSE;
- if (usRc != DID_ERROR && usRc == DID_CANCEL &&
- idColorBClient_s != idColorBClientOld_s)
- {
- idColorBClient_s = idColorBClientOld_s;
- DosBeep(1200, 100);
- fRc = WinInvalidateRect(hwnd,NULL,FALSE);
- }
- } // Ende des Aufbau einer Dialogbox
- return 0 ;
- } // Ende case
- case IDM_RESUME:
- break;
- default: // default für switch(command)
- return WinDefWindowProc(hwnd,msg,mp1,mp2);
- }
- }
- default: // default für switch(msg)
- return WinDefWindowProc(hwnd, msg, mp1, mp2);
- }
- return FALSE;
- }
-
- void PaintClient(HWND hwnd, USHORT idB)
- {
- HPS hps; // Presentation-Space-Handle
- RECTL rectl; // Struktur Rechteck-Koordinaten
- BOOL fRc;
- int rc;
- char szTmp[255];
- COLOR colorBClient; // Erzeuge einen Presentation Space
- hps = WinBeginPaint(hwnd, NULL, NULL);
- sprintf(szTmp, "%s (Farbe = %s)", szText_g,
- aszRadioButtonText_g[idB-ID_BBLACK]);
- colorBClient = aColors_g[idB-ID_BBLACK];
- // rect erhält die Koordinaten des Client
- // fRc = TRUE, wenn WinQueryWindowRect ok ist
- fRc = WinQueryWindowRect(hwnd, &rectl);
- // rc = Anzahl geschriebener Zeichen
- rc = WinDrawText(hps, -1, szTmp, &rectl, CLR_WHITE,
- colorBClient,
- DT_CENTER | DT_VCENTER | DT_ERASERECT);
- fRc = WinEndPaint(hps); // Paint ist erledigt
- }
-
- MRESULT EXPENTRY FarbenDlgProc(HWND hwnd, USHORT msg,
- MPARAM mp1, MPARAM mp2)
- {
- static USHORT idRadioButton_s;
- BOOL fRc;
- switch (msg)
- {
- case WM_INITDLG:
- {
- INFO FAR *pinfo;
- pinfo = (INFO FAR *) PVOIDFROMMP(mp2);
- idRadioButton_s = pinfo->idActColor;
- WinSendDlgItemMsg(hwnd, idRadioButton_s, BM_SETCHECK,
- MPFROM2SHORT (TRUE, 0), NULL);
- // Titel der Dialogbox
- fRc = WinSetWindowText(hwnd, pinfo->szTitel);
- // Dialogbox systemmodal machen
- if (pinfo->usType == IDM_SYSMODAL)
- fRc = WinSetSysModalWindow(HWND_DESKTOP, hwnd);
- return (MRESULT)FALSE ;
- }
- case WM_CONTROL:
- {
- USHORT id = SHORT1FROMMP (mp1);
- if (id >= ID_BBLACK && id <= ID_BPGRAY)
- {
- if (SHORT2FROMMP(mp1) == BN_CLICKED)
- {
- fRc = WinPostMsg(hwndClient_g, WM_USER,
- MPFROMSHORT(idRadioButton_s), 0L);
- if (fRc == TRUE) idRadioButton_s = id;
- }
- }
- return 0 ;
- }
- default: // default für switch(msg)
- return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
- }
- }
-
- BOOL EnableFarbMenueEintraege(BOOL fEnable)
- {
- BOOL fRc1, fRc2, fRc3;
- fRc1 = (BOOL) SHORT1FROMMR(
- WinSendMsg(hwndMenu_g,
- MM_SETITEMATTR,
- MPFROM2SHORT(IDM_APPMODAL, TRUE),
- MPFROM2SHORT(MIA_DISABLED,
- fEnable ? ~MIA_DISABLED:
- MIA_DISABLED)));
- fRc2 = (BOOL) SHORT1FROMMR(
- WinSendMsg(hwndMenu_g,
- MM_SETITEMATTR,
- MPFROM2SHORT(IDM_SYSMODAL, TRUE),
- MPFROM2SHORT(MIA_DISABLED,
- fEnable ? ~MIA_DISABLED:
- MIA_DISABLED)));
- fRc3 = (BOOL) SHORT1FROMMR(
- WinSendMsg(hwndMenu_g,
- MM_SETITEMATTR,
- MPFROM2SHORT(IDM_NONMODAL, TRUE),
- MPFROM2SHORT(MIA_DISABLED,
- fEnable ? ~MIA_DISABLED:
- MIA_DISABLED)));
- if (!fRc1 || !fRc2 || !fRc3) return FALSE;
- else return TRUE;
- }
-
- /*--------------------------------------------------------*/
- /* Ende von DIALOG2.C */