1 // Burner Input Constant dialog module
2 #include "burner.h"
3 
4 HWND hInpcDlg = NULL;								// Handle to the Input Dialog
5 unsigned int nInpcInput = 0;						// The input number we are redefining
6 
7 static HWND hValue = NULL;							// Handle to value edit control
8 static struct GameInp* pgi = NULL;					// Current GameInp
9 
InpcInit()10 static int InpcInit()
11 {
12 	TCHAR szOldTitle[1024] = _T("");
13 	TCHAR szNewTitle[1024] = _T("");
14 	int nCurrent = 0;
15 
16 	struct BurnInputInfo bii;						// Info about the input
17 
18 	hValue = GetDlgItem(hInpcDlg, IDC_INPC_VALUE);	// Get Edit controls
19 
20 	// Get the extra info about the input
21 	memset(&bii, 0, sizeof(bii));
22 	BurnDrvGetInputInfo(&bii, nInpcInput);
23 	if (bii.szName == NULL) {
24 		bii.szName= "";
25 	}
26 
27 	// Set the dialog title
28 	GetWindowText(hInpcDlg, szOldTitle, 1024);
29 	_sntprintf(szNewTitle, 1024, _T(APP_TITLE) _T(SEPERATOR_1) _T("%s %hs"), szOldTitle, bii.szName);
30 	SetWindowText(hInpcDlg, szNewTitle);
31 
32 	pgi = NULL;
33 	if (nInpcInput >= nGameInpCount) {				// input out of range
34 		return 1;
35 	}
36 	pgi = GameInp + nInpcInput;
37 
38 	// Get current constant
39 	if (pgi->nInput == GIT_CONSTANT) {
40 	nCurrent=pgi->Input.Constant.nConst; }
41 	_stprintf(szNewTitle, _T("0x%.2X"), nCurrent);
42 	SetWindowText(hValue, szNewTitle);
43 
44 	return 0;
45 }
46 
InpcExit()47 static int InpcExit()
48 {
49 	pgi=NULL;
50 	hValue=NULL;
51 	hInpcDlg=NULL;
52 
53 	return 0;
54 }
55 
DialogProc(HWND hDlg,UINT Msg,WPARAM wParam,LPARAM)56 static INT_PTR CALLBACK DialogProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM /*lParam*/)
57 {
58 	if (Msg == WM_INITDIALOG) {						// 1 = we didn't set focus?
59 		hInpcDlg = hDlg;
60 		InpcInit();
61 
62 		return 1;
63 	}
64 	if (Msg == WM_CLOSE){
65 		DestroyWindow(hInpcDlg);
66 
67 		return 0;
68 	}
69 	if (Msg == WM_DESTROY) {
70 		InpcExit();
71 
72 		return 0;
73 	}
74 
75 	if (Msg == WM_COMMAND) {
76 		int Id = LOWORD(wParam);
77 		int Notify = HIWORD(wParam);
78 		if (Id == IDOK     && Notify == BN_CLICKED) {		// OK = close
79 			SendMessage(hDlg, WM_CLOSE, 0, 0);
80 			return 0;
81 		}
82 		if (Id == IDCANCEL && Notify == BN_CLICKED) {		// cancel = close
83 			SendMessage(hDlg, WM_CLOSE, 0, 0);
84 			return 0;
85 		}
86 
87 		if (Id == IDC_INPC_VALUE && Notify == EN_CHANGE) {
88 			// Edit box may have been changed
89 			TCHAR szNew[16] = _T("");
90 			int nVal = 0;
91 
92 			if (pgi == NULL) {
93 				return 0;
94 			}
95 
96 			GetWindowText(hValue, szNew, sizeof(szNew));
97 
98 			// Set new constant
99 			pgi->nInput = GIT_CONSTANT;
100 			nVal = _tcstol(szNew, NULL, 0);
101 			pgi->Input.Constant.nConst = (unsigned char)nVal;
102 
103 			InpdListMake(0);								// refresh view
104 
105 			return 0;
106 		}
107 	}
108 
109 	return 0;
110 }
111 
InpcCreate()112 int InpcCreate()
113 {
114 	DestroyWindow(hInpcDlg);
115 	hInpcDlg = NULL;
116 
117 	hInpcDlg = FBACreateDialog(hAppInst, MAKEINTRESOURCE(IDD_INPC), hInpdDlg, (DLGPROC)DialogProc);
118 	if (hInpcDlg == NULL) {
119 		return 1;
120 	}
121 
122 	WndInMid(hInpcDlg, hInpdDlg);
123 	ShowWindow(hInpcDlg, SW_NORMAL);
124 
125 	return 0;
126 }
127