0
votes

I am currently facing issues when trying to compile my code that contains this WinProc function which is being used to process messages from our program. For example if a WM_DESTROY message is received via windows I want it to call PostQuitMessage(0) to signal Windows that the application has made a request to quit. Which will cause the WM_QUIT message to cause the WinMain to exit.

I have only been learning C++ a few weeks and don't have the experience or knowledge to fix this and would appreciate any help. I have looked around but so far I cannot find any solutions. I'm pretty new to this so I may have missed something really obvious.

LRESULT WINAPI WinProc (hWnd, msg, UNIT msg, WPARAM wParam, LPARAM lParam )
{
      switch( msg )
        {
                  case WM_DESTROY;
                  // Tell windows to kill the program
                  PostQuitMessage(0);
                  return 0;

        }
        return DefWindowProc (hWnd, msg, wParam, lParam );

}

Below is the errors I experience wit the code that I have provided.

error: 'LRESULT WinProc' redeclared as different kind of symbol error: previous declaration of 'LRESULT WinProc(HWND__*, UINT, WPARAM, LPARAM)' error: 'hWnd' was not declared in this scope error: 'msg' was not declared in this scope error: 'UNIT' was not declared in this scope

Any help would be greatly appreciated.

Thanks

3

3 Answers

0
votes

try using the callback calling convention instead of winapi

https://msdn.microsoft.com/en-us/library/windows/desktop/ms633570(v=vs.85).aspx

also note the usage of " : " instead of " ; " on switch statement , also specify a type before the handle and message arguments

LRESULT CALLBACK WinProc (HWND hWnd, UINT msg,  WPARAM wParam, LPARAM lParam)    
{
      switch( msg )
        {
                  case WM_DESTROY:
                  // Tell windows to kill the program
                  PostQuitMessage(0);
                  return 0;

        }
        return DefWindowProc (hWnd, msg, wParam, lParam );

}
3
votes

In the function declaration

LRESULT WINAPI WinProc (hWnd, msg, UNIT msg, WPARAM wParam, LPARAM lParam )

you forgot to set type specifiers for the first two parameters hWnd and msg

There must be

LRESULT WINAPI WinProc ( HWND hWnd, UNIT msg, WPARAM wParam, LPARAM lParam )

Also the label has to be followed by a colon while you placed a semicolon

case WM_DESTROY;
0
votes
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ) 

This should be the function declaration. Your case has a ";" semicolon instead of a ":" colon.

Besides this, I don't see any problems. Try this:

LRESULT CALLBACK WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam  ) 
{
      switch( msg )
      {
              case WM_DESTROY:
              // Tell windows to kill the program
              PostQuitMessage(0);
              return 0;

       }
       return DefWindowProc (hWnd, msg, wParam, lParam );

}