|
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
|
|
|
|
|
softwaremonkey wrote: Has anyone managed to display images with variable transparency in a CImageList?
Ya. I have used couple of years back. But I remeber it didnt work if we didnt use comctrl 6. Here is how to use comctrl 6 in your application
Using Windows XP Visual Styles[^]
|
|
|
|
|
Hey thanks Naveen that did the trick
The important thing was to add a manifest file specifying version 6 of common controls.
Thanks again you have saved my PC from being beaten to a pulp 
|
|
|
|
|
Please help , am trying to Design a matrix class that perform addition, multicpication, substraction and division. When everr i complie the code it show an error. please help me the the error.this is my code below.
include <iostream>
using namespace std;
class matrix{
public:
matrix();
matrix(int m,int n);
int getRow();
int getCol();
double& operator()(int, int);
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);
}
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;
}
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;
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;
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;
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(){
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<<a(0,0)<<endl;
cout<<a(1,1)<<endl;
cout<<a<<endl;
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<<b<<endl;
matrix c,d,e,f;
c=a+b;
d=a*b;
e=a-b;
f=a/b;
cout<<c<<endl;
cout <<"\n\n";
cout<<d<<endl;
cout<<e<<endl;
cout <<"\n\n";
cout<<f<<endl;
system("pause");
return 0;
}
|
|
|
|
|
Great
- subject line
- code formatting
- symptom description
|
|
|
|
|
Problems with the post:
1) the title of your post is worthless
2) are we supposed to guess what the error is?
3) use PRE tags to preserve code formatting
Problems with the code
1) memory is allocated but never deallocated
2) several functions are missing the closing curly brace (causing the compile error)
![Badger | [badger,badger,badger,badger...]](https://www.codeproject.com/script/Forums/Images/badger.gif)
|
|
|
|
|
1) Read the forum guidelines.
2) When posting code, use either the 'code block' or 'inline code' tags available just above the text box when editing a message.
3) Post the RELEVANT LINES OF CODE, not the whole file.
4) When seeking help resolving an error message, post the message. We can't read minds, and not many people are going to copy your entire file, create a project around it, compile it and attempt to divine which particular message you might have been referring to.
5) Read the forum guidelines.
L u n a t i c F r i n g e
|
|
|
|
|
I made some modifications to you code.
Note that your multiplication operation is out of standard (I haven't touched it and the division one): matrix multiplication is usually defined this way:
m[i,j] = a[i,0] * b[0,j] + a[i,1] * b[1,j] + ... + a[i,N] * b[N,j]
Beware, returning, as you did, element 0 when the requested index is out of bounds, it is not a good practice.
#include <iostream>
#include <string>
using namespace std;
class matrix
{
public:
struct Exception
{
string msg;
Exception(string emsg)
{
this->msg=msg;
}
};
matrix();
matrix(int m,int n);
~matrix(){ delete [] data; }
int getRows();
int getCols();
double& operator()(int, int);
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);
}
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::getRows() { return nrows;}
int matrix::getCols() { return ncols;}
double& matrix::operator ()(int r, int c){
if (r <0 || r>= nrows || c<0 || c>= ncols)
throw matrix::Exception("out of bounds");
return data[r*ncols+c];
}
ostream& operator<<(ostream& os, matrix &m)
{
for(int r=0; r<m.nrows; r++)
{
for(int c=0; c < m.ncols; c++)
os<<m(r,c) << " ";
os<<endl;
}
return os;
}
matrix matrix::operator+(matrix& a)
{
if ( nrows != a.nrows || ncols!= a.ncols )
throw Exception("invalid operands");
matrix sum(nrows, ncols);
for (int r=0; r<nrows; r++)
for(int c=0; c<ncols; c++)
{
int i = r * ncols + c;
sum.data[i] = data[i] + a.data[i];
}
return sum;
}
matrix matrix::operator*(matrix& a)
{
matrix product(nrows, ncols);
for (int r=0; r<nrows; r++)
for(int c=0; c<ncols; c++)
{
product(r,c) = (r,c) * a(r,c);
}
return product;
}
matrix matrix::operator-(matrix& a)
{
if ( nrows != a.nrows || ncols!= a.ncols )
throw Exception("invalid operands");
matrix difference(nrows, ncols);
for (int r=0; r<nrows; r++)
for(int c=0; c<ncols; c++)
{
int i = r * ncols + c;
difference.data[i] = data[i] - a.data[i];
}
return difference;
}
matrix matrix::operator/(matrix& a)
{
matrix divide(nrows, ncols);
for (int r=0; r<nrows; r++)
for(int c=0; c<ncols; c++)
divide(r,c) = (r,c) / a(r,c);
return divide;
}
int main()
{
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<<a(0,0)<<endl;
cout<<a(1,1)<<endl;
cout<<a<<endl;
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<<b<<endl;
matrix c,d,e,f;
c=a+b;
d=a*b;
e=a-b;
f=a/b;
cout<<c<<endl;
cout <<"\n\n";
cout<<d<<endl;
cout<<e<<endl;
cout <<"\n\n";
cout<<f<<endl;
system("pause");
return 0;
}
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]
modified on Sunday, January 3, 2010 2:18 PM
|
|
|
|
|
CPallini wrote: m[i,j] = a[i,0] * b[0,j] + a[i,1] * b[1,j] + ... + a[i,N] * b[2,N]
b[2,N] or b[N,j]?
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.
|
|
|
|
|
Nelek wrote: b[2,N] or b[N,j]?
b[2,N] is the right one, of course: keep you up to date man, there are many-many advantages with that definition, for instance in relativistic computations...
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]
|
|
|
|
|
CPallini wrote: for instance in relativistic computations
Oh... I thought it was for quantic physics
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.
|
|
|
|
|
|
such a long reply.. happy new year!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
ThatsAlok such a long reply..
Probably ignored: he posted again is question...
ThatsAlok happy new year!
Happy new year, Alok! Best wishes!
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]
|
|
|
|
|
The following program is taking the inputs in the structures but when it comes to print them the program terminates abruptly.
//OBJECT: To make a program to take the input from user as the names of the owner, chassis numbers,
//model, car brand and to store them in structures
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct data{
char oname[20];
int chno;
int model;
char brand[20];
};
main()
{
int slot,i=0;
typedef struct data a;
printf("Enter the no. of data slots you want to make\n");
scanf("%d",&slot);
a c[slot];
for (i=0;i<slot;i++)
{
printf("Enter the Owner's Name\n");
//gets(c[i].oname);
scanf("%s",&c[i].oname[20]);
printf("Enter the chassis number\n");
scanf("%d",&(c[i].chno));
printf("Enter the model year\n");
scanf("%d",&(c[i].model));
printf("Enter the brand name\n");
//gets(c[i].brand);
scanf("%s",&c[i].brand[20]);
}
for (i=0;i<slot;i++)
{
printf("%s %d %d %s\n",c[i].oname[20], c[i].chno,c[i].model,c[i].brand[20]);
}
getche();
}
|
|
|
|
|
Razanust wrote: a c[slot];
This will not work, you cannot allocate an array with an unknown size. I also don't know how you got this to work in the first place is it does not comile (as is to be expected).
|
|
|
|
|
As Richard said, the program shouldn't compile at all.
Also you need to put a fflush(stdin) call after each scanf statement so that the remaining characters in the input stream which cannot be read by scanf are removed.
|
|
|
|
|
Hi,
With reference to Mr Richards reply i made some changes which will make ur program to work. The changes are commented. the slot size should be created dynamically as suggested. Hope u can understand the code. I am beginner too.
Good luck
//OBJECT: To make a program to take the input from user as the names of the owner, chassis numbers,
//model, car brand and to store them in structures
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct data{
char oname[20];
int chno;
int model;
char brand[20];
};
const int slot =2; //changed here as pointed out by Mr Richard
void main()
{
int i=0;
typedef struct data a;
printf("Enter the no. of data slots you want to make\n");
//scanf("%d",&slot); //commented here
a c[slot];
for (i=0;i<slot;i++)
{
printf("Enter the Owner's Name\n");
//gets(c[i].oname);
scanf("%s",c[i].oname); //&c[i].oname[20] not necessary
printf("Enter the chassis number\n");
scanf("%d",&(c[i].chno));
printf("Enter the model year\n");
scanf("%d",&(c[i].model));
printf("Enter the brand name\n");
//gets(c[i].brand);
scanf("%s",c[i].brand); //&c[i].brand[20] not necessary
}
for (i=0;i<slot;i++)
{
printf("%s %d %d %s\n",c[i].oname, c[i].chno,c[i].model,c[i].brand);
}
getche();
}
|
|
|
|
|
I want to know the Brush file format, help me !
My email: dsclub@vip.qq.com
Thank You!
Coding, Learning, Smiling...
|
|
|
|
|