Home » Community » Forums » Article Feedback » Game Programming Genesis Part I : Beginning Windows Programming
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Game Programming Genesis Part I : Beginning Windows Programming
Post New Topic  Post Reply 
Comments for the article Game Programming Genesis Part I : Beginning Windows Programming

 User Rating: 2088   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

when i compile i get

Linking...
LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
Debug/Starfield.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

how do i fix it???

 User Rating: 1015    Report this Post to a Moderator | Link

I get exactly the same error.

There is probably something wrong with the settings, but when I try to figure it out and change some of them, I get even more errors

Please tell me how to fix this.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I think you have to create a Win32 application project, not a console app.

 User Rating: 1015    Report this Post to a Moderator | Link

Did you ever read your documentation? You know, MSDN (especially where it says Visual C++ Documentation )? Or the QuickStart card that comes with MSVC (I assume you're using MSVC)?

No? Well, go do so. It'll answer a lot of your questions.

(btw, the answer to your problem is to explicitly create a "Windows Application" project and add your source files to it. Letting the compiler assign a "default workspace" _always_ results in a Win32 Console App.)

 User Rating: 2027   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

Hey, thanks, it worked!
I'm only starting to learn programming, so I don't know all those things. I searched for that error in Help, and it found something which I did not understand anyway

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I'm really new to C++ and am used to the ease of Visual Basic. So, of course, I have no idea at all what is wrong with my program, and I get 8 errors! I would really appreciated if you would look over my code and the errors and see if you know what's up.

Code:

#include
#include
//These two are almost always included in Windows programming#include
#include
#define WIN32_LEAN_AND_MEAN


typedef struct _WNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HANDLE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX;

HWND CreateWindowEx(
DWORD dwExStyle, // extended window style
LPCTSTR lpClassName, // pointer to registered class name
LPCTSTR lpWindowName, // pointer to window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or owner window
HMENU hMenu, // handle to menu, or child-window identifier
HINSTANCE hInstance, // handle to application instance
LPVOID lpParam // pointer to window-creation data
);

LRESULT CALLBACK MsgHandler(
HWND hwnd, // window handle
UINT msg, // the message identifier
WPARAM wparam, // message parameters
LPARAM lparam // more message parameters
);

BOOL PeekMessage(
LPMSG lpMsg, // pointer to structure for message
HWND hWnd, // handle to window
UINT wMsgFilterMin, // first message
UINT wMsgFilterMax, // last message
UINT wRemoveMsg // removal flags
);
BOOL PostMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to post
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

LRESULT SendMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to post
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);


BOOL TranslateMessage(CONST MSG *lpmsg);
LONG DispatchMessage(CONST MSG *lpmsg);

//All Windows program start with the WinMain function.
int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)

{



HWND hwnd;
if (!(hwnd = CreateWindowEx(NULL, // extended style, not needed
"Sample Class", // class identifier
"Sample Window", // window title
WS_POPUP | WS_VISIBLE, // parameters
0, 0, 320, 240, // initial position, size
NULL, // handle to parent (the desktop)
NULL, // handle to menu (none)
hinstance, // application instance handle
NULL))) // who needs it?
return(0);

}

LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
return(DefWindowProc(hwnd, msg, wparam, lparam));

}

Errors:
c:\ned's turkey farm\application\applicationsource.cpp(21) : error C2371: 'WNDCLASSEX' : redefinition; different basic types
c:\program files\microsoft visual studio\vc98\include\winuser.h(1177) : see declaration of 'WNDCLASSEX'
c:\ned's turkey farm\application\applicationsource.cpp(36) : error C2373: 'CreateWindowExA' : redefinition; different type modifiers
c:\program files\microsoft visual studio\vc98\include\winuser.h(2993) : see declaration of 'CreateWindowExA'
c:\ned's turkey farm\application\applicationsource.cpp(51) : error C2373: 'PeekMessageA' : redefinition; different type modifiers
c:\program files\microsoft visual studio\vc98\include\winuser.h(2388) : see declaration of 'PeekMessageA'
c:\ned's turkey farm\application\applicationsource.cpp(57) : error C2373: 'PostMessageA' : redefinition; different type modifiers
c:\program files\microsoft visual studio\vc98\include\winuser.h(2683) : see declaration of 'PostMessageA'
c:\ned's turkey farm\application\applicationsource.cpp(64) : error C2373: 'SendMessageA' : redefinition; different type modifiers
c:\program files\microsoft visual studio\vc98\include\winuser.h(2511) : see declaration of 'SendMessageA'
c:\ned's turkey farm\application\applicationsource.cpp(67) : error C2373: 'TranslateMessage' : redefinition; different type modifiers
c:\program files\microsoft visual studio\vc98\include\winuser.h(2359) : see declaration of 'TranslateMessage'
c:\ned's turkey farm\application\applicationsource.cpp(68) : error C2373: 'DispatchMessageA' : redefinition; different type modifiers
c:\program files\microsoft visual studio\vc98\include\winuser.h(2365) : see declaration of 'DispatchMessageA'
c:\ned's turkey farm\application\applicationsource.cpp(87) : error C2440: '=' : cannot convert from 'struct HWND__ *(__stdcall *)(unsigned long,const char *,const char *,unsigned long,int,int,int,int,struct HWND__ *,struct HMENU__ *,struct HINSTANCE
__ *,void *)' to 'struct HWND__ *'
There is no context in which this conversion is possible

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

typedef struct _WNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HANDLE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX;

HWND CreateWindowEx(
DWORD dwExStyle, // extended window style
LPCTSTR lpClassName, // pointer to registered class name
LPCTSTR lpWindowName, // pointer to window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or owner window
HMENU hMenu, // handle to menu, or child-window identifier
HINSTANCE hInstance, // handle to application instance
LPVOID lpParam // pointer to window-creation data
);

LRESULT CALLBACK MsgHandler(
HWND hwnd, // window handle
UINT msg, // the message identifier
WPARAM wparam, // message parameters
LPARAM lparam // more message parameters
);

BOOL PeekMessage(
LPMSG lpMsg, // pointer to structure for message
HWND hWnd, // handle to window
UINT wMsgFilterMin, // first message
UINT wMsgFilterMax, // last message
UINT wRemoveMsg // removal flags
);
BOOL PostMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to post
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

LRESULT SendMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to post
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);


BOOL TranslateMessage(CONST MSG *lpmsg);
LONG DispatchMessage(CONST MSG *lpmsg);






Do you include these in your source file? If so, there is no need. Take them out and see if it works.


 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Can you help me?
LRESULT CALLBACK MsgHandler(HWND hwnd, UNIT msg, WPARAM w, LPARAM l);
Dev-C++ 's compiler gives me 2 errors with this line
1) type specifier omitted for parameter
2) parse error before ','

here's the entire program
#include <windows.h>
#include <windowsx.h>
#define WIN32_LEAN_AND_MEAN


LRESULT CALLBACK MsgHandler(HWND hwnd, UNIT msg, WPARAM w, LPARAM l);

int WINAPI
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
WNDCLASSEX wc;

wc.cbSize = sizeof(WNDCLASSEX); // always use this!
wc.style = CS_DBLCLKS | CS_OWNDC |
CS_HREDRAW | CS_VREDRAW; // standard settings
wc.lpfnWndProc = MsgHandler; // we need to write this!
wc.cbClsExtra = 0; // extra class info, not used
wc.cbWndExtra = 0; // extra window info, not used
wc.hInstance = hInst; // parameter passed to WinMain()
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Windows logo
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // standard cursor
wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // a simple black brush
wc.lpszMenuName = NULL; // no menu
wc.lpszClassName = "My First Windows Pgrm"; // class name
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO); // Windows logo again
RegisterClassEx(&wc);
HWND hwnd;
if(!(hwnd = CreateWindowEx(0, "My First Windows Pgrm","hello",WS_OVERLAPPEDWINDOW,0,0,320,240,NULL,NULL,hInst,NULL)));
MSG msg;
if(PeekMessage(&msg,hwnd,0,0,PM_REMOVE))
{ TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}


LRESULT CALLBACK MsgHandler(HWND hwnd, UNIT msg, WPARAM w, LPARAM l)
{
/*WM_ACTIVATE A new window is receiving the focus.
WM_CLOSE A window is being closed.
WM_COMMAND A menu option has been selected.
WM_CREATE A window has been created.
WM_LBUTTONDBLCLK Left mouse button has been double-clicked.
WM_LBUTTONDOWN Left mouse button has been pressed.
WM_MOUSEMOVE The mouse has been moved.
WM_MOVE A window has been moved.
WM_PAINT Part of a window needs to be repainted.
WM_RBUTTONDBLCLK Right mouse button has been double-clicked.
WM_RBUTTONDOWN Right mouse button has been pressed.
WM_SIZE A window has been resized.
WM_USER Use this for whatever you want.


*/
return DefWindowProc(hwnd,msg,w,l);
}

 User Rating: 1015    Report this Post to a Moderator | Link

First, defining WIN32_LEAN_AND_MEAN after including windows.h and windowsx.h is useless. Move it before.

Second, you don't quite have a message pump. You need to continuously process messages - usually with a while loop:
while( bRunning )
{
  if( PeekMessage( &msg, hwnd, 0, 0, PM_REMOVE ) )
  {
    TranslateMessage( &msg );
    DispatchMessage( &msg );
  }
} 


Other than that I really can't point to any critical errors. Perhaps your development environment isn't properly set up?

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions | Internet Acronyms ]
Thanks to Kylotan for the idea!


 User Rating: 2027   |  Rate This User  Send Private MessageView ProfileView Journal Report this Post to a Moderator | Link

In reply to the anon poster:

LRESULT CALLBACK MsgHandler(HWND hwnd, UNIT msg, WPARAM w, LPARAM l);

shouldn't this be:

LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM w, LPARAM l);

???

OK I've got a 3 errors with my code, they are:

error C2664: 'RegisterClassA' : cannot convert parameter 1 from 'struct _WNDCLASSEX *' to 'const struct tagWNDCLASSA *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

error C2373: 'CreateWindowExA' : redefinition; different type modifiers: see declaration of 'CreateWindowExA'

error C2065: 'msg' : undeclared identifier
Error executing cl.exe.


Can anyone see where I'm going wrong? I'm completely lost in win32 !! :'(

thanks in advance for any help/advice etc,

CaptainChainsaw


Here is my complete program:

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <windowsx.h>


typedef struct _WNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HANDLE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX;



LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
return (DefWindowProc(hwnd, msg, wparam, lparam));
}

//BOOL PeekMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg);
//BOOL TranslateMessage(CONST MSG *lpMsg);
//BOOL DispatchMessage(CONST MSG *lpMsg);


int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{

WNDCLASSEX sampleClass;


sampleClass.cbSize = sizeof(WNDCLASSEX);
sampleClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
sampleClass.lpfnWndProc = MsgHandler;
sampleClass.cbClsExtra = 0;
sampleClass.cbWndExtra = 0;
sampleClass.hInstance = hinstance;
sampleClass.hIcon = LoadIcon(NULL,IDI_WINLOGO);
sampleClass.hCursor = LoadCursor(NULL, IDC_ARROW);
sampleClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
sampleClass.lpszMenuName = NULL;
sampleClass.lpszClassName = "Sample Class";
sampleClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

RegisterClass(&sampleClass);


HWND CreateWindowEx(DWORD dwExStyle, LPCTSTR lpClassName, LPCTSTR lpWindowName, DWORD dwStyle
, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu,
HINSTANCE hInstance, LPVOID lpParam);

HWND hwnd;

if(!(hwnd = CreateWindowEx(NULL, "Sample Class", "Sample Window", WS_POPUP | WS_VISIBLE,
0, 0, 400, 400, 0, 0, hinstance, NULL)))

if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);

return 0;
}
}

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I Have no idea about windows programming but would like to learn. Can someone please help me I tried putting the lessons together for Beginning Windows Programming but am getting a lot of errors.

My code so far is as follows:

#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <windowsx.h>
#include <stdio.h>
#include <conio.h>

typedef struct _WNDCLASSEX {
UINT cbSize;
UINT style;
WNDPROC lpfnWndProc;
int cbClsExtra;
int cbWndExtra;
HANDLE hInstance;
HICON hIcon;
HCURSOR hCursor;
HBRUSH hbrBackground;
LPCTSTR lpszMenuName;
LPCTSTR lpszClassName;
HICON hIconSm;
} WNDCLASSEX;

LRESULT CALLBACK MsgHandler(
HWND hwnd, // window handle
UINT msg, // the message identifier
WPARAM wparam, // message parameters
LPARAM lparam // more message parameters
);

BOOL PeekMessage(
LPMSG lpMsg, // pointer to structure for message
HWND hWnd, // handle to window
UINT wMsgFilterMin, // first message
UINT wMsgFilterMax, // last message
UINT wRemoveMsg // removal flags
);
BOOL PostMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to post
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

LRESULT SendMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to post
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);

HWND CreateWindowEx(
DWORD dwExStyle, // extended window style
LPCTSTR lpClassName, // pointer to registered class name
LPCTSTR lpWindowName, // pointer to window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or owner window
HMENU hMenu, // handle to menu, or child-window identifier
HINSTANCE hInstance, // handle to application instance
LPVOID lpParam // pointer to window-creation data
);


BOOL TranslateMessage(CONST MSG *lpmsg);
LONG DispatchMessage(CONST MSG *lpmsg);

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX sampleClass;

sampleClass.cbSize = sizeof(WNDCLASSEX);
sampleClass.style = CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
sampleClass.lpfnWndProc = MsgHandler;
sampleClass.cbClsExtra = 0;
sampleClass.cbWndExtra = 0;
sampleClass.hInstance = hinstance;
sampleClass.hIcon = LoadIcon(NULL,IDI_WINLOGO);
sampleClass.hCursor = LoadCursor(NULL, IDC_ARROW);
sampleClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
sampleClass.lpszMenuName = NULL;
sampleClass.lpszClassName = "Sample Class";
sampleClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

RegisterClass(&sampleClass);

HWND hwnd;
if (!(hwnd = CreateWindowEx(NULL, // extended style, not needed
"Sample Class", // class identifier
"Sample Window", // window title
WS_POPUP | WS_VISIBLE, // parameters
0, 0, 320, 240, // initial position, size
NULL, // handle to parent (the desktop)
NULL, // handle to menu (none)
hinstance, // application instance handle
NULL))) // who needs it?
{
return(0);
}

return (0);
}//End WinMain()


---------ERRORS:::::


c:\C_Sharp_Solutions\RpgGame\Shinku.cpp(21): error C2371: 'WNDCLASSEX' : redefinition; different basic types
c:\C_Sharp_Solutions\RpgGame\Shinku.cpp(64): error C2373: 'CreateWindowExA' : redefinition; different type modifiers
c:\C_Sharp_Solutions\RpgGame\Shinku.cpp(68): error C2373: 'DispatchMessageA' : redefinition; different type modifiers
c:\C_Sharp_Solutions\RpgGame\Shinku.cpp(36): error C2373: 'PeekMessageA' : redefinition; different type modifiers
c:\C_Sharp_Solutions\RpgGame\Shinku.cpp(42): error C2373: 'PostMessageA' : redefinition; different type modifiers
c:\C_Sharp_Solutions\RpgGame\Shinku.cpp(49): error C2373: 'SendMessageA' : redefinition; different type modifiers
c:\C_Sharp_Solutions\RpgGame\Shinku.cpp(67): error C2373: 'TranslateMessage' : redefinition; different type modifiers
c:\C_Sharp_Solutions\RpgGame\Shinku.cpp(99): error C2440: '=' : cannot convert from 'HWND (__stdcall *)(DWORD,LPCSTR,LPCSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)' to 'HWND'
c:\C_Sharp_Solutions\RpgGame\Shinku.cpp(99): error C2440: '=' : cannot convert from 'HWND (__stdcall *)(DWORD,LPCSTR,LPCSTR,DWORD,int,int,int,int,HWND,HMENU,HINSTANCE,LPVOID)' to 'HWND'
c:\C_Sharp_Solutions\RpgGame\Shinku.cpp(88): error C2664: 'RegisterClassA' : cannot convert parameter 1 from 'WNDCLASSEX *__w64 ' to 'const WNDCLASSA *'


 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Why isn't there any source file to download???
It's our first window, right?

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

HERE IS WORKING SOURCE!
(i made a small alteration got rid of the if statement)

#define WIN32_LEAN_AND_MEAN
//Windows Headers
#include <windows.h>
#include <windowsx.h>

//I/O Headers
#include <stdio.h>
#include <conio.h>



LRESULT CALLBACK MsgHandler(HWND hwnd, //Window Handle
UINT msg, //the message identifier
WPARAM wparam, //message parameters
LPARAM lparam //more message parameters
);


int xPos, yPos, xSize, ySize;

int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)

{

MSG msg;
WNDCLASSEX gameWin; //declared structure variable

gameWin.cbSize = sizeof(WNDCLASSEX);
gameWin.style = CS_DBLCLKS | CS_OWNDC | //standard settings
CS_HREDRAW | CS_VREDRAW;
gameWin.lpfnWndProc = MsgHandler;
gameWin.cbClsExtra = 0; //extra class stuff not needed
gameWin.cbWndExtra = 0; //extra window stuff not needed
gameWin.hInstance = hinstance; //param passed to WinMain
gameWin.hIcon = LoadIcon(NULL, IDI_WINLOGO); //windows logo icon
gameWin.hCursor = LoadCursor(NULL, IDC_ARROW); //standard cursor
gameWin.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); // simple black brush
gameWin.lpszMenuName =NULL; //no menu
gameWin.lpszClassName = "gameWin Class"; //class name
gameWin.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

RegisterClassEx(&gameWin);

HWND hwnd;
bool b1= true;
int i2=0;


hwnd =CreateWindowEx(NULL, //extended style, not needed
"gameWin Class", //class identifier
"Game Window", //window title
WS_POPUP | WS_VISIBLE, // params
0,0, 640, 480, //initial position and size
NULL, //Handle to parent
NULL, //Handle to menu
hinstance, //application instance handle
NULL); // who needs it?


while (GetMessage( &msg, NULL, 0, 0))
{

TranslateMessage(&msg);
DispatchMessage(&msg);

}


return(0);

}


LRESULT CALLBACK MsgHandler(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (msg)
{
case WM_COMMAND:
wmId = LOWORD(wparam);
wmEvent = HIWORD(wparam);
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
RECT rt;
GetClientRect(hwnd, &rt);
EndPaint(hwnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return(DefWindowProc(hwnd, msg, wparam, lparam));
}
return 0;
}





 User Rating: 1015    Report this Post to a Moderator | Link

note:
there is no quit function on the window..
so to close it you will have to ctrl-alt-delete
and kill the process

 User Rating: 1015    Report this Post to a Moderator | Link

quote:
Original post by CaptainChainsaw
In reply to the anon poster:


OK I've got a 3 errors with my code, they are:

error C2664: 'RegisterClassA' : cannot convert parameter 1 from 'struct _WNDCLASSEX *' to 'const struct tagWNDCLASSA *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

error C2373: 'CreateWindowExA' : redefinition; different type modifiers: see declaration of 'CreateWindowExA'

error C2065: 'msg' : undeclared identifier
Error executing cl.exe.



/////////////////////////////////////////////////////////////////

Hello CaptainChainsaw


I know i am a bit late, and you have probably already solve these problems,but i had the same one and to help those who would make the same mistake i wish to post the solution here.

1)error C2664: 'RegisterClassA' : cannot convert parameter 1 from 'struct _WNDCLASSEX *' to 'const struct tagWNDCLASSA *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

and

2)error C2373: 'CreateWindowExA' : redefinition; different type modifiers: see declaration of 'CreateWindowExA'

These are due to redifinition of the _WNDCLASSEX structure.He gave us the protype of the structure,but it is already defined in winuser.cpp or the like.Basicly,you don't need to recreate structure.


3)error C2065: 'msg' : undeclared identifier

This is a MSG type that you need to declare before you past it's adresse to the PeekMessage().

You have to declare:

MSG msg;
then pass it's it's adresse to a pointer that will fill it with a message if there is one in the queue.

I have one question though.Why is my WINAPI WinMain not created with WINAPI but instead is created with APIENTRY.Does it matter and why?

I have changed this back to WINAPI, but i am curious.



[edited by - Neo_Phyte on January 18, 2004 1:54:50 PM]

[edited by - Neo_Phyte on January 18, 2004 1:55:25 PM]

[edited by - Neo_Phyte on January 18, 2004 1:56:21 PM]

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

"A bit late"? He posted freaking a year and a half ago... Why on earth did you necro this (again) just to make that comment?

(btw, APIENTRY is an alias for WINAPI - they're the same thing)

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links


 User Rating: 1076   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Well as i have stated it's for people that,like me and him, are having the same kind of errors while doing this, and since it was never answered, i wanted to put it up here.

Simple no!

And thank you for the answer!

The true Don juan is the one that seduce the same woman night after night.

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Can anyone point me how to implement double buffering in this type of application, I'm having some trouble 'erasing' things when I move them about the screen

 User Rating: 1015    Report this Post to a Moderator | Link

In the future, you might be better off starting a new thread and link to the article or original thread.

But, the fifth tutorial down on this page may aid you in your immediate quest.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links


 User Rating: 1076   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

By far the most common error that I've seen above is putting the definition of WNDCLASSEX in their source file. This should not be done. Don't define structures such as these in your source file, because they are already defined in windows.h and windowsx.h. Also, winmain doesn't need a prototype, and nor does the message handler.



 User Rating: 1419   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Trying to find some info on adding the mouse wheel.

 User Rating: 1019   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by ZealousElixir
"A bit late"? He posted freaking a year and a half ago... Why on earth did you necro this (again) just to make that comment?



I think i am even more late ,but i just want to discuss something in the article thats how i find this Post....

in that article i see..

Quote:

UINT wMsgFilterMin, wMsgFilterMax: The indices of the first and last messages in the queue to check. Most of the time, you'll only be interested in the first message on the queue, so you would set both of these parameters to 0.


Which to my understanding and MSDN, Not correct. these wMsgFilterMin and wMsgFilterMax filters are used for deciding which TYPES of messages to handle.And to be more precise, Range of Types of Messages to Handle...

Refer to : http://msdn.microsoft.com/en-us/library/ms644943(VS.85).aspx

For example should it Handle mouse messages or not, and such... but according to this article it says to specify the "indices of the first and last messages in the queue to check" , which does not makes sense because you only have access to the first element in a queue anyways...

Example:
Lets say WM_MOUSEFIRST = 5; and WM_MOUSELAST = 10; and we call
PeekMessage(&message, window, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE)


and now lets say our Message Queue is full with Mouse Messages ONLY.. so according to this article. our Message Queue will only processes from 5th to 10th Messages in the queue ignorning the first 4 messages which are still Mouse Messages.
While in real thats not the case. the PeekMessage() will handle all those messages in the Queue. since they all must be in the range of WM_MOUSEFIRST and WM_MOUSELAST....

..
waZim

 User Rating: 959   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

I started reading this article a few days ago and i realized it was from nearly a decade ago Dx. Is it still worth reading and learning from this article :o? And i was also wondering whether there are C++ windows programming tutorials similar to this one since this article was written about C. Or is it that C and C++ windows programming are similar enough that this article is still good if i want to write in C++?

 User Rating: 1015   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by Reggi
I started reading this article a few days ago and i realized it was from nearly a decade ago Dx. Is it still worth reading and learning from this article :o?

The WinApi hasn't changed in all these years when it comes to simply creating a window and handling its messages, so it still applies. I haven't read the article, so I can't say if it's any good or not, or whether better tutorials exist (but there probably are).
Quote:
And i was also wondering whether there are C++ windows programming tutorials similar to this one since this article was written about C. Or is it that C and C++ windows programming are similar enough that this article is still good if i want to write in C++?

The WinApi itself was written in C, but it there's no problem implementing it in a C++ based project. Both language are similar enough that you don't really need to know C in order to use it.

 User Rating: 1740   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link
All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: