ファイル名:controls.dlg

dialog DIALOG 6, 18, 199, 118
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "マルチメディアレコーダ"
FONT 12, "System"
BEGIN
	LTEXT "ファイル名", -1, 6, 6, 43, 8
	EDITTEXT            IDEDIT, 56, 4, 86, 12, ES_AUTOHSCROLL
	PUSHBUTTON  "参照", IDBROWSE, 150, 3, 40, 14
	PUSHBUTTON  "Help", IDHELP, 160, 22, 30, 10
	PUSHBUTTON  "About", IDABOUT, 160, 35, 30, 10
	LTEXT       "種類", -1, 10, 24, 20, 8
	COMBOBOX            IDTYPE, 38, 23, 91, 50, CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
	GROUPBOX    "動作", -1, 8, 39, 50, 49
	CONTROL     "記録", IDREC, "Button", BS_AUTORADIOBUTTON, 13, 48, 30, 10
	CONTROL     "再生", IDPLY, "Button", BS_AUTORADIOBUTTON, 13, 59, 30, 10
	CONTROL   "コンバート", IDCON, "Button", BS_AUTORADIOBUTTON, 14, 70, 36, 10
	LTEXT     "レベル", -1, 5, 97, 29, 8
	SCROLLBAR           IDSCR, 42, 97, 86, 8
	LTEXT     "周波数", -1, 68, 45, 47, 8
	LISTBOX             IDLIST, 68, 56, 48, 33, WS_VSCROLL | WS_TABSTOP
	CONTROL "ステレオ", IDCHK, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 130, 77, 54, 10
	GROUPBOX "ビット数", -1, 125, 48, 68, 23
	CONTROL        "8", IDRB8, "Button", BS_AUTORADIOBUTTON, 134, 57, 16, 10
	CONTROL       "16", IDRB16, "Button", BS_AUTORADIOBUTTON, 162, 57, 21, 10
	PUSHBUTTON  "開始", IDOK, 147, 92, 40, 14
	LTEXT   "停止中", IDSTATUS, 2, 108, 200, 8
END

ファイル名:controls.rc

#include "controls.h"
#include "controls.dlg"

ファイル名:controls.h

#define IDEDIT   101
#define IDBROWSE 102
#define IDTYPE   103
#define IDREC    104
#define IDPLY    105
#define IDCON    106
#define IDSCR    107
#define IDLIST   108
#define IDCHK    109
#define IDRB8    110
#define IDRB16   111
#define IDHELP   112
#define IDABOUT  113
#define IDSTATUS 114

ファイル名:controls.c

#include <windows.h>
#include <windowsx.h>
#include "controls.h"
#include <commdlg.h>
#include <stdio.h>
#include <string.h>
int level;
void OptionClass_OnHScroll(HWND hDlg, HWND hwndCtl, UINT code, int pos){
	switch(code){
		case SB_LINEUP:   level--; break;
		case SB_LINEDOWN: level++; break;
		case SB_PAGEUP:   level-=10; break;
		case SB_PAGEDOWN: level+=10; break;
		case SB_THUMBTRACK:
		case SB_THUMBPOSITION: level=pos; break;
	}
	if (level<0) level=0;
	if (level>100) level=100;
	SetScrollPos(GetDlgItem(hDlg, IDSCR), SB_CTL, level, TRUE);
	if (code!=SB_THUMBPOSITION)
		RedrawWindow(GetDlgItem(hDlg,IDSCR), NULL, NULL,
			RDW_FRAME|RDW_INVALIDATE/*|RDW_ALLCHILDREN*/);
}
void EnableAllControls(HWND hwnd, BOOL flag){
	EnableWindow(GetDlgItem(hwnd, IDEDIT  ), flag);
	EnableWindow(GetDlgItem(hwnd, IDBROWSE), flag);
	EnableWindow(GetDlgItem(hwnd, IDTYPE  ), flag);
	EnableWindow(GetDlgItem(hwnd, IDREC   ), flag);
	EnableWindow(GetDlgItem(hwnd, IDPLY   ), flag);
	EnableWindow(GetDlgItem(hwnd, IDCON   ), flag);
	EnableWindow(GetDlgItem(hwnd, IDLIST  ), flag);
	EnableWindow(GetDlgItem(hwnd, IDCHK   ), flag);
	EnableWindow(GetDlgItem(hwnd, IDRB8   ), flag);
	EnableWindow(GetDlgItem(hwnd, IDRB16  ), flag);
}
/*ダイアログ関数(Windowsからコールバックされる)*/
#ifdef __cplusplus
extern "C"
#endif
BOOL FAR PASCAL dlgproc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam){
	static OPENFILENAME ofn;
	static int flag, type;
	static char achFilePath[260], achFileTitle[256], buf[260], tmp[128];

	switch(msg){
	case WM_HSCROLL:
		HANDLE_WM_HSCROLL(hDlg, wParam, lParam, OptionClass_OnHScroll);
		break;
	case WM_COMMAND:
		switch((WORD)wParam) {/*コントロールID*/
		case IDHELP:
			MessageBox(hDlg, "ヘルプはありません", "エラー", MB_OK);
			break;
		case IDABOUT:
			MessageBox(hDlg, "マルチメディアレコータ\nVersion 0.00\nCopyright(c)のぐー",
				"バージョン情報", MB_OK);
			break;
		case IDBROWSE:
			memset(&ofn, 0, sizeof(OPENFILENAME));
			ofn.lStructSize = sizeof(OPENFILENAME);
			ofn.hwndOwner = hDlg;
			ofn.lpstrFilter = "サウンド(*.WAV)\0*.WAV\0全ファイル(*.*)\0*.*\0";
			ofn.lpstrCustomFilter = NULL;
			ofn.nFilterIndex = 1;
			achFilePath[0] = 0;
			ofn.lpstrFile = (LPSTR)achFilePath;
			ofn.nMaxFile = sizeof(achFilePath);
			ofn.lpstrFileTitle = (LPSTR)achFileTitle;
			ofn.nMaxFileTitle = sizeof(achFileTitle);
			ofn.lpstrInitialDir = NULL;
			ofn.lpstrTitle = "再生用にファイルを開く";
			ofn.lpstrDefExt = NULL;
			ofn.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST;
			flag=GetOpenFileName((LPOPENFILENAME)&ofn);
			if (flag)
				SetDlgItemText(hDlg, IDEDIT, achFilePath);
			break;
		case IDOK:
			//GetWindowText(GetDlgItem(hDlg, IDEDIT), achFilePath, sizeof(achFilePath));
			GetDlgItemText(hDlg, IDEDIT, achFilePath, sizeof(achFilePath));
			if (flag==0 && strlen(achFilePath)==0) {
				MessageBox(hDlg, "ファイル名を入力してください", "エラー", MB_OK);
				break;
			}
			if (flag==0) {
				int stereo, mode, bits; unsigned int freq;
				SetDlgItemText(hDlg, IDOK, "停止");
				EnableAllControls(hDlg, FALSE);
				if (IsDlgButtonChecked(hDlg, IDCHK)) stereo=1; else stereo=0;
				type = (int)SendDlgItemMessage (hDlg, IDLIST, LB_GETCURSEL, 0, 0L);
				switch(type){
				case 0: freq= 8000u; break;
				case 1: freq=11025u; break;
				case 2: freq=22050u; break;
				case 3: freq=32000u; break;
				case 4: freq=44100u; break;
				case 5: freq=48000u; break;
				}
				type = (int)SendDlgItemMessage (hDlg, IDTYPE, CB_GETCURSEL, 0, 0L);
				GetDlgItemText(hDlg, IDTYPE, buf, sizeof(buf));
				sprintf(tmp, " %uHz", freq); strcat(buf, tmp);
				if (IsDlgButtonChecked(hDlg, IDRB8)) bits=8; else bits=16;
				sprintf(tmp, " %dbits", bits); strcat(buf, tmp);
				if (stereo) strcat(buf, " ステレオ"); else strcat(buf, "モノラル");
				sprintf(tmp, " level=%d",level); strcat(buf, tmp);
				if      (IsDlgButtonChecked(hDlg, IDREC)) mode=IDREC, strcat(buf,"て記録中");
				else if (IsDlgButtonChecked(hDlg, IDPLY)) mode=IDPLY, strcat(buf,"で再生中");
				else                                      mode=IDCON, strcat(buf,"でコンバート中");
				strcat(buf, "のつもり");
				SetDlgItemText(hDlg, IDSTATUS, buf);
			}else{
				SetDlgItemText(hDlg, IDOK, "開始");
				EnableAllControls(hDlg, TRUE);
				SetDlgItemText(hDlg, IDSTATUS, "停止中");
			}
			flag=!flag;
			break;
		case IDCANCEL:		/* 「閉じる」ボタン OR システムメニューの「閉じる」 */
			EndDialog( hDlg, wParam );
			break;
		default:
			return FALSE; /*メッセージを処理しなかった*/
		}
		break;
	case WM_INITDIALOG:
		SetScrollRange(GetDlgItem(hDlg, IDSCR), SB_CTL, 0, 100, FALSE);
		SetScrollPos(GetDlgItem(hDlg, IDSCR), SB_CTL, 50, TRUE);
		level=50;
		CheckRadioButton(hDlg, IDREC, IDCON, IDPLY);
		CheckRadioButton(hDlg, IDRB8, IDRB16, IDRB8);

		SendDlgItemMessage(hDlg, IDTYPE, CB_ADDSTRING, 0, (LONG)(LPSTR)"PCM");
		SendDlgItemMessage(hDlg, IDTYPE, CB_ADDSTRING, 0, (LONG)(LPSTR)"Microsoft ADPCM");
		SendDlgItemMessage(hDlg, IDTYPE, CB_ADDSTRING, 0, (LONG)(LPSTR)"IEEE Froat");
		SendDlgItemMessage(hDlg, IDTYPE, CB_ADDSTRING, 0, (LONG)(LPSTR)"VCELP");
		SendDlgItemMessage(hDlg, IDTYPE, CB_ADDSTRING, 0, (LONG)(LPSTR)"CCITT-A-Law");
		SendDlgItemMessage(hDlg, IDTYPE, CB_ADDSTRING, 0, (LONG)(LPSTR)"IMA-ADPCM");
		SendDlgItemMessage(hDlg, IDTYPE, CB_ADDSTRING, 0, (LONG)(LPSTR)"MP3");
		SendDlgItemMessage(hDlg, IDTYPE, CB_SETCURSEL, type, 0L);

		SendDlgItemMessage(hDlg, IDLIST, LB_ADDSTRING, 0, (LONG)(LPSTR)"8000");
		SendDlgItemMessage(hDlg, IDLIST, LB_ADDSTRING, 0, (LONG)(LPSTR)"11025");
		SendDlgItemMessage(hDlg, IDLIST, LB_ADDSTRING, 0, (LONG)(LPSTR)"22050");
		SendDlgItemMessage(hDlg, IDLIST, LB_ADDSTRING, 0, (LONG)(LPSTR)"32000");
		SendDlgItemMessage(hDlg, IDLIST, LB_ADDSTRING, 0, (LONG)(LPSTR)"44100");
		SendDlgItemMessage(hDlg, IDLIST, LB_ADDSTRING, 0, (LONG)(LPSTR)"48000");
		SendDlgItemMessage(hDlg, IDLIST, LB_SETCURSEL, 1, 0L);

		SetFocus(GetDlgItem(hDlg,IDEDIT));
		return FALSE;/* SetFocusしたらFALSE */
	default:
		return FALSE; /*メッセージを処理しなかった*/
	}
	return TRUE; /*メッセージを処理した*/
}
/*メイン関数*/
int PASCAL WinMain(HINSTANCE hinst, HINSTANCE hprev, LPSTR cmdline, int cmdshow){
	DLGPROC lpProc = (DLGPROC)MakeProcInstance((FARPROC)dlgproc, hinst);
	DialogBox(hinst, "dialog", NULL, lpProc);/*ここでダイアログボックスを作成*/
	FreeProcInstance((FARPROC)lpProc);
	return 0;
}

ファイル名:controls.def

NAME	CONTROLS
DESCRIPTION  'CONTROLS: DIALOG CONTROLS SAMPLE'
EXETYPE WINDOWS
STUB	    'WINSTUB.EXE'
CODE    PRELOAD MOVEABLE
DATA    MOVEABLE PRELOAD MULTIPLE
HEAPSIZE  4096
STACKSIZE 8192
EXPORTS
	DLGPROC  @1
戻る