I am trying to run Win32 app using SFML 1.6.
Here's the whole code:
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML\Graphics.hpp>
#include <Windows.h>
////////////////////////////////////////////////////////////
/// Function called whenever one of our windows receives a message
///
////////////////////////////////////////////////////////////
LRESULT CALLBACK OnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam)
{
switch (Message)
{
// Quit when we close the main window
case WM_CLOSE :
{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(Handle, Message, WParam, LParam);
}
////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \param Instance : Instance of the application
///
/// \return Error code
///
////////////////////////////////////////////////////////////
INT WINAPI WinMain(HINSTANCE Instance, HINSTANCE, LPSTR, INT)
{
// Define a class for our main window
WNDCLASS WindowClass;
WindowClass.style = 0;
WindowClass.lpfnWndProc = &OnEvent;
WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.hInstance = Instance;
WindowClass.hIcon = NULL;
WindowClass.hCursor = 0;
WindowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND);
WindowClass.lpszMenuName = NULL;
WindowClass.lpszClassName = TEXT("SFML App");
RegisterClass(&WindowClass);
// Let's create the main window
HWND Window = CreateWindow(TEXT("SFML App"), TEXT("SFML Win32"), WS_SYSMENU | WS_VISIBLE, 0, 0, 800, 600, NULL, NULL, Instance, NULL);
// Let's create two SFML views
HWND View1 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 0, 0, 800, 600, Window, NULL, Instance, NULL);
sf::RenderWindow SFMLView1(View1);
// Load images to display
sf::Image Image1;
Image1.LoadFromFile("image.png");
sf::Sprite Sprite1(Image1);
Sprite1.SetPosition(55,105);
// Loop until a WM_QUIT message is received
MSG Message;
Message.message = ~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
{
SFMLView1.Clear(sf::Color(0,0,0));
// Draw sprite 1 on view 1
SFMLView1.Draw(Sprite1);
// Display each view on screen
SFMLView1.Display();
}
}
// Destroy the main window
DestroyWindow(Window);
// Don't forget to unregister the window class
UnregisterClass(TEXT("SFML App"), Instance);
return EXIT_SUCCESS;
}
Though, I get memory access violation on this line:
Image1.LoadFromFile("image.png");
What could possibly be wrong?
@EDIT
Nevermind me! I forgot to use Win32 Application templace instead of console.
Though, I have another question. Do you know any tutorials on how to programitically use edit boxes/combo boxes/buttons and so on?