|
It throws the same exception when I tried to do so,
I know that DAO is not working well in multithreaded environment, but I heard that this is fixed if I turn my DLL to UNICODE version, which I‘ve done, but still not working.
thanks Ryan,
|
|
|
|
|
Hi
am developing activex control, and in the OnDraw method i want to draw a round rectangle and fill it with gradient color
can you help me in that
thaks alot
Tarek Jabri
|
|
|
|
|
Try something like this:
------------------------
COLORREF Rainbow(int x)
{
enum
{
maximum = 255, // Range of x is from 0 to this value.
h1 = maximum/4,
h2 = maximum/2,
h3 = 3*maximum/4,
};
const double m = 255/h1;
BYTE red;
if ( x<=h1 )
{
red = 255;
}
else if (x>=h2)
{
red = 0;
}
else
{
red = static_cast<BYTE>(-m*x+510.0 + 0.5);
}
BYTE green;
if (x<h1)
{
green = static_cast<BYTE>(m*x + 0.5);
}
else if (x>h3)
{
green = static_cast<BYTE>(-m*x+1020.0 + 0.5);
}
else
{
green = 255;
}
BYTE blue;
if (x<=h2)
{
blue = 0;
}
else if (x>=h3)
{
blue = 255;
}
else
{
blue = static_cast<BYTE>(m*x-510.0 + 0.5);
}
return RGB(red, green, blue);
}
Steve
|
|
|
|
|
i am using the code below which i copied from somewhere for an application which uses a vertical scrollable child. now i realise my application need a horizontal scroll also.....can i use back the same code ?
void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
int nDelta;
int nMaxPos = m_rcOriginalRect.Height() - m_nCurHeight;
switch (nSBCode)
{
case SB_LINEDOWN:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(max(nMaxPos/20,5),nMaxPos-m_nScrollPos);
break;
case SB_LINEUP:
if (m_nScrollPos <= 0)
return;
nDelta = -min(max(nMaxPos/20,5),m_nScrollPos);
break;
case SB_PAGEDOWN:
if (m_nScrollPos >= nMaxPos)
return;
nDelta = min(max(nMaxPos/10,5),nMaxPos-m_nScrollPos);
break;
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
nDelta = (int)nPos - m_nScrollPos;
break;
case SB_PAGEUP:
if (m_nScrollPos <= 0)
return;
nDelta = -min(max(nMaxPos/10,5),m_nScrollPos);
break;
default:
return;
}
m_nScrollPos += nDelta;
SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
ScrollWindow(0,-nDelta);
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
|
|
|
|
|
Yes you do as same way in OnHScroll handler.
But ratio would be different so you have to calc it.
Enjoy
|
|
|
|
|
sorry i have to ask this...but how do i calculate it ?
Thanks
|
|
|
|
|
there are several way to calc it. it depends on what kind of coordinate system you are using. you have to consider whether absolute or relative, whether integer or float, whether zoom in/out feature will be added or not, and etc.
scrollbar control has its absolute coordinate like 'range' like 0~255 or 0~32767. this is physical coordinate. So your logical coordinate in your mind has to be matched to physical coordinate as correct ratio. for example, if the maximum size of logical map is 327680 pixel and physical scroll range is 0~32767, then current pixel position to draw to screen has to be scrollbar position * 10. so if the scrollbar position is 16384 (1/2 of range), then current map position is 16384 * 10 = 163840.
and you also have to consider view window width, height.
anyway, scroll bar controling is a little complex and i'd like to suggest you to research formal way. there are lectures on the internet.
Enjoy
|
|
|
|
|
hello i want to make an overload of the assignement operator in C++ but it generated this error ... someone help please
thank you!
this is the code:
friend CMot& operator = (const CMot); --> in CMot.h
CMot& operator = (const CMot m) --> in CMot.cpp
{
return m;
}
C++ Beginner
|
|
|
|
|
>hello i want to make an overload of the assignement operator in C++ but it generated this
>error ... someone help please
>thank you!
>this is the code:
>friend CMot& operator = (const CMot); --> in CMot.h
>CMot& operator = (const CMot m) --> in CMot.cpp
>{
>return m;
>}
>C++ Beginner
It's been a while since I've dealt with this but my guess would be that "friend" indicates an external function or class. Since the only entitity you're dealing with is the object itself, both as object and returned value, you don't need the "friend" designation. It puts it outside the class.
Lilith
|
|
|
|
|
operator= must be a member function. Make you code look this this:
<code>
class CMot
{
CMot& operator = (const CMot);
}
CMot& CMot::operator = (const CMot m)
{
return m;
}
Steve
|
|
|
|
|
Close
class CMot
{
CMot & operator = (const CMot &);
};
CMot &CMot::operator = (const CMot &m)
{
this->member_variable = m.member_variable;
return *this;
}
You may be right
I may be crazy
But it just may be a lunatic you’re looking for
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
|
I'd recommend making the return value const. Otherwise you'll find some nitwit that does this:
(mot1 = mot2) = mot3; Having to debug that can cause an enormous amount of hair loss
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Enabling chaining is why operator= returns a reference to itself. This kind of usage is common:
int x, y, z;
x=y=z=1;
Personally I'd think twice before diabling such usage, but to each his own.
Steve
|
|
|
|
|
I completely agree with you, but that's not what I was meaning. In your example, they assignments are evaluated right-to-left, basically the same as
x = (y = (z = 1)); I was meaning to prevent the other way, using parentheses so that the assignments are evaluated left-to-right
((x = y) = z) = 1; In this case, x is assigned the value 1, and all the rest are not assigned at all. Note the position of the parentheses in my example.
If you make the return value const, you allow the first case, but disallow the second, IMO a desirable thing to do.
Using const also allows the compiler to optimise some situations a bit more.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I'm with you now, and now I find that I completely agree with you. Good call.
Steve
|
|
|
|
|
I have never seen anyone post a joke/game message so I'm going to now. Here are three games that I have written. There on my web site and I know there not that great but I want to shere them any way. You probably will not be interested in "grace game" but the other two may be kinda neat. Any comments are welcome.
http://www.productionkey.com/programs/[^]
----------------------------------------------------------------
"To an optimist the glass is half full.
To the pessimist the glass is half empty.
To the programmer the glass is twice as big as it needs to be."
GC13: "Mature-Ages 16 and up. 'your mature, right?'"
FARGORE: "no, but I am over 16."
-- modified at 9:04 Sunday 26th February, 2006
|
|
|
|
|
Hi,
I'd like to know how the 'address of (&)'
applies to methods in Visual C++.
Here is an example :
<br />
<br />
void CMainWnd::OnRButtonDown(UINT nFlags, CPoint point)<br />
{<br />
CWindowDC dc(this);<br />
<br />
CRect rc;<br />
GetWindowRect(&rc);<br />
<br />
}<br />
<br />
Whats the difference between :
GetWindowRect(&rc); and
GetWindowRect(rc);
I would appreciate some more examples along with an explanation with
what it does, why and how? I know I'm asking alot here but I would very appreciative.
Thanks in Advance
Tom
|
|
|
|
|
Hi,
in the case u describe it is used to pass the object by address or by reference.
It will depend on the signature of the called function. If I'm not mistaken this
function GetWindowRect expects a pass by address (a pointer) because its
based on the an API call which is written in plain C where there are no references
int iValue = 3;
int* pValue = &iValue;
*pValue = 4;
int& rValue = &iValue;
rValue = 5; Here you van see that when using a pointer (pValue) you need the to dereference it
using the '*' operator;
When using the reference (rValue) you can use it like you would have used iValue;
Now this brings the following benefit, look at the following code:
struct Point{
int x;
int y;
};
void FunctionA(Point ptMouse)
{
ptMouse.x = 100;
}
void FunctionB(Point* pMouse)
{
pMouse->x = 100;
}
void FunctionC(Point& rMouse)
{
rMouse.x = 100;
} When using FunctionA the Point object will be copied onto the stack and
in the function you only use this copy. [pass by value]
When using FunctionB only the address is placed on the stack and inside the function
you can access the original object. So when changing the object inside the function is will
be changed outside the function (its the same object) [pass by address]
When using FunctionC alsoo only the address is placed on the stack and inside we are using the original object. So when changing the object inside the function is will
be changed outside the function. [pass by reference]
When passing large objects (classes with many members, or large ones) the pass by value is not so good (slow, stack space consuming). So either pass by address or pass by reference are preferred.
codito ergo sum
|
|
|
|
|
Thanks I think I understand!
The reason why is? When windows was created using GDI things were written in good old C!
Unlike C++, C didnt use pass references, so you had to use pass by address.
Also since pass by Value such as :
<br />
CClientDC dc(this);<br />
<br />
CPen penBlue = new CPen();<br />
penBlue.Create(PS_SOLID,1,RGB(0,0,255));<br />
<br />
dc.SelectObject(penBlue)
<br />
<br />
dc.SelectObject(&penBlue)
<br />
also you could use<br />
<br />
CPen& rPenBlue = &penBlue;<br />
dc.SelectObject(rPenBlue)
<br />
Thanks Tom
|
|
|
|
|
Tom Moore wrote: CClientDC dc(this);
CPen penBlue = new CPen();
penBlue.Create(PS_SOLID,1,RGB(0,0,255));
dc.SelectObject(penBlue) // pass by value, makes a copy - uses up a lot of memory (BAD)
Actually, this code will not even compile. CDC::SelectObject expects a CPen* pointer, so you have to pass by address.
You may be right
I may be crazy
But it just may be a lunatic you’re looking for
-- Billy Joel --
Within you lies the power for good - Use it!
|
|
|
|
|
I think I understand some of it now, but theres still some things that elude me.
An example is
<br />
CClient* pDC(this);<br />
CPen penRed = new CPen()<br />
<br />
penRed.Create(PS_SOLID,1,RGB(255,0,0);
<br />
CPen penOld = dc->SelectObject(&penRed);
<br />
dc.DrawText(300,400,penRed,"Hello World");
<br />
dc.SelectObject(penOld)
I still am a bit confused like the previous snippet
<br />
CRect rc;<br />
GetWindowRect(&rc);<br />
Thanks in advance again
Tom
|
|
|
|
|
CClient* pDC(this);
CPen *penRed = new CPen();
penRed->Create(PS_SOLID,1,RGB(255,0,0));
CPen *penOld = dc->SelectObject(penRed);
dc.SelectObject(penOld) I've marked up the code you posted. Notice the bold areas.
1. The new operator returns the address of an object allocated on the heap. The value on the left side of the assignment therefore has to be a pointer variable.
2. If you refer to a member of an object through a pointer, you have to use the -> operator, as in penRed->Create .
3. The SelectObject function in the CDC class takes a pointer to a CGdiObject .
4. The CDC class doesn't have a DrawText member that takes a pen argument.
Software Zen: delete this;
|
|
|
|
|
hihi,
u should learn C++ before u know GetWindowRect().
&rc is address of the rc.
rc is rc.
address means memory place in which the data of rc stored.
it sounds very dangerous u go so far in programming.
A nice tool for optimizing your Microsoft html-help contents.
Includeh10
|
|
|
|
|
Hi,
I do know C++!
I did a programming course on it, but I covered a small portion of address of operator in it, and we didnt cover address of operator with objects.
Thanks
Tom
|
|
|
|