Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I know that win32 API is written in C language and also why Qt is portable?
Could someone explain this to me?
Because WinAPI was not designed to be portable as it targets only the Windows OS while the QT framework targets multiple OS-es. The fact that WinAPI was written in C does not make a difference.
The windows API is portable in the sense of being processor agnostic (indeed, it has run on many non-Intel processors over the years). It is not portable in the sense of being OS agnostic; although even there Microsoft's is not the only implementation of the API. The wine project has done a credible job of re-implementing the API for other platforms, to the point that windows binaries will run, at least on processors that match the binary.
The fact that the WinAPI is aimed at C makes no difference.
Just because the language is cross platform it does not mean the library (especially in the case of those like WinAPI which are not in the standard library) are the same.
It's just a library that interacts with the video card/processor to make a GUI on a very low level. At this point it is so low level the process depends more on memory locations or processor specific operations. IE saying that certain memory locations (specific to the OS) will reference a pixel on a screen ect.
The Win32API has been built so that it only "knows" the tasks for computers with Windows OS, libraries like QT, once again are still not truly "cross-platform" they have just been built to include all the relevant operations needed for each OS it covers.
Why is a rather open question; but here's my take on it:
Win32 API is produced by microsoft; which has commercial reasons for not being portable.
QT is open source; which was created with the sole intention to be portable.
Bonus:
X11 is open source; which was created with the idea that the machine displaying the images might not be the machine running the program that wants the window. Which makes it inherently non-portable to other APIs that don't (eg windows)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
clear a specific place on the Console by C++ 17 in vs2017, like this:
hello guys, I want to clear something, pls help me.
clear → want or clear → something else
Without refresh screen and using system("cls") or like these.
The C++11 standard (check some C++ reference site, then read the standard i.e. n3337) does not know about and does not mention screens. You can code C++ programs on computers without screens (e.g. web servers, embedded appliances, etc...), and notice that the standard output -e.g. std::cout - might not be a screen (think of redirections and pipelines), even on a laptop or desktop computer & OS (Windows, Linux, MacOSX, ...).
But many libraries might be useful to you. First, you can use OS specific libraries (e.g. WinAPI on Windows). You can also target a terminal emulator and use a library such as ncurses (or similar), and you might even output directly ANSI escape codes (I don't recommend this). And you could want to develop a GUI application with toolkits like Qt. You might even want to code a Web application (using HTTP server libraries like Wt or libonion, with more code in Javascript & HTML5).
I mentioned a few libraries, but you could find a lot more.
Be aware that terminals (and their emulators) are complex devices and their OS support is chaotic (for historical reasons). For POSIX and Unix read the Tty Demystified and see also termios(3). Have a glance at them even if you are using Windows, to feel how complex terminal emulators have to be.
In a comment, you mention "mouse". They are not known to the C++11 standard. My feeling is that an application handling the mouse should preferably provide a GUI (even if you could code a terminal application using the mouse thru other libraries or OS specific code), so I would recommend Qt (however, you might use some other GUI toolkit).
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Given that Java is highly portable and it is not having serious overheads, can't C++ be made platform independent?
Yes, it is perfectly possible. For example, you can compile C++ to JavaScript ( see https://softwareengineering.stackexchange.com/questions/197940/how-to-run-c-code-in-browser-using-asm-js ) or to CLI byte code ( https://en.wikipedia.org/wiki/C%2B%2B/CLI ) to run on Windows or Linux, or various other targets.
None of these currently performs as well as native C++, and most lack direct access to operating system resources. So the portability comes at some cost, and usually if you wanted to pay the cost of targeting web browsers or CLI, you have languages better suited to those platforms.
In reality, the method of code execution (whether the code is compiled, interpreted, run by VM, etc) is more a property of the implementation, and not the language.
when people say C++ is a compiled language and that JavaScript is an interpreted language, that does not necessarily mean that you can't write a compiler that translates JavaScript code to machine code on your hardware of choice, but rather what is a common way to provide implementation for said language.
In practice, C++ is used because of its efficiency and close to the metal features that is a good choice for performance critical tasks like embedded systems programming, systems programming, graphics, etc, so getting C++ to run in a VM would defeat its purpose.
kinda like buying a fillet Mignon and cooking it in the microwave.
Java compiles to an intermediate platform-independent byte code that is then interpreted at runtime by platform-specific JVMs. That is what allows Java to be portable. Each type of JVM is tailored to run the byte code on the platform's particular hardware architecture.
C/C++ compiles to native machine code that runs directly on the CPU (or as directly as the OS will allow). So no, you cannot compile C/C++ in a platform-independent manner. You have to use platform-specific compilers to compile C/C++ code for each hardware architecture that you want to run your code on.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have had numerous bad experiences with GUI library
so I would like to know how to create a window from scratch in c++
I am not talking about win32, what I mean is basically create it myself without any external library
is there any way to maybe use a picture or something to create a window
yes I know how hard this will be.
also I read somewhere that library could be made for c++ in assembly
is there a way to create a custom gui in assembly or c++
EDIT:
I am aiming at just windows
PS: another reason I want to learn how to do this is because
I might want to actually create an OS. so I would want GUI with that...
In order to create a window you'll need to interface with whatever windowing system is currently present on your operating system. This will either require system calls if the window manager runs in kernel space (as is the case in Windows) or some sort of interprocess communication for user space window managers (like X). To create the window from scratch, you'll need to read up on how these window managers work and what protocols they use. In the case of X, it shouldn't be too hard to find resources on how the protocol works. In the case of Windows, your only option might be to use the API, since the internals of the window manager are proprietary.
You could try perusing the source code to MenuetOS - I believe it's written entirely in assembly and it has a GUI. Of course, this won't work if you're trying to write a program that runs on Windows, Linux, etc. But if you want to avoid all external libraries, including interfacing with Windows, you will have to run on the bare metal.
If you are crazy enough to do this thing in assembly go ahead and install masm32 , it can do basic GUIs like windows/messageboxes etc.
You create a window "from scratch" on windows, by calling the "CreateWindowEx" Win32 API.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm looking for something to abstract the standard operating system functionality in C/C++: span/kill a thread, send/receive a message, start/stop a timer, maybe even memory management, although I can probably handle that myself with my own buffer pool.
I want to to be able to develop and unit test on Linux/windows and then recompile the c/c++ code for various target O/Ses (for embedded systems: eCos, FreeRTOS, VxWorks, etc)
Something as "light" as possible would be best, hopefully just a library, maybe even a collection of macros.
Have you looked at the Boost library? It has threads, timers, memory management, and a signals library.
The library is not a small download, but most of the library components are header-only implementations (though the OS abstraction libraries tend to have to be linked), and you only have to use what you need.
I keep a (long) list of OS Abstraction Libraries. Hope it helps.
Why don't you directly call only POSIX functions (POSIX1 seems to fill all your needs) and install a POSIX layer above non-compliant operating system (to be read as Microsoft Windows)?
I think boost is worth to look into; it can provide you an os abstraction, but also a compiler independence, and much, much more. It does require C++ of course. Other options: Posix.
In your list:
eCos, VxWorks, Linux : good posix support, so you can use this.
freertos: see link
Windows lacks good posix support out of the box (see wikipedia Posix)
If cygwin is ok for you, you can propably use it. If you need to mix with Visual Studio, a library like boost seems more interesting (you'd abstract away from it)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm looking for a minimal and easy to learn C or C++ cross platform gui library.
In a nutshell I only need the following functionality:
application window
menu bar
some simple dialogs, File-open and save. Maybe a user-written one.
user canvas where I can draw lines an circles on.
some kind of message/event loop mechanism.
Target platforms would be Win32 and linux. MacOS would be nice to have but is not important at the moment.
Why am I looking for something minimal? I don't want to spend much time to learn a big and full blown abstraction system for a really small application. The easier and leaner, the better.
Any suggestions?
If you need something small, try FLTK libs: I used them at work (embedded development) and I think it's a valid option. Maybe apps are not as "cool" as QT-based ones, but developing with FLTK libs is fast and easy.
I don't know about minimal, but Qt is pretty easy to learn.
Its light-weight enough to run on embedded devices, so you be the judge.
EDIT after seeing the comments:
Yes, Qt is a fullblown application framework, but here's my case: an app with cross platform GUI but other platform-dependent code is not really platform independent. I don't think moving existing C++ code into Qt entails any work at all. If anything, this would allow Nils to use his existing C++ code, and only use Qt for a GUI. But of course, I assume that the existing C++ code is portable.
wxWidgets (formerly wxWindows) is a widget toolkit for creating graphical user interfaces (GUIs) for cross-platform applications. wxWidgets enables a program's GUI code to compile and run on several computer platforms with minimal or no code changes. It covers systems such as Microsoft Windows, Mac OS X, Linux/Unix (X11, Motif, and GTK+), OpenVMS, OS/2 and AmigaOS. A version for embedded systems is under development.
http://www.wxwidgets.org/
See Good C++ GUI library for Windows for relevant answers.
Personally, I would go with Qt, now that it's open. You don't necessarily want a minimal library, you want one that is easy to use, and quality documentation and community support will give you just that.
Small projects have the nasty habit of sticking around and picking up scope -- as things get hairier, you don't want to be stuck with some small library that nobody knows about.