ok. so i'm having trouble with the Windows API. i'm just learing how to use it, so i don't know much about it.
anyways, i just wanted to create a window and have it displayed then catch the exit message and close, but VC Compiler is throwing errors.
1>c:\users\furrix\documents\visual studio 2008\projects\test\test\test.cpp(9) : error C2144: syntax error : 'int' should be preceded by ';'
1>c:\users\furrix\documents\visual studio 2008\projects\test\test\test.cpp(24) : error C2065: 'WindowProc' : undeclared identifier
1>c:\users\furrix\documents\visual studio 2008\projects\test\test\test.cpp(32) : error C2664: 'CreateWindowExW' : cannot convert parameter 10 from 'HINSTANCE' to 'HMENU'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
could someone please help me with this? i'm a bit confused.
code:
#include <windows.h>
#include <windowsx.h>
//WinProc Function prototype
LRESULT CALLBACK WinProc (HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
//entry point for any windows program
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
//window handle
HWND hWnd;
//holds informaintion for windows class
WNDCLASSEX wc;
//clear windows were using
ZeroMemory(&wc, sizeof(WNDCLASSEX));
//WC structure data
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = L"WindowsClass1";
//generate the window
hWnd = CreateWindowEx(NULL, L"WindowsClass1", L"Windows Form Frame 1", WS_OVERLAPPEDWINDOW, 300, 300, 500, 400, NULL, hInstance, NULL, NULL);
//Show generated Window
ShowWindow(hWnd, nCmdShow);
MSG msg;
// wait for the next message in the queue, store the result in 'msg'
while(GetMessage(&msg, NULL, 0, 0))
{
// translate keystroke messages into the right format
TranslateMessage(&msg);
// send the message to the WindowProc function
DispatchMessage(&msg);
}
// return this part of the WM_QUIT message to Windows
return msg.wParam;
}
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
// sort through and find what code to run for the message given
switch(message)
{
// this message is read when the window is closed
case WM_DESTROY:
{
// close the application entirely
PostQuitMessage(0);
return 0;
} break;
}
// Handle any messages the switch statement didn't
return DefWindowProc (hWnd, message, wParam, lParam);
}