Guest User

C++ Help

a guest
Jan 10th, 2011
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.48 KB | None | 0 0
  1. Well I've been working on a program, it's kinda big, I guess.
  2.  
  3. It has multiple source files, but not all are big:
  4.  
  5. main.cpp
  6. [code]
  7. /* Include the file PreProcessor Calls.h into this file */
  8. #include "PreProcessor Calls.h"
  9.  
  10. /* Entry point of my application */
  11. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpsCmdLine, int iCmdShow)
  12. {
  13. /* Call the SetUpWindowClass function
  14. "1": Title for the window class
  15. 255: Rgb for window background color
  16. 255: rGb for window background color
  17. 255: rgB for window background color
  18. hInstance: Module handle
  19. See the SetUpWindowClass function for more information on how these arguments are used
  20. It is in the Functions.h file
  21. */
  22. if (!SetUpWindowClass ("1", 255, 255, 255, hInstance))
  23. {
  24. /* Notify the user that the window class has failed, then exit the program */
  25. MessageBox (NULL, "Window class failed", NULL, NULL);
  26. return 0;
  27. }
  28. /* Create the parent window. WS_NO_RESIZE is defined in the file "Defines.h"*/
  29. hWnd = CreateWindowEx (WS_EX_CLIENTEDGE, "1", "-LeetGamer-'s PSPAIO", WS_NO_RESIZE, 0, 0, 0, 0, NULL, NULL, hInstance, NULL);
  30. /* Notify the user if the window creation has failed */
  31. if (!hWnd)
  32. {
  33. /* Notify the user that the window creation has failed, then exit the program */
  34. MessageBox (NULL, "Window creation failed", NULL, NULL);
  35. return 0;
  36. }
  37. /* Load and set the menu */
  38. HMENU hmMenu = LoadMenu (hInstance, MAKEINTRESOURCE (ID_MENU));
  39. SetMenu (hWnd, hmMenu);
  40. /* Show the window to the user */
  41. ShowWindow (hWnd, SW_SHOWMAXIMIZED);
  42. /* Call the SetUpAndCreateChildWindows function, this function will create all the child windows used in my MDI
  43. hWnd: Window handle to the parent window.
  44. */
  45. if (!SetUpAndCreateChildWindows (hWnd))
  46. {
  47. /* Notify the user that the chld window creation has failed, then exit the program */
  48. MessageBox (hWnd, "Child window creation failed", NULL, NULL);
  49. return 0;
  50. }
  51. /* Call the HideAllChildWindows function, this function is small:
  52. void HideAllChildWindows ()
  53. {
  54. for (int iLoopCounter = 0; iLoopCounter < 10; iLoopCounter++)
  55. {
  56. ShowWindow (hWndC [iLoopCounter], SW_HIDE);
  57. }
  58. return;
  59. }
  60. Its job is to ShowWindow (hWndC [], SW_HIDE); all the handles in the hWndC array.
  61. Why I do this will be shown a few lines down.
  62. */
  63. HideAllChildWindows ();
  64. /* Here I show the welcome child window. This has some text that will tell the user how to use the program.
  65. I used the last function call to hide all the other windows, and only show this one on start up.
  66. */
  67. ShowWindow (hWndC [0], SW_SHOW);
  68. /* Message loop */
  69. MSG uMsg;
  70. while (GetMessage (&uMsg, NULL, 0, 0) > 0)
  71. {
  72. TranslateMessage (&uMsg);
  73. DispatchMessage (&uMsg);
  74. }
  75. /* Exit program */
  76. return 0;
  77. }
  78. [/code]
  79.  
  80. PreProcessor Calls.h
  81. [code]
  82. /* Include Windows.h into this file */
  83. #include <Windows.h>
  84. /* Include all my local header files */
  85. #include "Defines.h"
  86. #include "Globals.h"
  87. #include "Function Prototypes.h"
  88. #include "WindowProcedure.h"
  89. #include "Functions.h"
  90. [/code]
  91.  
  92. Defines.h
  93. [code]
  94. /* This file is easy to understand if you know C/C++, so, I won't comment on it. */
  95. #define WS_NO_RESIZE WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX
  96. #define WS_CHILD_WINDOW WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_CHILD|WS_VISIBLE
  97. #define WS_MULTI_LINE_EDIT WS_CHILD|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE
  98. #define ID_MENU 0x1337
  99. #define IDM_MENU_EXIT 0x1338
  100. #define IDM_MENU_FEATURES_PS2DIS_HEX_FIXER 0x1339
  101. #define IDM_MENU_FEATURES_IMPOSTER_GENERATOR 0x1340
  102. #define IDM_MENU_FEATURES_CODE_ARCHIVE_NITEPR 0x1341
  103. #define IDM_MENU_FEATURES_CODE_ARCHIVE_CWCHEAT 0x1342
  104. #define IDM_MENU_FEATURES_WELCOME 0x1343
  105. #define PS2DIS_HEX_FIXER_INPUT 0x1344
  106. [/code]
  107.  
  108. Globals.h
  109. [code]
  110. /* Global variables */
  111. /* The main/parent window's handle */
  112. HWND hWnd = NULL;
  113. /* An array of window handles for the child windows */
  114. HWND hWndC [10];
  115. [/code]
  116.  
  117. Function Prototypes.h
  118. [code]
  119. /* Function prototypes/declairations */
  120. bool SetUpWindowClass (char*, int, int, int, HINSTANCE);
  121. bool CreateChildWindows (HWND);
  122. bool SetUpAndCreateChildWindows (HWND);
  123. void HideAllChildWindows ();
  124. [/code]
  125.  
  126. WindowProcedure.h
  127. [code]
  128. /* This namespace holds all the window procedures */
  129. namespace WindowProcedures
  130. {
  131. /* This namespace holds all the child window procedures */
  132. namespace CWP
  133. {
  134. // Welcome window
  135. LRESULT CALLBACK CWP_1 (HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
  136. {
  137. switch (uMsg)
  138. {
  139. case WM_CLOSE:
  140. ShowWindow (hWnd, SW_SHOWMINIMIZED);
  141. return 0;
  142. break;
  143. case WM_PAINT:
  144. {
  145. PAINTSTRUCT ps;
  146. HDC hDC = BeginPaint (hWnd, &ps);
  147. int iY = 0;
  148. char* cpaText [5];
  149. cpaText [0] = "Welcome to -LeetGamer-'s PSPAIO (PSP All in one) v1!";
  150. cpaText [1] = "This program will help people with a number of things, if they have a CFW";
  151. cpaText [2] = "To use the features click on the \"Features\" drop down.";
  152. cpaText [3] = "If you need any help with using this program then contact me with the \"Contact Me\" drop down.";
  153. cpaText [4] = "If you have any ideas for new features that I should add please contact me with the info";
  154. for (int iLoopCounter = 0; iLoopCounter < 5; iLoopCounter++, iY += 20)
  155. {
  156. TextOut (hDC, 0, iY, cpaText [iLoopCounter], strlen (cpaText [iLoopCounter]));
  157. }
  158. EndPaint (hWnd, &ps);
  159. }
  160. break;
  161. }
  162. return DefWindowProc (hWnd, uMsg, wParam, lParam);
  163. }
  164. // Ps2Dis.exe Hex Value Fixer
  165. LRESULT CALLBACK CWP_2 (HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
  166. {
  167. HINSTANCE hInstance = GetModuleHandle (NULL);
  168. switch (uMsg)
  169. {
  170. case WM_CLOSE:
  171. ShowWindow (hWnd, SW_SHOWMINIMIZED);
  172. return 0;
  173. break;
  174. case WM_CREATE:
  175. CreateWindowEx (WS_EX_CLIENTEDGE, "edit", "", WS_MULTI_LINE_EDIT, 0, 0, 150, 300, hWnd, (HMENU) PS2DIS_HEX_FIXER_INPUT, hInstance, NULL);
  176. break;
  177. }
  178. return DefWindowProc (hWnd, uMsg, wParam, lParam);
  179. }
  180. // Imposter generator
  181. LRESULT CALLBACK CWP_3 (HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
  182. {
  183. switch (uMsg)
  184. {
  185. case WM_CLOSE:
  186. ShowWindow (hWnd, SW_SHOWMINIMIZED);
  187. return 0;
  188. break;
  189. }
  190. return DefWindowProc (hWnd, uMsg, wParam, lParam);
  191. }
  192. // Code Archive NitePR
  193. LRESULT CALLBACK CWP_4 (HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
  194. {
  195. switch (uMsg)
  196. {
  197. case WM_CLOSE:
  198. ShowWindow (hWnd, SW_SHOWMINIMIZED);
  199. return 0;
  200. break;
  201. }
  202. return DefWindowProc (hWnd, uMsg, wParam, lParam);
  203. }
  204. // Code Archive CwCheat
  205. LRESULT CALLBACK CWP_5 (HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
  206. {
  207. switch (uMsg)
  208. {
  209. case WM_CLOSE:
  210. ShowWindow (hWnd, SW_SHOWMINIMIZED);
  211. return 0;
  212. break;
  213. }
  214. return DefWindowProc (hWnd, uMsg, wParam, lParam);
  215. }
  216. };
  217. /* Main/Parent window procedure */
  218. LRESULT CALLBACK MainWindowProcedure (HWND hWnd, unsigned int uMsg, WPARAM wParam, LPARAM lParam)
  219. {
  220. switch (uMsg)
  221. {
  222. case WM_CLOSE:
  223. DestroyWindow (hWnd);
  224. break;
  225. case WM_DESTROY:
  226. PostQuitMessage (0);
  227. break;
  228. case WM_COMMAND:
  229. switch (LOWORD (wParam))
  230. {
  231. case IDM_MENU_EXIT:
  232. DestroyWindow (hWnd);
  233. break;
  234. /* These will hide all the windows then it will show the window that the user selected */
  235. case IDM_MENU_FEATURES_WELCOME:
  236. HideAllChildWindows ();
  237. ShowWindow (hWndC [0], SW_SHOW);
  238. break;
  239. case IDM_MENU_FEATURES_PS2DIS_HEX_FIXER:
  240. HideAllChildWindows ();
  241. ShowWindow (hWndC [1], SW_SHOW);
  242. break;
  243. case IDM_MENU_FEATURES_IMPOSTER_GENERATOR:
  244. HideAllChildWindows ();
  245. ShowWindow (hWndC [2], SW_SHOW);
  246. break;
  247. case IDM_MENU_FEATURES_CODE_ARCHIVE_NITEPR:
  248. HideAllChildWindows ();
  249. ShowWindow (hWndC [3], SW_SHOW);
  250. break;
  251. case IDM_MENU_FEATURES_CODE_ARCHIVE_CWCHEAT:
  252. HideAllChildWindows ();
  253. ShowWindow (hWndC [4], SW_SHOW);
  254. break;
  255. }
  256. break;
  257. }
  258. return DefWindowProc (hWnd, uMsg, wParam, lParam);
  259. }
  260. };
  261. [/code]
  262.  
  263. Functions.h
  264. [code]
  265. /*
  266. Function: SetUpWindowClass ()
  267. Arguments:
  268. char* cpTitle: Holds the title of the window class
  269. int iR: Holds the Rgb of the window's bg color
  270. int iG: Holds the rGb of the window's bg color
  271. int iB: Holds the rgB of the window's bg color
  272. HINSTANCE hInstance: Holds the module handle
  273. Function's job:
  274. Set up a working window class
  275. Returns: true if all was good, false if something failed
  276. */
  277. bool SetUpWindowClass (char* cpTitle, int iR, int iG, int iB, HINSTANCE hInstance)
  278. {
  279. WNDCLASSEX WindowClass; /* Declair the window class structure */
  280. WindowClass.cbClsExtra = 0; /* Extra bytes to allocate for the class */
  281. WindowClass.cbWndExtra = 0; /* Extra bytes to allocate for the window */
  282. WindowClass.cbSize = sizeof (WNDCLASSEX); /* The size of the class */
  283. WindowClass.style = 0; /* The style */
  284. WindowClass.lpszClassName = cpTitle; /* The class name, I use the first argument here */
  285. WindowClass.lpszMenuName = NULL; /* The menu name */
  286. /* Here is where I fill in WindowClass.lpfnWndProc
  287. I use if statements to see what class title was passed into this function,
  288. I use a different window procedure (they are held in a namespace) for each class title
  289. because, well, I want it like that :P */
  290. if (cpTitle == "1") WindowClass.lpfnWndProc = WindowProcedures::MainWindowProcedure;
  291. else if (cpTitle == "2") WindowClass.lpfnWndProc = WindowProcedures::CWP::CWP_1;
  292. else if (cpTitle == "3") WindowClass.lpfnWndProc = WindowProcedures::CWP::CWP_2;
  293. else if (cpTitle == "4") WindowClass.lpfnWndProc = WindowProcedures::CWP::CWP_3;
  294. else if (cpTitle == "5") WindowClass.lpfnWndProc = WindowProcedures::CWP::CWP_4;
  295. else if (cpTitle == "6") WindowClass.lpfnWndProc = WindowProcedures::CWP::CWP_5;
  296. WindowClass.hInstance = hInstance; /* Module handle */
  297. WindowClass.hCursor = LoadCursor (NULL, IDC_ARROW); /* The cursor */
  298. WindowClass.hbrBackground = CreateSolidBrush (RGB (iR, iG, iB)); /* The background color */
  299. WindowClass.hIcon = LoadIcon (NULL, IDI_APPLICATION); /* Large icon */
  300. WindowClass.hIconSm = LoadIcon (NULL, IDI_APPLICATION); /* Small icon */
  301. if (!RegisterClassEx (&WindowClass)) return false; /* If the window class registration failed then return false */
  302. else return true; /* Else return true */
  303. }
  304. /*
  305. Function: SetUpAndCreateChildWindows ()
  306. Arguments:
  307. HWND hWnd: Holds the window handle to the main/parent window
  308. Function's Job:
  309. Set up the window classes for, and create the child windows
  310. Returns: true is all was good, false if something failed
  311. */
  312. bool SetUpAndCreateChildWindows (HWND hWnd)
  313. {
  314. HINSTANCE hInstance = GetModuleHandle (NULL); /* Put the module handle in hInstance */
  315. if (!SetUpWindowClass ("2", 255, 255, 255, hInstance)) return false; /* Set up the window class */
  316. hWndC [0] = CreateWindowEx (WS_EX_CLIENTEDGE, "2", "Welcome", WS_CHILD_WINDOW, 0, 0, 650, 140, hWnd, NULL, hInstance, NULL); /* Create the "Welcome" window */
  317. if (!hWndC [0]) return false; /* Check if the "Welcome" window was created right or not, if not return false */
  318. if (!SetUpWindowClass ("3", 255, 255, 255, hInstance)) return false; /* Set up another window class for the "Ps2Dis Hex Fixer" window */
  319. hWndC [1] = CreateWindowEx (WS_EX_CLIENTEDGE, "3", "Ps2Dis Hex Fixer", WS_CHILD_WINDOW, 0, 0, 700, 480, hWnd, NULL, hInstance, NULL); /* Create the "Ps2Dis Hex Fixer" window */
  320. if (!hWndC [1]) return false; /* Check if the "Ps2Dis Hex Fixer" window was created right or not, if not return false */
  321. if (!SetUpWindowClass ("4", 255, 255, 255, hInstance)) return false; /* Set up another window class for the "Imposter Generator" window */
  322. hWndC [2] = CreateWindowEx (WS_EX_CLIENTEDGE, "4", "Imposter Generator", WS_CHILD_WINDOW, 0, 0, 540, 140, hWnd, NULL, hInstance, NULL); /* Create the "Imposter Generator" window */
  323. if (!hWndC [2]) return false; /* Check if the "Imposter Generator" window was created right or not, if not return false*/
  324. if (!SetUpWindowClass ("5", 255, 255, 255, hInstance)) return false; /* Set up another window class for the "Code Archive (NitePR)" window */
  325. hWndC [3] = CreateWindowEx (WS_EX_CLIENTEDGE, "5", "Code Archive (NitePR)", WS_CHILD_WINDOW, 0, 0, 540, 140, hWnd, NULL, hInstance, NULL); /* Create the "Code Archive (NitePR)" window */
  326. if (!hWndC [3]) return false; /* Check if the "Code Archive (NitePR)" window was created right or not, if not return false */
  327. if (!SetUpWindowClass ("6", 255, 255, 255, hInstance)) return false; /* Set up another window class for the "Code Archive (CwCheat)" window */
  328. hWndC [4] = CreateWindowEx (WS_EX_CLIENTEDGE, "6", "Code Archive (CwCheat)", WS_CHILD_WINDOW, 0, 0, 540, 140, hWnd, NULL, hInstance, NULL); /* Create the "Code Archive (CwCheat)" window */
  329. if (!hWndC [4]) return false; /* Check if the "Code Archive (CwCheat)" window was created right or not, if not return false */
  330. return true; /* All has gone good, return true */
  331. }
  332. /*
  333. Function: HideAllChildWindows ()
  334. Arguments: None
  335. Function's Job:
  336. Use ShowWindow (hWndC [], SW_HIDE); on all child window handles.
  337. This will hide them all from the user, I will then show then when I want to.
  338. Returns: None
  339. This function is really simple to understand so I won't comment on it
  340. */
  341. void HideAllChildWindows ()
  342. {
  343. for (int iLoopCounter = 0; iLoopCounter < 10; iLoopCounter++)
  344. {
  345. ShowWindow (hWndC [iLoopCounter], SW_HIDE);
  346. }
  347. return;
  348. }
  349. [/code]
  350.  
  351. Resource.rc
  352. [code]
  353. /* This file is easy to understand if you know the Win32 API, so, I won't comment on it. */
  354. #include "Defines.h"
  355. ID_MENU MENU
  356. BEGIN
  357. POPUP "&File"
  358. BEGIN
  359. MENUITEM "&Exit", IDM_MENU_EXIT
  360. END
  361. POPUP "&Features"
  362. BEGIN
  363. MENUITEM "&Welcome Message", IDM_MENU_FEATURES_WELCOME
  364. MENUITEM "&Ps2Dis Hex Fixer", IDM_MENU_FEATURES_PS2DIS_HEX_FIXER
  365. MENUITEM "&Imposter Generator", IDM_MENU_FEATURES_IMPOSTER_GENERATOR
  366. POPUP "&Code Archive"
  367. BEGIN
  368. MENUITEM "&NitePR Format Codes", IDM_MENU_FEATURES_CODE_ARCHIVE_NITEPR
  369. MENUITEM "&CwCheat Format Codes", IDM_MENU_FEATURES_CODE_ARCHIVE_CWCHEAT
  370. END
  371. END
  372. END
  373. [/code]
  374.  
  375. Here is the project download: http://www.sendspace.com/file/hqx08p
  376. And the .exe download: http://www.sendspace.com/file/st8gel
  377.  
  378. Now here is where my problem is :P
  379.  
  380. If you run the program, and you go to "Ps2Dis Hex Value Fixer" from the "Features" drop down a new window will pop up. But I can't type in the edit control, can anyone help me with this? I know it might be hard for some of you guys to read that much code (Well, it looks like a lot) but it's not that much.
  381.  
  382. Thanks !!!!!!!!
Advertisement
Add Comment
Please, Sign In to add comment