I'm trying to move the WinProc from the winmain.cpp file into another cpp file(winproc.cpp) because it has become rather large. It didn't work so I am trying to move it with just the skeleton win32 app but I'm getting all sorts of syntax errors with that too. The basic windows program compiles fine when all the parts are in the same file(winmain.cpp), the problems occur(about 30 errors and warnings which weren't there before) when I start splitting it up into these parts. I'm using Visual Studio .NET and this is my first ever problem that I can't solve myself. If you need more information don't hesitate to ask.
The files are;
winmain.cpp
Code:
// Includes
#include <windows.h>; // The Windows stuff
#include <stdio.h>; // Some other useful stuff
#include "winproc.h";
// Defines
#define WIN_32_LEAN_AND_MEAN // Cut the crap
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
// hInstance - handle to the instance of the window
// hPrevInstance - Previous instance of the application
// szCmdLine - Holds information about the command line calling procedure
// iCmdShow - Holds the state of the window
{
HWND hwnd; // The main window handle
MSG msg; // The message
WNDCLASSEX wndclass; // The window class
wndclass.cbSize = sizeof(wndclass); // required information
wndclass.style = CS_HREDRAW | CS_VREDRAW; // The styles of the window
wndclass.lpfnWndProc = WndProc; // Pointer to the WinProc
wndclass.cbClsExtra = 0; // Useless crap
wndclass.cbWndExtra = 0; // Useless crap
wndclass.hInstance = hInstance; // Handle to the instance of the window passed by WinMain
wndclass.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load the application icon
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); // Load the cursor
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); // Set background white
wndclass.lpszMenuName = NULL; // Menu stuff
wndclass.lpszClassName = "Window Class"; // The name of the class
wndclass.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // Loads the small icon at the top left of the window
RegisterClassEx(&wndclass); // Register the class
hwnd = CreateWindow("Window Class", // The name of the class again
"Win32App", // The title of the window
WS_OVERLAPPEDWINDOW, // Window style
CW_USEDEFAULT, // Initial x position - top left corner
CW_USEDEFAULT, // Initial y position - top left corner
CW_USEDEFAULT, // Initial x size
CW_USEDEFAULT, // Initial y size
NULL, // The parent window handle
NULL, // The menu handle
hInstance, // Handle to the previous instance
NULL); // Space for a struct - not required
ShowWindow(hwnd, iCmdShow); // This shows the window
UpdateWindow(hwnd); // Adds a WM_PAINT message to the message queue
while(1)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
// &msg - address of msg, GetMessage() will fill in the msg structure
// PM_REMOVE - A flag to tell windows to remove the message once it has been passed
{
if(msg.message == WM_QUIT)
break;
TranslateMessage(&msg); // Translates the messages into something understandable
DispatchMessage(&msg); // Dispatches the message to the WinProc
}
else
{
}
}
UnregisterClass("Window Class", hInstance); // Free up the memory used to register the class
return msg.wParam; // Return wParam of the message
}
winproc.h
Code:
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // WndProc prototype
winproc.cpp
Code:
#include "winproc.h"
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
break;
case WM_SIZE:
break;
case WM_PAINT:
break;
case WM_DESTROY:
PostQuitMessage(0); // Send the application the WM_QUIT message
break;
}
return DefWindowProc(hwnd, msg, wParam, lParam); // Sort out any unhandled messages
}
Thanks in advance!