Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

API-Call to change Color of Textbox

Posted on 1998-09-09
4
Medium Priority
?
360 Views
Last Modified: 2008-02-01
Hi,

I am calling a C++-Function from a Visual Basic App. From within the C++-Function I want to change the textcolor of a Textbox, which is placed in the VB-form. I give the hwnd of the textbox to the C++-function.
Can anyone please write me, which API-Function (SendMessage??) I have to use to change the textcolor.

Thanks,

Thomas Kramer
0
Comment
Question by:thomaskramer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 200 total points
ID: 1172345
You need to handle the WM_CTLCOLORSTATIC or WM_CTLCOLORTEXT messages.  Details follow.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1172346
When a static text or edit text window needs to paint itsself, it sends one of these messages to its parent window.  The DC that the window will paint with is passed in the parameters.  The parent window's handler code can alter this DC.  It can set the text color (SetTextColor()) and the background color (SetBkColor()).  It can return a handle to a brush that will be used to paint the background of the window.  Note that this brush is not deleted, so you should not be creating the brush on each call (This is s common mistake).

Let me know if you have questions.
0
 

Author Comment

by:thomaskramer
ID: 1172347
nietod, I am not really sure, how I can realize. Can you please give an example, how to change the color of the textbox from within the C++-Code.
Thanks
0
 
LVL 22

Expert Comment

by:nietod
ID: 1172348
What do you want to change?  the border?  the background?  the text?  
Is this a static text control?  (uneditable text, usually with no border) Or is this an edit box? (editable text).

The following example will produce a red background and green text in an edit box.

// declare brush global handle along with other globals somewhere.
HBRUSH RedBrush = CreateSolidBrush(RGB(255,0,0));

       *     *     *

// Inside the window procedure for the edit box's parent window, you need.
   case WM_CTLCOLOREDIT:
   {
      HDC DCHnd = (HDC *) wParam; // Get handle to DC to be used to draw control.
      SetTextColor(DCHnd,RGB(0,255,0)); // Set text to green.
      SetBkColor(DCHnd,RGB(255,0,0)); // Set background to red (might not be necessary, but I think it is).
      return RedBrush; // Return handle to brush to paint background with.
   }
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

598 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question