Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
test2.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
20// $File: //depot/GeneralsMD/Staging/code/Libraries/Source/debug/test2/test2.cpp $
21// $Author: mhoffe $
22// $Revision: #1 $
23// $DateTime: 2003/07/03 11:55:26 $
24//
25// ©2003 Electronic Arts
26//
27// Debug module - Test 2 (Checking commands, CON I/O, cmddbg file)
29
30#include "stdafx.h"
31#include "resource.h"
32#include "..\debug.h"
33
34#define MAX_LOADSTRING 100
35
36// Global Variables:
37HINSTANCE hInst; // current instance
38TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
39TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
40
41// Foward declarations of functions included in this code module:
42ATOM MyRegisterClass(HINSTANCE hInstance);
43BOOL InitInstance(HINSTANCE, int);
44LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
45LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
46
47class TestCmdInterface: public DebugCmdInterface
48{
49public:
50
51 virtual bool Execute(class Debug& dbg, const char *cmd, CommandMode cmdmode,
52 unsigned argn, const char * const * argv)
53 {
54 if (strcmp(cmd,"box"))
55 return false;
56
57 MessageBox(NULL,"Hello world!","Command",MB_OK);
58 return true;
59 }
60
61 virtual void Delete(void) { delete this; }
62};
63
65
66int APIENTRY WinMain(HINSTANCE hInstance,
67 HINSTANCE hPrevInstance,
68 LPSTR lpCmdLine,
69 int nCmdShow)
70{
71 // TODO: Place code here.
72 MSG msg;
73 HACCEL hAccelTable;
74
75 // Initialize global strings
76 LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
77 LoadString(hInstance, IDC_TEST2, szWindowClass, MAX_LOADSTRING);
78 MyRegisterClass(hInstance);
79
80 // Perform application initialization:
81 if (!InitInstance (hInstance, nCmdShow))
82 {
83 return FALSE;
84 }
85
86 hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TEST2);
87
88 // Send a command to Debug interface
89 Debug::Command("debug.io ; send via EXE, try test.box!");
90
91 // Main message loop:
92 while (GetMessage(&msg, NULL, 0, 0))
93 {
94 if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
95 {
96 TranslateMessage(&msg);
97 DispatchMessage(&msg);
98 }
99 }
100
101 return msg.wParam;
102}
103
104
105
106//
107// FUNCTION: MyRegisterClass()
108//
109// PURPOSE: Registers the window class.
110//
111// COMMENTS:
112//
113// This function and its usage is only necessary if you want this code
114// to be compatible with Win32 systems prior to the 'RegisterClassEx'
115// function that was added to Windows 95. It is important to call this function
116// so that the application will get 'well formed' small icons associated
117// with it.
118//
119ATOM MyRegisterClass(HINSTANCE hInstance)
120{
121 WNDCLASSEX wcex;
122
123 wcex.cbSize = sizeof(WNDCLASSEX);
124
125 wcex.style = CS_HREDRAW | CS_VREDRAW;
126 wcex.lpfnWndProc = (WNDPROC)WndProc;
127 wcex.cbClsExtra = 0;
128 wcex.cbWndExtra = 0;
129 wcex.hInstance = hInstance;
130 wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TEST2);
131 wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
132 wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
133 wcex.lpszMenuName = (LPCSTR)IDC_TEST2;
134 wcex.lpszClassName = szWindowClass;
135 wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
136
137 return RegisterClassEx(&wcex);
138}
139
140//
141// FUNCTION: InitInstance(HANDLE, int)
142//
143// PURPOSE: Saves instance handle and creates main window
144//
145// COMMENTS:
146//
147// In this function, we save the instance handle in a global variable and
148// create and display the main program window.
149//
150BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
151{
152 HWND hWnd;
153
154 hInst = hInstance; // Store instance handle in our global variable
155
156 hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
157 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
158
159 if (!hWnd)
160 {
161 return FALSE;
162 }
163
164 // create a timer for calling Debug::Update
165 SetTimer(hWnd,1,100,NULL);
166
167 ShowWindow(hWnd, nCmdShow);
168 UpdateWindow(hWnd);
169
170 return TRUE;
171}
172
173//
174// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
175//
176// PURPOSE: Processes messages for the main window.
177//
178// WM_COMMAND - process the application menu
179// WM_PAINT - Paint the main window
180// WM_DESTROY - post a quit message and return
181//
182//
183LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
184{
185 int wmId, wmEvent;
186 PAINTSTRUCT ps;
187 HDC hdc;
188 TCHAR szHello[MAX_LOADSTRING];
189 LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
190
191 switch (message)
192 {
193 case WM_COMMAND:
194 wmId = LOWORD(wParam);
195 wmEvent = HIWORD(wParam);
196 // Parse the menu selections:
197 switch (wmId)
198 {
199 case IDM_ABOUT:
200 DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
201 break;
202 case IDM_EXIT:
203 DestroyWindow(hWnd);
204 break;
205 default:
206 return DefWindowProc(hWnd, message, wParam, lParam);
207 }
208 break;
209 case WM_PAINT:
210 hdc = BeginPaint(hWnd, &ps);
211 // TODO: Add any drawing code here...
212 RECT rt;
213 GetClientRect(hWnd, &rt);
214 DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
215 EndPaint(hWnd, &ps);
216 break;
217 case WM_DESTROY:
218 PostQuitMessage(0);
219 break;
220 case WM_TIMER:
222 break;
223 default:
224 return DefWindowProc(hWnd, message, wParam, lParam);
225 }
226 return 0;
227}
228
229// Mesage handler for about box.
230LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
231{
232 switch (message)
233 {
234 case WM_INITDIALOG:
235 return TRUE;
236
237 case WM_COMMAND:
238 if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
239 {
240 EndDialog(hDlg, LOWORD(wParam));
241 return TRUE;
242 }
243 break;
244 }
245 return FALSE;
246}
#define NULL
Definition BaseType.h:92
#define TRUE
Definition BaseType.h:109
#define FALSE
Definition BaseType.h:113
unsigned int UINT
Definition bittype.h:63
const char * LPCSTR
Definition bittype.h:62
#define IDM_ABOUT
Definition resource.h:27
#define IDS_APP_TITLE
Definition resource.h:26
#define IDD_ABOUTBOX
Definition resource.h:25
#define IDM_EXIT
Definition resource.h:28
#define IDI_TEST2
Definition resource.h:30
#define IDI_SMALL
Definition resource.h:31
#define IDS_HELLO
Definition resource.h:29
#define IDC_TEST2
Definition resource.h:32
#define BOOL
Definition Wnd_File.h:57
CommandMode
possible command modes
Definition debug_cmd.h:67
Debug module main class (singleton).
Definition debug_debug.h:45
static void Command(const char *cmd)
Issues a debug command.
static void Update(void)
Update method, must be called on a regular basis.
virtual bool Execute(class Debug &dbg, const char *cmd, CommandMode cmdmode, unsigned argn, const char *const *argv)
Execute the given command.
Definition test2.cpp:51
virtual void Delete(void)
Destroys the current command interface.
Definition test2.cpp:61
int CALLBACK WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int)
#define DEBUG_CREATE_COMMAND_GROUP(groupname, type)
Definition debug_cmd.h:124
MSG msg
Definition patch.cpp:409
TCHAR szTitle[MAX_LOADSTRING]
Definition test2.cpp:38
#define MAX_LOADSTRING
Definition test2.cpp:34
HINSTANCE hInst
Definition test2.cpp:37
BOOL InitInstance(HINSTANCE, int)
Definition test2.cpp:150
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM)
Definition test2.cpp:183
ATOM MyRegisterClass(HINSTANCE hInstance)
Definition test2.cpp:119
TCHAR szWindowClass[MAX_LOADSTRING]
Definition test2.cpp:39
LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM)
Definition test2.cpp:230
int test
Definition test6.cpp:32