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

Author Topic: [SOLVED]SFML freezes when operating with Win-Api  (Read 1940 times)

0 Members and 1 Guest are viewing this topic.

Blublop

  • Newbie
  • *
  • Posts: 13
    • View Profile
[SOLVED]SFML freezes when operating with Win-Api
« on: March 14, 2011, 06:47:41 pm »
Hello

I'm using SFML with the Win32 Api.
I followed the tutorial "Integrating to a Win32 interface" but changed it :
Code: [Select]

    HWND View1 = CreateWindow(szClassName, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 20,  20, 800, 800, hwnd, NULL, hThisInstance, NULL);
    sfview1.SetView(View1);

    HWND View2 = CreateWindow(szClassName, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 1320,  20, 400, 800, hwnd, NULL, hThisInstance, NULL);
    sfview2.SetView(View2);


Instead of "STATIC" I'm using the same string for the main app and for the two sfml views.
This way I can handle events in SFML and main Winproc.

My main loop looks like this :
Code: [Select]

while (messages.message != WM_QUIT)
    {
        if (PeekMessage(&messages, NULL, 0, 0, PM_REMOVE))
        {
            // If a message was waiting in the message queue, process it
            TranslateMessage(&messages);
            DispatchMessage(&messages);
        }
        else
        /*if (!pause) */ // Why sfml is freezing with this ???
        {
            sfview1.act();
            sfview2.act();
        }

        Sleep(1 - (DWORD)Sleeptimer.GetElapsedTime());
        Sleeptimer.Reset();
    }


As you can see I'm using an global bool to stop drawing both subapps.
It can be changed through WinProc of the main app :

Code: [Select]

LRESULT CALLBACK WindowProcedure(HWND hWnd, UINT umsg, WPARAM wParam, LPARAM lParam)
{
     switch (umsg)
    {
         // [...]
         
         case WM_KILLFOCUS :
         {
              pause = true;
              return 0;
          }
          case WM_SETFOCUS :
          {
              pause = false;
              return 0;
          }

        // [...]
    }
    return DefWindowProc(hWnd, umsg, wParam, lParam);
}


So , I click on the menu in order to pop up an dialog and wait 2 secs and the whole thing freezes.
I noticed this also when I build the sfml app without win32-Api.
If you drag the window for a certain time sfml freezes either.

Is there a way while catching the lostfocus event to tell sfml to stop actually ?

I'm using 1.6 : D

Thanks in advance !

EDIT :

Ok I've got it working
The sleeptimer was the problem - I can't use it, when sfview1/2 lost their focus.

 

anything