Dear ladies and gentlemen,

I am interesting in Computer Graphics programming with VC. I found a
piece of code segment in a book, the code is in the following:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

CDC *pDC = GetDC();
if (! pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
{
AfxMessageBox("Current system doesn't support Palette.");
return;
}

CString str;
int nColorNum = pDC->GetDeviceCaps(SIZEPALETTE);
str.Format("Current system palette could simultaneously display a number of
colors is %d.", nColorNum);
AfxMessageBox(str);

int nColorReserved = pDC->GetDeviceCaps(NUMRESERVED);
str.Format("The reserved color count of the current system palette is %d.",
nColorReserved);
AfxMessageBox(str);

ReleaseDC(pDC);

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I created a MFC project with VC in the Visual Studio .NET 2003 . When I
compile this code above, the compiler gives me the following error code:

error C2660: ¡°GetDC¡± : Function doesn't accept 0 parameters.

How can I compile this code successfully? Help me, please.

By the way, where can I find a newsgroup specialized for the Computer
Graphics Development with VC++ .NET?

Thank you very much.

Best regards.

Xiaoming

Re: How can I compile this code? by William

William
Thu Jul 20 21:25:52 CDT 2006

"Ma Xiaoming" <maxiaoming10000@hotmail.com> wrote in message
news:eeknfpGrGHA.5108@TK2MSFTNGP05.phx.gbl...
> CDC *pDC = GetDC();
> if (! pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
> {
> AfxMessageBox("Current system doesn't support Palette.");
> return;
> }
> ...
>
> I created a MFC project with VC in the Visual Studio .NET 2003 . When I
> compile this code above, the compiler gives me the following error code:
>
> error C2660: ¡°GetDC¡± : Function doesn't accept 0 parameters.
>
> How can I compile this code successfully? Help me, please.

GetDC() is a function in the Win32 API. It is also a member function of
MFC's CWnd class. My guess is that the code you copied was taken from the
implementation of a member function. I'm guessing that the code you compiled
stands alone. If that's the case, that's the cause of the error. Of course,
I could be wrong on both counts.

Regards,
Will



Re: How can I compile this code? by Doug

Doug
Thu Jul 20 21:47:50 CDT 2006

On Thu, 20 Jul 2006 22:25:52 -0400, "William DePalo [MVP VC++]"
<willd.no.spam@mvps.org> wrote:

>"Ma Xiaoming" <maxiaoming10000@hotmail.com> wrote in message
>news:eeknfpGrGHA.5108@TK2MSFTNGP05.phx.gbl...
>> CDC *pDC = GetDC();
>> if (! pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)
>> {
>> AfxMessageBox("Current system doesn't support Palette.");
>> return;
>> }
>> ...
>>
>> I created a MFC project with VC in the Visual Studio .NET 2003 . When I
>> compile this code above, the compiler gives me the following error code:
>>
>> error C2660: ¡°GetDC¡± : Function doesn't accept 0 parameters.
>>
>> How can I compile this code successfully? Help me, please.
>
>GetDC() is a function in the Win32 API. It is also a member function of
>MFC's CWnd class. My guess is that the code you copied was taken from the
>implementation of a member function. I'm guessing that the code you compiled
>stands alone. If that's the case, that's the cause of the error. Of course,
>I could be wrong on both counts.

Sounds right to me; the GetDC he's trying to use is a member of CWnd. In
addition, the condition is certainly wrong:

if (! pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE)

The high precedence of logical not requires parens:

if (!(pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE))

Those who've drunk enough of the C# kool-aid would insist upon:

if ((pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) == 0)

Then there are those who would prefer:

if (0 == (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE))

To them, I would say, "Don't do that." :)

--
Doug Harrison
Visual C++ MVP

Re: How can I compile this code? by William

William
Thu Jul 20 22:19:57 CDT 2006

"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:eaf0c258a0bc0s7smll6qpflm0idf06lbc@4ax.com...
> The high precedence of logical not requires parens:
>
> if (!(pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE))

I missed that.

> Those who've drunk enough of the C# kool-aid would insist upon:
>
> if ((pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE) == 0)

:-) But I gotta tell ya, that compiler is _fast_.

> Then there are those who would prefer:
>
> if (0 == (pDC->GetDeviceCaps(RASTERCAPS) & RC_PALETTE))
>
> To them, I would say, "Don't do that." :)

I completey agree. I know the error that doing that prevents. But if you can
take the time to write something backasswards, then surely you can count the
number of equal signs. <GD&R>

Regards,
Will



Re: How can I compile this code? by Doug

Doug
Thu Jul 20 22:54:41 CDT 2006

On Thu, 20 Jul 2006 23:19:57 -0400, "William DePalo [MVP VC++]"
<willd.no.spam@mvps.org> wrote:

>I completey agree. I know the error that doing that prevents. But if you can
>take the time to write something backasswards, then surely you can count the
>number of equal signs. <GD&R>

Speaking of which, I'd be interested to hear how others pronounce it, e.g.

if (x == y)

1. if x equals y
2. if x is equal to y
3. if x equal equal y

--
Doug Harrison
Visual C++ MVP

Re: How can I compile this code? by William

William
Thu Jul 20 23:45:57 CDT 2006

"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:5ej0c29l51vcmqarqi8eppb3kpvhdajqic@4ax.com...
> Speaking of which, I'd be interested to hear how others pronounce it, e.g.
>
> if (x == y)
>
> 1. if x equals y
> 2. if x is equal to y
> 3. if x equal equal y

#1

Regards,
Will



Re: How can I compile this code? by Ma

Ma
Fri Jul 21 02:14:05 CDT 2006

Hello William,

Thanks for your help.

> GetDC() is a function in the Win32 API. It is also a member function of
> MFC's CWnd class. My guess is that the code you copied was taken from the
> implementation of a member function. I'm guessing that the code you
> compiled stands alone. If that's the case, that's the cause of the error.
> Of course, I could be wrong on both counts.
>

You guessed right that the code I compiled stands alone. After I created
a MFC project, I created a menu item, and then add a event for it by the
Wizard. The type of the event which for the menu item is COMMAND. Then I
copied the code into the event. Finally, I couldn't through the compile
process.

Best regards.

Xiaoming



Re: How can I compile this code? by Bruno

Bruno
Fri Jul 21 06:14:01 CDT 2006

> Speaking of which, I'd be interested to hear how others pronounce it, e.g.
>
> if (x == y)
>
> 1. if x equals y
> 2. if x is equal to y
> 3. if x equal equal y

usually #1, unless i am discussing some piece over the phone in a support
call, then I use #2 or #3 to avoid ambiguity.

#1 should also be un-ambiguous however, because assignment inside an if
condition is bad practice IMO.
Most coding guidelines also discourage it.
Because of that, #1 should never mean if(x=y)

--

Kind regards,
Bruno van Dooren
bruno_nos_pam_van_dooren@hotmail.com
Remove only "_nos_pam"



Re: How can I compile this code? by Arnie

Arnie
Fri Jul 21 09:20:02 CDT 2006

"Doug Harrison [MVP]" <dsh@mvps.org> wrote in message
news:5ej0c29l51vcmqarqi8eppb3kpvhdajqic@4ax.com...
> On Thu, 20 Jul 2006 23:19:57 -0400, "William DePalo [MVP VC++]"
> <willd.no.spam@mvps.org> wrote:
>
>>I completey agree. I know the error that doing that prevents.
>>But if you can
>>take the time to write something backasswards, then surely you
>>can count the
>>number of equal signs. <GD&R>
>
> Speaking of which, I'd be interested to hear how others
> pronounce it, e.g.
>
> if (x == y)
>
> 1. if x equals y
> 2. if x is equal to y
> 3. if x equal equal y
>
> --
> Doug Harrison
> Visual C++ MVP

4. if x is pretty close to y //Floating point

- Arnie



Re: How can I compile this code? by William

William
Fri Jul 21 11:18:41 CDT 2006

"Ma Xiaoming" <maxiaoming10000@hotmail.com> wrote in message
news:es1uCVJrGHA.3996@TK2MSFTNGP04.phx.gbl...
> You guessed right that the code I compiled stands alone.

OK.

> After I created a MFC project, I created a menu item, and then add a event
> for it by the Wizard. The type of the event which for the menu item is
> COMMAND. Then I copied the code into the event. Finally, I couldn't
> through the compile process.

Well, the code as written makes the assumption that it sits inside a member
function of a CWnd class or one derived from that class.

While there is less to know about MFC than there is to know about Win32, it
is still bigger than a breadbox. :-)

You may need to find a good book, work through a tutorial like this one

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vctutor98/HTML/_gs_scribble_tutorial.asp

or post again in an MFC group in order to get you started.

Regards,
Will