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

Author Topic: Winapi edit box on sfml  (Read 5415 times)

0 Members and 1 Guest are viewing this topic.

Nobody

  • Newbie
  • *
  • Posts: 7
    • View Profile
Winapi edit box on sfml
« on: May 25, 2008, 04:12:15 pm »
Hi

I`ve read the Winapi Sfml turtorial.
In my project I want to use both. So I`ve loaded the background picture with sfml and I want to add the edit box and a button of Winapi on the picture.

There is nothing.
I took the handle of the sfml window View1 but notthing happened

Sorry, english is not my native language

Thank you

Code: [Select]

#include <SFML/Graphics.hpp>
#include <windows.h>

#define ID_ButtonStart  1

HWND Window;
HINSTANCE hInstance;
MSG Message;
HWND View1;

LRESULT CALLBACK OnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam);

INT WINAPI WinMain(HINSTANCE Instance, HINSTANCE, LPSTR, int Stil)
{
    // 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 = "SFML App";
    RegisterClass(&WindowClass);

    Instance=hInstance;

    // Let's create the main window
    Window = CreateWindow("SFML App", "SFML Win32", WS_SYSMENU | WS_VISIBLE, 500, 300, 300, 500, NULL, NULL, Instance, NULL);

    // Let's create two SFML views
    View1 = CreateWindow("STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,0,  0, 300, 500, Window, NULL, Instance, NULL);
    //HWND View2 = CreateWindow("STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 400, 100, 300, 400, Window, NULL, Instance, NULL);
    ShowWindow(Window,Stil);
    UpdateWindow(Window);


    sf::RenderWindow SFMLView1(View1);
    //sf::RenderWindow SFMLView2(View2);

    // Load images to display
    sf::Image Image1, Image2;
    if (!Image1.LoadFromFile("Resources\\mainbackground.jpg") || !Image2.LoadFromFile("image2.jpg"))
        return EXIT_FAILURE;
    sf::Sprite Sprite1(Image1);
    //sf::Sprite Sprite2(Image2);

    // Loop until a WM_QUIT message is received


    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
        {
            // Draw sprite 1 on view 1
            SFMLView1.Draw(Sprite1);


            // Draw sprite 2 on view 2
            //SFMLView2.Draw(Sprite2);

            // Display each view on screen
            SFMLView1.Display();
            //SFMLView2.Display();
        }
    }
    //return Message.wParam;


    // Destroy the main window
    DestroyWindow(Window);

    // Don't forget to unregister the window class
    UnregisterClass("SFML App", Instance);

    return EXIT_SUCCESS;
}

LRESULT CALLBACK OnEvent(HWND Handle, UINT Message, WPARAM WParam, LPARAM LParam)
{
    HWND hwndButtonStart,hwndButton1,hwndEdit;
    HDC hdc;
    RECT rect;
    PAINTSTRUCT ps;

    switch (Message)
    {
        case WM_CREATE:
        {
        hwndButtonStart = CreateWindow( "button",
                                   "starten",
                                   WS_CHILD | WS_VISIBLE,
                                   10,10,100,100,
                                   View1, (HMENU)ID_ButtonStart, hInstance, NULL) ;
        hwndButton1 = CreateWindow( TEXT("button"),
                        "Alle meine Entchen",
                        WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,
                        50, 50, 500, 100,
                        Window, NULL, hInstance,NULL);

          hwndEdit = CreateWindow ("EDIT","",
                         WS_CHILD | WS_VISIBLE | WS_BORDER |ES_MULTILINE ,
                         1, 0, 600, 100, View1, NULL,
                         hInstance, NULL) ;

        return 0;
        }


        case WM_PAINT:
            InvalidateRect(Window, &rect, TRUE);
            hdc = BeginPaint (Window, &ps) ;

            //SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT)) ;
            //SetBkMode (hdc, TRANSPARENT) ;

            TextOut (hdc, 400, 600, "Hallo", lstrlen ("Hallo")) ;

            EndPaint (Window, &ps) ;
            return 0 ;

        case WM_COMMAND:

            switch(WParam)
            {
            case ID_ButtonStart:
                    Beep(100,100);
                    return 0;
            }
            return 0;

        case WM_CLOSE :
        {
            PostQuitMessage(0);
            return 0;
        }
    }

    return DefWindowProc(Handle, Message, WParam, LParam);
}


Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Winapi edit box on sfml
« Reply #1 on: May 25, 2008, 05:20:55 pm »
Hmm, I'm not sure you can draw Windows controls on top of the SFML one.
Laurent Gomila - SFML developer

Nobody

  • Newbie
  • *
  • Posts: 7
    • View Profile
Winapi edit box on sfml
« Reply #2 on: May 25, 2008, 06:40:58 pm »
okay, I look for an option anyway

thanks
Do you know another way to use an editbox in sfml

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Winapi edit box on sfml
« Reply #3 on: May 25, 2008, 06:57:16 pm »
Why don't you use an OpenGL GUI, rather than a system one ? Take a look at projects like CeGUI or Guichan, they can be integrated to SFML very easily.
Laurent Gomila - SFML developer

 

anything