|
Hi all,
I need to paint the background of a CStatic control created dynamically this way:
CUnknownCtrl* pUnknown;
pUnknown = new CUnknownCtrl;
pUnknown->Create("Text", SS_CENTER | WS_CHILD | WS_VISIBLE | WS_GROUP, CRect(11,35,360,526), this, 0x31);
Notice that CUnknownCtrl is a CStatic-derived mfc class.
I can't figure out how to set background color of the label created with this code, someone can help me?
Calling OnCtlColor inside CUnknownCtrl won't even be executed and OnPaint fails. Some idea?
Thanks for advance
---
|
|
|
|
|
Hi,
Simply handle the WM_CTLCOLORSTATIC message in your class. The WM_CTLCOLORSTATIC is send to a static control when its background color need to drawn.
thanks.
Nitheesh
|
|
|
|
|
WM_CTLCOLORSTATIC is sent to the parent window of the static control, not the static control itself.
|
|
|
|
|
4288 wrote: and OnPaint fails
What does that mean?
led mike
|
|
|
|
|
I used OnCtlColor handler, but because my label was created with a CStatic-derived class, the code provided into CMyClass::OnCtlColor won't be executed!
OnPaint seemed me a good solution but if I insert the OnPaint handler with Visual Studio, the control won't even show
---
|
|
|
|
|
4288 wrote: but if I insert the OnPaint handler with Visual Studio, the control won't even show
Did you subclass the control?[^]
led mike
|
|
|
|
|
I thought I subclassed it, but my subclassing seems not to work.
Have you got please a link that show how to perform a subclassing with a dynamical control created like mine?
---
|
|
|
|
|
|
Problem solved, thanks!
---
|
|
|
|
|
Very good.
|
|
|
|
|
Hi every body!
From where can I get some information about "Connection Strings" used to connect to MS Access Database. For example I don't know what "MaxBufferSize" means and so on...
Don't laught at me! I know what U R thinking about...
|
|
|
|
|
Usef Marzbani wrote: For example I don't know what "MaxBufferSize" means and so on...
It refers to the amount of RAM Access sets aside for its use as an internal storage space. The larger the storage space, the higher are the odds that the data necessary for a request can be found in RAM and will not require physical disk access.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
|
So I have this COM object that's packing up an array floats for me.
Here's the loop where the VARIANT* array is getting stuffed:
for (i = 0; i < cElements; i++)
{
VariantInit(&vDataValues[i]);
V_VT(&vDataValues[i]) = VT_R4;
//Works ok UNLESS float_data[i] == 0.0;
V_R4(&vDataValues[i]) = float_data[i];
if (!V_R4(&vDataValues[i]))
{
*pErrorCode = 1;
m_strMessage.Format("V_R4 failed!");
hr = E_FAIL;
goto Error;
}
}
The VT_R4() operation works unless the element in float_data
happens to be 0.0. When that happens, VT_R4 fails.
I know it fails only with 0.0, because I tried this:
if( float_data[i] != 0.0 )
V_R4(&vDataValues[i]) = float_data[i];
else
V_R4(&vDataValues[i]) = float_data[i] + 0.1;
Then, it never fails.
I can't figure out why.
|
|
|
|
|
Well I have no idea what your float_data is or if it has been properly initialized but this works without error
VARIANT DataValues[4];
V_R4( &DataValues[0]) = 0.0;
led mike
|
|
|
|
|
I'm new to using COM, so maybe I'm missing something obvious here.
The data I can verify is OK.
led mike wrote: VARIANT DataValues[4]; V_R4( &DataValues[0]) = 0.0;
Those lines work for me, too.
The examples I'm looking show that you verify it's OK by doing this sort of thing:
if (!V_R4(&vDataValues[i]))
{
//Do some error stuff
}
And !V_R4(&vDataValues[i]) evaluates to false if the data is 0.0.
Why is that?
If I comment out that error check, everything seems to work fine. Is it not needed?
|
|
|
|
|
Eurosid wrote: The examples I'm looking show that you verify it's OK by doing this sort of thing:
I don't think that's correct. Where are you getting these examples?
V_R4 is just a macro that evaluates to the specified VARIANT member during pre-compile. It does not return an status indication value.
led mike
|
|
|
|
|
You are exactly correct. I misunderstood what I was looking at.
The example was for packing up a BSTR, so they did such a check
to make sure the pointer wasn't NULL.
Doing the same thing on a float isn't needed, but will look OK unless the value happens to be 0, which will look like FALSE.
I told you I was a Chump!
Thank you for help!
|
|
|
|
|
I'm slightly curious what you mean by "fails". Do you put the variant in a watch window, and see wrong numbers? From your later post, I think you think that V_R4 is a function which passes success / failure.
Looking in OLEAUTO.H,
#define V_UNION(X, Y) ((X)->Y)
#define V_VT(X) ((X)->vt)
#define V_R4(X) V_UNION(X, fltVal)
So...
VARIANT var;
VariantInit (&var);
V_VT(&var) = VT_R4;
V_R4(&var) = 0.0;
becomes
V_UNION(&var,ftlVal) = 0.0;
becomes
(&var)->ftlVal = 0.0;
which looks fine to me.
BUT:
You are using this in an if statement.
Imagine the following:
if (1)
{
} else {
}
and
if (a=0)
{
} else {
}
The second if evaluates to 0, which will fail the if.
Cutting to the chase:
V_R4(&blah) = a number
evaluates to whatever the number is - and 0 is FALSE.
Here endeth the lesson.
Iain.
Iain Clarke appears because CPallini still cares.
|
|
|
|
|
Iain Clarke wrote: Here endeth the lesson.
Iain.
Yes. That was it. I was being a Chump.
I knew it, but I just couldn't see why.
Thanks!
|
|
|
|
|
How to determine which field in a database table is the
primary key (in OLEDB or ODBC) using MFC (VC++ 2005)?
Thanks in advance..
|
|
|
|
|
Hi,
I don't think this can be done using MFC. You can find it from sys tables of the database.
thanks
Nitheesh
|
|
|
|
|
I do not think anything has changed since you last asked this question. Just out of curiosity, why do you need to know such information (i.e, what part of your code is relying upon it)?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I will update a field (Say fieldName)in the application. A trigger is executed outside the application in oracle, which changes the value of another field (Say fieldNumber=1, Now changed to fieldNumber=2 after trigger).
The method i follow after field update is :
1. Update (fieldName) to database
2. Refresh the updated value and trigger changed value (fieldNumber=2) to text box. I am doing refresh using select statement .. where ...
(select * from tbl where fieldNumber=1)
Since the trigger changes value outside application, my select statement's where clause have old value (fieldNumber=1). It fails.
Hence i want to know the primary key of the table and use refresh using select statement (only primary key)..
|
|
|
|
|