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] sprite error ?

[win32] sprite error ?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelpquestion
11 Posts 4 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

    error : 24 no operator = for thie 104 string to TCHAR warning i have a 'player.bmp' in the same map

    // blua tigro 1 nov 2017
    // sprite 1

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

    #include
    #include
    bool key[ 256 ] ;
    int winx , winy ;
    #define FRAME_TIMER 1
    class Sprite
    {
    public :
    int x , y , w , h ;
    bool visable ;
    BITMAP bmp ;
    Sprite(){;}
    void loadbmpfromfile( HINSTANCE hinstance , TCHAR * file )
    {
    bmp = LoadBitmap( hinstance , _T( file ) ) ;
    w = bmp.bmWidth ;
    h = bmp.bmHeight ;
    visable = true ;
    }
    void show( HDC hdc )
    {
    if ( visable )
    {
    //draw mask whit and [ upper half of bmp ]
    BitBlt( hdc , x , y , w , h/2 , hdc , 0 , 0 , MERGECOPY ) ;
    //draw picture whit or [ lower half of bmp ]
    BitBlt( hdc , x , y , w , h/2 , hdc , 0 , h/2 , MERGEPAINT ) ;
    }
    }
    bool hit( Sprite spr )
    {
    if ( x + w < spr.x ) return false ;
    if ( x > spr.x + spr.w ) return false ;
    if ( y + h < spr.y ) return false ;
    if ( y > spr.y + spr.h ) return false ;
    return true ;
    }
    } ;
    Sprite player ;
    /* 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;                      /
    
    L J D 3 Replies Last reply
    0
    • B bluatigro

      error : 24 no operator = for thie 104 string to TCHAR warning i have a 'player.bmp' in the same map

      // blua tigro 1 nov 2017
      // sprite 1

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

      #include
      #include
      bool key[ 256 ] ;
      int winx , winy ;
      #define FRAME_TIMER 1
      class Sprite
      {
      public :
      int x , y , w , h ;
      bool visable ;
      BITMAP bmp ;
      Sprite(){;}
      void loadbmpfromfile( HINSTANCE hinstance , TCHAR * file )
      {
      bmp = LoadBitmap( hinstance , _T( file ) ) ;
      w = bmp.bmWidth ;
      h = bmp.bmHeight ;
      visable = true ;
      }
      void show( HDC hdc )
      {
      if ( visable )
      {
      //draw mask whit and [ upper half of bmp ]
      BitBlt( hdc , x , y , w , h/2 , hdc , 0 , 0 , MERGECOPY ) ;
      //draw picture whit or [ lower half of bmp ]
      BitBlt( hdc , x , y , w , h/2 , hdc , 0 , h/2 , MERGEPAINT ) ;
      }
      }
      bool hit( Sprite spr )
      {
      if ( x + w < spr.x ) return false ;
      if ( x > spr.x + spr.w ) return false ;
      if ( y + h < spr.y ) return false ;
      if ( y > spr.y + spr.h ) return false ;
      return true ;
      }
      } ;
      Sprite player ;
      /* 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;                      /
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Please stop doing this. Do not just dump a load of code with a vague comment and expect someone to figure out what the problem is and then fix it for you. Edit your question, remove the code not relevant to the problem, and explain clearly what is going wrong, and where it happens.

      1 Reply Last reply
      0
      • B bluatigro

        error : 24 no operator = for thie 104 string to TCHAR warning i have a 'player.bmp' in the same map

        // blua tigro 1 nov 2017
        // sprite 1

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

        #include
        #include
        bool key[ 256 ] ;
        int winx , winy ;
        #define FRAME_TIMER 1
        class Sprite
        {
        public :
        int x , y , w , h ;
        bool visable ;
        BITMAP bmp ;
        Sprite(){;}
        void loadbmpfromfile( HINSTANCE hinstance , TCHAR * file )
        {
        bmp = LoadBitmap( hinstance , _T( file ) ) ;
        w = bmp.bmWidth ;
        h = bmp.bmHeight ;
        visable = true ;
        }
        void show( HDC hdc )
        {
        if ( visable )
        {
        //draw mask whit and [ upper half of bmp ]
        BitBlt( hdc , x , y , w , h/2 , hdc , 0 , 0 , MERGECOPY ) ;
        //draw picture whit or [ lower half of bmp ]
        BitBlt( hdc , x , y , w , h/2 , hdc , 0 , h/2 , MERGEPAINT ) ;
        }
        }
        bool hit( Sprite spr )
        {
        if ( x + w < spr.x ) return false ;
        if ( x > spr.x + spr.w ) return false ;
        if ( y + h < spr.y ) return false ;
        if ( y > spr.y + spr.h ) return false ;
        return true ;
        }
        } ;
        Sprite player ;
        /* 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;                      /
        
        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        The _T() macro is for constant strings (and characters) only:

        // Wrong:
        //bmp = LoadBitmap( hinstance , _T( file ) ) ;
        // Correct:
        bmp = LoadBitmap(hinstance, file);

        When supporting Unicode and non-Unicode builds, all constant strings must be embedded in that macro:

        // Wrong:
        //player.loadbmpfromfile(hThisInstance,"player.bmp") ;
        // Correct:
        player.loadbmpfromfile(hThisInstance, _T("player.bmp"));

        1 Reply Last reply
        0
        • B bluatigro

          error : 24 no operator = for thie 104 string to TCHAR warning i have a 'player.bmp' in the same map

          // blua tigro 1 nov 2017
          // sprite 1

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

          #include
          #include
          bool key[ 256 ] ;
          int winx , winy ;
          #define FRAME_TIMER 1
          class Sprite
          {
          public :
          int x , y , w , h ;
          bool visable ;
          BITMAP bmp ;
          Sprite(){;}
          void loadbmpfromfile( HINSTANCE hinstance , TCHAR * file )
          {
          bmp = LoadBitmap( hinstance , _T( file ) ) ;
          w = bmp.bmWidth ;
          h = bmp.bmHeight ;
          visable = true ;
          }
          void show( HDC hdc )
          {
          if ( visable )
          {
          //draw mask whit and [ upper half of bmp ]
          BitBlt( hdc , x , y , w , h/2 , hdc , 0 , 0 , MERGECOPY ) ;
          //draw picture whit or [ lower half of bmp ]
          BitBlt( hdc , x , y , w , h/2 , hdc , 0 , h/2 , MERGEPAINT ) ;
          }
          }
          bool hit( Sprite spr )
          {
          if ( x + w < spr.x ) return false ;
          if ( x > spr.x + spr.w ) return false ;
          if ( y + h < spr.y ) return false ;
          if ( y > spr.y + spr.h ) return false ;
          return true ;
          }
          } ;
          Sprite player ;
          /* 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;                      /
          
          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          Both errors look like they could be coming from the call to LoadBitmap(), but since you failed to include line numbers, it's hard to say for sure. That function returns a BOOL not a BITMAP. Also, the _T() macro is for string literals.

          "One man's wage rise is another man's price increase." - Harold Wilson

          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

          "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

          B 1 Reply Last reply
          0
          • D David Crow

            Both errors look like they could be coming from the call to LoadBitmap(), but since you failed to include line numbers, it's hard to say for sure. That function returns a BOOL not a BITMAP. Also, the _T() macro is for string literals.

            "One man's wage rise is another man's price increase." - Harold Wilson

            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

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

            a error font by the compler can have a source elsewere so i have to post al the code i don't know how to include the line numbers my english in writing is not great so i have to be short

            B 1 Reply Last reply
            0
            • B bluatigro

              a error font by the compler can have a source elsewere so i have to post al the code i don't know how to include the line numbers my english in writing is not great so i have to be short

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

              ok i try it i changed the folowing : player.loadbmpformfil( ,_T("player.bmp)) ; my sprite looks like this now :

              class Sprite
              {
              public :
              int x , y , w , h ;
              bool visable ;
              HBITMAP hbmp ;
              HDC bmphdc ;
              Sprite(){;}
              void loadbmpfromfile( HINSTANCE hinstance , TCHAR * file )
              {
              hbmp = LoadBitmap( hinstance , file ) ;
              w = hbmp.i ;
              h = hbmp.i ;
              visable = true ;
              }
              void show( HDC hdc )
              {
              if ( visable )
              {
              //draw mask whit and [ upper half of bmp ]
              BitBlt( hdc , x , y , w , h/2 , bmphdc , 0 , 0 , MERGECOPY ) ;
              //draw picture whit or [ lower half of bmp ]
              BitBlt( hdc , x , y , w , h/2 , bmphdc , 0 , h/2 , MERGEPAINT ) ;
              }
              }
              bool hit( Sprite spr )
              {
              if ( x + w < spr.x ) return false ;
              if ( x > spr.x + spr.w ) return false ;
              if ( y + h < spr.y ) return false ;
              if ( y > spr.y + spr.h ) return false ;
              return true ;
              }
              } ;
              Sprite player ;

              i know this is wrong . how do i do this ? my wm_paint :

              case WM\_PAINT :
                GetClientRect( hwnd , &rect ) ;
                winx = rect.right ;
                winy = rect.bottom ;
              
                player.bmphdc = CreateCompatibleDC(hdc);
              
                player.show( hdc ) ;
              
                DeleteDC( player.bmphdc ) ;
              
                EndPaint( hwnd , &paint ) ;
              

              this can be wrong . how do i do this ?

              L 1 Reply Last reply
              0
              • B bluatigro

                ok i try it i changed the folowing : player.loadbmpformfil( ,_T("player.bmp)) ; my sprite looks like this now :

                class Sprite
                {
                public :
                int x , y , w , h ;
                bool visable ;
                HBITMAP hbmp ;
                HDC bmphdc ;
                Sprite(){;}
                void loadbmpfromfile( HINSTANCE hinstance , TCHAR * file )
                {
                hbmp = LoadBitmap( hinstance , file ) ;
                w = hbmp.i ;
                h = hbmp.i ;
                visable = true ;
                }
                void show( HDC hdc )
                {
                if ( visable )
                {
                //draw mask whit and [ upper half of bmp ]
                BitBlt( hdc , x , y , w , h/2 , bmphdc , 0 , 0 , MERGECOPY ) ;
                //draw picture whit or [ lower half of bmp ]
                BitBlt( hdc , x , y , w , h/2 , bmphdc , 0 , h/2 , MERGEPAINT ) ;
                }
                }
                bool hit( Sprite spr )
                {
                if ( x + w < spr.x ) return false ;
                if ( x > spr.x + spr.w ) return false ;
                if ( y + h < spr.y ) return false ;
                if ( y > spr.y + spr.h ) return false ;
                return true ;
                }
                } ;
                Sprite player ;

                i know this is wrong . how do i do this ? my wm_paint :

                case WM\_PAINT :
                  GetClientRect( hwnd , &rect ) ;
                  winx = rect.right ;
                  winy = rect.bottom ;
                
                  player.bmphdc = CreateCompatibleDC(hdc);
                
                  player.show( hdc ) ;
                
                  DeleteDC( player.bmphdc ) ;
                
                  EndPaint( hwnd , &paint ) ;
                

                this can be wrong . how do i do this ?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                I told you a week ago, you must call BeginPaint inside your WM_PAINT code. So it needs to be:

                case WM\_PAINT :
                  hdc = BeginPaint( hwnd , &paint );
                

                // All painting code or calls to functions that paint:

                  EndPaint( hwnd , &paint ) ;
                  break; // make sure you have a break or return after every case block
                
                B 1 Reply Last reply
                0
                • L Lost User

                  I told you a week ago, you must call BeginPaint inside your WM_PAINT code. So it needs to be:

                  case WM\_PAINT :
                    hdc = BeginPaint( hwnd , &paint );
                  

                  // All painting code or calls to functions that paint:

                    EndPaint( hwnd , &paint ) ;
                    break; // make sure you have a break or return after every case block
                  
                  B Offline
                  B Offline
                  bluatigro
                  wrote on last edited by
                  #8

                  ok done that how do i proseed next ?

                  case WM\_PAINT :
                    hdc = BeginPaint( hwnd , &paint ) ;
                    GetClientRect( hwnd , &rect ) ;
                    winx = rect.right ;
                    winy = rect.bottom ;
                  
                    player.bmphdc = CreateCompatibleDC( hdc ) ;
                  
                    player.show( hdc ) ;
                  
                    DeleteDC( player.bmphdc ) ;
                  
                    EndPaint( hwnd , &paint ) ;
                    break ;
                  case WM\_DESTROY :
                  
                  L 1 Reply Last reply
                  0
                  • B bluatigro

                    ok done that how do i proseed next ?

                    case WM\_PAINT :
                      hdc = BeginPaint( hwnd , &paint ) ;
                      GetClientRect( hwnd , &rect ) ;
                      winx = rect.right ;
                      winy = rect.bottom ;
                    
                      player.bmphdc = CreateCompatibleDC( hdc ) ;
                    
                      player.show( hdc ) ;
                    
                      DeleteDC( player.bmphdc ) ;
                    
                      EndPaint( hwnd , &paint ) ;
                      break ;
                    case WM\_DESTROY :
                    
                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    bluatigro wrote:

                    how do i proseed next ?

                    What do you mean? As far as I can see the above code does not do anything.

                    B 1 Reply Last reply
                    0
                    • L Lost User

                      bluatigro wrote:

                      how do i proseed next ?

                      What do you mean? As far as I can see the above code does not do anything.

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

                      by me pc its giving error's if i knew what to do i won't ask this is new to me what do i ad / change so it does work as expected ? it shoot show a sprite 'player.bmp' whit cursor control

                      L 1 Reply Last reply
                      0
                      • B bluatigro

                        by me pc its giving error's if i knew what to do i won't ask this is new to me what do i ad / change so it does work as expected ? it shoot show a sprite 'player.bmp' whit cursor control

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #11

                        bluatigro wrote:

                        by me pc its giving error's

                        What errors? Where do they occur? What is your code trying to do? Please provide proper information so we can try to help. Also, if this is all new to you then you would do well to study some tutorials on Windows programming. Here are two that are very useful: EFNet #Winprog[^] Win32 Programming - FunctionX[^]

                        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