|
Hi Mahesh ,
The problem with your sugeestion is that, I cannot call the obj.someFunction() with both int and long at the same time like..
int n = 0;<br />
long l = 0;<br />
obj.someFunction( n ); <br />
obj.someFunction( l );
|
|
|
|
|
I think that Naveen wants (member) function templates of a class, not class templates .
If it is a class template, the argument type is fixed when the class object is declared. So we can not invoke member functions with different input types (something like function overloading).
Maxwell Chen
|
|
|
|
|
HI Naveen and MaxWell
I am really sorry ..It was my misunderstanding.
later I worked for wht Naveen exactly want, on VC6
But it was not working then i googled,
I found the Following link
http://forums.devx.com/archive/index.php/t-82949.html[^]
The secret of life is not enjoyment
but education through experience.
- Swami Vivekananda.
|
|
|
|
|
To tell the truth, I have been 7 years not coding template stuffs.
I just tried hard to recall everything about templates (both member function template and class template), and tried with VC++2008. It works well finally.
Maxwell Chen
|
|
|
|
|
How to resize bitmap which in CStatic
<code>
CStatic* myStatic;
myStatic = new CStatic();
myStatic->Create(_T("my static"), WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_CENTERIMAGE, CRect(50,80, 150, 150), this);
myStatic->SetBitmap(LoadBitmap(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(IDB_BITMAP_default)));
</code>
these code set bitmap in CStatic control, but the picture is not whole displaied, because its area more than CRect(50,80, 150, 150),
how to resize the bitmap area that to dispaly full onto the CStatic control?
thanks!
|
|
|
|
|
This control[^] does all the dirty work.
This article[^] shows what you can do with the static control. Not settng the SS_CENTERIMAGE or SS_REALSIZEIMAGE style supposedly makes the image fit the static control.
Note that the actual size of the static control in pixels, and even its aspect ratio depends on the dialog font, so it may be different when moving to another PC.
|
|
|
|
|
|
I define a class CArray2D,inside it I imeplement a "proxy" class CArray1D, so that if I create a object of CArray2D like CArray2D array(2,3), I can output the its element like cout<<array[0][0].
But when I run it, I met with serials of strange questions like error address.
Can anyone tell me why?
Many thanks
The code is as follows
class CArray2D
{
public:
void Print()
{
CArray1D *pHead = pArray1D;
for(int i=0; i<size2D; i++)
{
cout<<"[ "<<i<<" }";
pHead->Print1D();
pHead = pHead+i*sizeof(CArray1D);
cout<<endl;
}
}
CArray2D(int n2DWidth, int n1DWidth):size2D(n2DWidth)
{
pArray1D = new CArray1D[size2D];
};
~CArray2D()
{
delete[] pArray1D;
};
class CArray1D
{
public:
CArray1D(int n1DWidth=3):size1D(n1DWidth)
{
pArray = new int[size1D];
for(int i=0; i<size1D; i++)
{
*(pArray+i*sizeof(int)) = 0;
}
};
~CArray1D()
{
delete[] pArray;
};
const int& operator[](int nIndex) const
{
return *(pArray+nIndex*sizeof(int));
}
int& operator[](int nIndex)
{
return *(pArray+nIndex*sizeof(int));
}
void Print1D()
{
for(int i=0; i<size1D; i++)
{
cout<<"["<<i<<"]="<<*(pArray+i*sizeof(int))<<" ";
}
}
private:
int size1D;
int *pArray;
};
const CArray1D& operator[](int nIndex) const
{
return *(pArray1D+nIndex*sizeof(CArray1D));
};
CArray1D& operator[](int nIndex)
{
return *(pArray1D+nIndex*sizeof(CArray1D));
};
public:
int size2D;
CArray1D *pArray1D;
};
int main()
{
CArray2D array(2,3);
array.Print();
array[0][0] = 3;
array.Print();
cout<<array[0][0]<<endl;
return 0;
}
}
Tomorrow is another day
|
|
|
|
|
Hi,
I'm doing a CPU-intensive program right now (C++ WinAPI, no MFC but I could use it if I had to) that uses some graphics, frequently calling a FillRect function to clear its back-buffered HDC to white. Is there a more efficient way to do this? Maybe by using bitwise operators somehow?
Thanks!
KR
|
|
|
|
|
You could use a DIB section for the back buffer's bitmap and write the
bits directly to memory in a loop.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ok I'll try that, thanks!
KR
|
|
|
|
|
Using BitBlt API with WHITENESS isn't better?
|
|
|
|
|
BitBlt with WHITENESS seems to be the fastest way to do it that I've tried. I guess I might be able to get it a little faster using a straight memcpy but I think BitBlt basically is a memcpy already so I doubt it'll help much.
KR
|
|
|
|
|
Through BitBlt we can avoid the risk of bugs, since we dont need to handle the DC bitmap directly.
|
|
|
|
|
RECT r = {...};
SetBkColor(dc, your_white);
ExtTextOut(dc, r.left, r.top, ETO_OPAQUE, &r, NULL, 0, NULL);
[EDIT]
Not saying it's faster, just another way.
At one point i believe it was the prefered way (don't recall why).
[/EDIT]
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
That way seems to be faster than FillRect, but copying directly to memory with BitBlt is slightly faster. Thanks!
KR
|
|
|
|
|
You may want to read:
http://blogs.msdn.com/oldnewthing/archive/2006/01/03/508694.aspx[^]
However, if BitlBlt accepts hdcSrc = NULL when dwRop is WHITENESS then you may as well stick with that if it's faster. This is a special case (color is set to palette index 1 = usually white). ExtTextOut is still fastest for setting any color.
...cmk
The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying.
- John Carmack
|
|
|
|
|
How can I get the paths of the directories from which the application has been loaded, and the "current" directory (the one, which is specified in the "Start in" of the properties)?
|
|
|
|
|
GetModuleFileName(NULL, buffer, buffersize)
and
GetCurrentDirectory(...)
|
|
|
|
|
Thanks, it was very quick.
|
|
|
|
|
I has already been tried to this codes.. It does not work. Anybody can help me about picture control usage to review a picture.
HBITMAP hBmp = (HBITMAP)::LoadImage(AfxGetInstanceHandle(), <br />
MAKEINTRESOURCE(IDB_BITMAP2),<br />
IMAGE_BITMAP, <br />
0,0, <br />
LR_LOADMAP3DCOLORS);<br />
<br />
CStatic* pSt = (CStatic*) GetDlgItem(IDC_STATIC);<br />
pSt->SetBitmap(hBmp);<br />
pSt->UpdateWindow();<br />
pSt->InvalidateRect(NULL);
Was is das¿
|
|
|
|
|
(1) are the style correct? IIRC, you need to set the SS_BITMAP style for the static.
(2) UpdateWindow and IncvalidateRect aren't necessary here (unless you don't exit the message handler where you have this for quite a while, which is a bad idea)
(3) If you would need them, they are in the wrong order
(4) Test your program with different DLU to pixel conversions (i.e. with different dialog fonts)
(5) My first CP article[^] handles the extras that oyu might need to make the bitmap look good.
|
|
|
|
|
Thanks friend.. Your article will be helpful.
Was is das¿
|
|
|
|
|
You can also use of CBitmap::Load if you are using of resource.
|
|
|
|
|
How is the usage of CBitmap class to load a saved bitmap in the resourceID. Request from you so Hamid.
Bitte tun Sie mir nicht antworten, wenn Sie nicht wissen, die Ursache des Problems wirklich oder nur als Antwort.
|
|
|
|