Windows Troubles

Started by
3 comments, last by grimr3ap3r 22 years, 4 months ago
I usually just copy and paste Windows from the book, just to speed things up. I decided to create everything from scratch this time round, including the Windows code. For some odd reason, I get this error everytime I compile --------------------Configuration: TicTacToe - Win32 Debug-------------------- Compiling... Main.cpp C:\Windows\Desktop\c++files\TicTacToe\Main.cpp(138) : warning C4715: 'WinMain' : not all control paths return a value Linking... TicTacToe.exe - 0 error(s), 1 warning(s) The code isn't overly long, so I'll post it here: // INCLUDES #define WIN32_LEAN_AND_MEAN #include #include #include #include #include // DEFINES #define WINDOW_CLASS_NAME "WINCLASS1" // GLOBALS HWND main_window_handle = NULL; // WINDOWS FUNCTIONS LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { PAINTSTRUCT ps; HDC hdc; switch(msg) { case WM_CREATE: { return(0); } break; case WM_PAINT: { hdc = BeginPaint(hwnd, &ps); EndPaint(hwnd, &ps); return(0); } break; case WM_DESTROY: { PostQuitMessage(0); return(0); } break; default:break; } // end switch // process any messages I didn't take care of return (DefWindowProc(hwnd, msg, wparam, lparam)); } // end WinProc // WINMAIN ///////////////////////////// int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hprevinstance, LPSTR lpcmdline, int ncmdshow) { WNDCLASS winclass; HWND hwnd; MSG msg; winclass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; winclass.lpfnWndProc = WindowProc; winclass.cbClsExtra = 0; winclass.cbWndExtra = 0; winclass.hInstance = hinstance; winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION); winclass.hCursor = LoadCursor(NULL, IDC_ARROW); winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); winclass.lpszMenuName = NULL; winclass.lpszClassName = WINDOW_CLASS_NAME; if (!RegisterClass(&winclass)) { return (0); } if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class "Window", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0,0, 640,480, NULL, NULL, hinstance, NULL))) { return(0); } // save the window handle to a global main_window_handle = hwnd; // main loop while(1) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } return(msg.wParam); } } Anyone know why I get this error, and more importantly, how do I fix it ?? Edited by - grimr3ap3r on December 9, 2001 8:39:44 PM
Advertisement
That''s not an error, that''s a warning...

Anyhow, I think that because in your main loop you don''t really loop, you go through it once and return, but that''s not the proper way. move "return(msg.wParam);" out of the while(1) loop.


------------
- outRider -
Try moving return(msg.wParam); ouside of your while loop. You want your WinMain to look something like this:

    int WINAPI WinMain (HINSTANCE hInstance,                    HINSTANCE hPrevInstance,                    PSTR szCmdLine,                    int iCmdShow){   // Windows message structure   MSG msg;   // Initialize window and whatever here...   // Enter the message loop   while (GetMessage (&msg, NULL, 0, 0))   {      TranslateMessage (&msg);      DispatchMessage (&msg);   }   // Exit the application   return msg.wParam;}    


Edit: Heh, outRider beat me to it . Anyway, you get the idea...

Game: The Adventure (tm).
-------------------------


Edited by - RabidOcelot on December 9, 2001 9:04:11 PM
I''m glad to see that you decided to start typing the code out instead of cutting and pasting it. It becomes a bad habit which really hinders learning when the code becomes mind bogglingly complex.
Cheers,
-Jesse
EXCELLENT GUYS!!!!!

thanks for the help, I was really stumped as to why. It all works fine and dandy now .

RabidOcelot: Thanks for the link to your game, I forgot the forums post, I love that game so much .



Thanks again!

This topic is closed to new replies.

Advertisement