Salutare la toata lumea si "Craciun Fericit!"
Am o problema cu un program luat de pe "http://www.directxtutorial.com/Tutorial9/A-Win32/dx9A3.aspx" in care te invata sa faci o fereastra in windows in the good old fashioned way.
Problema e ca atunci cand il iau pur si simplu cu "copy/paste" de pe site merge fara probleme dar urmatoarea varianta care e copiata "manual" de mine cand incerc sa o compilez imi da eroare C2084
1>c:beginning visual c++ 2005real programstesttestmain.cpp(105) : error C2084: function 'int WinMain(HINSTANCE,HINSTANCE,LPSTR,int)' already has a body
Cod sursă:
#include
#include
// #define XPOS 300
// #define YPOS 300
// #define WIDTH 500
// #define HEIGHT 400
//the Windows function prototype
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd )
{
HWND hWnd; //the handle for the window, filled by a function
WNDCLASSEX wc; //structure that holds information for the window class
ZeroMemory(&wc, sizeof(WNDCLASSEX));
//fill in the structure
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) COLOR_WINDOW;
wc.lpszClassName = L"WindowClass";
//register the window class
RegisterClassEx(&wc);
//create the window and use the result as the handle
hWnd = CreateWindow(NULL,
L"WindowClass", //name of the class of the window
WS_OVERLAPPEDWINDOW, //window style
/*XPOS*/300, //x pos of the window
/*YPOS*/300, //y pos of the window
/*WIDTH*/500, //width of the window
/*HEIGHT*/400, //height of the window
NULL, //no parent window
NULL, //we arent't using menus
hInstance, //application handle
NULL); //used with multiple windows
//display the window on the screen
ShowWindow(hWnd, nShowCmd);
//enter the main loop
MSG msg; //this structure contains window messages
//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;
}
//this is the main message handler for the program
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);
}
// include the basic windows header file
#include
#include
// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam);
// the entry point for any Windows program
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// the handle for the window, filled by a function
HWND hWnd;
// this struct holds information for the window class
WNDCLASSEX wc;
// clear out the window class for use
ZeroMemory(&wc, sizeof(WNDCLASSEX));
// fill in the struct with the needed information
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = L"WindowClass1";
// register the window class
RegisterClassEx(&wc);
// create the window and use the result as the handle
hWnd = CreateWindowEx(NULL,
L"WindowClass1", // name of the window class
L"Our First Windowed Program", // title of the window
WS_OVERLAPPEDWINDOW, // window style
300, // x-position of the window
300, // y-position of the window
500, // width of the window
400, // height of the window
NULL, // we have no parent window, NULL
NULL, // we aren't using menus, NULL
hInstance, // application handle
NULL); // used with multiple windows, NULL
// display the window on the screen
ShowWindow(hWnd, nCmdShow);
// enter the main loop:
// this struct holds Windows event messages
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;
}
// this is the main message handler for the program
LRESULT CALLBACK WindowProcEx(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);
}
Am verificat de mai multe ori si e exact acelasi lucru. Pur si simplu nu inteleg ce are.