Merge from branch ReactX to Trunk,
[reactos.git] / reactos / dll / cpl / mmsys / volume.c
1 /* $Id: main.c 12852 2005-01-06 13:58:04Z mf $
2 *
3 * PROJECT: ReactOS Multimedia Control Panel
4 * FILE: lib/cpl/mmsys/mmsys.c
5 * PURPOSE: ReactOS Multimedia Control Panel
6 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
7 * Johannes Anderwald <janderwald@reactos.com>
8 */
9
10 #include <windows.h>
11 #include <commctrl.h>
12 #include <setupapi.h>
13 #include <cpl.h>
14 #include <tchar.h>
15 #include <stdio.h>
16 #include "mmsys.h"
17 #include "resource.h"
18
19 typedef struct _IMGINFO
20 {
21 HBITMAP hBitmap;
22 INT cxSource;
23 INT cySource;
24 } IMGINFO, *PIMGINFO;
25
26
27 static VOID
28 InitImageInfo(PIMGINFO ImgInfo)
29 {
30 BITMAP bitmap;
31
32 ZeroMemory(ImgInfo, sizeof(*ImgInfo));
33
34 ImgInfo->hBitmap = LoadImage(hApplet,
35 MAKEINTRESOURCE(IDB_SPEAKIMG),
36 IMAGE_BITMAP,
37 0,
38 0,
39 LR_DEFAULTCOLOR);
40
41 if (ImgInfo->hBitmap != NULL)
42 {
43 GetObject(ImgInfo->hBitmap, sizeof(BITMAP), &bitmap);
44
45 ImgInfo->cxSource = bitmap.bmWidth;
46 ImgInfo->cySource = bitmap.bmHeight;
47 }
48 }
49
50 void
51 InitVolumeControls(HWND hwndDlg)
52 {
53 UINT NumWavOut;
54 WAVEOUTCAPS woc;
55 MMRESULT errcode;
56 DWORD dwDeviceID;
57 DWORD dwStatus;
58
59 NumWavOut = waveOutGetNumDevs();
60 if (!NumWavOut)
61 {
62 //FIXME
63 // deactivate all controls
64 return;
65 }
66
67 errcode = waveOutMessage((HWAVEOUT)WAVE_MAPPER, DRVM_MAPPER_PREFERRED_GET, (DWORD_PTR)&dwDeviceID, (DWORD_PTR)&dwStatus);
68 if (errcode != MMSYSERR_NOERROR)
69 {
70 MessageBox(hwndDlg, _T("Failed to enumerate default device"), NULL, MB_OK);
71 return;
72 }
73
74 if (waveOutGetDevCaps(dwDeviceID, &woc, sizeof(WAVEOUTCAPS)) != MMSYSERR_NOERROR)
75 {
76 MessageBox(hwndDlg, _T("waveOutGetDevCaps failed"), NULL, MB_OK);
77 return;
78 }
79
80 SendDlgItemMessage(hwndDlg, IDC_DEVICE_NAME, WM_SETTEXT, (WPARAM)0, (LPARAM)woc.szPname);
81
82 if (!(woc.dwSupport & WAVECAPS_VOLUME))
83 {
84 /// the device does not support volume changes
85 /// disable volume control
86 EnableWindow(GetDlgItem(hwndDlg, IDC_VOLUME_TRACKBAR), FALSE);
87 }
88 else
89 {
90 SendDlgItemMessage(hwndDlg, IDC_VOLUME_TRACKBAR, TBM_SETRANGE, (WPARAM)TRUE, (LPARAM)MAKELONG(0, 10));
91 SendDlgItemMessage(hwndDlg, IDC_VOLUME_TRACKBAR, TBM_SETPAGESIZE, (WPARAM)FALSE, (LPARAM)1);
92 SendDlgItemMessage(hwndDlg, IDC_VOLUME_TRACKBAR, TBM_SETSEL, (WPARAM)FALSE, (LPARAM)MAKELONG(0, 10));
93 SendDlgItemMessage(hwndDlg, IDC_VOLUME_TRACKBAR, TBM_SETPOS, (WPARAM)TRUE, (LPARAM)4);
94 }
95 }
96
97 /* Volume property page dialog callback */
98 //static INT_PTR CALLBACK
99 INT_PTR CALLBACK
100 VolumeDlgProc(HWND hwndDlg,
101 UINT uMsg,
102 WPARAM wParam,
103 LPARAM lParam)
104 {
105 static IMGINFO ImgInfo;
106 UNREFERENCED_PARAMETER(lParam);
107 UNREFERENCED_PARAMETER(wParam);
108
109 switch(uMsg)
110 {
111 case WM_INITDIALOG:
112 {
113 InitImageInfo(&ImgInfo);
114 InitVolumeControls(hwndDlg);
115 break;
116 }
117 case WM_DRAWITEM:
118 {
119 LPDRAWITEMSTRUCT lpDrawItem;
120 lpDrawItem = (LPDRAWITEMSTRUCT) lParam;
121 if(lpDrawItem->CtlID == IDC_SPEAKIMG)
122 {
123 HDC hdcMem;
124 LONG left;
125
126 /* position image in centre of dialog */
127 left = (lpDrawItem->rcItem.right - ImgInfo.cxSource) / 2;
128
129 hdcMem = CreateCompatibleDC(lpDrawItem->hDC);
130 if (hdcMem != NULL)
131 {
132 SelectObject(hdcMem, ImgInfo.hBitmap);
133 BitBlt(lpDrawItem->hDC,
134 left,
135 lpDrawItem->rcItem.top,
136 lpDrawItem->rcItem.right - lpDrawItem->rcItem.left,
137 lpDrawItem->rcItem.bottom - lpDrawItem->rcItem.top,
138 hdcMem,
139 0,
140 0,
141 SRCCOPY);
142 DeleteDC(hdcMem);
143 }
144 }
145 return TRUE;
146 }
147 }
148
149 return FALSE;
150 }