Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. [ win32 ][ code::block's ] game 1 error ?

[ win32 ][ code::block's ] game 1 error ?

Scheduled Pinned Locked Moved C / C++ / MFC
helpgame-devquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bluatigro
    wrote on last edited by
    #1

    hello this is a try at a verry simple game it is a try at moving a circle whit cursor-key's i use code::block's 4 error's were detected : somting wrong whit case any help is welkome

    // bluatigro 23 okt 2017
    // win game 1

    #if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
    #elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
    #endif

    #include #include bool key[ 256 ] ;
    int playerx , playery , winx , winy ;
    #define FRAME_TIMER 1

    /* Declare Windows procedure */
    LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

    /* Make the class name into a global variable */

    = _T("CodeBlocksWindowsApp");

    int WINAPI WinMain (HINSTANCE hThisInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpszArgument,
    int nCmdShow)
    {
    HWND hwnd; /* This is the handle for our window */
    MSG messages; /* Here messages to the application are saved */
    WNDCLASSEX wincl; /* Data structure for the windowclass */

    /\* The Window structure \*/
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /\* This function is called by windows \*/
    wincl.style = CS\_DBLCLKS;                 /\* Catch double-clicks \*/
    wincl.cbSize = sizeof (WNDCLASSEX);
    
    /\* Use default icon and mouse-pointer \*/
    wincl.hIcon = LoadIcon (NULL, IDI\_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI\_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC\_ARROW);
    wincl.lpszMenuName = NULL;                 /\* No menu \*/
    wincl.cbClsExtra = 0;                      /\* No extra bytes after the window class \*/
    wincl.cbWndExtra = 0;                      /\* structure or the window instance \*/
    /\* Use Windows's default colour as the background of the window \*/
    wincl.hbrBackground = (HBRUSH) COLOR\_BACKGROUND;
    
    /\* Register the window class, and if it fails quit the program \*/
    if (!RegisterClassEx (&wincl))
        return 0;
    
    /\* The class is registered, let's create the program\*/
    hwnd = CreateWindowEx (
           0,                   /\* Extended possibilites for variation \*/
           szClassName,         /\* Classname \*/
           \_T("Game 1"),       /\* Title Text \*/
           WS\_OVERLAPPEDWINDOW | WS\_MAXIMIZE , /\* default window \*/
           CW\_USEDEFAULT,       /\* Windows decides the position \*/
           CW\_USEDEFAULT,
    
    CPalliniC L 2 Replies Last reply
    0
    • B bluatigro

      hello this is a try at a verry simple game it is a try at moving a circle whit cursor-key's i use code::block's 4 error's were detected : somting wrong whit case any help is welkome

      // bluatigro 23 okt 2017
      // win game 1

      #if defined(UNICODE) && !defined(_UNICODE)
      #define _UNICODE
      #elif defined(_UNICODE) && !defined(UNICODE)
      #define UNICODE
      #endif

      #include #include bool key[ 256 ] ;
      int playerx , playery , winx , winy ;
      #define FRAME_TIMER 1

      /* Declare Windows procedure */
      LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

      /* Make the class name into a global variable */

      = _T("CodeBlocksWindowsApp");

      int WINAPI WinMain (HINSTANCE hThisInstance,
      HINSTANCE hPrevInstance,
      LPSTR lpszArgument,
      int nCmdShow)
      {
      HWND hwnd; /* This is the handle for our window */
      MSG messages; /* Here messages to the application are saved */
      WNDCLASSEX wincl; /* Data structure for the windowclass */

      /\* The Window structure \*/
      wincl.hInstance = hThisInstance;
      wincl.lpszClassName = szClassName;
      wincl.lpfnWndProc = WindowProcedure;      /\* This function is called by windows \*/
      wincl.style = CS\_DBLCLKS;                 /\* Catch double-clicks \*/
      wincl.cbSize = sizeof (WNDCLASSEX);
      
      /\* Use default icon and mouse-pointer \*/
      wincl.hIcon = LoadIcon (NULL, IDI\_APPLICATION);
      wincl.hIconSm = LoadIcon (NULL, IDI\_APPLICATION);
      wincl.hCursor = LoadCursor (NULL, IDC\_ARROW);
      wincl.lpszMenuName = NULL;                 /\* No menu \*/
      wincl.cbClsExtra = 0;                      /\* No extra bytes after the window class \*/
      wincl.cbWndExtra = 0;                      /\* structure or the window instance \*/
      /\* Use Windows's default colour as the background of the window \*/
      wincl.hbrBackground = (HBRUSH) COLOR\_BACKGROUND;
      
      /\* Register the window class, and if it fails quit the program \*/
      if (!RegisterClassEx (&wincl))
          return 0;
      
      /\* The class is registered, let's create the program\*/
      hwnd = CreateWindowEx (
             0,                   /\* Extended possibilites for variation \*/
             szClassName,         /\* Classname \*/
             \_T("Game 1"),       /\* Title Text \*/
             WS\_OVERLAPPEDWINDOW | WS\_MAXIMIZE , /\* default window \*/
             CW\_USEDEFAULT,       /\* Windows decides the position \*/
             CW\_USEDEFAULT,
      
      CPalliniC Online
      CPalliniC Online
      CPallini
      wrote on last edited by
      #2

      You should at least report the exact error messages and mark the offending lines.

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • B bluatigro

        hello this is a try at a verry simple game it is a try at moving a circle whit cursor-key's i use code::block's 4 error's were detected : somting wrong whit case any help is welkome

        // bluatigro 23 okt 2017
        // win game 1

        #if defined(UNICODE) && !defined(_UNICODE)
        #define _UNICODE
        #elif defined(_UNICODE) && !defined(UNICODE)
        #define UNICODE
        #endif

        #include #include bool key[ 256 ] ;
        int playerx , playery , winx , winy ;
        #define FRAME_TIMER 1

        /* Declare Windows procedure */
        LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

        /* Make the class name into a global variable */

        = _T("CodeBlocksWindowsApp");

        int WINAPI WinMain (HINSTANCE hThisInstance,
        HINSTANCE hPrevInstance,
        LPSTR lpszArgument,
        int nCmdShow)
        {
        HWND hwnd; /* This is the handle for our window */
        MSG messages; /* Here messages to the application are saved */
        WNDCLASSEX wincl; /* Data structure for the windowclass */

        /\* The Window structure \*/
        wincl.hInstance = hThisInstance;
        wincl.lpszClassName = szClassName;
        wincl.lpfnWndProc = WindowProcedure;      /\* This function is called by windows \*/
        wincl.style = CS\_DBLCLKS;                 /\* Catch double-clicks \*/
        wincl.cbSize = sizeof (WNDCLASSEX);
        
        /\* Use default icon and mouse-pointer \*/
        wincl.hIcon = LoadIcon (NULL, IDI\_APPLICATION);
        wincl.hIconSm = LoadIcon (NULL, IDI\_APPLICATION);
        wincl.hCursor = LoadCursor (NULL, IDC\_ARROW);
        wincl.lpszMenuName = NULL;                 /\* No menu \*/
        wincl.cbClsExtra = 0;                      /\* No extra bytes after the window class \*/
        wincl.cbWndExtra = 0;                      /\* structure or the window instance \*/
        /\* Use Windows's default colour as the background of the window \*/
        wincl.hbrBackground = (HBRUSH) COLOR\_BACKGROUND;
        
        /\* Register the window class, and if it fails quit the program \*/
        if (!RegisterClassEx (&wincl))
            return 0;
        
        /\* The class is registered, let's create the program\*/
        hwnd = CreateWindowEx (
               0,                   /\* Extended possibilites for variation \*/
               szClassName,         /\* Classname \*/
               \_T("Game 1"),       /\* Title Text \*/
               WS\_OVERLAPPEDWINDOW | WS\_MAXIMIZE , /\* default window \*/
               CW\_USEDEFAULT,       /\* Windows decides the position \*/
               CW\_USEDEFAULT,
        
        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Most compilers object if you put local variables inside a case statement. You should either declare them before the first switch or enclose the case block in braces, thus:

        case WM\_PAINT :
        {
          PAINTSTRUCT paint ;
          HDC hdc = BeginPaint( hwnd , &paint ) ;
          RECT rect ;
          GetClientRect( hwnd , &rect ) ;
          winx = rect.right ;
          winy = rect.bottom ;
        

        /*
        HPEN pen = CreatePen( PS_SOLID ,
        1 , RGB( 255 , 255 , 0 ) ) ;
        HBRUSH brush =
        CreateSolidBrush( RGB( 255 , 255 , 0 ) ) ;
        */
        Ellipse( hdc ,
        playerx - 20 ,
        playery - 20 ,
        playerx + 20 ,
        playery + 20 ) ;

          EndPaint( hwnd , &paint ) ;
        }
        break ;
        

        Also, in future, please provide the exact text of error messages, and indicate where they occur.

        B 1 Reply Last reply
        0
        • L Lost User

          Most compilers object if you put local variables inside a case statement. You should either declare them before the first switch or enclose the case block in braces, thus:

          case WM\_PAINT :
          {
            PAINTSTRUCT paint ;
            HDC hdc = BeginPaint( hwnd , &paint ) ;
            RECT rect ;
            GetClientRect( hwnd , &rect ) ;
            winx = rect.right ;
            winy = rect.bottom ;
          

          /*
          HPEN pen = CreatePen( PS_SOLID ,
          1 , RGB( 255 , 255 , 0 ) ) ;
          HBRUSH brush =
          CreateSolidBrush( RGB( 255 , 255 , 0 ) ) ;
          */
          Ellipse( hdc ,
          playerx - 20 ,
          playery - 20 ,
          playerx + 20 ,
          playery + 20 ) ;

            EndPaint( hwnd , &paint ) ;
          }
          break ;
          

          Also, in future, please provide the exact text of error messages, and indicate where they occur.

          B Offline
          B Offline
          bluatigro
          wrote on last edited by
          #4

          update : i tryed it [ thanks for sugestions and i got somthing on screen error : my screen isn't black and isn't fulscreen my ellipse isn't yellow

          // bluatigro 23 okt 2017
          // win game 1

          #if defined(UNICODE) && !defined(_UNICODE)
          #define _UNICODE
          #elif defined(_UNICODE) && !defined(UNICODE)
          #define UNICODE
          #endif

          #include
          #include

          bool key[ 256 ] ;
          int playerx , playery , winx , winy ;
          #define FRAME_TIMER 1

          /* Declare Windows procedure */
          LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

          /* Make the class name into a global variable */

          = _T("CodeBlocksWindowsApp");

          int WINAPI WinMain (HINSTANCE hThisInstance,
          HINSTANCE hPrevInstance,
          LPSTR lpszArgument,
          int nCmdShow)
          {
          HWND hwnd; /* This is the handle for our window */
          MSG messages; /* Here messages to the application are saved */
          WNDCLASSEX wincl; /* Data structure for the windowclass */

          /\* The Window structure \*/
          wincl.hInstance = hThisInstance;
          wincl.lpszClassName = szClassName;
          wincl.lpfnWndProc = WindowProcedure;      /\* This function is called by windows \*/
          wincl.style = CS\_DBLCLKS;                 /\* Catch double-clicks \*/
          wincl.cbSize = sizeof (WNDCLASSEX);
          
          /\* Use default icon and mouse-pointer \*/
          wincl.hIcon = LoadIcon (NULL, IDI\_APPLICATION);
          wincl.hIconSm = LoadIcon (NULL, IDI\_APPLICATION);
          wincl.hCursor = LoadCursor (NULL, IDC\_ARROW);
          wincl.lpszMenuName = NULL;                 /\* No menu \*/
          wincl.cbClsExtra = 0;                      /\* No extra bytes after the window class \*/
          wincl.cbWndExtra = 0;                      /\* structure or the window instance \*/
          /\* Use Windows's default colour as the background of the window \*/
          wincl.hbrBackground = (HBRUSH)BLACK\_BRUSH;
          
          /\* Register the window class, and if it fails quit the program \*/
          if (!RegisterClassEx (&wincl))
              return 0;
          
          /\* The class is registered, let's create the program\*/
          hwnd = CreateWindowEx (
                 0,                   /\* Extended possibilites for variation \*/
                 szClassName,         /\* Classname \*/
                 \_T("Game 1"),       /\* Title Text \*/
                 WS\_OVERLAPPEDWINDOW | WS\_MAXIMIZE , /\* default window \*/
                 CW\_USEDEFAULT,       /\* Windows decides the position \*/
                 CW\_USEDEFAULT,       /\* where the window ends up on the screen
          
          L 1 Reply Last reply
          0
          • B bluatigro

            update : i tryed it [ thanks for sugestions and i got somthing on screen error : my screen isn't black and isn't fulscreen my ellipse isn't yellow

            // bluatigro 23 okt 2017
            // win game 1

            #if defined(UNICODE) && !defined(_UNICODE)
            #define _UNICODE
            #elif defined(_UNICODE) && !defined(UNICODE)
            #define UNICODE
            #endif

            #include
            #include

            bool key[ 256 ] ;
            int playerx , playery , winx , winy ;
            #define FRAME_TIMER 1

            /* Declare Windows procedure */
            LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

            /* Make the class name into a global variable */

            = _T("CodeBlocksWindowsApp");

            int WINAPI WinMain (HINSTANCE hThisInstance,
            HINSTANCE hPrevInstance,
            LPSTR lpszArgument,
            int nCmdShow)
            {
            HWND hwnd; /* This is the handle for our window */
            MSG messages; /* Here messages to the application are saved */
            WNDCLASSEX wincl; /* Data structure for the windowclass */

            /\* The Window structure \*/
            wincl.hInstance = hThisInstance;
            wincl.lpszClassName = szClassName;
            wincl.lpfnWndProc = WindowProcedure;      /\* This function is called by windows \*/
            wincl.style = CS\_DBLCLKS;                 /\* Catch double-clicks \*/
            wincl.cbSize = sizeof (WNDCLASSEX);
            
            /\* Use default icon and mouse-pointer \*/
            wincl.hIcon = LoadIcon (NULL, IDI\_APPLICATION);
            wincl.hIconSm = LoadIcon (NULL, IDI\_APPLICATION);
            wincl.hCursor = LoadCursor (NULL, IDC\_ARROW);
            wincl.lpszMenuName = NULL;                 /\* No menu \*/
            wincl.cbClsExtra = 0;                      /\* No extra bytes after the window class \*/
            wincl.cbWndExtra = 0;                      /\* structure or the window instance \*/
            /\* Use Windows's default colour as the background of the window \*/
            wincl.hbrBackground = (HBRUSH)BLACK\_BRUSH;
            
            /\* Register the window class, and if it fails quit the program \*/
            if (!RegisterClassEx (&wincl))
                return 0;
            
            /\* The class is registered, let's create the program\*/
            hwnd = CreateWindowEx (
                   0,                   /\* Extended possibilites for variation \*/
                   szClassName,         /\* Classname \*/
                   \_T("Game 1"),       /\* Title Text \*/
                   WS\_OVERLAPPEDWINDOW | WS\_MAXIMIZE , /\* default window \*/
                   CW\_USEDEFAULT,       /\* Windows decides the position \*/
                   CW\_USEDEFAULT,       /\* where the window ends up on the screen
            
            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            You are calling BeginPaint for every message (not just WM_PAINT), but you only call EndPaint after processing a WM_PAINT message. You need to move all code related the the painting into the block that handles the WM_PAINT message. You also need to select your brushes and pens into the device context before you draw anything. And lastly you need to delete any DC objects that you use in painting. I would suggest studying the GDI documentation on MSDN for sample code. But be aware that GDI and GDI+ are being deprecated by Microsoft in favour of Direct2D API Reference (Windows)[^]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups