home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------*/
- /* DIALOG1.C */
- /* Dialogboxen für den OS/2-Presentation Manager */
- /* (c) 1991 Jürgen Heid & TOOLBOX */
- /*--------------------------------------------------------*/
- #include <stdio.h>
- #include "dialog1.h" // Symbol. Konstanten
- #define INCL_WIN
- #include <os2.h> // PM-Include-Datei
-
- typedef struct INFO
- { USHORT usDialogType; USHORT idActColor; }
- INFO;
- /*-------------- Funktions-Prototypen --------------------*/
- int cdecl main(VOID);
- 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);
- void PaintClient(HWND hwnd, USHORT idB);
- /*-------------- globale Variablen -----------------------*/
- HAB hab_g; // Programmanker
- HWND hwndFrame_g; // Handle für das Frame-Fenster
- HWND hwndClient_g; // Handle für den Client-Bereich
- CHAR szText_g[] = " Hello World by PM ";
- /*-------------- 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};
-
- int cdecl main()
- {
- HMQ hmq; // Handle fuer die Message-Queue
- QMSG qmsg; // Message in der Message-Queue
- hab_g = WinInitialize(0); //Initialisiere PM
- hmq = WinCreateMsgQueue(hab_g, 0); //Erzeuge Message-Queue
- 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)
- {
-
- CHAR szClientClass[] = "KlasseDialog1"; // Name Fensterkl.
- ULONG flCreateFrame; // Flags für die Erzeugung d. Contr.
- BOOL fRc; // Hilfsvariable zur Prüfung des
- // Rückgabewertes von API-Funktionen
- fRc = WinRegisterClass(
- hab_g, // Programmanker
- szClientClass, // Name der Fensterklasse
- ClientWindowProc, // Adr. der Fensterprozedur
- CS_SIZEREDRAW, // Klassen-Style
- 0); // keine Extra-Bytes reservier.
- if (fRc == FALSE) return (FALSE);
- flCreateFrame = FCF_STANDARD & ~FCF_ICON;
- hwndFrame_g = WinCreateStdWindow(
- HWND_DESKTOP, // Handle des Vaterfensters
- WS_VISIBLE, // Style des Frame-Fensters
- (PULONG)&flCreateFrame,
- szClientClass, // Client-Fenster-Klasse
- "", // Kein expliziter Titel
- 0L, // Style des Client-Fensters
- (HMODULE)NULL, // Resourcen sind in EXE-Datei
- ID_RESOURCE, // Bezeichner für Resources
- (PHWND)&hwndClient_g);
- if (hwndFrame_g == (HWND)NULL) return (FALSE);
- return (TRUE);
- }
-
- MRESULT EXPENTRY ClientWindowProc(HWND hwnd, USHORT msg,
- MPARAM mp1, MPARAM mp2)
- { // ID der aktuell angezeigten Farbe !
- static USHORT idColorBClient_s = ID_BRED;
- // ID der ClientFarbe vordem Aufklappen der
- // Dialogbox vom Typ 2. Wichtig bei "CANCEL"!
- static USHORT idColorBClientOld_s;
- USHORT usRc;
- BOOL fRc;
-
- switch(msg)
- {
- 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_BCOLOR1:
- info.usDialogType = IDM_BCOLOR1;
- info.idActColor = idColorBClient_s;
- usRc = WinDlgBox (HWND_DESKTOP, hwnd,
- FarbenDlgProc, (HMODULE) NULL,
- IDD_BCOLOR12, (PVOID)&info);
- if (usRc != DID_CANCEL && usRc != DID_ERROR)
- {
- if (idColorBClient_s != usRc)
- {
- idColorBClient_s = usRc; DosBeep(1200, 100);
- fRc = WinInvalidateRect(hwnd,NULL,FALSE);
- }
- }
- return 0;
- case IDM_BCOLOR2:
- idColorBClientOld_s = idColorBClient_s;
- info.usDialogType = IDM_BCOLOR2;
- info.idActColor = idColorBClient_s;
- usRc = WinDlgBox (HWND_DESKTOP, hwnd,
- FarbenDlgProc, (HMODULE) NULL,
- IDD_BCOLOR12, (PVOID)&info);
- if (usRc == DID_CANCEL &&
- idColorBClient_s != idColorBClientOld_s )
- {
- idColorBClient_s = idColorBClientOld_s;
- DosBeep(1200, 100);
- fRc = WinInvalidateRect(hwnd,NULL,FALSE);
- }
- return 0 ;
- 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;
- hps = WinBeginPaint(hwnd, NULL, NULL);
- sprintf(szTmp, "%s (idColorBClient = %d)", szText_g, idB);
- colorBClient = aColors_g[idB-ID_BBLACK];
- fRc = WinQueryWindowRect(hwnd, &rectl);
- 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;
- static USHORT usDialogType_s;
- BOOL fRc;
- switch (msg)
- {
- case WM_INITDLG:
- {
- INFO FAR *pinfo;
- pinfo = (INFO FAR *) PVOIDFROMMP(mp2);
- idRadioButton_s = pinfo->idActColor;
- usDialogType_s = pinfo->usDialogType;
- WinSendDlgItemMsg(hwnd, idRadioButton_s,
- BM_SETCHECK, MPFROM2SHORT (TRUE, 0),
- NULL);
- return (MRESULT)FALSE;
- }
- case WM_CONTROL:
- {
- USHORT id = SHORT1FROMMP (mp1);
- if (id >= ID_BBLACK && id <= ID_BPGRAY)
- {
- idRadioButton_s = id; // gilt für Typ 1 + 2!
- if (usDialogType_s == IDM_BCOLOR2 &&
- SHORT2FROMMP(mp1) == BN_CLICKED)
- {
- fRc = WinPostMsg(hwndClient_g, WM_USER,
- MPFROMSHORT(idRadioButton_s),0L);
- }
- }
- return 0 ;
- }
- case WM_COMMAND:
- {
- USHORT command;
- if (usDialogType_s == IDM_BCOLOR1)
- {
- command = COMMANDMSG(&msg)->cmd;
- if (command == DID_CANCEL)
- return WinDefDlgProc (hwnd, msg, mp1, mp2);
- else
- { // fRc muss TRUE sein!
- fRc = WinDismissDlg (hwnd, idRadioButton_s );
- return NULL;
- }
- }
- else return WinDefDlgProc (hwnd, msg, mp1, mp2);
- }
- default:
- return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
- }
- }
- /*--------------------------------------------------------*/
- /* Ende von DIALOG1.C */