How does one write code to make drawings in the Windows main client area of a Win32 C++ app?
I found an example online that uses the "eclipse" API but when I put it in my program, the IDE complained so it would not compile.
Assuming you mean basic drawing (primitives, rendering bitmaps, stuff like that), then GDI and GDI+ are most likely what you want. I haven't used GDI+ much, but theForger's Win32 API tutorial will show you how to work with bitmaps. Drawing primitives is more GDI+ territory, and I can really only refer you to the MSDN GDI+ documentation for details of those functions.
If you're looking for game-type graphics, on the other hand, then you might need to research DirectX or OpenGL.
By using GDI and/or GDI+ functions in the WM_PAINT handler of the form.
Here is a site with some examples.
Related
I am interested in making a game trainer but I stumbled over the question of making a menu which the player can choose from. I am using C++ and my target client is windows based.
I searched around and people mostly use DirectX and hook into the game to draw (A little bit like the discord overlay) but I find it extremely difficult to use DirectX.
Here is an example I found:
I really like the way the SFML library draws but I can't seem to find any APIs which support that ease of drawing.
I once did manage to make a menu in C# by using System.Drawing to draw an external overlay which I could draw to using C#'s brush API, however I prefer to write in C++ as I feel I can do more in that language.
My question is:
Is the a way I could use something like the System.Drawing/SFML API to draw an overlay over another window in C++ (Which would be accessible in a console application)?
Is it easily portable (As a DLL or even including a header)? (Most of the solutions I have seen are not portable and/or widely supported)
Check out Qt for drawing images, text, etc.
http://doc.qt.io/qt-5/qtwidgets-painting-basicdrawing-example.html
It is widely supported, and also cross-platform
You can create a transparent window and use setWindowFlags(Qt::WindowStaysOnTopHint);
I already have a Direct3d device at my beck and call...
I am working on a Windows 8 modern UI application (Metro if you will)
What's the general technique of getting text drawn to the screen?
Extra points: Can I do 3d stuff with it too? This is what originally got me here as I started to do some direct2d thing then I thought, but how can I do 3d with direct2d... second of all the d2d create text functions require a handle to a window hwnd and there is no such thing (or it has been abstracted away) in windows 8 metro apps.
Anyone got any good examples or demos I can take a look at?
You should look into DirectWrite.
Regarding your second question you can render your text to a texture and then when you render that texture on screen do 3d stuff with it.
Rendering text with DirectWrite and Direct2D it's relatively simple, however, if you want something higher level, you can look into Drawing Library for Windows Store Apps, which wraps raw DirectX calls into some more GDI like.
I was wondering what is the difference between the windows that will render images on the screen (such as SDL, SFML or OpenGL) and the classic GUI window (with the gray background by default) where you can implement buttons like in Qt for C++ or AWT/Swing in Java?
What is going on in the background code? Are they the same type? Is there a rendering layer over the graphics window allowing to display such images?
Well first of all they are different APIs. SDL and SFML are libraries directed at making games and quite possibly other applications. OpenGL is a graphics API, it is not a full suite of libraries.
Note also that SFML pretty much uses OpenGL to render to the window. The actual window its self is created via platform specific functions. The Win32 API is used for windows and the X11 Window System is generally used on Linux.
The "classic GUI window" is pretty much the platform specific APIs. The differences in background code is really just defined by the purpose of the API. Note that in the end of the line Qt/SFML/SDL all go down to the platform specific API. OpenGL even requires you to interface with the platform specific API. SFML/SDL/QT essentially do the lower level work for you.
I hope I gave what you are looking for as this question really has a wide range of answers.
I am new to C++ and I would like to know what the limitations are in graphics for a console application. For example---Could I create something as compicated as some of the
very colorful screensavers that have all kinds of splashes of color?? Could I draw lines
of changing color based on input strings??? I would appreciate any advice someone could
give me.
Thanks Doug
If you want to do some serious animation you'll pribably want hardware accelerated graphics (DirectX, OpenGL). If you just want simple images and animations a GUI app would do. As far as the console it's not really intended for more than text output but it can draw lines and change colors if you really want too.
However none of the three are limitations of C++ ... C++ as a language does not care about graphics that would be an OS limitation primarily and you'll find most of your drawing code however you go about it will be somewhat OS or hardware dependent unless you use a cross platform library with GUI or graphics support like QT, wxWidgets, OpenGL, etc.
As others have said, a console application is for text, not graphics! I don't know of any way (or reason) to do graphics in a console.
To do the kinds of things you are interested in (except maybe Windows screensavers) using Visual C++, I would recommend starting off with the SDL library. The Lazy Foo Productions website has an excellent series of game programming tutorials, and the first lesson gives you a step-by-step guide to build an app that displays stuff on the screen. It even has screenshots showing how to configure Visual Studio 2010, which is pretty important if you're new to this kind of thing.
SDL is free, cross-platform, and will let you (within your program's window):
draw pixels, lines, and rectangles in any color
draw text
draw images
make animations (by changing/redrawing the screen many times per second)
obtain keyboard input (including when keys are released)
It will also let you do 3D graphics with OpenGL, but that's another story.
You could, if you're very desperate- but certainly not platform-independently. From memory, the Windows API is quite good about letting you do a lot of crazy shit to it's console. However, it's probably better advised to get a genuine graphical API for this purpose, such as GDI, DirectX or OpenGL.
C++ does not have any standard facilities for drawing graphics in a console application. Any features (like changing the font color) will depend on your OS. I doubt you will find functions that do much more than changing the text color though. (For example, on Windows you would use system("color xx") to change the foreground and background color.)
Basically, if you want graphics you're going to have to abandon the console application and look for a graphics API.
Could I create something as compicated as some of the very colorful screensavers that have all kinds of splashes of color??
If by "splash" you mean "chunk of text", then yes. Otherwise no.
Could I draw lines of changing color based on input strings???
No, consoles are textual media.
If you want to try to do things to the console you need to use the Windows Console Functions. Standard C++ does not have any way to change console color.
I'm writing a plugin in firebreath, C++.
I don't have any experience with both, so my question may be very basic.
How do I place a JPEG image inside my plugin window?
Or at least, how do I do it in C++ simple program?
Thanks,
RRR
There are a couple of other questions that may help you better understand this:
How to write a web browser plugin for IE, Firefox and Chrome
Directx control in browser plugin
Basically you'll get a drawing model from FireBreath with the AttachedEvent. Depending on your platform, you will draw to that window using platform-specific drawing APIs. On Windows, for example, you would get the HWND from the PluginWindow (cast it to a PluginWindowWin) and then draw to that. Just make sure you stop drawing when DetachedEvent shows up.
For more information, you'll need to be a lot more specific; but follow those links and do some reading, then you'll know better what questions to ask.
FireBreath 1.5.2 was just released, btw! Good luck!
Good luck!
You can also use OpenGL to display images in plugin. You can get several tutorials to load jpeg image in OpenGL as texture. Same code can be ported into the Firebreath plugin using the already given OpenGL sample plugin for windows. Though OpenGL context creation will vary from one OS to the other. If you want to load jpeg images from web, you'll have to download image before converting it into opengl texture.