944,076 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 851
  • C++ RSS
Nov 4th, 2009
0

Help with WndProc Mapping

Expand Post »
I am trying to get a WndProc Mapping solution to work so that I can avoid just making my WndProc static. In addition, a mapping solution is supposed to be great because I don't need to declare variables in my .cpp file, I can do it in my .h file like it should be.

However, this is exactly my problem: if you uncomment lines 3 and 4 of GameManager.cpp and you comment lines 24 and 25 of GameManager.h, the program runs just fine. But, I need it to be the other way around! Instead what happens is the window opens and closes abruptly. Any insight would be greatly appreciated:

*Edit: sorry if the post is too long, I'm new to these forums. If it's too long just let me know and I'll cut out things I *think* are not causing this issue. However, a big reason I left it is so someone can compile it (it should compile and run straight out of the box!).

main.cpp:
C++ Syntax (Toggle Plain Text)
  1. #include "GameManager.h" // Include our GameManager and let it handle everything.
  2. #include <windows.h>
  3. int WINAPI WinMain( HINSTANCE hInstance, // Instance
  4. HINSTANCE hPrevInstance, // Previous Instance
  5. LPSTR lpCmdLine, // Command Line Parameters
  6. int nCmdShow) // Window Show State
  7. {
  8. GameManager gameManager;
  9. GameManager *gm = &gameManager;
  10. return gm->run();
  11. }

GameManager.h:
C++ Syntax (Toggle Plain Text)
  1. #ifndef GAMEMANAGER_H
  2. #define GAMEMANAGER_H
  3.  
  4. #pragma comment(lib, "opengl32.lib")
  5. #pragma comment(lib, "glu32.lib")
  6.  
  7. #include <windows.h> // Header File For Windows
  8. #include <gl\gl.h> // Header File For The OpenGL32 Library
  9. #include <gl\glu.h> // Header File For The GLu32 Library
  10. #include <gl\glaux.h> // Header File For The Glaux Library
  11.  
  12. class GameManager
  13. {
  14. public:
  15. GameManager();
  16. ~GameManager();
  17. int run();
  18. private:
  19. HDC hDC; // Private GDI Device Context
  20. HGLRC hRC; // Permanent Rendering Context
  21. HWND hWnd; // Holds Our Window Handle
  22. HINSTANCE hInstance; // Holds The Instance Of The Application
  23.  
  24. bool keys[256]; // Array Used For The Keyboard Routine
  25. bool active; // Window Active Flag Set To TRUE By Default
  26. //
  27. bool fullscreen; // Fullscreen Flag Set To Fullscreen Mode By Default
  28.  
  29. GLfloat rtri; // Angle For The Triangle ( NEW )
  30. GLfloat rquad; // Angle For The Quad ( NEW )
  31.  
  32. virtual LRESULT CALLBACK MsgProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
  33. static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
  34. GLvoid ReSizeGLScene(GLsizei width, GLsizei height);
  35. int InitGL(GLvoid);
  36. int DrawGLScene(GLvoid);
  37. GLvoid KillGLWindow(GLvoid);
  38. BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag);
  39.  
  40. };
  41. #endif


And the biggie, GameManger.cpp:
C++ Syntax (Toggle Plain Text)
  1. #include "GameManager.h"
  2.  
  3. // bool keys[256]; // Array Used For The Keyboard Routine
  4. // bool active = true; // Window Active Flag Set To TRUE By Default
  5.  
  6. GameManager::GameManager()
  7. {
  8. active = true; // Window Active Flag Set To TRUE By Default
  9. fullscreen = false; // Fullscreen Flag Set To Fullscreen Mode By Default
  10.  
  11. hDC=NULL;
  12. hRC=NULL;
  13. hWnd=NULL;
  14. }
  15. GameManager::~GameManager()
  16. {
  17.  
  18. }
  19. int GameManager::run()
  20. {
  21. MSG msg; // Windows Message Structure
  22. BOOL done=FALSE; // Bool Variable To Exit Loop
  23.  
  24. fullscreen=FALSE; // Windowed Mode
  25.  
  26. // Create Our OpenGL Window
  27. if (!CreateGLWindow("NeHe's Rotation Tutorial",640,480,16,fullscreen))
  28. {
  29. return 0; // Quit If Window Was Not Created
  30. }
  31.  
  32. while(!done) // Loop That Runs While done=FALSE
  33. {
  34. if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
  35. {
  36. if (msg.message==WM_QUIT) // Have We Received A Quit Message?
  37. {
  38. done=TRUE; // If So done=TRUE
  39. }
  40. else // If Not, Deal With Window Messages
  41. {
  42. TranslateMessage(&msg); // Translate The Message
  43. DispatchMessage(&msg); // Dispatch The Message
  44. }
  45. }
  46. else // If There Are No Messages
  47. {
  48. // Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
  49. if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received?
  50. {
  51. done=TRUE; // ESC or DrawGLScene Signalled A Quit
  52. }
  53. else // Not Time To Quit, Update Screen
  54. {
  55. SwapBuffers(hDC); // Swap Buffers (Double Buffering)
  56. }
  57.  
  58. if (keys[VK_F1]) // Is F1 Being Pressed?
  59. {
  60. keys[VK_F1]=FALSE; // If So Make Key FALSE
  61. KillGLWindow(); // Kill Our Current Window
  62. fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
  63. // Recreate Our OpenGL Window
  64. if (!CreateGLWindow("NeHe's Rotation Tutorial",640,480,16,fullscreen))
  65. {
  66. return 0; // Quit If Window Was Not Created
  67. }
  68. }
  69. }
  70. }
  71.  
  72. // Shutdown
  73. KillGLWindow(); // Kill The Window
  74. return (msg.wParam); // Exit The Program
  75. }
  76.  
  77. GLvoid GameManager::ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
  78. {
  79. if (height==0) // Prevent A Divide By Zero By
  80. {
  81. height=1; // Making Height Equal One
  82. }
  83.  
  84. glViewport(0,0,width,height); // Reset The Current Viewport
  85.  
  86. glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
  87. glLoadIdentity(); // Reset The Projection Matrix
  88.  
  89. // Calculate The Aspect Ratio Of The Window
  90. gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
  91.  
  92. glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
  93. glLoadIdentity(); // Reset The Modelview Matrix
  94. }
  95.  
  96. int GameManager::InitGL(GLvoid) // All Setup For OpenGL Goes Here
  97. {
  98. glShadeModel(GL_SMOOTH); // Enable Smooth Shading
  99. glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
  100. glClearDepth(1.0f); // Depth Buffer Setup
  101. glEnable(GL_DEPTH_TEST); // Enables Depth Testing
  102. glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
  103. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
  104. return TRUE; // Initialization Went OK
  105. }
  106.  
  107. int GameManager::DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
  108. {
  109. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
  110. glLoadIdentity(); // Reset The Current Modelview Matrix
  111. glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
  112. glRotatef(rtri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y axis ( NEW )
  113. glBegin(GL_TRIANGLES); // Start Drawing A Triangle
  114. glColor3f(1.0f,0.0f,0.0f); // Set Top Point Of Triangle To Red
  115. glVertex3f( 0.0f, 1.0f, 0.0f); // First Point Of The Triangle
  116. glColor3f(0.0f,1.0f,0.0f); // Set Left Point Of Triangle To Green
  117. glVertex3f(-1.0f,-1.0f, 0.0f); // Second Point Of The Triangle
  118. glColor3f(0.0f,0.0f,1.0f); // Set Right Point Of Triangle To Blue
  119. glVertex3f( 1.0f,-1.0f, 0.0f); // Third Point Of The Triangle
  120. glEnd(); // Done Drawing The Triangle
  121. glLoadIdentity(); // Reset The Current Modelview Matrix
  122. glTranslatef(1.5f,0.0f,-6.0f); // Move Right 1.5 Units And Into The Screen 6.0
  123. glRotatef(rquad,1.0f,0.0f,0.0f); // Rotate The Quad On The X axis ( NEW )
  124. glColor3f(0.5f,0.5f,1.0f); // Set The Color To Blue One Time Only
  125. glBegin(GL_QUADS); // Draw A Quad
  126. glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
  127. glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right
  128. glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right
  129. glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left
  130. glEnd(); // Done Drawing The Quad
  131. rtri+=0.2f; // Increase The Rotation Variable For The Triangle ( NEW )
  132. rquad-=0.15f; // Decrease The Rotation Variable For The Quad ( NEW )
  133. return TRUE; // Keep Going
  134. }
  135.  
  136. GLvoid GameManager::KillGLWindow(GLvoid) // Properly Kill The Window
  137. {
  138. if (fullscreen) // Are We In Fullscreen Mode?
  139. {
  140. ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop
  141. ShowCursor(TRUE); // Show Mouse Pointer
  142. }
  143.  
  144. if (hRC) // Do We Have A Rendering Context?
  145. {
  146. if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts?
  147. {
  148. MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
  149. }
  150.  
  151. if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC?
  152. {
  153. MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
  154. }
  155. hRC=NULL; // Set RC To NULL
  156. }
  157.  
  158. if (hDC && !ReleaseDC(hWnd,hDC)) // Are We Able To Release The DC
  159. {
  160. MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
  161. hDC=NULL; // Set DC To NULL
  162. }
  163.  
  164. if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window?
  165. {
  166. MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
  167. hWnd=NULL; // Set hWnd To NULL
  168. }
  169.  
  170. if (!UnregisterClass("OpenGL",hInstance)) // Are We Able To Unregister Class
  171. {
  172. MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
  173. hInstance=NULL; // Set hInstance To NULL
  174. }
  175. }
  176.  
  177. /* This Code Creates Our OpenGL Window. Parameters Are: *
  178.  * title - Title To Appear At The Top Of The Window *
  179.  * width - Width Of The GL Window Or Fullscreen Mode *
  180.  * height - Height Of The GL Window Or Fullscreen Mode *
  181.  * bits - Number Of Bits To Use For Color (8/16/24/32) *
  182.  * fullscreenflag - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE) */
  183.  
  184. BOOL GameManager::CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
  185. {
  186. GLuint PixelFormat; // Holds The Results After Searching For A Match
  187. WNDCLASS wc; // Windows Class Structure
  188. DWORD dwExStyle; // Window Extended Style
  189. DWORD dwStyle; // Window Style
  190. RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
  191. WindowRect.left=(long)0; // Set Left Value To 0
  192. WindowRect.right=(long)width; // Set Right Value To Requested Width
  193. WindowRect.top=(long)0; // Set Top Value To 0
  194. WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height
  195.  
  196. fullscreen=fullscreenflag; // Set The Global Fullscreen Flag
  197.  
  198. hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
  199. wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
  200. wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
  201. wc.cbClsExtra = 0; // No Extra Window Data
  202. wc.cbWndExtra = 0; // No Extra Window Data
  203. wc.hInstance = hInstance; // Set The Instance
  204. wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
  205. wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
  206. wc.hbrBackground = NULL; // No Background Required For GL
  207. wc.lpszMenuName = NULL; // We Don't Want A Menu
  208. wc.lpszClassName = "OpenGL"; // Set The Class Name
  209.  
  210. if (!RegisterClass(&wc)) // Attempt To Register The Window Class
  211. {
  212. MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  213. return FALSE; // Return FALSE
  214. }
  215.  
  216. if (fullscreen) // Attempt Fullscreen Mode?
  217. {
  218. DEVMODE dmScreenSettings; // Device Mode
  219. memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
  220. dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
  221. dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
  222. dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
  223. dmScreenSettings.dmBitsPerPel = bits; // Selected Bits Per Pixel
  224. dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
  225.  
  226. // Try To Set Selected Mode And Get Results. NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
  227. if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
  228. {
  229. // If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode.
  230. if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
  231. {
  232. fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE
  233. }
  234. else
  235. {
  236. // Pop Up A Message Box Letting User Know The Program Is Closing.
  237. MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
  238. return FALSE; // Return FALSE
  239. }
  240. }
  241. }
  242.  
  243. if (fullscreen) // Are We Still In Fullscreen Mode?
  244. {
  245. dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
  246. dwStyle=WS_POPUP; // Windows Style
  247. ShowCursor(FALSE); // Hide Mouse Pointer
  248. }
  249. else
  250. {
  251. dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
  252. dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
  253. }
  254.  
  255. AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size
  256.  
  257. // Create The Window
  258. if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
  259. "OpenGL", // Class Name
  260. title, // Window Title
  261. dwStyle | // Defined Window Style
  262. WS_CLIPSIBLINGS | // Required Window Style
  263. WS_CLIPCHILDREN, // Required Window Style
  264. 0, 0, // Window Position
  265. WindowRect.right-WindowRect.left, // Calculate Window Width
  266. WindowRect.bottom-WindowRect.top, // Calculate Window Height
  267. NULL, // No Parent Window
  268. NULL, // No Menu
  269. hInstance, // Instance
  270. NULL))) // Dont Pass Anything To WM_CREATE
  271. {
  272. KillGLWindow(); // Reset The Display
  273. MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  274. return FALSE; // Return FALSE
  275. }
  276.  
  277. static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
  278. {
  279. sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
  280. 1, // Version Number
  281. PFD_DRAW_TO_WINDOW | // Format Must Support Window
  282. PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
  283. PFD_DOUBLEBUFFER, // Must Support Double Buffering
  284. PFD_TYPE_RGBA, // Request An RGBA Format
  285. bits, // Select Our Color Depth
  286. 0, 0, 0, 0, 0, 0, // Color Bits Ignored
  287. 0, // No Alpha Buffer
  288. 0, // Shift Bit Ignored
  289. 0, // No Accumulation Buffer
  290. 0, 0, 0, 0, // Accumulation Bits Ignored
  291. 16, // 16Bit Z-Buffer (Depth Buffer)
  292. 0, // No Stencil Buffer
  293. 0, // No Auxiliary Buffer
  294. PFD_MAIN_PLANE, // Main Drawing Layer
  295. 0, // Reserved
  296. 0, 0, 0 // Layer Masks Ignored
  297. };
  298.  
  299. if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context?
  300. {
  301. KillGLWindow(); // Reset The Display
  302. MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  303. return FALSE; // Return FALSE
  304. }
  305.  
  306. if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
  307. {
  308. KillGLWindow(); // Reset The Display
  309. MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  310. return FALSE; // Return FALSE
  311. }
  312.  
  313. if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format?
  314. {
  315. KillGLWindow(); // Reset The Display
  316. MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  317. return FALSE; // Return FALSE
  318. }
  319.  
  320. if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context?
  321. {
  322. KillGLWindow(); // Reset The Display
  323. MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  324. return FALSE; // Return FALSE
  325. }
  326.  
  327. if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context
  328. {
  329. KillGLWindow(); // Reset The Display
  330. MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  331. return FALSE; // Return FALSE
  332. }
  333.  
  334. SetWindowLongPtr(hWnd, GWLP_USERDATA, (long)this);
  335.  
  336. ShowWindow(hWnd,SW_SHOW); // Show The Window
  337. UpdateWindow(hWnd);
  338. SetForegroundWindow(hWnd); // Slightly Higher Priority
  339. SetFocus(hWnd); // Sets Keyboard Focus To The Window
  340. ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen
  341.  
  342. if (!InitGL()) // Initialize Our Newly Created GL Window
  343. {
  344. KillGLWindow(); // Reset The Display
  345. MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
  346. return FALSE; // Return FALSE
  347. }
  348.  
  349. return TRUE; // Success
  350. }
  351.  
  352. LRESULT CALLBACK GameManager::MsgProc( HWND hWnd, // Handle For This Window
  353. UINT uMsg, // Message For This Window
  354. WPARAM wParam, // Additional Message Information
  355. LPARAM lParam) // Additional Message Information
  356. {
  357. switch (uMsg) // Check For Windows Messages
  358. {
  359. case WM_ACTIVATE: // Watch For Window Activate Message
  360. {
  361. if (!HIWORD(wParam)) // Check Minimization State
  362. {
  363. active=TRUE; // Program Is Active
  364. }
  365. else
  366. {
  367. active=FALSE; // Program Is No Longer Active
  368. }
  369.  
  370. return 1; // Return To The Message Loop
  371. }
  372.  
  373. case WM_SYSCOMMAND: // Intercept System Commands
  374. {
  375. switch (wParam) // Check System Calls
  376. {
  377. case SC_SCREENSAVE: // Screensaver Trying To Start?
  378. case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?
  379. return 1; // Prevent From Happening
  380. }
  381. break; // Exit
  382. }
  383.  
  384. case WM_CLOSE: // Did We Receive A Close Message?
  385. {
  386. PostQuitMessage(0); // Send A Quit Message
  387. return 1; // Jump Back
  388. }
  389.  
  390. case WM_KEYDOWN: // Is A Key Being Held Down?
  391. {
  392. keys[wParam] = TRUE; // If So, Mark It As TRUE
  393. return 1; // Jump Back
  394. }
  395.  
  396. case WM_KEYUP: // Has A Key Been Released?
  397. {
  398. keys[wParam] = FALSE; // If So, Mark It As FALSE
  399. return 1; // Jump Back
  400. }
  401.  
  402. case WM_SIZE: // Resize The OpenGL Window
  403. {
  404. // ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height
  405. return 1; // Jump Back
  406. }
  407. }
  408.  
  409. // Pass All Unhandled Messages To DefWindowProc
  410. return DefWindowProc(hWnd,uMsg,wParam,lParam);
  411. }
  412.  
  413.  
  414. LRESULT CALLBACK GameManager::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
  415. // Recover the pointer to our class, don't forget to type cast it back
  416.  
  417. GameManager* winptr = (GameManager*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
  418. // Check if the pointer is NULL and call the Default WndProc
  419.  
  420. if (winptr == NULL)
  421. {
  422. return DefWindowProc(hwnd, message, wParam, lParam);
  423. } else
  424. {
  425. // Call the Message Handler for my class (MsgProc in my case)
  426. return winptr->MsgProc(hwnd, message, wParam, lParam);
  427. }
  428. }
Last edited by dalcocer; Nov 4th, 2009 at 9:32 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
dalcocer is offline Offline
3 posts
since Nov 2009
Mar 21st, 2010
0
Re: Help with WndProc Mapping
Looking for something unrelated and found your unresolved issue. Replying in case someone else bumps into it, or you still have the issue from many months ago. Essentially, the problem is where you are declaring your variables.
In the GameManager.h, you are declaring them inside of the private member of the class GameManager.
In the GameManager.cpp you are declaring them outside of the GameManager class in a Global scope.

In order to fix you problem, you must consider how you want these variables implemented. Should they be inside of the class, or should they be Global variables as you have them now?

If you are planning to continue using them as globals, declare them on line 11 in your GameManager.h
C++ Syntax (Toggle Plain Text)
  1.  
  2. include <windows.h> // Header File For Windows
  3. include <gl\gl.h> // Header File For The OpenGL32 Library
  4. include <gl\glu.h> // Header File For The GLu32 Library
  5. include <gl\glaux.h> // Header File For The Glaux Library
  6.  
  7. bool keys[256]; // Array Used For The Keyboard Routine
  8. bool active; // Window Active Flag Set To TRUE By Default
  9.  
  10. class GameManager
  11. {

However, this is not the proper solution. What you really need to do, is to create 'helper' functions inside of your GameManager private class, then use your GameManager handle to call the helper function, to change/retrieve the variables whenever you need them. ie:
C++ Syntax (Toggle Plain Text)
  1. //in your .h
  2. private:
  3. void switch_active();
  4. bool get_active();
  5. void flip_key(int index);
  6. bool get_key(int index);
  7. //in your .cpp
  8. void GameManager::switch_active(){ //Change the private
  9. active = !active;
  10. }
  11.  
  12. bool GameManager::get_active(){
  13. return active;
  14. }
  15. void GameManager::flip_key(int index){
  16. key[index] = !key[index];
  17. }
  18. bool GameManager::get_key(int index){
  19. return key[index];
  20. }
  21.  
  22. bool temp_key = get_key(25);
As for a long post, yes, way to long. Only need the class GameManager in your .h and the place where you are declaring it in your .cpp and where you are using it in your code. No fun when the scroll button is 3/8's of an inch
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kwiering is offline Offline
5 posts
since Mar 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Need Help With Centering Triangle
Next Thread in C++ Forum Timeline: Round Robin algorithm and memory leak





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC