Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - blojayble

Pages: 1 [2]
16
General / Using events with WinAPI.
« on: October 31, 2011, 05:02:34 pm »
OK, my bad.

Now I changed it to:

Code: [Select]
if( Event.Type == sf::Event::KeyPressed  && Event.Key.Code == sf::Key::A ) lol = true;


But it don't work at all.

17
General / Using events with WinAPI.
« on: October 31, 2011, 04:45:53 pm »
Still nothing.

I also tried like this:


Code: [Select]
MSG Message;

bool lol = false;


Message.message = static_cast<UINT>(~WM_QUIT);
    while (Message.message != WM_QUIT)
    {
        if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE))
        {
            // If a message was waiting in the message queue, process it
            TranslateMessage(&Message);
            DispatchMessage(&Message);
        }
        else
{
           


sf::Event Event;
         while(SFMLView.GetEvent(Event))
      {

      if( Event.Key.Code == sf::Key::A ) lol = true;


      }



// SFML
SFMLView.Clear(sf::Color::Yellow);

if(lol == true)SFMLView.Draw(sf::Shape::Circle(30,30,30,sf::Color::Blue));

//SFMLView.Draw(sf::Shape::Circle(Message.pt.x,Message.pt.y,30,sf::Color::Cyan));
SFMLView.Draw(sf::Shape::Circle(20,20,30,sf::Color::Cyan));

SFMLView.Display();


     
        }
    }




But it doesn't work too.

To be honest it work, but not when I press "A", but when i move mouse a lot. It's kinda bug.


/EDIT

I also found an issue while using Event.Key.Code == sf::something. When i move my mouse it can activate without pressing key I need. It happened  in other game too.

18
General / Using events with WinAPI.
« on: October 31, 2011, 04:28:44 pm »
The problem is, that I don't have it. :P

But I will write it now. :P


Code: [Select]
#include <windows.h>
#include <SFML\Graphics.hpp>


LPCWSTR NazwaKlasy = L"SFML App";

LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
   
    // WYPEŁNIANIE STRUKTURY
    WNDCLASSEX wc;
   
    wc.cbSize = sizeof( WNDCLASSEX );
    wc.style = 0;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground =( HBRUSH )( COLOR_WINDOW + 1 );
    wc.lpszMenuName = NULL;
    wc.lpszClassName = NazwaKlasy;
    wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
   
    // REJESTROWANIE KLASY OKNA
    if( !RegisterClassEx( & wc ) )
    {
        MessageBox( NULL, L"Wysoka Komisja odmawia rejestracji tego okna!", L"Niestety...",
        MB_ICONEXCLAMATION | MB_OK );
        return 1;
    }
   
    // TWORZENIE OKNA
    HWND hwnd;
   
    hwnd = CreateWindowEx( WS_EX_CLIENTEDGE, NazwaKlasy, L"Oto okienko", WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 240, 120, NULL, NULL, hInstance, NULL );
    HWND View = CreateWindowEx(NULL, NazwaKlasy,L"STATIC" ,WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,0,0,200,200,hwnd,NULL, hInstance,NULL);
    sf::RenderWindow SFMLView(View);




    if( hwnd == NULL )
    {
        MessageBox( NULL, L"Okno odmówiło przyjścia na świat!", L"Ale kicha...", MB_ICONEXCLAMATION );
        return 1;
}
   
    ShowWindow( hwnd, nCmdShow ); // Pokaż okienko...
    UpdateWindow( hwnd );
ShowWindow( View, nCmdShow ); // Pokaż okienko...
    UpdateWindow( View );
   
    // Pętla komunikatów
    MSG Message;
sf::Event Event;
   
while(SFMLView.GetEvent(Event))
{

if( Event.Key.Code == sf::Key::A ) SFMLView.Draw(sf::Shape::Circle(40,40,30,sf::Color::Green));


}


Message.message = static_cast<UINT>(~WM_QUIT);
    while (Message.message != WM_QUIT)
    {
        if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE))
        {
            // If a message was waiting in the message queue, process it
            TranslateMessage(&Message);
            DispatchMessage(&Message);
        }
        else
{
            // SFML
SFMLView.Clear(sf::Color::Yellow);

//SFMLView.Draw(sf::Shape::Circle(Message.pt.x,Message.pt.y,30,sf::Color::Cyan));
SFMLView.Draw(sf::Shape::Circle(20,20,30,sf::Color::Cyan));

SFMLView.Display();


     
        }
    }




    // Destroy the main window (all its child controls will be destroyed)
    DestroyWindow(hwnd);

    // Don't forget to unregister the window class
    UnregisterClass(TEXT("SFML App"), hInstance);

}

// OBSŁUGA ZDARZEŃ
LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
    case WM_CLOSE:
        DestroyWindow( hwnd );
        break;
       
    case WM_DESTROY:
        PostQuitMessage( 0 );
        break;
       
        default:
        return DefWindowProc( hwnd, msg, wParam, lParam );
    }
   
    return 0;
}




I know that what i done is stupid, but i have no idea what else can I do.

19
General / Using events with WinAPI.
« on: October 31, 2011, 04:11:30 pm »
Hi all.


I have searched, but I still don't know it. Does events work if I use WinAPI like this:

http://www.sfml-dev.org/tutorials/1.6/graphics-win32.php  ?


If yes, how to do it? I tried by .GetEvent(Event) and

if( Event.Key.Code == sf::Key::A ) do something;

and it doesn't work. Maybe I placed it in wrong place...


I don't need a complete code,  just how to make it working. ;)



Thanks a lot for all answers.

Pages: 1 [2]