I am learning how to program through the windows.h library and was following a tutorial. After I copied the code to just create a window I got a lot of errors
here is the code
#include <windows.h>
#define WNDCLASSNAME "wndclass"
//the needed global variables
using namespace std;
HWND handleWin;
HDC hdc;
bool quit = FALSE;
//the main function
WINAPI WinMain (HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int nshowcmd)
{
//set up the window class
MSG msg;
WINCLASSEX ex;
ex.cbSize = sizeof(WNDCLASSEX);
ex.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
ex.lpfnWinProc = WinProc;
ex.cbClsExtra = 0;
ex.cbWndExtra = 0;
ex.hInstance = hinstance;
ex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
ex.hCursor = LoadCursor(NULL, IDC_ARROW);
ex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
ex.lpszMenuName = NULL;
ex.lpszClassName = WNDCLASSNAME;
ex.IconSm = NULL;
RegisterClassEx(&ex);
//create the window
hwnd = CreateWindowEx(NULL,
WNDCLASSNAME,
"Window",
WS_OVERLAPPEDWINDOW,
0, 0,
300, 300,
NULL, NULL,
hinstance,
NULL);
ShowWindow(handleWin, SM_SHOW);
UpdateWindow(handleWin);
//the message loop
while(!quit){
if (PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE)){
if (msg.message == WM_QUIT){
quit = TRUE;
TranslateMessge(&msg);
DispatchMessage(&msg);
}
}
}
return msg.lParam;
}
here are the errors I get
C:\C++\Graph\testers\main.c|4|error: syntax error before "namespace"|
C:\C++\Graph\testers\main.c|4|warning: type defaults to `int' in declaration of `std'|
C:\C++\Graph\testers\main.c|4|warning: data definition has no type or storage class|
C:\C++\Graph\testers\main.c|7|error: syntax error before "quit"|
C:\C++\Graph\testers\main.c|7|warning: type defaults to `int' in declaration of `quit'|
C:\C++\Graph\testers\main.c|7|warning: data definition has no type or storage class|
C:\C++\Graph\testers\main.c|14|warning: return type defaults to `int'|
C:\C++\Graph\testers\main.c||In function `WinMain':|
C:\C++\Graph\testers\main.c|17|error: `WINCLASSEX' undeclared (first use in this function)|
C:\C++\Graph\testers\main.c|17|error: (Each undeclared identifier is reported only once|
C:\C++\Graph\testers\main.c|17|error: for each function it appears in.)|
C:\C++\Graph\testers\main.c|17|error: syntax error before "ex"|
C:\C++\Graph\testers\main.c|18|error: `ex' undeclared (first use in this function)|
C:\C++\Graph\testers\main.c|20|error: `WinProc' undeclared (first use in this function)|
C:\C++\Graph\testers\main.c|34|error: `hwnd' undeclared (first use in this function)|
C:\C++\Graph\testers\main.c|42|warning: passing arg 1 of `CreateWindowExA' makes integer from pointer without a cast|
C:\C++\Graph\testers\main.c|43|error: `SM_SHOW' undeclared (first use in this function)|
C:\C++\Graph\testers\main.c|48|warning: passing arg 3 of `PeekMessageA' makes integer from pointer without a cast|
C:\C++\Graph\testers\main.c|48|warning: passing arg 4 of `PeekMessageA' makes integer from pointer without a cast|
C:\C++\Graph\testers\main.c|51|warning: implicit declaration of function `TranslateMessge'|
||=== Build finished: 10 errors, 9 warnings ===|
I went over the code a couple of times to make sure I copied everything right and it seems that I did I don't know what is wrong.