Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

(1) Check whether you are using GDI or GDI+. (2) In case you are using GDI, here is the documentation for the function you can use to paint a rectangle (but not filling the inside with color):

BOOL Rectangle( HDC hdc, int left, int top, int right, int bottom );

https://docs.microsoft.com/en-us/windows/desktop/api/Wingdi/nf-wingdi-rectangle

Example usage:

https://stackoverflow.com/questions/16159127/win32-how-to-draw-a-rectangle-around-a-text-string

To confirm that your application uses GDI, search your source code for a data type called HDC. This data type is a Handle to a Device Context.

Selecting the color and thickness for the rectangle border is slightly complicated in GDI programming. You need to create a GDI Pen object with the color and thickness, then temporarily swap (or "select", which is a terminology with special meaning in GDI) your Pen with the currently-in-use Pen in the HDC, then issue the Rectangle command to the HDC, and finally restore the original Pen object.

It is best to get a book "GDI programming with Windows 32 API". Without a book, it is hard to learn.