I have always wanted to start creating a simple window from scratch in C++ but the only results I've found on the internet are either using the Win32 API, DirectX or OpenGL. I want to make it without any of those APIs. Also would Win32 be compatible with other operating systems other than Windows. I want to make one program that is compatible with all operating systems that doesn't use any API except from plain C++ that creates a window.
-
3Use a crossplatform framework such as Qt?– UnholySheepOct 7, 2016 at 20:18
-
2You may try cross compilable UI systems like Qt. "except from plane c++" assumed you're asking for plain c++, there's no language standard for UI (yet).– πάντα ῥεῖOct 7, 2016 at 20:18
-
@πάνταῥεῖ: Maybe there's a dialect of C++ for aviation use. ;v)– Fred LarsonOct 7, 2016 at 20:22
-
@FredLarson I doubt so. The staff is all ill anyways right now.– πάντα ῥεῖOct 7, 2016 at 20:25
-
avoiding win32? if you're on windows use mfc which is in fact outer layer of win32. however you can use QT as cross platform– Raindrop7Oct 7, 2016 at 20:33
2 Answers
I think you misunderstand the purpose of these APIs. You cannot simply make a window in "Plain C++". Ultimately, this task requires co-ordination with the operating system (Windows) or a window manager that sits on top of the operating system. The only way you can co-ordinate with the OS is by using the APIs it provides (On Windows, Win32 does exactly this).
If you are striving for portable code that will be able to display windows on many platforms, you can use a library like the Qt framework, wxWidgets, or any other such cross-platform GUI library. These libraries will communicate with the OS and/or window manager on your behalf. They will wrap up all the different Windows/Mac/Linux APIs for creating and displaying windows and will give you one consistent and relatively easy to use API that works on all platforms. Underneath, they will use the API for the platform the application was compiled for.
On Windows, you can't avoid the Win32 API if you want to create a window. Everything you use will ultimately be using Win32 API calls to create your window for you.
That said, use a good graphics library or GUI library to create the window you want. I personally recommend Allegro 5 (http://liballeg.org), but you can also use SDL, SFML, ClanLib, Qt, WxWidgets, or any of many other libraries to create a window for you.
In Allegro 5, creating and displaying a window is as simple as :
#include "allegro5/allegro.h"
int main(int argc , char** argv) {
if (!al_init()) {return -1;}
ALLEGRO_DISPLAY* display = al_create_display(800,600);
if (!display) {return -2;}
al_clear_to_color(al_map_rgb(255,255,255));
al_flip_display();
al_rest(5.0);
return 0;
}