| szymeczek31 Temat założony przez niniejszego użytkownika | [SFML][winAPI]  Zdarzenia » 2014-06-22 22:10:18 Tworzę apkę w SFML i wszystko działało jak trzeba, ale chciałem połączyć z winAPI, żeby stworzyć menu itp. ale komuikaty się zwaliły. Tak wiem był temat o prawie identycznym tytule ale mi nic nie dał. Walnę kod: #include <SFML/Graphics.hpp>#include <windows.h>
 
 sf::Event zdarzenie;
 HWND hwnd;
 HMENU hMenu;
 
 bool Wcisnieto( int przycisk )
 {
 if( zdarzenie.type == sf::Event::KeyPressed && zdarzenie.key.code == przycisk ) return 1;
 else return 0;
 
 }
 
 LRESULT CALLBACK onEvent( HWND handle, UINT message, WPARAM wParam, LPARAM lParam )
 {
 switch( message )
 {
 case WM_CLOSE:
 {
 PostQuitMessage( 0 );
 return 0;
 }
 
 case WM_COMMAND:
 {
 switch( wParam )
 {
 case 101:
 {
 PostQuitMessage( 0 );
 return 0;
 }
 }
 }
 }
 
 return DefWindowProc( handle, message, wParam, lParam );
 }
 
 INT WINAPI WinMain( HINSTANCE hThisInstance, HINSTANCE, LPSTR, INT )
 {
 hMenu = LoadMenu( hThisInstance, MAKEINTRESOURCE( 100 ) );
 WNDCLASS wc;
 wc.style = 0;
 wc.lpfnWndProc = & onEvent;
 wc.cbClsExtra = 0;
 wc.cbWndExtra = 0;
 wc.hInstance = hThisInstance;
 wc.hIcon = NULL;
 wc.hCursor = 0;
 wc.hbrBackground = reinterpret_cast < HBRUSH >( COLOR_BACKGROUND );
 wc.lpszMenuName = 0;
 wc.lpszClassName = "SF Game";
 RegisterClass( & wc );
 
 hwnd = CreateWindow( "SF Game", TEXT( "SF Game" ), WS_SYSMENU | WS_MINIMIZEBOX | WS_THICKFRAME | WS_VISIBLE, 200, 200, 800, 600, NULL, hMenu, hThisInstance, NULL );
 HWND hOkno = CreateWindow( TEXT( "STATIC" ), NULL, WS_CHILD | WS_MAXIMIZE | WS_CLIPSIBLINGS, 20, 20, 300, 400, hwnd, NULL, hThisInstance, NULL );
 sf::RenderWindow okno( hOkno );
 
 
 
 sf::Image image;
 image.loadFromFile( "pliki/obrazek.png" );
 image.createMaskFromColor( sf::Color( 0, 100, 200 ), 0 );
 sf::Texture tekstura;
 tekstura.loadFromImage( image );
 sf::Sprite obrazek;
 obrazek.setTexture( tekstura );
 
 sf::Image image2;
 image2.loadFromFile( "pliki/czolg.png" );
 image2.createMaskFromColor( sf::Color( 0, 100, 200 ), 0 );
 sf::Texture tekstura2;
 tekstura2.loadFromImage( image2 );
 sf::Sprite czolg;
 czolg.setTexture( tekstura2 );
 
 sf::Image image3;
 image3.loadFromFile( "pliki/dziura.png" );
 image3.createMaskFromColor( sf::Color( 0, 100, 200 ), 0 );
 sf::Texture tekstura3;
 tekstura3.loadFromImage( image3 );
 sf::Sprite dziura;
 dziura.setTexture( tekstura3 );
 
 okno.draw( dziura );
 okno.draw( obrazek );
 okno.draw( czolg );
 
 obrazek.setPosition( 10, 100 );
 czolg.setPosition( 500, 100 );
 dziura.setPosition( - 30, - 50 );
 
 sf::CircleShape kolo( 10 );
 kolo.setPosition( 100, 100 );
 kolo.setFillColor( sf::Color( 0, 0, 0 ) );
 kolo.setOrigin( 100, 50 );
 okno.draw( kolo );
 
 MSG message;
 message.message = static_cast < UINT >( ~WM_QUIT );
 while( okno.isOpen() && message.message != WM_QUIT )
 {
 while( okno.pollEvent( zdarzenie ) )
 {
 if( zdarzenie.type == sf::Event::Closed )
 {
 okno.close();
 }
 else if( Wcisnieto( sf::Keyboard::Escape ) )
 {
 okno.close();
 }
 else if( zdarzenie.type == sf::Event::MouseButtonPressed && zdarzenie.mouseButton.button == sf::Mouse::Left )
 {
 obrazek.rotate( 60 );
 }
 else if( zdarzenie.type == sf::Event::MouseButtonPressed && zdarzenie.mouseButton.button == sf::Mouse::Right )
 {
 obrazek.rotate( - 60 );
 }
 else if( Wcisnieto( sf::Keyboard::Right ) )
 {
 obrazek.move( 10, 0 );
 kolo.move( 10, 0 );
 kolo.rotate( 10 );
 }
 else if( Wcisnieto( sf::Keyboard::Left ) )
 {
 obrazek.move( - 10, 0 );
 kolo.move( - 10, 0 );
 kolo.rotate( - 10 );
 }
 else if( Wcisnieto( sf::Keyboard::Down ) )
 {
 obrazek.move( 0, 10 );
 kolo.move( 0, 10 );
 kolo.rotate( 10 );
 }
 else if( Wcisnieto( sf::Keyboard::Up ) )
 {
 obrazek.move( 0, - 10 );
 kolo.move( 0, - 10 );
 kolo.rotate( - 10 );
 }
 else if( Wcisnieto( sf::Keyboard::D ) )
 {
 czolg.move( 10, 0 );
 }
 else if( Wcisnieto( sf::Keyboard::A ) )
 {
 czolg.move( - 10, 0 );
 }
 else if( Wcisnieto( sf::Keyboard::S ) )
 {
 czolg.move( 0, 10 );
 }
 else if( Wcisnieto( sf::Keyboard::W ) )
 {
 czolg.move( 0, - 10 );
 }
 }
 okno.clear( sf::Color( 0, 100, 200 ) );
 okno.draw( dziura );
 okno.draw( obrazek );
 okno.draw( czolg );
 okno.draw( kolo );
 okno.display();
 
 
 if( PeekMessage( & message, NULL, 0, 0, PM_REMOVE ) )
 {
 TranslateMessage( & message );
 DispatchMessage( & message );
 }
 }
 DestroyWindow( hwnd );
 UnregisterClass( "SF Game", hThisInstance );
 return( int ) message.wParam;
 }
 
Mam jeszcze plik *.rc ale tam jest tylko menu więc nie ma sensu go dołączać. Jak ktoś jest geniuszem i wie jak to zrobić to pliss napisać. O i dla ciekawych -> Mój program powinien działać na windows a czy działa na linux itp. mnie nie obchodzi :P. |