[win32] sprite error ?
-
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; /
-
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; /
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.
-
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; /
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")); -
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; /
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 aBOOL
not aBITMAP
. 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
-
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 aBOOL
not aBITMAP
. 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
-
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
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 ?
-
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 ?
I told you a week ago, you must call
BeginPaint
inside yourWM_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
-
I told you a week ago, you must call
BeginPaint
inside yourWM_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
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 :
-
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 :
-
bluatigro wrote:
how do i proseed next ?
What do you mean? As far as I can see the above code does not do anything.
-
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
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[^]