dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17

Thread: Changing the color of elements - Win API

  1. #16
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,589

    Re: Changing the color of elements - Win API

    Quote Originally Posted by binary2 View Post
    For creating a filled rectangle I have this code:

    Code:
          hdc=CreateDC(TEXT("DISPLAY"),NULL,NULL,NULL);
            rect = {0, 0, 500,500};
            brush = CreateSolidBrush(RGB(50, 151, 151));
            FillRect(hdc, &rect, brush);
            DeleteObject(brush);
    This goes in "case WM_CREATE:"

    The problem is that the rectangle is created at x = 0, y = 0 relative to the screen instead of the window
    You might use a "control" approach instead and place an empty border-less custom-colored static control on the main window for achieving exactly the same result. A zero-cost benefit would be no need in playing with screen-to-window coordinate translation.
    Last edited by Igor Vartanov; July 23rd, 2018 at 02:35 AM.
    Best regards,
    Igor

  2. #17
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,589

    Re: Changing the color of elements - Win API

    Quote Originally Posted by binary2 View Post
    Thank you!

    Is there a way to set a border color and style to a "static" control? I'm interested in applying a dotted border to the top and bottom of the control
    Bitmap-based brush might help. Please note that you are to draw the bitmap with the entire control border, including all the style effects, e.g. bevels, round corners, etc.

    Per my experience, classic Windows controls like button, edit box, static, etc. are real stubborn things and PITA to customize. Sometimes it's simpler to implement a your own control from scratch than subclass any of the native old-school Windows controls.
    Best regards,
    Igor

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)