RE: Member call removes display of text????
OOPS again!!!!
my wndProc should of read as so, with the object innitated!
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
HDC hdc;
PAINTSTRUCT ps;
TEXTMETRIC tm;
RECT rect;
Cat Frisky(11); //This was left out in my previous post, but is in my
program.
A million Sorry's
--
Best regards
Robert
"Robby" wrote:
Hello,
This one is a good one!
Okay, here is the relative code:
=====================================================
class Cat
{
public:
Cat(int initialAge); //Constructor
~Cat(); //Destructor
int getAge();
void setAge(int age);
void Meow(HDC hdc,RECT rect);
private:
int itsAge;
};
//Constructor
Cat::Cat(int initialAge)
{
itsAge = initialAge;
}
//Destructor
Cat::~Cat()
{}
int Cat::getAge()
{
return itsAge;
}
void Cat::setAge(int age)
{
itsAge = age;
}
void Cat::Meow(HDC hdc,RECT rect)
{
TCHAR szBuffer[2];
wsprintf(szBuffer,TEXT("%d"),itsAge);
DrawText (hdc,TEXT ("Message in Method"),-1, &rect,
DT_CENTER | DT_TOP | DT_SINGLELINE);
DrawText (hdc,szBuffer,-1, &rect,
DT_CENTER | DT_BOTTOM | DT_SINGLELINE);
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM
lParam)
{
HDC hdc;
PAINTSTRUCT ps;
TEXTMETRIC tm;
RECT rect;
case WM_CREATE:
hdc = GetDC (hWnd);
GetTextMetrics(hdc,&tm);
cxChar = tm.tmAveCharWidth;
cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar /2;
cyChar = tm.tmHeight + tm.tmExternalLeading;
ReleaseDC (hWnd,hdc);
return 0;
case WM_PAINT:
hdc = BeginPaint (hWnd,&ps);
GetClientRect(hWnd,&rect);
/ /If I comment out the next line then the DrawText and the ExtTextOut
// functions don't display their text.
//Frisky.setAge(5);
Frisky.Meow(hdc,rect);
//The next two commands display nothing if "Frisky.setAge(5); " is
commented
DrawText (hdc,TEXT ("Message in Main"),-1, &rect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
ExtTextOut(hdc,100,100,ETO_OPAQUE ,NULL, //ETO_CLIPPED,NULL,
messages[0].szMessage,lstrlen(messages[0].szMessage),NULL);
EndPaint (hWnd, &ps);
return 0;
===================================================
Even though I am using this piece of code in eVC++, I think it would do the
same in VC++.... I can't really be 100% sure though.... However, the funny
thing is that, if I don't comment out the line:
Frisky.setAge(5);
in my WM_PAINT handler, then the following 3 lines work OKAY and display
whatever they are supposed to! But, if I comment out the line:
Frisky.setAge(5);
Then, whatever "Frisky.Meow(hdc,rect);" is supposed to display is OKAY, but
the 2 lines after that don't display anything at all??????
If this has something to do with the fact that I am running this code in
eVC++, then please feel free to advise me that this question should be
appropriately posted in the eVC++ newsgroups, however, if you feel that
weather this code would reside in VC++ or in eVC++ compilers is irrelivant to
its mysterious behaviour, then, I would love to heare from you....
All suggestions are *very* appreciated !!!
Thankyou guys!
P.S. post me anytime... I will be up all night! :-)
--
Best regards
Robert