how to create a round/circular button in win32 API using visual c++ - api

I have a Window (Win32 API) Application in Visual C++. I am not using MFC. I have to create a round/circular button with bitmap image. My application have a skinned view. Can any one help me out in achieving this task.

Buttons are windows. You can create a button with the CreateWindow or CreateWindowEx call:
-http://msdn.microsoft.com/en-us/library/ms632680(VS.85).aspx
When you create your button window ensure that you pass the BS_OWNDERDRAW style:
-http://msdn.microsoft.com/en-us/library/bb775951(VS.85).aspx
That will tell the button to send WM_DRAWITEM messages to your buttons' WNDPROC:
-http://msdn.microsoft.com/en-us/library/bb775923(v=VS.85).aspx
In your buttons' WNDPROC you would handle the WM_DRAWITEM message and paint your button according to the information in the DRAWITEMSTRUCT received as a pointer in lParam.
To render a bitmap as anything but rectangular you will need to provide a 1-bit bitmask bitmap the same size as the bitmap you wish to render for your button. The bitmask has bits set where you want the pixels in your button bitmap to be set on the screen. The pixels in your button bitmap that do not display need to be black. Bitblt your bitmask bitmap to the screen with the AND operator then OR your button bitmap. Of course you will need to account for the various button states (normally a push button is only two states.)
I may have mixed the black/white or set/unset bits in the explanation above, but the AND / OR bitwise (SRCAND/SRCPAINT) Raster Operations are the correct operations for what you are trying to acheive.
-http://msdn.microsoft.com/en-us/library/aa930997.aspx
Hope that helps.

You can google to find techniques for BitBlting images using memory DC and various ROP2 settings to achieve a masking effect. Your round image that represents the button would use a specific color to represent transparency. I don't have the specific code at hand but it is non-trivial.

The key api call you need to know is SetWindowRgn. This is what you call to tell windows that the the window is not rectangular but an irregular region. If you google around for that, you will find lots of sample code.
One promising example is this project. It does depend on MFC, but you can use it to learn what you need to call in what order to get the desired effect.

Related

How to track the location of a window belonging to another app

When screen sharing a specific window on macOS with Zoom or Skype/Teams, they draw a red or green highlight border around that window (which belongs to a different application) to indicate it is being shared. The border is following the target window in real time, with resizing, z-order changes etc.
See example:
What macOS APIs and techniques might be used to achieve this effect?
You can find the location of windows using CGWindowListCopyWindowInfo and related API, which is available to Sandboxed apps.
This is a very fast and efficient API, fast enough to be polled. The SonOfGrab sample code is great platform to try out this stuff.
You can also install a global event tap using +[NSEvent addGlobalMonitorForEventsMatchingMask:handler:] (available in sandbox) to track mouse down, drag and mouse up events and then you can respond immediately whenever the user starts or releases a drag. This way your response will be snappy.
(Drawing a border would be done by creating your own transparent window, slightly larger than, and at the same window layer as, the window you are tracking. And then simply draw a pretty green box into it. I'm not exactly sure about setting the z-order. The details of this part would be best as a separate question.)

How would I create a visual simulation in C++/CLI within a panel? (What libraries?)

Using C++/CLI on Visual Studio I want to create a 2D simulation, with the options to change the user's inputs on one side of the screen and the simulation on the other side. (The user's inputs would be used to calculate what to draw for the simulation)
I would like to be able to do this within a panel/fixed region keeping the drawing separate from UI elements (buttons etc). Essentially I would like to draw multiple dots on the screen and the position of those dots changes every second. Trouble is all the examples of of drawing I've seen take up the whole form.
What libraries and how can I use to create multiple 2D drawings either by controlling the colours of pixels or any other way inside a fixed region like a panel?
This really depends on what GUI toolkit you're using.
If you're using WinForms, create a control and override the OnPaint method.
If you're using WPF, I'd use WritableBitmap.
There are other methods for both toolkits, of course, but those are the ones I would use. Plus there's things like DirectX and OpenGL, but it sounds like you want something simple, so those would probably be overkill.

Better way of defining several clickable area in a single large image in Corona SDK

I have a large image background with several areas or objects in the images which can be clicked and an event is triggered. The method I'm currently using to accomplish this is by slicing the images of objects and area and positioning them over the background image and assigning a click handler to them.
This works for the moment but I feel that there should be a better way of doing this. One way I thought and tried is to fill the sliced images with black or white, position them over the background image, make their opacity 0, make them hit testable and assign a click handler.
Does this method have advantage over the previous one? Does making an image object transparent use less texture memory or is it the same?
And are there other better ways to do so? My main objective is about making the game use less texture memory and cutting the overall project file size by using less of those sliced images.
Use display.newRect/newCircle to mark down area, make them transparent and hit testable.
This should be more efficient than using images.

How to create a swanky SurfaceSlider

I am new to surface programming and stumbled upon this Image which I understand is a slider control on a tag visualization (in this case a card). This slider is
curved as opposed to conventional straight track
has a bigger thumb which displays the current position (thus eliminating the need of a separate label)
has a glowing feel (I understand this is due to overlapping controls with different blur radius)
Can anyone help with how to make such control.
-V
This is a custom-built control rather than a standard SurfaceSlider. It's not build using TagVisualizer either but that's only because the app that this picture shows was built ~2 years prior to TagVisualizer existing.
Now you should certainly use TagVisualizer to streamline an implementation of this but you'll still have to create a custom slider control - SurfaceSlider will not be a good fit because it assumes that the user is moving their finger linearly.
Within your custom arching slider control, you can use SurfaceThumb (which SurfaceSlider itself uses) to get the big glowing thumb... then just needs to listen to the Delta events on the thumb and move it along the constrained path as appropriate.

Using System.Drawing to make a selection tool, and cropping an image in vb.net

If i wanted to crop an image in VB.net, how would I go about doing it? I am trying to let the user drag out the box they want (system.drawing.rectangle), and it will automatically remove the edges surrounding the box.
My first problem is primarily the fact that I cannot make the system.drawing.rectangle visible. It is not displaying at all, I am setting its location and height programmatically, but nothing is showing up. I know there is probably something fairly obvious I am missing...but I cannot seem to find it.
My larger issue, however, lies with the cropping itself. I cannot find any crop methods, at all. Is there a hidden one I am missing? Or must I code it myself? How would I go about doing this? It ought to be able to output to a bitmap image object.
Thanks for the help, I am surprised this hasn't been asked on here before....
Regarding your first problem: a Rectangle isn't by itself visible. You have to draw it on your canvas using the Graphics object's DrawRectangle(...) method. For drawing a selection tool, you'll want to set your Pen object's DashCap and DashPattern properties.
To "crop" an image, you basically want to take the portion of a larger image delineated by a smaller Rectangle, and turn it into a new Bitmap. This can be done using one of the 30 overloads of the Graphics object's DrawImage(...) method. You can either keep the cropped portion in its original dimensions (resulting in a smaller Bitmap than your original), or you can "blow it up" to something like the original image's size. If you do the latter approach, it is usually a good idea to set your Graphics object's InterpolationMode property to HighQualityBicubic (I think that's the one, anyway), since the default InterpolationMode is pretty crappy.
There are a number of different ways of rendering images in .Net - it might help if you posted some of your code, along with an explanation of the exact problems you're running into.
Here is another answer with a link to a sample app (and source code in C#, sorry) that may help you get started.
There are a number of articles on these topics on CodeProject:
Pick your favorite flavor (though I encourage you to check out the C# projects - it shouldn't be too hard to convert).
VB
Image Cropping with Image Resizing Using vb.net
C#
Cropping Images
An Easy to Use Image Resizing and Cropping Control
Image Processing using C# (see the Cropping section - I was able to use this code in one of my projects)
WPF/C#
WPF Interactive Image Cropping Control
A Photoshop-like Cropping Adorner for WPF