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

Author Topic: Window Applications?  (Read 1239 times)

0 Members and 1 Guest are viewing this topic.

AF2013

  • Newbie
  • *
  • Posts: 4
    • View Profile
Window Applications?
« on: July 02, 2013, 12:46:06 am »
Hello everyone :)

I just starting doing SFML but I got stuck because I want window application instead of having console window that keep coming up every time I run the program

I get the error saying

WinMain must return a value

I am using Visual Studio express 2012

the code does work in Console Window but when I went to Project > SFML 2.0 Properties > Linker > System > Subsystem and I changed Console (/SUBSYSTEM:CONSOLE) TO Windows(/SUBSYSTEM:WINDOWS)

The code that I learn are blow

#include <SFML/Graphics.hpp>
#include <iostream>
#include <stdlib.h>
#include <ctime>

 
int main()
{

sf::RenderWindow Window(sf::VideoMode(800,600,32),"First SFML Game");

sf::Texture ptexture;
sf::Sprite playerImage;

if(!ptexture.loadFromFile("background.png"))
   std::cout << "Error could not load player image"<< std::endl;

playerImage.setTexture(ptexture);

sf::Vector2u Size(400,400);

Window.setSize(sf::Vector2u(400,400));
Window.setTitle("Coding Made Easy");
Window.setPosition(sf::Vector2i(200,100));


   while(Window.isOpen())
   {
      sf::Event Event;
       while(Window.pollEvent(Event))
   {
      if(Event.type==sf::Event::Closed)
         Window.close();
   }
    Window.clear(sf::Color(0, 255, 255));
   Window.draw(playerImage);
   Window.display();
}

}

Second Questions that does bugged me lots.....if you going start new applications and why does I have keep setting SFML every time i start my VS Express 2012.........Surely that Once I have setup SFML then it should stay there on every time i open the VS Express 2012 and do you know what I mean?

P.S. I just bought SFML Game Development book now on my Ipad :)

« Last Edit: July 02, 2013, 01:00:25 am by AF2013 »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10846
    • View Profile
    • development blog
    • Email
Re: Window Applications?
« Reply #1 on: July 02, 2013, 03:08:35 am »
The default setting of VS is /SUBSYSTEM:CONSOLE which uses the int main(...) as entrypoint. So everything works smoothly. But when changing to /SUBSYSTEM:WINDOWS the entrypoint changes as well to WinMain-something, but since that's Microsoft Windows specific and SFML aims to be cross-platform, it provides the library sfml-main, which you have to link against.

In short, if you use the windows subsystem you have to link against sfml-main.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/