|
|
1.1 root 1: /*---------------------------------------------------------------------------*\
2: | DIALOG MODULE
3: | This module contains the dialogbox routines for this application.
4: |
5: |
6: | segment: _DIALOG (DOS16)
7: | created: 31-Oct-90
8: | history: 31-Oct-90 <chriswil> created.
9: |
10: \*---------------------------------------------------------------------------*/
11:
12: #include <windows.h>
13: #include "gdidemo.h"
14:
15: /*---------------------------------------------------------------------------*\
16: | DISPLAY DIALOG BOX
17: | This is a routine to display a generic modal-dialog box.
18: |
19: | created: 20-Oct-90
20: | history: 20-Oct-90 <chriswil> created.
21: |
22: \*---------------------------------------------------------------------------*/
23: int FAR DisplayDialogBox(HWND hWnd, LPSTR lpszTemplate, WNDPROC lpfFunction, LONG lExtra)
24: {
25: HANDLE hInstance;
26: WNDPROC lpfDlg;
27: int nRet;
28:
29:
30: nRet = -1;
31: if(hInstance = GETINSTANCE(hWnd))
32: {
33: if(lpfDlg = MakeProcInstance(lpfFunction,hInstance))
34: {
35: nRet = DialogBoxParam(hInstance,lpszTemplate,hWnd,lpfDlg,lExtra);
36: FreeProcInstance(lpfDlg);
37: }
38: }
39: return(nRet);
40: }
41:
42:
43: /*---------------------------------------------------------------------------*\
44: | ABOUT DIALOG PROCEDURE
45: | This is the main dialogbox routine for the HELPABOUT template.
46: |
47: | created: 31-Oct-90
48: | history: 31-Oct-90 <chriswil> created.
49: |
50: \*---------------------------------------------------------------------------*/
51: BOOL APIENTRY AboutDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LONG lParam)
52: {
53: lParam = lParam;
54:
55: switch(wMsg)
56: {
57: /*
58: ** Set the focus to the OK button.
59: */
60: case WM_INITDIALOG:
61: SetFocus(GetDlgItem(hDlg,IDOK));
62: break;
63:
64:
65: /*
66: ** Look for an ESC or RETURN event.
67: */
68: case WM_COMMAND:
69: switch(wParam)
70: {
71: case IDOK:
72: case IDCANCEL:
73: EndDialog(hDlg,TRUE);
74: break;
75:
76: default:
77: return(FALSE);
78: }
79: break;
80:
81:
82: /*
83: ** Wash the background of the aboutbox to give it a nice blue-scaling
84: ** effect. Invalidate the OK button to force it to the top. This
85: ** seems to be necessary since the OK button gets overwritten during
86: ** the washing.
87: */
88: case WM_PAINT:
89: PaintWindow(hDlg,COLOR_SCALE_BLUE);
90: InvalidateRect(GetDlgItem(hDlg,IDOK),NULL,TRUE);
91:
92:
93: /*
94: ** Default handler.
95: */
96: default:
97: return(FALSE);
98: }
99: return(TRUE);
100: }
101:
102:
103: /*---------------------------------------------------------------------------*\
104: | PAINT WND BACKGROUND
105: | This routine is used to wash the background of a window.
106: |
107: | created: 23-Jan-91
108: | history: 23-Jan-91 <chriswil> created.
109: |
110: \*---------------------------------------------------------------------------*/
111: VOID PaintWindow(HWND hWnd, int nColor)
112: {
113: HDC hDC;
114: int nMapMode,idx,nSize,nReserved,nLoop;
115: RECT rect;
116: HBRUSH hBrush;
117: PAINTSTRUCT ps;
118: HPALETTE hPal;
119:
120:
121: if(hDC = BeginPaint(hWnd,&ps))
122: {
123: GetClientRect(hWnd,&rect);
124: nMapMode = SetMapMode(hDC,MM_ANISOTROPIC);
125:
126:
127: if(GetDeviceCaps(hDC,RASTERCAPS) & RC_PALETTE)
128: {
129: nReserved = GetDeviceCaps(hDC,NUMRESERVED);
130: nSize = GetDeviceCaps(hDC,SIZEPALETTE) - nReserved;
131:
132: if(hPal = CreateColorScalePalette(hDC,nColor))
133: {
134: hPal = SelectPalette(hDC,hPal,FALSE);
135: RealizePalette(hDC);
136:
137:
138: #ifdef WIN16
139: SetWindowExtEx(hDC,nSize,nSize);
140: SetViewportExtEx(hDC,rect.right,-rect.bottom);
141: SetViewportOrgEx(hDC,0,rect.bottom);
142: #else
143:
144: SetWindowExtEx(hDC,nSize,nSize,NULL);
145: SetViewportExtEx(hDC,rect.right,-rect.bottom,NULL);
146: SetViewportOrgEx(hDC,0,rect.bottom,NULL);
147:
148: #endif
149:
150: nLoop = nSize >> 1;
151: for(idx=0; idx < nLoop; idx++)
152: {
153: hBrush = CreateSolidBrush(PALETTEINDEX(idx+nLoop));
154: SetRect(&rect,idx,idx,nSize-idx,nSize-idx);
155: FillRect(hDC,&rect,hBrush);
156: DeleteObject(hBrush);
157: }
158: DeleteObject(SelectPalette(hDC,hPal,FALSE));
159: RealizePalette(hDC);
160: }
161: }
162: else
163: {
164:
165: #ifdef WIN16
166:
167: SetWindowExtEx(hDC,512,512);
168: SetViewportExtEx(hDC,rect.right,-rect.bottom);
169: SetViewportOrgEx(hDC,0,rect.bottom);
170:
171: #else
172:
173: SetWindowExtEx(hDC,512,512,NULL);
174: SetViewportExtEx(hDC,rect.right,-rect.bottom,NULL);
175: SetViewportOrgEx(hDC,0,rect.bottom,NULL);
176:
177: #endif
178:
179: for(idx=0; idx < 256; idx++)
180: {
181: hBrush = CreateSolidBrush(RGB(0,0,idx));
182: SetRect(&rect,idx,idx,512-idx,512-idx);
183: FillRect(hDC,&rect,hBrush);
184: DeleteObject(hBrush);
185: }
186: }
187:
188: SetMapMode(hDC,nMapMode);
189:
190: EndPaint(hWnd,&ps);
191: }
192: return;
193: }
194:
195:
196:
197:
198:
199:
200: /*---------------------------------------------------------------------------*\
201: | CREATE COLOR SCALE PALETTE
202: | This routine creates a palette representing the scale values of a
203: | particular RGB color. A gray-scale palette can also be created.
204: |
205: | created: 01-Nov-90
206: | history: 01-Nov-90 <chriswil> created.
207: |
208: \*---------------------------------------------------------------------------*/
209: HPALETTE CreateColorScalePalette(HWND hDC, int nColor)
210: {
211: HPALETTE hPalette;
212: GLOBALHANDLE hMem;
213: LPLOGPALETTE lpMem;
214: int idx,nReserved,nSize;
215:
216:
217: hPalette = NULL;
218: if(GetDeviceCaps(hDC,RASTERCAPS) & RC_PALETTE)
219: {
220: nReserved = GetDeviceCaps(hDC,NUMRESERVED);
221: nSize = GetDeviceCaps(hDC,SIZEPALETTE) - nReserved;
222:
223: if(hMem = GlobalAlloc(GHND,(DWORD)sizeof(LOGPALETTE)+(sizeof(PALETTEENTRY)*nSize)))
224: {
225: if(lpMem = (LPLOGPALETTE)GlobalLock(hMem))
226: {
227: lpMem->palNumEntries = (WORD)nSize;
228: lpMem->palVersion = (WORD)0x0300;
229:
230: switch(nColor)
231: {
232: case COLOR_SCALE_RED:
233: for(idx=0; idx < nSize; idx++)
234: {
235: lpMem->palPalEntry[idx].peRed = (BYTE)idx;
236: lpMem->palPalEntry[idx].peGreen = 0;
237: lpMem->palPalEntry[idx].peBlue = 0;
238: lpMem->palPalEntry[idx].peFlags = PC_RESERVED;
239: }
240: break;
241:
242: case COLOR_SCALE_GREEN:
243: for(idx=0; idx < nSize; idx++)
244: {
245: lpMem->palPalEntry[idx].peRed = 0;
246: lpMem->palPalEntry[idx].peGreen = (BYTE)idx;
247: lpMem->palPalEntry[idx].peBlue = 0;
248: lpMem->palPalEntry[idx].peFlags = PC_RESERVED;
249: }
250: break;
251:
252: case COLOR_SCALE_BLUE:
253: for(idx=0; idx < nSize; idx++)
254: {
255: lpMem->palPalEntry[idx].peRed = 0;
256: lpMem->palPalEntry[idx].peGreen = 0;
257: lpMem->palPalEntry[idx].peBlue = (BYTE)idx;
258: lpMem->palPalEntry[idx].peFlags = PC_RESERVED;
259: }
260: break;
261:
262: default:
263: case COLOR_SCALE_GRAY:
264: for(idx=0; idx < nSize; idx++)
265: {
266: lpMem->palPalEntry[idx].peRed = (BYTE)idx;
267: lpMem->palPalEntry[idx].peGreen = (BYTE)idx;
268: lpMem->palPalEntry[idx].peBlue = (BYTE)idx;
269: lpMem->palPalEntry[idx].peFlags = PC_RESERVED;
270: }
271: break;
272: }
273:
274: hPalette = CreatePalette(lpMem);
275:
276: GlobalUnlock(hMem);
277: }
278: GlobalFree(hMem);
279: }
280: }
281: return(hPalette);
282: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.