|
hi all,
i have a value like this in my application..
CString strTemp = "hello world";
now, i want the word "world" to be disabled(grayed out..) like wat appear in a static text box..
is it possible?
Thanks,
Rakesh.
|
|
|
|
|
CString class holds just a string (array of characters). It doesn't have any color information associated with it.
|
|
|
|
|
How are you displaying the string ? As already mentioned by somebody else, CString is just a class containing data and doesn't have any relation with how it will displayed.
|
|
|
|
|
What you want is a different color for a word.
You can only disable/enable windows and not words.
Also as Rejeesh said, you cannot do that with a CString alone.
You could use a control similar to a rich edit control and show one word with a different color.
|
|
|
|
|
If you are using the string in pDC->TextOut (...) you can do it as well by changing the font color, but you can't do it only depending on words, you will need different strings, so you print one, change the color and then print the next.
this[^] or this[^]may be useful for you as well.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Rakesh5 wrote: i have a value like this in my application..
CString strTemp = "hello world";
now, i want the word "world" to be disabled(grayed out..) like wat appear in a static text box..
is it possible?
Sorry, but that isn't possible.
Kindly buy and read a beginner level book on Windows programming.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
One way to store colour information in a CString is to use HTML tags and then dump the string into a HTML enabled control.
-or-
Use RTF codes and dump into a Rich Edit Control.
|
|
|
|
|
Michael Schubert wrote: One way to store colour information in a CString is to use HTML tags and then dump the string into a HTML enabled control.
Another way to store color information in a CString :
CString strBackground = "Blue";
(pardon!)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Good point.
Another method:
CString strBackground = "Blue";
|
|
|
|
|
CString strBackground = " █";
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Im using following code to reduce the dialog width.it show assertion error
void CToolTab::ReduceWidth()
{
this->SetWindowPos(&CWnd::wndBottom,0,80,100,800,SWP_NOSIZE);
}
assertion error in bolded line
BOOL CWnd::SetWindowPos(const CWnd* pWndInsertAfter, int x, int y, int cx,
int cy, UINT nFlags)
{
ASSERT(::IsWindow(m_hWnd) || (m_pCtrlSite != NULL));
Here m_hWnd shows 0x0000.
Im reducing the width after pressing button in the same dialog.
Anu
|
|
|
|
|
From which function are you calling ReduceWidth()?
|
|
|
|
|
I believe you're calling SetWindowPos in a place where the window has not been created yet.
Is it in the WM_SIZE handler?
Add a condition before you call SetWindowPos .
if (::IsWindow(this->m_hWnd))
this->SetWindowPos(&CWnd::wndBottom,0,80,100,800,SWP_NOSIZE);
|
|
|
|
|
actually im using WPF C# dll in vc++ code.
In that dll i have button ,so the button handler calls collapse() delgate fucntion.
in VC++ im coding like
Tabcontrol::ToolBar::Collapse += gcnew Tabcontrol::ToolBar::Navigation(OnCollapse);
void OnCollapse()
{
CToolTab tab;
tab.ReduceWidth();
}
void CToolTab::ReduceWidth()
{
if (::IsWindow(this->m_hWnd))
this->SetWindowPos(&CWnd::wndBottom,0,80,100,800,SWP_NOSIZE);
}
But my cursor get out form the IsWindow linw.Because m_hWnd shows 0x0000.
Then how can i use this SetWindowPos?
In OnInitDialog im using SetWidnowPos as follow
SetWindowPos(&CWnd::wndBottom,0,80,300,800,SWP_SHOWWINDOW);
Anu
|
|
|
|
|
'tab' variable in OnCollapse() is local to OnCollapse(). The 'tab' variable will get destroyed after OnCollapse() call.
|
|
|
|
|
By declaring CToolTab globally,its not working.
Anu
|
|
|
|
|
Please help with this code.Am trying to design a Matrix class with the following operation Addition, Multiplication, Subtraction and division.The code compile , But my result is incorrect
.please if someone can to solve this incorrect result.
This is my code Below.
#include <iostream>
using namespace std;
//member function of matrix class
class matrix{
public:
matrix();
matrix(int m,int n);
int getRow();
int getCol();
double& operator()(int, int);
//the operator used in the matrix class which are (addition operator, multiplication operator,substraction operator, and divide operator).
friend ostream& operator<<(ostream& os, matrix& m);
matrix operator + (matrix&);
matrix operator * (matrix&);
matrix operator - (matrix&);
matrix operator / (matrix&);
private:
void init(int, int);
int nrows,ncols;
double *data;
};
matrix::matrix(){
init(1,1);
}
matrix::matrix(int m, int n){
init(m,n);
}
//destructor to delete the used dynamic memory.
void matrix::init(int m, int n){
nrows=m;
ncols=n;
data= new double[m*n];
for(int i=0; i<m*n; i++)
data[i]=0;
}
int matrix::getRow() { return nrows;}
int matrix::getCol() { return ncols;}
double& matrix::operator ()(int r, int c){
if (r <0 || r> nrows){
cout<<"Illegal row index";
return data[0];
}
else if (c <0 || c > ncols){
cout<<"Illegal Column Index:";
return data[0];
}
else return data[r*ncols+c];
}
ostream& operator<<(ostream& os, matrix &m){
int mval=m.getRow();
int nval=m.getCol();
for(int i=0; i<mval; i++){
for(int j=0; j < nval; j++)
os<<m(i,j)<<" ";
os<<endl;
}
return os;
}
//To compute the summation
matrix matrix::operator+(matrix& a){
matrix sum(nrows, ncols);
for (int i=0; i<nrows; i++)
for(int j=0; j<ncols; j++)
sum(i,j) = (i,j) + a(i,j);
return sum;
}
//To compute the multiplication
matrix matrix::operator*(matrix& a){
matrix product(nrows, ncols);
for (int i=0; i<nrows; i++)
for(int j=0; j<ncols; j++)
product(i,j) = (i,j) * a(i,j);
return product;
}
//To compute the substraction
matrix matrix::operator-(matrix& a){
matrix difference(nrows, ncols);
for (int i=0; i<nrows; i++)
for(int j=0; j<ncols; j++)
difference(i,j) = (i,j) - a(i,j);
return difference;
}
//To compute the division
matrix matrix::operator/(matrix& a){
matrix divide(nrows, ncols);
for (int i=0; i<nrows; i++)
for(int j=0; j<ncols; j++)
divide(i,j) = (i,j) / a(i,j);
return divide;
}
int main(){
//the array of matrix a
matrix a(2,2);
a(1,1)=5.0;
a(0,0)=6.0;
a(0,1)=7.0;
a(1,0)=8.0;
cout<<"matrix a\n";
cout<<a<<endl;
//the array of matrix b
matrix b(2,2);
b(0,0) = 5.0;
b(0,1) = 5.0;
b(1,0) = 5.0;
b(1,1) = 5.0;
cout<<"matrix b\n";
cout<<b<<endl;
matrix c,d,e,f;
//to compute the operation of the matrix (addition, multiplication, substraction and division).
c=a+b;
d=a*b;
e=a-b;
f=a/b;
//to Display the result operation of the matrix (addition, multiplication, substraction and division).
cout<<"matrix a+b \n";
cout<<c<<endl;
cout <<"\n\n";
cout<<"matrix a*b\n";
cout<<d<<endl;
cout<<"matrix a-b\n";
cout<<e<<endl;
cout <<"\n\n";
cout<<"matrix a/b\n";
cout<<f<<endl;
system("pause");
return 0;
}
|
|
|
|
|
Hey Richard, this is just a repost. Please avoid doing it.
Someone already answered your question. Your code is a bit messy and it looks like you haven't a clear idea about matrix multiplication and division.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Did you even read the replies you got from your previous question ? Your post was wrong on so many points, now you can add "Reposting is bad" to the list.
|
|
|
|
|
"The code compile , But my result is incorrect"
When this happens, the Toy Problem debugging pattern is appropriate: Run your code on the simplest problem possible, so you can look at values in the debugger and figure out what you're doing wrong.
In your application, try working with 2x2 matrices. Step through your code and see where it's doing something wrong.
|
|
|
|
|
Hi,
I am loading a 32 bit bitmap (24 bit + alpha channel) into a CImageList and then attempting to draw it without much success. The 'transparent' bits are drawn in black. If I specify black as the mask when I add the bitmap it works OK but this means I cant have any black pixels in the bitmap.
Does anyone know what is needed to make this work. For info, I am dioing the following...
Loading the bitmap...
HBITMAP hBM = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), s,
IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
if(hBM)
{
BITMAP bmp;
::GetObject(hBM, sizeof(bmp), &bmp);
UINT flags;
switch(bmp.bmBitsPixel)
{
case 4:
flags = ILC_COLOR4;
break;
case 8:
flags = ILC_COLOR8;
break;
case 16:
flags = ILC_COLOR16;
break;
case 24:
flags = ILC_COLOR24;
break;
case 32:
flags = ILC_COLOR32;
break;
}
m_imageList.DeleteImageList();
m_nImageWidth = bmp.bmWidth / m_nStates / m_nStyles;
m_nImageHeight = bmp.bmHeight;
m_imageList.Create(m_nImageWidth, m_nImageHeight, flags | ILC_MASK, m_nStates * m_nStyles, 0);
CBitmap bm;
m_bImageLoaded = true;
bm.Attach(hBM);
m_imageList.Add(&bm, RGB(255,0,255));
And drawing...
if(m_bImageLoaded)
{
m_imageList.Draw(pDC, nImage, loc, ILD_NORMAL);
}
Thanks
Tony 
|
|
|
|
|
If you want black pixels in your transparent bitmap, you could change the alpha channels to any of the other 16 million colors and specify that as the mask color.
|
|
|
|
|
It's been a while and I've to scrounge up the code, but I believe you have to use a flag of ILC_COLOR32 and 32-bit bitmap must be a DIB section.
|
|
|
|
|
32 bit bitmap in imagelist is only supported in common control 6 and above. so please enure you are using common control versio 6 or later.
|
|
|
|
|
After a bit of trial and error programming, I have found that if I set the mask to CLR_NONE when adding a ILC_COLOR32 bitmap to the image list the image is drawn with a transparent background but it is always 100% transparent, even though the image has variable transparency. This results in rough edges around the image.
Has anyone managed to display images with variable transparency in a CImageList?
Thanks
Tony
modified on Monday, January 4, 2010 1:31 PM
|
|
|
|
|