Results 1 to 5 of 5

Thread: SetBkColor API call

  1. #1

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    SetBkColor API call

    The "Setbkcolor" API call sets the back color of an object with the hwnd/hdc property like this

    Call Setbkcolor(command1.hwnd, RGB(34,54,123))

    This does not work. It does not change the color of my command button.

    Does anybody know why its not changing the color of my command button
    Baaaaaaaaah

  2. #2
    Member bizzyVB's Avatar
    Join Date
    Jun 2001
    Location
    Florida
    Posts
    38
    why are you using api? you have vb6, can't you just set the style to graphical and make the back color the color you want?

  3. #3
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    To start with, hWnd and hDC are two different things.
    hWnd is a window handle, and hDC is the handle to a device context.
    If a function needs a hDC, you can't just use the hWnd.
    If a control doesn't expose the hDC as a property, you can get it using the GetWindowDC function. If you use this function, you should use ReleaseDC as soon as you don't need the hDC anymore, otherwise your application will leak handles.

    But now we come to the real problem.
    Visual Basic does recreate the device context every time it draws the command button. Your backcolor change won't be persistent, VB changes it back to it's property settings.
    If all you want to do is to change the backcolor, I would suggest setting the backcolor property of the button (don't forget to change the style to graphical).

  4. #4
    Megatron
    Guest
    You don't even need API to change the backcolor. Change the Style property to Graphical then change the BackColor to whatever colour you want.

  5. #5

    Thread Starter
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    But..........

    OK, Actually I did not have vb installed at that time so I just guessed that it may the hwnd but even if i need hdc, i get the hdc of command button and it does not change the backcolor even if i give it correct parameters.

    If vb is not able to change the backcolor of the command button then will it work in C++?
    And is there any API call to change the forecolor(Setforecolor) or textcolor(SetTextColor) to change the text color on any object?
    Baaaaaaaaah

Posting Permissions

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



Click Here to Expand Forum to Full Width