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 - djlynn03

Pages: [1]
1
General / Re: Application becomes unresponsive on focus change
« on: March 30, 2022, 10:03:22 pm »
Issue is fixed. I removed my custom window code and now it all works as expected.

2
General / Re: Application becomes unresponsive on focus change
« on: March 30, 2022, 07:20:12 pm »
The problem with using a debugger is that the program only crashes when I run it as an executable, and works fine when I am in Visual Studio. I do not have a reason for creating my own window, the project just sort of ended up that way. I will switch my custom window code to SFML and see if it makes a difference. It could be a problem with the SFML window not receiving the events because of the custom window.

3
General / [SOLVED] Application becomes unresponsive on focus change
« on: March 29, 2022, 10:28:03 pm »
I am creating an application to display a slideshow of images. My application starts and runs successfully, but when I click somewhere else on my screen and change the window focus, the app becomes unresponsive. I am unsure if it is a problem with my event loop or something else.

Below is my main function and I have my event loop inside the main loop.
int WINAPI WinMain(
    _In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPSTR     lpCmdLine,
    _In_ int       nCmdShow
)
{

    EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, 0);

    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = WndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = szWindowClass;
    wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);


    if (!RegisterClassEx(&wcex))
    {
        MessageBox(NULL,
            _T("Call to RegisterClassEx failed!"),
            _T(""),
            NULL);

        return 1;
    }

    hInst = hInstance;

    HWND hWnd = createWindow(hInst);

    DWORD Style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
    HWND View1 = CreateWindow(L"STATIC", NULL, Style, 0, 0, windowWidth, windowHeight, hWnd, NULL, hInst, NULL);

    SFMLView1.create(View1);
    SFMLView1.setMouseCursorVisible(false);
    SFMLView1.setFramerateLimit(10);
    SFMLView1.setVerticalSyncEnabled(true);

    if (!hWnd)
    {
        MessageBox(NULL,
            _T("Call to CreateWindow failed!"),
            _T(""),
            NULL);

        return 1;
    }

    DEVMODE fullscreenSettings;
    bool isChangeSuccessful;

    EnumDisplaySettings(NULL, 0, &fullscreenSettings);
    fullscreenSettings.dmPelsWidth = 1080;
    fullscreenSettings.dmPelsHeight = 720;
    fullscreenSettings.dmBitsPerPel = 8;
    fullscreenSettings.dmDisplayFrequency = 30;
    fullscreenSettings.dmFields = DM_PELSWIDTH |
        DM_PELSHEIGHT |
        DM_BITSPERPEL |
        DM_DISPLAYFREQUENCY;

    SetWindowLongPtr(hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST);
    SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
    SetWindowPos(hWnd, HWND_BOTTOM, windowX, windowY, windowWidth, windowHeight, SWP_SHOWWINDOW); // Z-order set to the bottom so other windows can be displayed above it
    isChangeSuccessful = ChangeDisplaySettings(&fullscreenSettings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
    ShowWindow(hWnd, SW_MAXIMIZE);

    DWORD dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
    dwExStyle &= ~WS_EX_APPWINDOW;
    dwExStyle |= WS_EX_TOOLWINDOW;
    SetWindowLong(hWnd, GWL_EXSTYLE, dwExStyle);

    ShowWindow(hWnd,
        nCmdShow);
    UpdateWindow(hWnd);

    std::vector<std::string> imagePaths = populateImages(hWnd);
    if (imagePaths.size() == 0) {
        exit(2);
    }

    std::cout << imagePaths.at(0) << "\n";

    //MSG msg;
    int index = 0;

    sf::Image image;
 
    sf::FileInputStream stream;
    sf::Texture texture;

    sf::Vector2f targetSize(windowWidth, windowHeight);

    std::vector<sf::Sprite> sprites;

    sf::Sprite sprite;
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);

    while (SFMLView1.isOpen()) {
        sf::Event event;
        while (SFMLView1.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                SFMLView1.close();
        }

        stream.open(imagePaths.at(index));
        texture.loadFromStream(stream);

        sf::Sprite sprite(texture);

        sprite.setScale(
            targetSize.x / sprite.getLocalBounds().width,
            targetSize.y / sprite.getLocalBounds().height
        );

        SFMLView1.clear();
        SFMLView1.draw(sprite);
        SFMLView1.display();

        if (index == imagePaths.size() - 1) {
            index = 0;
        }
        else {
            index += 1;
        }
        std::this_thread::sleep_for(std::chrono::seconds(2));
    }
    return 0;
}

Thanks

4
Window / Re: Window freezes when not moused over
« on: March 10, 2022, 11:52:27 pm »
I removed the event handler and the reference to it in the main loop and it started working correctly.

5
Window / Window freezes when not moused over
« on: March 09, 2022, 08:21:10 pm »
Hello everyone,
I am creating a image slideshow application, and after running for a few cycles, the slideshow stops until I move my mouse over the window. When I move my mouse over the window, sometimes it runs another cycle and sometimes it only moves to the next image. I would like it to continue running indefinitely and change images after a second.

My main function looks like this:
int WINAPI WinMain(
    _In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPSTR     lpCmdLine,
    _In_ int       nCmdShow
)
{
    AllocConsole();
    freopen("CONOUT$", "w", stdout);
    freopen("CONOUT$", "w", stderr);

    EnumDisplayMonitors(NULL, NULL, MyInfoEnumProc, 0);

    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc = WndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(wcex.hInstance, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = szWindowClass;
    wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);


    if (!RegisterClassEx(&wcex))
    {
        MessageBox(NULL,
            _T("Call to RegisterClassEx failed!"),
            _T(""),
            NULL);

        return 1;
    }

    hInst = hInstance;

    HWND hWnd = createWindow(hInst);

    DWORD Style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
    HWND View1 = CreateWindow(L"STATIC", NULL, Style, 0, 0, windowWidth, windowHeight, hWnd, NULL, hInst, NULL);

    SFMLView1.create(View1);
    SFMLView1.setMouseCursorVisible(false);

    if (!hWnd)
    {
        MessageBox(NULL,
            _T("Call to CreateWindow failed!"),
            _T(""),
            NULL);

        return 1;
    }

    DEVMODE fullscreenSettings;
    bool isChangeSuccessful;

    EnumDisplaySettings(NULL, 0, &fullscreenSettings);
    fullscreenSettings.dmPelsWidth = 1080;
    fullscreenSettings.dmPelsHeight = 720;
    fullscreenSettings.dmBitsPerPel = 8;
    fullscreenSettings.dmDisplayFrequency = 30;
    fullscreenSettings.dmFields = DM_PELSWIDTH |
        DM_PELSHEIGHT |
        DM_BITSPERPEL |
        DM_DISPLAYFREQUENCY;

    SetWindowLongPtr(hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST);
    SetWindowLongPtr(hWnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
    SetWindowPos(hWnd, HWND_BOTTOM, windowX, windowY, windowWidth, windowHeight, SWP_SHOWWINDOW); // Z-order set to the bottom so other windows can be displayed above it
    isChangeSuccessful = ChangeDisplaySettings(&fullscreenSettings, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
    ShowWindow(hWnd, SW_MAXIMIZE);

    DWORD dwExStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
    dwExStyle &= ~WS_EX_APPWINDOW;
    dwExStyle |= WS_EX_TOOLWINDOW;
    SetWindowLong(hWnd, GWL_EXSTYLE, dwExStyle);

    ShowWindow(hWnd,
        nCmdShow);
    UpdateWindow(hWnd);

    std::string path = "\\";
    std::vector<std::string> imagePaths;

    for (const auto& entry : fs::directory_iterator(path))
    {
        if ((lastN(entry.path().string(), 3) == std::string{ "png" } || lastN(entry.path().string(), 3) == std::string{ "jpg" } || lastN(entry.path().string(), 3) == std::string{ "bmp" })
            && entry.exists() && entry.file_size() > 0)
        {
           
            imagePaths.push_back(entry.path().string());
        }
    }
    std::cout << imagePaths.at(0) << "\n";

    MSG msg;
    int index = 0;

    sf::Image image;
 
    sf::FileInputStream stream;
    sf::Texture texture;

    sf::Vector2f targetSize(windowWidth, windowHeight);

    while (1) {
        if (GetMessage(&msg, NULL, 0, 0) > 0) {
            std::cout << &msg << "\n";
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        stream.open(imagePaths.at(index));
        texture.loadFromStream(stream);


        sf::Sprite sprite(texture);

        sprite.setScale(
            targetSize.x / sprite.getLocalBounds().width,
            targetSize.y / sprite.getLocalBounds().height
        );

        SFMLView1.clear();
        SFMLView1.draw(sprite);
        SFMLView1.display();

        if (index == imagePaths.size() - 1) {
            index = 0;
        }
        else {
            index += 1;
        }
        std::this_thread::sleep_for(std::chrono::seconds(1));
    }
    return (int)msg.wParam;
}
 

It appears to get hung up during my main loop. The images are all accessed correctly, because it is able to cycle through all of them a few times before it gets hung up. Any help would be greatly appreciated.


Pages: [1]
anything