source: cmedia/trunk/Cmpciset/cmpciset.c@ 354

Last change on this file since 354 was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 26.0 KB
Line 
1//----------------------------------------------------------------------//
2// //
3// erzeugt: 16.02.02 R.Ihle //
4// //
5//----------------------------------------------------------------------//
6
7#define INCL_WINSYS
8#define INCL_WININPUT
9#define INCL_WINSTDDLGS
10#define INCL_WINBUTTONS
11#define INCL_WINDIALOGS
12#define INCL_WINWINDOWMGR
13#define INCL_WINRECTANGLES
14#define INCL_WINSWITCHLIST
15#define INCL_DOSDEVICES
16#define INCL_DOSPROCESS
17#define INCL_DOSSEMAPHORES
18#include <os2.h>
19
20#define INCL_32
21#include <mcios2.h>
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <stdarg.h>
26#include <string.h>
27#include <process.h>
28#include <malloc.h>
29
30#include "warp4.h"
31
32
33//#define DEBUG
34
35
36#include "cmpciset.h"
37#include "../include/ioctl90.h"
38
39
40
41// See CMPCI.C
42
43#define DO_LINE_AS_REAR 0x00000010
44#define DO_LINE_AS_BASS 0x00000020
45#define DO_MIC_AS_BASS 0x00000040
46#define DO_SPDIF_OUT 0x00000100
47#define DO_SPDIF_IN 0x00000200
48#define DO_SPDIF_LOOP 0x00000400
49#define DO_SPDIF_MONITOR 0x00010000
50#define DO_SPDIF_COPYRIGHT 0x00020000
51#define DO_SPDIF_5V 0x00040000
52#define DO_SPDIF_INPUT2 0x00080000
53#define DO_SPDIF_INVERSE 0x00100000
54#define DO_SPDIF_OUT_ENABLE 0x00200000
55#define DO_POWER_DOWN 0x00400000
56#define DO_MIC_BOOST 0x00800000
57
58
59
60//----------------------------------------------------------------------//
61// Prototypen //
62//----------------------------------------------------------------------//
63
64MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
65MRESULT EXPENTRY DlgPage1Proc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
66MRESULT EXPENTRY DlgPage2Proc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
67
68typedef VOID (*THREAD)(PVOID);
69
70
71#define UM_MIXERCHANGE (WM_USER + 100)
72
73
74//----------------------------------------------------------------------//
75// statische Daten //
76//----------------------------------------------------------------------//
77
78static HWND hwndFrame = NULLHANDLE;
79static HWND hwndClient = NULLHANDLE;
80static PFNWP pfnOldClientProc = NULL;
81
82
83
84/************************************************************************/
85/* */
86/* Device access */
87/* */
88/************************************************************************/
89
90typedef struct
91{
92 HFILE hDev;
93 ULONG arInfo[5];
94 BOOL fInfoOK;
95 ULONG ulFlags;
96 ULONG ulMasterVol;
97 BOOL fTerminate;
98 TID tidCallback;
99 HEV hevMixerChange;
100 SIZEL szWinPos;
101} CMI_DATA, *PCMI_DATA;
102
103
104//----------------------------------------------------------------------//
105// //
106//----------------------------------------------------------------------//
107
108HFILE CMIOpenDevice(VOID)
109{
110 HFILE hDev;
111 ULONG ulAction;
112
113 if( DosOpen("CMPCI1$", &hDev, &ulAction, 0,
114 FILE_NORMAL, FILE_OPEN,
115 OPEN_ACCESS_READWRITE |
116 OPEN_SHARE_DENYNONE |
117 OPEN_FLAGS_FAIL_ON_ERROR, NULL) != 0 )
118 {
119 hDev = (HFILE)-1;
120 }
121
122 return hDev;
123}
124
125
126//----------------------------------------------------------------------//
127// //
128//----------------------------------------------------------------------//
129
130VOID CMICloseDevice(HFILE hDev)
131{
132 DosClose(hDev);
133}
134
135
136//----------------------------------------------------------------------//
137// //
138//----------------------------------------------------------------------//
139
140BOOL CMIQueryInfo(HFILE hDev, PULONG arInfo, ULONG ctInfo)
141{
142 return DosDevIOCtl(hDev, 0x81, 0x80,
143 NULL, 0, NULL, arInfo, ctInfo*sizeof(ULONG), NULL) == 0;
144}
145
146
147//----------------------------------------------------------------------//
148// //
149//----------------------------------------------------------------------//
150
151ULONG CMIQueryFlags(HFILE hDev)
152{
153 ULONG arTemp[3] = { 0, 0 };
154
155 if( DosDevIOCtl(hDev, 0x81, 0x81,
156 &arTemp[0], 2*sizeof(ULONG), NULL,
157 &arTemp[2], 1*sizeof(ULONG), NULL) != 0 )
158 {
159 arTemp[2] = 0;
160 }
161
162 return arTemp[2];
163}
164
165
166//----------------------------------------------------------------------//
167// //
168//----------------------------------------------------------------------//
169
170ULONG CMISetFlags(HFILE hDev, ULONG ulOnMask, ULONG ulOffMask)
171{
172 ULONG arTemp[3];
173
174 arTemp[0] = ulOnMask;
175 arTemp[1] = ulOffMask;
176 if( DosDevIOCtl(hDev, 0x81, 0x81,
177 &arTemp[0], 2*sizeof(ULONG), NULL,
178 &arTemp[2], 1*sizeof(ULONG), NULL) != 0 )
179 {
180 arTemp[2] = 0;
181 }
182
183 return arTemp[2];
184}
185
186
187//----------------------------------------------------------------------//
188// //
189//----------------------------------------------------------------------//
190
191BOOL CMISetRecordSource(HFILE hDev, ULONG ulRecSrc)
192{
193 ULONG ulDataLen;
194 MIXSTRUCT MixStruct;
195
196 MixStruct.Mute = ( !ulRecSrc ) ? 2 : 0;
197 MixStruct.VolumeL = ulRecSrc;
198 MixStruct.VolumeR = 0;
199
200 ulDataLen = sizeof(MixStruct);
201 return DosDevIOCtl(hDev, 0x90, RECORDSRCSET,
202 NULL, 0, NULL, &MixStruct, ulDataLen, &ulDataLen) == 0;
203}
204
205
206//----------------------------------------------------------------------//
207// //
208//----------------------------------------------------------------------//
209
210#pragma pack(1)
211
212#ifndef FAR16PTR
213 #define FAR16PTR __far16 *
214#endif
215
216#ifndef AUDIO_CHANGE
217 #define AUDIO_CHANGE 0
218#endif
219
220#ifndef AUDIO_IGNORE
221 #define AUDIO_IGNORE (-1)
222#endif
223
224
225typedef struct _MCI_AUDIO_CONTROL { /* contr */
226 USHORT usIOCtlRequest;
227 VOID FAR16PTR pbRequestInfo;
228 ULONG ulPosition;
229 SHORT sReturnCode;
230 } MCI_AUDIO_CONTROL;
231
232typedef struct _MCI_AUDIO_DEVID { /* devid */
233 ULONG ulDevType;
234 ULONG ulDevNum;
235 } MCI_AUDIO_DEVID;
236
237typedef struct _MCI_AUDIO_CHANGE { /* chang */
238 VOID FAR16PTR pvDevInfo;
239 LONG lInput;
240 LONG lOutput;
241 LONG lMonitor;
242 LONG lVolume;
243 LONG lVolumeDelay;
244 LONG lBalance;
245 LONG lBalanceDelay;
246 LONG lTreble;
247 LONG lBass;
248 LONG lPitch;
249 MCI_AUDIO_DEVID rInputList[8];
250 MCI_AUDIO_DEVID rOutputList[8];
251
252 MCI_AUDIO_DEVID FAR16PTR prMoreInputs;
253 MCI_AUDIO_DEVID FAR16PTR prMoreOutputs;
254 LONG lGain;
255 VOID FAR16PTR pvModeInfo;
256 } MCI_AUDIO_CHANGE;
257
258typedef struct _MCI_TRACK_INFO { /* info */
259 USHORT usMasterVolume;
260 USHORT usDitherPct;
261 USHORT usMasterVolumeDelay;
262 USHORT usMasterBalance;
263 USHORT usMasterBalanceDelay;
264 } MCI_TRACK_INFO;
265
266#pragma pack()
267
268
269BOOL CMISetMasterVolume(HFILE hDev, ULONG ulValue, BOOL fToCardOnly)
270{
271 MCI_TRACK_INFO *pTrackInfo;
272 MCI_AUDIO_CHANGE *pAudioChange;
273 MCI_AUDIO_CONTROL *pAudioCtrl;
274 CHAR achTemp[64];
275 ULONG ulDataLen = sizeof(MCI_TRACK_INFO) +
276 sizeof(MCI_AUDIO_CHANGE) +
277 sizeof(MCI_AUDIO_CONTROL);
278
279 // Make sure, that structures don't cross a 64k boundary !
280 pAudioCtrl = (MCI_AUDIO_CONTROL *)alloca(2 * ulDataLen);
281 if( LOUSHORT(pAudioCtrl) > LOUSHORT(~ulDataLen) )
282 pAudioCtrl = (MCI_AUDIO_CONTROL *)(((ULONG)pAudioCtrl) + ulDataLen);
283
284 memset(pAudioCtrl, 0, ulDataLen);
285 pAudioChange = (MCI_AUDIO_CHANGE *)&pAudioCtrl[1];
286 pTrackInfo = (MCI_TRACK_INFO *)&pAudioChange[1];
287
288 pAudioCtrl->usIOCtlRequest = AUDIO_CHANGE;
289 pAudioCtrl->pbRequestInfo = pAudioChange;
290
291 pAudioChange->lInput = pAudioChange->lOutput =
292 pAudioChange->lMonitor = pAudioChange->lBalance =
293 pAudioChange->lTreble = pAudioChange->lBass =
294 pAudioChange->lPitch = pAudioChange->lGain =
295 pAudioChange->lBalanceDelay = pAudioChange->lVolumeDelay = AUDIO_IGNORE;
296 pAudioChange->pvDevInfo = pTrackInfo;
297
298 pTrackInfo->usMasterVolume = (USHORT)((ulValue * 0x7fff) / 100);
299 pTrackInfo->usMasterVolumeDelay = pTrackInfo->usMasterBalance =
300 pTrackInfo->usMasterBalanceDelay = pTrackInfo->usDitherPct = (USHORT)AUDIO_IGNORE;
301
302 if( !fToCardOnly )
303 {
304 sprintf(achTemp, "MASTERAUDIO VOLUME %u", ulValue);
305 mciSendString(achTemp, NULL, 0, 0, 0);
306 mciSetSysValue(MSV_MASTERVOLUME, &ulValue);
307 }
308
309 ulDataLen = sizeof(MCI_AUDIO_CONTROL);
310 return DosDevIOCtl(hDev, 0x80, 0x42,
311 NULL, 0, NULL, pAudioCtrl, ulDataLen, &ulDataLen) == 0;
312}
313
314
315//----------------------------------------------------------------------//
316// //
317//----------------------------------------------------------------------//
318
319ULONG CMIQueryMasterVolume(HFILE hDev)
320{
321 CHAR achTemp[32];
322
323 (void)hDev;
324 sprintf(achTemp, "MASTERAUDIO QUERY VOLUME WAIT");
325 mciSendString(achTemp, achTemp, sizeof(achTemp), 0, 0);
326 return strtoul(achTemp, NULL, 10);
327}
328
329
330//----------------------------------------------------------------------//
331// //
332//----------------------------------------------------------------------//
333
334VOID CMICallbackThread(CMI_DATA *pWndData)
335{
336 HEV hevTemp;
337 ULONG ulDataLen;
338
339 if( DosCreateEventSem(NULL,
340 &pWndData->hevMixerChange, DC_SEM_SHARED, FALSE) == 0 )
341 {
342 hevTemp = pWndData->hevMixerChange;
343
344 ulDataLen = sizeof(hevTemp);
345 if( DosDevIOCtl(pWndData->hDev, 0x90, CALLBACKREG,
346 NULL, 0, NULL, &hevTemp, ulDataLen, &ulDataLen) == 0 )
347 {
348 while( DosWaitEventSem(hevTemp, SEM_INDEFINITE_WAIT) == 0 &&
349 !pWndData->fTerminate )
350 {
351 WinPostMsg(hwndClient, UM_MIXERCHANGE, 0, 0);
352 }
353
354 hevTemp = NULLHANDLE;
355 ulDataLen = sizeof(hevTemp);
356 DosDevIOCtl(pWndData->hDev, 0x90, CALLBACKREG,
357 NULL, 0, NULL, &hevTemp, ulDataLen, &ulDataLen);
358 }
359
360 DosCloseEventSem(pWndData->hevMixerChange);
361 pWndData->hevMixerChange = NULLHANDLE;
362 }
363}
364
365
366
367
368/************************************************************************/
369/* */
370/* Dialog Page #1 */
371/* */
372/************************************************************************/
373
374//----------------------------------------------------------------------//
375// Dialog Procedure //
376//----------------------------------------------------------------------//
377
378MRESULT EXPENTRY DlgPage1Proc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
379{
380 PCMI_DATA pWndData = (PCMI_DATA)WinQueryWindowPtr(hwnd, QWL_USER);
381 ULONG ulOnBits, ulOffBits, ulVol;
382 int i;
383 static BOOL fInit = FALSE;
384 static ULONG ulIDList[] =
385 {
386 ID_RADIO1, ID_RADIO2, ID_RADIO3, ID_RADIO4, ID_RADIO5, ID_RADIO6, ID_RADIO7,
387 ID_CHECK1, ID_CHECK2, ID_CHECK3, ID_SLIDER1, 0
388 };
389
390
391 switch( msg )
392 {
393 case WM_INITDLG :
394 pWndData = (PCMI_DATA)mp2;
395 WinSetWindowPtr(hwnd, QWL_USER, pWndData);
396
397 fInit = TRUE;
398
399 if( !pWndData || pWndData->hDev == (HFILE)-1 || !pWndData->fInfoOK )
400 {
401 for( i = 0; ulIDList[i]; i++ )
402 WinEnableControl(hwnd, ulIDList[i], FALSE);
403 }
404 else
405 {
406 if( pWndData->ulFlags & DO_SPDIF_LOOP )
407 (VOID)WinCheckButton(hwnd, ID_RADIO3, TRUE);
408 else if( pWndData->ulFlags & DO_SPDIF_OUT_ENABLE )
409 (VOID)WinCheckButton(hwnd, ID_RADIO2, TRUE);
410 else
411 (VOID)WinCheckButton(hwnd, ID_RADIO1, TRUE);
412
413 (VOID)WinCheckButton(hwnd, ID_CHECK1, (pWndData->ulFlags & DO_SPDIF_MONITOR) != 0);
414 (VOID)WinCheckButton(hwnd, ID_CHECK2, (pWndData->ulFlags & DO_SPDIF_COPYRIGHT) != 0);
415 (VOID)WinCheckButton(hwnd, ID_CHECK3, (pWndData->ulFlags & DO_SPDIF_5V) == 0);
416
417 (VOID)WinCheckButton(hwnd, ( pWndData->ulFlags & DO_SPDIF_INVERSE ) ? ID_RADIO5 : ID_RADIO4, TRUE);
418 (VOID)WinCheckButton(hwnd, ( pWndData->ulFlags & DO_SPDIF_INPUT2 ) ? ID_RADIO7 : ID_RADIO6, TRUE);
419
420 WinSendDlgItemMsg(hwnd, ID_SLIDER1, SLM_SETSLIDERINFO,
421 MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE),
422 MPFROMLONG(pWndData->ulMasterVol));
423 }
424
425 fInit = FALSE;
426 return (MRESULT)TRUE;
427
428 case WM_CONTROL :
429 if( !fInit && pWndData && pWndData->hDev != (HFILE)-1 )
430 {
431 if( SHORT1FROMMP(mp1) == ID_SLIDER1 )
432 {
433 if( SHORT2FROMMP(mp1) == SLN_CHANGE ||
434 SHORT2FROMMP(mp1) == SLN_SLIDERTRACK )
435 {
436 pWndData->ulMasterVol = (ULONG)
437 WinSendDlgItemMsg(hwnd, ID_SLIDER1, SLM_QUERYSLIDERINFO,
438 MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE),
439 MPVOID);
440
441 CMISetMasterVolume(pWndData->hDev, pWndData->ulMasterVol, FALSE);
442 }
443 }
444 else
445 {
446 ulOnBits = ulOffBits = 0;
447
448 if( WinQueryButtonCheckstate(hwnd, ID_RADIO1) )
449 {
450 ulOffBits |= DO_SPDIF_OUT_ENABLE | DO_SPDIF_LOOP;
451 }
452 else if( WinQueryButtonCheckstate(hwnd, ID_RADIO2) )
453 {
454 ulOffBits |= DO_SPDIF_LOOP; ulOnBits |= DO_SPDIF_OUT_ENABLE;
455 }
456 else if( WinQueryButtonCheckstate(hwnd, ID_RADIO3) )
457 {
458 ulOffBits |= DO_SPDIF_OUT_ENABLE; ulOnBits |= DO_SPDIF_LOOP;
459 }
460
461 if( WinQueryButtonCheckstate(hwnd, ID_CHECK1) ) ulOnBits |= DO_SPDIF_MONITOR;
462 else ulOffBits |= DO_SPDIF_MONITOR;
463
464 if( WinQueryButtonCheckstate(hwnd, ID_CHECK2) ) ulOnBits |= DO_SPDIF_COPYRIGHT;
465 else ulOffBits |= DO_SPDIF_COPYRIGHT;
466
467 if( !WinQueryButtonCheckstate(hwnd, ID_CHECK3) ) ulOnBits |= DO_SPDIF_5V;
468 else ulOffBits |= DO_SPDIF_5V;
469
470 if( WinQueryButtonCheckstate(hwnd, ID_RADIO5) ) ulOnBits |= DO_SPDIF_INVERSE;
471 else ulOffBits |= DO_SPDIF_INVERSE;
472
473 if( WinQueryButtonCheckstate(hwnd, ID_RADIO7) ) ulOnBits |= DO_SPDIF_INPUT2;
474 else ulOffBits |= DO_SPDIF_INPUT2;
475
476 pWndData->ulFlags = CMISetFlags(pWndData->hDev, ulOnBits, ulOffBits);
477 }
478 }
479 return (MRESULT)0;
480
481 case UM_MIXERCHANGE :
482 ulVol = CMIQueryMasterVolume(pWndData->hDev);
483//printf("ulVol: %u, old: %u\n", ulVol, pWndData->ulMasterVol);
484 if( ulVol != pWndData->ulMasterVol )
485 {
486 pWndData->ulMasterVol = ulVol;
487
488 fInit = TRUE;
489 WinSendDlgItemMsg(hwnd, ID_SLIDER1, SLM_SETSLIDERINFO,
490 MPFROM2SHORT(SMA_SLIDERARMPOSITION, SMA_INCREMENTVALUE),
491 MPFROMLONG(pWndData->ulMasterVol));
492 fInit = FALSE;
493
494 return (MRESULT)TRUE;
495 }
496 return (MRESULT)FALSE;
497 }
498
499 return WinDefDlgProc(hwnd, msg, mp1, mp2);
500}
501
502
503
504
505/************************************************************************/
506/* */
507/* Dialog Page #2 */
508/* */
509/************************************************************************/
510
511typedef struct
512{
513 PCHAR pchLabel;
514 PCHAR pchText;
515 CHAR achBuffer[1];
516} PAGE2CNRDATA, *PPAGE2CNRDATA;
517
518
519//----------------------------------------------------------------------//
520// Helper //
521//----------------------------------------------------------------------//
522
523void Page2InitContainer(HWND hwndCnr)
524{
525 CNRINFO CnrInfo;
526 FIELDINFOINSERT FldInsert;
527 INT nIdx, nStructOffset;
528 PFIELDINFO pFirstFieldInfo, pFieldInfo;
529
530 memset(&CnrInfo, 0, sizeof(CnrInfo));
531 memset(&FldInsert, 0, sizeof(FldInsert));
532
533 pFirstFieldInfo = (PFIELDINFO)WinSendMsg(hwndCnr,
534 CM_ALLOCDETAILFIELDINFO,
535 MPFROMLONG(2), NULL);
536 nIdx = 0;
537 pFieldInfo = pFirstFieldInfo;
538 nStructOffset = sizeof(MINIRECORDCORE);
539 while( pFieldInfo )
540 {
541 pFieldInfo->offStruct = nStructOffset;
542 pFieldInfo->flTitle = CFA_LEFT | CFA_FITITLEREADONLY;
543 pFieldInfo->flData = CFA_LEFT | CFA_STRING | CFA_HORZSEPARATOR;
544// pFieldInfo->cxWidth = 0;
545// pFieldInfo->pTitleData = "";
546
547 switch( nIdx++ )
548 {
549 case 0 : pFieldInfo->flData |= CFA_SEPARATOR;
550 break;
551
552 case 1 :
553 break;
554 }
555
556 nStructOffset += sizeof(PCHAR);
557
558 pFieldInfo = pFieldInfo->pNextFieldInfo;
559 }
560
561 FldInsert.cb = sizeof(FldInsert);
562 FldInsert.pFieldInfoOrder = (PFIELDINFO)CMA_FIRST;
563 FldInsert.cFieldInfoInsert = nIdx;
564 FldInsert.fInvalidateFieldInfo = TRUE;
565 WinSendMsg(hwndCnr, CM_INSERTDETAILFIELDINFO,
566 MPFROMP(pFirstFieldInfo), MPFROMP(&FldInsert));
567
568 CnrInfo.cb = sizeof(CnrInfo);
569 CnrInfo.flWindowAttr = CV_DETAIL;
570 WinSendMsg(hwndCnr, CM_SETCNRINFO,
571 MPFROMP(&CnrInfo), MPFROMLONG(CMA_FLWINDOWATTR));
572}
573
574
575//----------------------------------------------------------------------//
576// Helper //
577//----------------------------------------------------------------------//
578
579void Page2InsertRecord(HWND hwndCnr, PCHAR pchText)
580{
581 INT cbExtra;
582 PMINIRECORDCORE pRecord;
583 PPAGE2CNRDATA pCnrData;
584 RECORDINSERT RcdInsert;
585
586 cbExtra = strlen(pchText) + sizeof(PAGE2CNRDATA);
587
588 pRecord = (PMINIRECORDCORE)WinSendMsg(hwndCnr,
589 CM_ALLOCRECORD,
590 MPFROMSHORT(cbExtra), MPFROMSHORT(1));
591 if( pRecord )
592 {
593 pCnrData = (PPAGE2CNRDATA)((PCHAR)pRecord + pRecord->cb);
594
595 strcpy(pCnrData->achBuffer, pchText);
596
597 if( (pchText = strchr(pCnrData->achBuffer, '|')) != NULL )
598 {
599 *pchText++ = '\0';
600 pCnrData->pchLabel = pCnrData->achBuffer;
601 pCnrData->pchText = pchText;
602 }
603 else
604 {
605 pCnrData->pchLabel = "";
606 pCnrData->pchText = pCnrData->achBuffer;
607 }
608
609 memset(&RcdInsert, 0, sizeof(RcdInsert));
610 RcdInsert.cb = sizeof(RcdInsert);
611 RcdInsert.cRecordsInsert = 1;
612 RcdInsert.fInvalidateRecord = TRUE;;
613 RcdInsert.pRecordOrder = (PRECORDCORE)CMA_END;
614 WinSendMsg(hwndCnr, CM_INSERTRECORD,
615 MPFROMP(pRecord), MPFROMP(&RcdInsert));
616 }
617}
618
619
620//----------------------------------------------------------------------//
621// Dialog Procedure //
622//----------------------------------------------------------------------//
623
624MRESULT EXPENTRY DlgPage2Proc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
625{
626 CHAR achTemp[256];
627 PCMI_DATA pWndData;
628 HWND hwndCnr;
629
630 switch( msg )
631 {
632 case WM_INITDLG :
633 pWndData = (PCMI_DATA)mp2;
634
635 hwndCnr = WinWindowFromID(hwnd, ID_CONTAINER1);
636 Page2InitContainer(hwndCnr);
637
638 if( pWndData && pWndData->fInfoOK )
639 {
640 sprintf(achTemp, "PCI ID|0x%04x : 0x%04x",
641 pWndData->arInfo[0] >> 16, pWndData->arInfo[0] & 0xffff);
642 Page2InsertRecord(hwndCnr, achTemp);
643
644 sprintf(achTemp, "I/O Base|0x%04x", pWndData->arInfo[1]);
645 Page2InsertRecord(hwndCnr, achTemp);
646
647 sprintf(achTemp, "IRQ No.|%d", pWndData->arInfo[2]);
648 Page2InsertRecord(hwndCnr, achTemp);
649
650 sprintf(achTemp, "Chip Rev.|%d", pWndData->arInfo[3]);
651 Page2InsertRecord(hwndCnr, achTemp);
652
653 sprintf(achTemp, "Chip Caps|0x%08lx", pWndData->arInfo[4]);
654 Page2InsertRecord(hwndCnr, achTemp);
655 }
656 else
657 {
658 sprintf(achTemp, "Error|Unable to query information !");
659 Page2InsertRecord(hwndCnr, achTemp);
660 }
661
662 return (MRESULT)FALSE;
663
664 case WM_COMMAND :
665 return (MRESULT)0;
666 }
667
668 return WinDefDlgProc(hwnd, msg, mp1, mp2);
669}
670
671
672//----------------------------------------------------------------------//
673// Notizbuch initialisieren //
674//----------------------------------------------------------------------//
675
676VOID InitNotebook(HAB hab, HWND hwndNotebook,
677 PVOID pPageParam, PRECTL prcNotebook)
678{
679 ULONG ulPageID, ulIdx;
680 CHAR achTemp[256];
681 HWND hwndPage;
682 RECTL rcPage;
683 static struct
684 {
685 ULONG ulDlgID;
686 ULONG ulTabTextID;
687 PFNWP pfnDlgProc;
688 } arPageInfo[] =
689 {
690 { IDD_PAGE1, ID_STATIC1, DlgPage1Proc },
691 { IDD_PAGE2, ID_STATIC1, DlgPage2Proc },
692 { 0, 0, NULL }
693 };
694
695 WinSendMsg(hwndNotebook, BKM_SETDIMENSIONS,
696 MPFROM2SHORT(0, 0), MPFROMSHORT(BKA_MINORTAB));
697
698 WinSendMsg(hwndNotebook, BKM_SETDIMENSIONS,
699 MPFROM2SHORT(100, 25), MPFROMSHORT(BKA_MAJORTAB));
700
701 WinSendMsg(hwndNotebook, BKM_SETDIMENSIONS,
702 MPFROM2SHORT(18, 18), MPFROMSHORT(BKA_PAGEBUTTON));
703
704 WinSendMsg(hwndNotebook, BKM_SETNOTEBOOKCOLORS,
705 MPFROMLONG(CLR_PALEGRAY), MPFROMLONG(BKA_BACKGROUNDPAGECOLORINDEX));
706
707 WinSendMsg(hwndNotebook, BKM_SETNOTEBOOKCOLORS,
708 MPFROMLONG(CLR_WHITE), MPFROMLONG(BKA_BACKGROUNDMAJORCOLORINDEX));
709
710
711 memset(prcNotebook, 0, sizeof(*prcNotebook));
712
713 for( ulIdx = 0; arPageInfo[ulIdx].ulDlgID; ulIdx++ )
714 {
715 hwndPage = WinLoadDlg(hwndNotebook, hwndNotebook,
716 arPageInfo[ulIdx].pfnDlgProc, NULLHANDLE,
717 arPageInfo[ulIdx].ulDlgID, pPageParam);
718 if( hwndPage )
719 {
720 ulPageID = (ULONG)WinSendMsg(hwndNotebook, BKM_INSERTPAGE,
721 0, MPFROM2SHORT(BKA_AUTOPAGESIZE | BKA_MAJOR, BKA_LAST));
722
723 WinQueryWindowRect(hwndPage, &rcPage);
724 WinUnionRect(hab, prcNotebook, prcNotebook, &rcPage);
725
726 WinQueryDlgItemText(hwndPage,
727 arPageInfo[ulIdx].ulTabTextID, sizeof(achTemp), achTemp);
728 WinSendMsg(hwndNotebook, BKM_SETTABTEXT,
729 MPFROMLONG(ulPageID), MPFROMP(achTemp));
730
731 WinSendMsg(hwndNotebook, BKM_SETPAGEWINDOWHWND,
732 MPFROMLONG(ulPageID), MPFROMLONG(hwndPage));
733 }
734 }
735
736 WinSendMsg(hwndNotebook, BKM_CALCPAGERECT,
737 MPFROMP(prcNotebook), MPFROMSHORT(FALSE));
738}
739
740
741
742//----------------------------------------------------------------------//
743// Window Procedure //
744//----------------------------------------------------------------------//
745
746MRESULT EXPENTRY ClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
747{
748 PCMI_DATA pWndData = (PCMI_DATA)WinQueryWindowPtr(hwnd, QWL_USER);
749 ULONG ulPageID;
750 HWND hwndPage;
751 BOOL fChanged;
752 SWP swp;
753
754 switch( msg )
755 {
756 case WM_ACTIVATE :
757 if( SHORT1FROMMP(mp1) )
758 WinSendMsg(hwnd, UM_MIXERCHANGE, MPVOID, MPVOID);
759 break;
760
761 case WM_CREATE :
762 pWndData = (PCMI_DATA)malloc(sizeof(CMI_DATA));
763 if( pWndData )
764 {
765 memset(pWndData, 0, sizeof(CMI_DATA));
766 pWndData->hDev = CMIOpenDevice();
767 if( pWndData->hDev != (HFILE)-1 )
768 {
769 pWndData->fInfoOK = CMIQueryInfo(pWndData->hDev, pWndData->arInfo, 5);
770 pWndData->ulFlags = CMIQueryFlags(pWndData->hDev);
771 pWndData->ulMasterVol = CMIQueryMasterVolume(pWndData->hDev);
772
773 // Register callback
774 pWndData->tidCallback =
775#if defined(__BORLANDC__) || __WATCOMC__ < 110
776 _beginthread((THREAD)CMICallbackThread, 16384, pWndData);
777#else
778 _beginthread((THREAD)CMICallbackThread, NULL, 16384, pWndData);
779#endif
780
781 // Override record source
782 CMISetRecordSource(pWndData->hDev, I90SRC_SPDIF);
783 }
784 }
785
786 WinSetWindowPtr(hwnd, QWL_USER, pWndData);
787 return (MRESULT)0;
788
789 case UM_MIXERCHANGE :
790 fChanged = FALSE;
791 ulPageID = (ULONG)WinSendMsg(hwnd, BKM_QUERYPAGEID,
792 MPVOID, MPFROM2SHORT(BKA_FIRST, 0));
793 while( ulPageID )
794 {
795 hwndPage = (HWND)WinSendMsg(hwnd, BKM_QUERYPAGEWINDOWHWND,
796 MPFROMLONG(ulPageID), MPVOID);
797 if( hwndPage )
798 fChanged |= (BOOL)WinSendMsg(hwndPage, UM_MIXERCHANGE, 0, 0);
799
800 ulPageID = (ULONG)WinSendMsg(hwnd, BKM_QUERYPAGEID,
801 MPFROMLONG(ulPageID),
802 MPFROM2SHORT(BKA_NEXT, 0));
803 }
804
805 if( fChanged )
806 CMISetMasterVolume(pWndData->hDev, pWndData->ulMasterVol, TRUE);
807
808 return (MRESULT)0;
809
810 case WM_CLOSE :
811/*
812 ulPageID = (ULONG)WinSendMsg(hwnd, BKM_QUERYPAGEID,
813 0, MPFROM2SHORT(BKA_TOP, 0));
814 ulPageIdx = (ULONG)WinSendMsg(hwnd, BKM_QUERYPAGEDATA,
815 MPFROMLONG(ulPageID), 0);
816 PrfWriteProfileString(HINI_USERPROFILE, APP_NAME,
817 INIKEY_PAGENO, ultoa(ulPageIdx, achTemp, 10));
818*/
819 if( pWndData )
820 {
821 if( pWndData->hDev != (HFILE)-1 )
822 {
823 // terminate callback thread
824 if( pWndData->tidCallback && pWndData->hevMixerChange )
825 {
826 pWndData->fTerminate = TRUE;
827 DosPostEventSem(pWndData->hevMixerChange);
828 DosWaitThread(&pWndData->tidCallback, DCWW_WAIT);
829 }
830
831 // disable SPDIF monitoring
832 CMISetFlags(pWndData->hDev, 0, DO_SPDIF_MONITOR);
833
834 // release record src override
835 CMISetRecordSource(pWndData->hDev, 0);
836
837 CMICloseDevice(pWndData->hDev);
838 }
839
840 WinSetWindowPtr(hwnd, QWL_USER, NULL);
841 free(pWndData);
842 }
843 break;
844
845 case WM_SIZE :
846 WinQueryWindowPos(WinQueryWindow(hwnd, QW_PARENT), &swp);
847 if( pWndData && !(swp.fl & (SWP_MINIMIZE | SWP_MAXIMIZE)) )
848 {
849 pWndData->szWinPos.cx = swp.cx; pWndData->szWinPos.cy = swp.cy;
850 }
851 break;
852
853 case WM_MOUSEMOVE :
854 WinDefWindowProc(hwnd, msg, mp1, mp2);
855 return (MRESULT)TRUE;
856
857 case WM_COMMAND :
858/* switch( SHORT1FROMMP(mp1) )
859 {
860 case IDM_ABOUT :
861 WinDlgBox(HWND_DESKTOP, WinQueryWindow(hwnd, QW_PARENT),
862 WinDefDlgProc, NULLHANDLE, IDD_ABOUT, NULL);
863 break;
864
865 default:
866 DosBeep(1000, 100);
867 }
868*/
869 return (MRESULT)0;
870 }
871
872 return (*pfnOldClientProc)(hwnd, msg, mp1, mp2);
873}
874
875
876
877//----------------------------------------------------------------------//
878// H A U P T P R O G R A M M //
879//----------------------------------------------------------------------//
880
881int main(/*int argc, char *argv[]*/void)
882{
883 HAB hab;
884 HMQ hmq;
885 QMSG qmsg;
886 SWP swp;
887 SIZEL szWin;
888 RECTL rcTemp;
889 PVOID pPageParam;
890 ULONG ulFrameCreationFlags;
891
892 hab = WinInitialize(0);
893 hmq = WinCreateMsgQueue(hab, 0);
894
895 ulFrameCreationFlags = FCF_STANDARD & ~FCF_ACCELTABLE & ~FCF_MENU;
896 hwndFrame = WinCreateStdWindow(HWND_DESKTOP,
897 0,
898 &ulFrameCreationFlags,
899 WC_NOTEBOOK,
900 APP_NAME,
901 BKS_SPIRALBIND | BKS_TABBEDDIALOG |
902 BKS_MAJORTABTOP | BKS_BACKPAGESTR |
903 BKS_STATUSTEXTLEFT | BKS_TABTEXTCENTER,
904 NULLHANDLE,
905 IDW_CLIENT,
906 &hwndClient);
907 if( hwndFrame )
908 {
909 WinSetPresParam(hwndClient, PP_FONTNAMESIZE, 7, "8.Helv");
910 pfnOldClientProc = WinSubclassWindow(hwndClient, ClientWndProc);
911
912 // Simulate WM_CREATE ...
913 ClientWndProc(hwndClient, WM_CREATE, MPVOID, MPVOID);
914
915// InitFrame(hab, hwndFrame);
916 pPageParam = WinQueryWindowPtr(hwndClient, QWL_USER);
917 InitNotebook(hab, hwndClient, pPageParam, &rcTemp);
918
919 rcTemp.yTop += WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR) +
920 2 * WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
921 rcTemp.xRight += 2 * WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER);
922
923 szWin.cx = szWin.cy = 0;
924// szWin.cx = PrfQueryProfileInt(HINI_USERPROFILE, APP_NAME, INIKEY_CX, 0);
925// szWin.cy = PrfQueryProfileInt(HINI_USERPROFILE, APP_NAME, INIKEY_CY, 0);
926 if( !szWin.cx ) szWin.cx = rcTemp.xRight - rcTemp.xLeft;
927 if( !szWin.cy ) szWin.cy = rcTemp.yTop - rcTemp.yBottom;
928
929 WinQueryTaskSizePos(hab, 0, &swp);
930 if( swp.cx > szWin.cx ) swp.x += szWin.cx / 2;
931 if( swp.cy > szWin.cy ) swp.y += szWin.cy / 2;
932
933 WinSetWindowPos(hwndFrame, NULLHANDLE,
934 swp.x, swp.y, szWin.cx, szWin.cy,
935 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ACTIVATE);
936 WinSetFocus(HWND_DESKTOP, hwndClient);
937
938 while( WinGetMsg(hab, &qmsg, 0, 0, 0) ) WinDispatchMsg(hab, &qmsg);
939 }
940
941 WinDestroyMsgQueue(hmq);
942 WinTerminate(hab);
943
944 return 0;
945}
946
947
948
Note: See TracBrowser for help on using the repository browser.