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

Author Topic: MFC and SFML Window problem  (Read 29477 times)

0 Members and 2 Guests are viewing this topic.

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
MFC and SFML Window problem
« on: March 25, 2014, 06:08:00 am »
Hi everyone.
I have a CDialog with SFML RenderWindow created in a separated class. Everything is working OK, with the exception of two things.

1. Because I want to keep the CDialog events instead of the SFML I have problem that I loose the focus for mouse wheel event. I can use the mouse and the buttons, but the mouse wheel event is not triggered until I use the right button and click on the menu on the Windows bar where the programs icon is. And after I click outside of the  program I loose the focus again. Is there a workaround this?

2. How can I resize SFML window. I use custom events to resize the CDialog window using SetWindowPos().
« Last Edit: March 25, 2014, 06:23:33 am by xumepoc »

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #1 on: March 26, 2014, 12:30:04 pm »
Any one? ;D ;D ;D

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: MFC and SFML Window problem
« Reply #2 on: March 26, 2014, 12:53:43 pm »
I highly doubt anyone is still seriously working with MFC...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #3 on: March 26, 2014, 03:42:14 pm »
Using MFC is not the problem here.

setSize() is not doing anything on the RenderWindow when set. I can't make it change.

The focus is also strange, because I can use all othe mouse functions, except the mouse wheel.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: MFC and SFML Window problem
« Reply #4 on: March 26, 2014, 04:56:31 pm »
setSize() works only on top-level windows.
Laurent Gomila - SFML developer

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #5 on: March 26, 2014, 05:12:36 pm »
So there is no way to resize the RenderWindow?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: MFC and SFML Window problem
« Reply #6 on: March 26, 2014, 06:15:44 pm »
If it is embedded inside a MFC control, you can resize the MFC control itself.
Laurent Gomila - SFML developer

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #7 on: March 26, 2014, 06:29:13 pm »
I am doing that, but it has no effect. I am passing a HWND from the CDialog in order to create the RenderWindow. I then resize the CDialog window and pass the size to the RenderWindow's setSize() too. The result it that the CDialog is resized, but the drawing "stops" in the old size of the RenderWindow.
« Last Edit: March 26, 2014, 06:34:19 pm by xumepoc »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: MFC and SFML Window problem
« Reply #8 on: March 26, 2014, 07:46:12 pm »
This is not supposed to happen, the SFML window should automatically adjust to the new size.
Laurent Gomila - SFML developer

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #9 on: March 26, 2014, 09:46:59 pm »
Well its either not working correctly or I am not doing it correctly. I will post a pseudo code tomorrow to show you what I am doing.

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: MFC and SFML Window problem
« Reply #10 on: March 26, 2014, 09:58:32 pm »
... I will post a pseudo code tomorrow to show you what I am doing.

Do better than that and post a "complete and minimal" example that shows the problem.
See these links:
 https://github.com/SFML/SFML/wiki/FAQ#tr-grl-minimal
 http://en.sfml-dev.org/forums/index.php?topic=5559.msg36368#msg36368

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #11 on: March 27, 2014, 06:08:28 am »
Wouldn't that will be a bit hard, because the problem is exactly in the use of CDialog and SFML, so it can't be as minimal as described in the links.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: MFC and SFML Window problem
« Reply #12 on: March 27, 2014, 07:53:58 am »
There's always a minimal code that reproduces the problem.

If all you need is a CDialog with a sf::RenderWindow inside, and call SetWindowPos on it, you won't need thousands of lines of code.
Laurent Gomila - SFML developer

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #13 on: March 27, 2014, 08:22:24 am »
Of course not, that is why I said I will post a pseudo code that will include only the relative parts of the program that are in connection to the problem.  ;)

xumepoc

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: MFC and SFML Window problem
« Reply #14 on: March 27, 2014, 08:53:39 am »
Here is the code sample, I am not including the CDialog in its full minimal form because it will take too much space, but I can create a minimalistic project and uploaded for anyone who wants to test it.
CDialog:

This is the defined _SFML variable
SFML_CL _SFML

This is the pseudo code of the main CDialog class
BOOL CClassTestsDlg::OnInitDialog()
{
 CDialog::OnInitDialog();

 FIRSTRESIZE = true;
 HWND hWND = GetSafeHwnd();

 _SFML.Initialize(hWND);

return TRUE;
}
void CClassTestsDlg::OnSize(UINT nType, int cx, int cy){
 if(FIRSTRESIZE){
      SetWindowPos(&CWnd::wndTopMost , 0, 0, 500, 500 ,SWP_SHOWWINDOW|SWP_NOZORDER );
      FIRSTRESIZE = false;
   }
 CDialog::OnSize(nType, cx, cy);
}
void CClassTestDlg::ChangeSize()
{
 SetWindowPos(&CWnd::wndTopMost ,0,0,700,700,SWP_SHOWWINDOW|SWP_NOZORDER);
}
 

SFML_CL:

#pragma once
#include <SFML/Graphics.hpp>


class SFML_CL
{
public:
        SFML_CL(void);
        virtual ~SFML_CL(void);
        void Initialize(HWND hWnd);
        void Render();

protected:
        HWND hWND;
        sf::RenderWindow *ttl2D;
     sf::Font font;
     COLORREF ColorBG;
};

SFML_CL::SFML_CL(void)
{
        ttl2D = NULL;
    ColorBG = RGB(90,90,90);
}

SFML_CL::~SFML_CL(void)
{
        delete ttl2D;
}
void SFML_CL::Initialize(HWND hWnd)
{
        hWND = hWnd;
        sf::ContextSettings ws;
        ws.antialiasingLevel = 8;

        ttl2D = new sf::RenderWindow( hWND,ws );
        ttl2D->setVerticalSyncEnabled(true);

        font.loadFromFile("res/Arial.otf");
}
void SFML_CL::Render()
{
        sf::Color color(GetRValue(ColorBG ),GetGValue(ColorBG ),GetBValue(ColorBG ),255);
        ttl2D->clear(color);

    sf::Text text;
        text.setCharacterSize(13);
        text.setColor(sf::Color::White);
        text.setPosition(20,80);

    CRect rect;
        GetClientRect(hWND,rect);
        CString fp;
        fp.Format("%d (%d : %d %d %d %d)",ttl2D->getSize().x,ttl2D->getSize().y,rect.left,rect.top,rect.Width(),rect.Height());
        text.setString(fp.GetBuffer());
        fp.ReleaseBuffer();
        text.setPosition(20,150);
        ttl2D->draw(text);

        ttl2D->display();
}

This will result in a constant values for ttl2D->getSize().x and ttl2D->getSize().y, but the rect coordinates will be updated accordingly
« Last Edit: March 27, 2014, 09:43:01 am by xumepoc »