I'm trying to frame a window using GDI+ Graphics class in OnPaint(). Since DrawPath() function requires GraphicsPath, Is there a way to get GraphicsPath of a window ?
Why not use DrawRectangle(Pen*,Rect&) instead. It only requires a rectangle and you can easily get that with GetClientRect().
Related
Is it possible to disable a window resize created with opengl using c++? I'm looking for this because I'm trying to draw a graph and the letters in the scale (or title) will have their position changed after a resize.
That can't be done in OpenGL without a windowing API. Using GLUT, you can call glutReshapeWindow in the reshape callback to reset the size when the user tries to change it. Alternatively, if you don't need it windowed, go fullscreen via glutFullScreen to stop the user from reshaping the window.
As far as I know that's the only portable way to do it.
Hope this helps.
I need to save image of my DrawingArea object to Bitmap, but I can't find how to do it. Can anybody tell, how save DrawingArea image to Bitmap?
There are a few ways to do this, it depends exactly what you want to do and whether/why you really need a System.Drawing.Bitmap.
Copy the Widget
You can P/Invoke gtk_widget_get_snapshot to get a Gdk.Pixbuf.
The Pixbuf can be can be saved into a a file, or copied into a System.Drawing.Bitmap.
Using System.Drawing
You could port your drawing code to the System.Drawing API.
In your DrawingArea's Expose method, use Gtk.DotNet.Graphics.FromDrawable to get a System.Drawing.Graphics for your widget and draw onto that using your ported drawing code.
Then, you can create a System.Drawing.Bitmap and use the same drawing code to draw to it.
Using Cairo
You could port your drawing code to Mono.Cairo (the new GTK# drawing APIs, which are much more powerful than System.Drawing).
In your DrawingArea's Expose method, use Gdk.CairoHelper.Create to get a Cairo context for your widget and draw onto that using your ported drawing code.
Then, you can use your Cairo drawing logic to write to a Cairo ImageSurface, which can be saved into a a file, or copied into a System.Drawing.Bitmap.
If you create a window by using SDL_SetVideoMode(), you are returned a surface, not a window handle. Is there a way to get the SDL_Window handle? I know there is a SDL_GetWindowFromID function, but I'm also not sure how to get the ID, other than the SDL_GetWindowID function, which would require me to already have the window handle.
Any suggestions? Note that it is very important that I maintain cross platform portability, so I prefer to stick with built in SDL functionality if at all possible.
If it helps any, I'm trying to get and set the window position and window size, and those functions require a window handle.
Thanks!
EDIT: I should mention also that I am changing video modes at the user's request, so I cannot just use the default ID of 1, since this ID changes every time I call SDL_SetVideoMode().
I had the same problem with SDL-1.2.15 for windows ,but the problem solved by GetActiveWindow.
You can get SDL window handle like this :
...
screen = SDL_SetVideoMode(w, h, 0, flags);
...
HWND hnd= GetActiveWindow();
See this :
GetActiveWindow function
I had this exact problem - old SDL 1.2 only uses one window, so it keeps the handle to itself. Here's the method I found from reading the source code:
Include SDL_syswm.h then get the window handle using SDL_GetWMInfo
e.g. my code for getting the handle in Windows:
SDL_SysWMinfo wmInfo;
SDL_GetWMInfo(&wmInfo);
HWND window = wmInfo.window;
SDL_SetVideoMode returns a surface based on the video frame buffer, not on a window (just like SDL_GetVideoSurface). You seem to assume that all surfaces correspond to windows, but that is not the case.
I am trying to create a custom CStatic control in vc++ and have a few problems.
I originally was just using a CStatic control with the SS_BLACKRECT style. This was good for the situation until I needed to display an image over the control on demand.
I figured out all the logistics behind actually drawing the image onto the control but I cant seem to figure out how to do so without interfering with other things.
Basically I want the control to function as a normal CStatic with the SS_BLACKRECT style most of the time.
Then I need to be able to call a method that will cause it to draw an image over the control instead. I am doing the drawing using GDI and have tried it both in the OnPaint() method and the DrawItem() method without success. I can get it to draw in the OnPaint() but when I call the base CStatic::OnPaint() it draws over my image.
I need to be able to allow it to draw like normal but then just throw an image in on top. When I tried to do it in the DrawItem() method I had a problem because obviously it was not drawing using the SS_BLACKRECT style but waiting for me to draw the control like its supposed to.
I guess what I think I'm looking for is one of three things. A way to draw using GDI after the base OnPaint() method finishes. A way to have the control draw the default SS_BLACKRECT style and then OWNERDRAW the image afterwards. Or the code to mimic the drawing of SS_BLACKRECT.
The last one might be the easiest but I just don't know all the things I need to set up to draw a CStatic control like the default DrawItem.
Try calling Default() in your OnPaint() handler.
Then, depending on whether you're drawing your image, you can then draw over the top of the standard CStatic control.
Here's a couple ideas:
If CStatic::OnPaint() draws over your image, then try calling it first and drawing your image afterwards.
Otherwise, from what little I've seen of SS_BLACKRECT, you should be able to replicate it's drawing simply be calling CDC::FillSolidRect() passing the rectangle of your control obtained through GetClientRect() and using the color returned by GetSysColor(COLOR_WINDOWFRAME)
I'm creating a non-intrusive popup window to notify the user when processing a time-consuming operation. At the moment I'm setting its transparency by calling SetLayeredWindowAttributes which gives me a reasonable result:
alt text http://img6.imageshack.us/img6/3144/transparentn.jpg
However I'd like the text and close button to appear opaque (it doesn't quite look right with white text) while keeping the background transparent - is there a way of doing this?
In order to do "proper" alpha in a layered window you need to supply the window manager with a PARGB bitmap by a call to UpdateLayeredWindow.
The cleanest way to achieve this that I know of is the following:
Create a GDI+ Bitmap object with the PixelFormat32bppPARGB pixel format.
Create a Graphics object to draw in this Bitmap object.
Do all your drawing into this object using GDI+.
Destroy the Graphics object created in step 2.
Call the GetHBITMAP method on the Bitmap object to get a Windows HBITMAP.
Destroy the Bitmap object.
Create a memory DC using CreateCompatibleDC and select the HBITMAP from step 5 into it.
Call UpdateLayeredWindow using the memory DC as a source.
Select previous bitmap and delete the memory DC.
Destroy the HBITMAP created in step 5.
This method should allow you to control the alpha channel of everything that is drawn: transparent for the background, opaque for the text and button.
Also, since you are going to be outputting text, I recommend that you call SystemParametersInfo to get the default antialiasing setting (SPI_GETFONTSMOOTHING), and then the SetTextRenderingHint on the Graphics object to set the antialiasing type to the same type that is configured by the user, for a nicer look.
I suspect you'll need two top level windows rather than one - one that has the alpha blend and a second that is display above the first with the opaque text and button but with a transparent background. To accomplish this with a single window you'll need to use the UpdateLayeredWindow API call, but using this will cause your buttons to not redraw when they are interacted with (hover highlights, focus etc.)
It is possible that if this application is for Vista only there is a new API call that you can use, but I do not believe it is available in XP or earlier.
I can't say for sure, you'll need to try it, but since everything is a window, you could try setting the layered attributes for your button to make it opaque.
As for the text, you may be able to put that in its own frame with a set background and foreground color, and modify its layered attributes to make the background color transparent...
But since these are child windows and not the top-level window, I really don't know that it'll work.