CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2017
    Posts
    1

    C++ Create Simple Window

    //The first box appears, but then it stops after that. Please help, and thanks in advanced!

    Code:
    #include <iostream>
    #include <windows.h>
    using namespace std;
    
    const string title = "Diplomacy :: Version 0.01 :: Created by onlineone22";
    
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow)
    {
        int launch = MessageBox(NULL, "Would you like to launch Diplomacy?", title.c_str(), MB_YESNO);
    
        if(launch == IDYES)
        {
            CreateWindowEx
            (
                0,
                NULL,
                title.c_str(),
                WS_SYSMENU,
                CW_USEDEFAULT,
                CW_USEDEFAULT,
                445,
                445,
                HWND_DESKTOP,
                NULL,
                hInstance,
                NULL
            );
        }
    
        return 0;
    }
    Last edited by 2kaud; March 23rd, 2017 at 03:46 AM. Reason: Added code tags

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: C++ Create Simple Window

    Did you try to debug your code?
    Anyway, it looks like you just return from the WinMain after creating (or not creating) the window...
    Victor Nijegorodov

  3. #3
    Join Date
    Mar 2017
    Posts
    105
    You can do that by sfml graphics, its so simple:

    Just follow this syntax:

    RenderWindow windowname(Videomode(height,width), "Name to appear on the top")

    But for that you need to have sfml libraries on your computer.

    [Multiple posts merged into 1 post]
    Last edited by 2kaud; March 29th, 2017 at 08:28 AM. Reason: Posts merged

  4. #4
    Join Date
    Mar 2017
    Posts
    105

    Re: C++ Create Simple Window

    Do it like this :

    Code:

    Code:
    #include<iostream>
    #include<SFML/Graphics.hpp>
    
    using namespace std;
    using namespace sf; 
    
    int main()
    {
         cout << "Would you like to launch diplomacy?" << endl;
         char YESNO = '/0';
         do
    {
         RenderWindow window(VideoMode(445, 445), "Diplomacy :: version 0.01 :: Created by onlineone22);
         window.setFrameratelimit(60);
          window.clear();
           window.display();
    
    }while (YESNO == IDYES)
    
    return 0;
    }
    Last edited by A_Singh; April 1st, 2017 at 09:05 AM. Reason: Added code tags

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: C++ Create Simple Window

    As this simple test program doesn't contain the required sfml #include statement, I doubt it will compile. Also the YESNO variable isn't changed within the loop and the while condition is an assignment rather than an equality test.
    Last edited by 2kaud; March 29th, 2017 at 08:40 AM.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  6. #6
    Join Date
    Mar 2017
    Posts
    105

    Re: C++ Create Simple Window

    Oh sorry!

  7. #7
    Join Date
    Mar 2017
    Posts
    105

    Re: C++ Create Simple Window

    Now it will compile

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: C++ Create Simple Window

    CreateWindowEx just creates a window. To make it be alive and respond to user events, keyboard or mouse, you need to implement window procedure and spin up a message loop.
    Best regards,
    Igor

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured