V(ery) Basic
Oct 1st, 2000, 09:30 AM
Thank you, and sorry about this but I thought I'd express my feelings in song:
I turn to you,
Like a flower turning towards the Sun,
I turn to you,
Because you're the only one,
You turn me around
when I'm upside-down
etc.
OK. Anyway, I thought that I was that little bit better than everybody else, and I'd make my own Foundation Classes, just nice and simple.
I've made nice ones using inheritance ( :D ) and the ones I've made all work, except the Edit one, here it is with the classes from which it inherits:
//Window Class
class Window
{
public:
void Show();
void Hide();
void SetFont(HFONT NewFont);
HWND GethWnd();
protected:
HWND itshWnd;
};
HWND Window::GethWnd()
{
return itshWnd;
}
void Window::Show()
{
ShowWindow(itshWnd, SW_NORMAL);
}
void Window::Hide()
{
ShowWindow(itshWnd, SW_HIDE);
}
void Window::SetFont(HFONT NewFont)
{
SendMessage(itshWnd, WM_SETFONT, (WPARAM) NewFont, (LPARAM) true);
}
//Control Class
class Control: public Window
{
protected:
HWND Owner;
HINSTANCE hIns;
};
//Edit Class
class Edit: public Control
{
public:
//constructor
Edit(RECT area, HWND OwnerhWnd, HINSTANCE hStance);
~Edit();
char *GetText();
void SetText(char *Text);
};
Edit::~Edit()
{
//Nothing
}
Edit::Edit(RECT area, HWND OwnerhWnd, HINSTANCE hStance)
{
Owner = OwnerhWnd;
hIns = hStance;
itshWnd = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "", WS_CHILD , area.left, area.top, area.right - area.left, area.bottom - area.top, Owner, 0, hStance, NULL);
}
void Edit::SetText(char *Text)
{
SetWindowText(itshWnd, Text);
}
char *Edit::GetText()
{
int Len;
int IsError;
char *retVal = " ";
Len = GetWindowTextLength(itshWnd);
GetWindowText(itshWnd, (LPTSTR) retVal, Len+1);
return retVal;
}
SetText works fine, but as soon as I call GetText:
edVal1->GetText()
It raises a General Protection Fault.
And there was me thinking that the API couldn't actually cause a General Protection Fault because it was self-contained and if there was an error it just returned 0.
And I have checked that it is GetWindowText, because if it comment it out, it works fine, if I change the function to a void so that it just calls it for fun, it still crashes.
Is this a record for the first API that directly causes a General Protection Fault. Should I send this in to the Guinness Book of Records?
Please Help.
I turn to you,
Like a flower turning towards the Sun,
I turn to you,
Because you're the only one,
You turn me around
when I'm upside-down
etc.
OK. Anyway, I thought that I was that little bit better than everybody else, and I'd make my own Foundation Classes, just nice and simple.
I've made nice ones using inheritance ( :D ) and the ones I've made all work, except the Edit one, here it is with the classes from which it inherits:
//Window Class
class Window
{
public:
void Show();
void Hide();
void SetFont(HFONT NewFont);
HWND GethWnd();
protected:
HWND itshWnd;
};
HWND Window::GethWnd()
{
return itshWnd;
}
void Window::Show()
{
ShowWindow(itshWnd, SW_NORMAL);
}
void Window::Hide()
{
ShowWindow(itshWnd, SW_HIDE);
}
void Window::SetFont(HFONT NewFont)
{
SendMessage(itshWnd, WM_SETFONT, (WPARAM) NewFont, (LPARAM) true);
}
//Control Class
class Control: public Window
{
protected:
HWND Owner;
HINSTANCE hIns;
};
//Edit Class
class Edit: public Control
{
public:
//constructor
Edit(RECT area, HWND OwnerhWnd, HINSTANCE hStance);
~Edit();
char *GetText();
void SetText(char *Text);
};
Edit::~Edit()
{
//Nothing
}
Edit::Edit(RECT area, HWND OwnerhWnd, HINSTANCE hStance)
{
Owner = OwnerhWnd;
hIns = hStance;
itshWnd = CreateWindowEx(WS_EX_CLIENTEDGE, "Edit", "", WS_CHILD , area.left, area.top, area.right - area.left, area.bottom - area.top, Owner, 0, hStance, NULL);
}
void Edit::SetText(char *Text)
{
SetWindowText(itshWnd, Text);
}
char *Edit::GetText()
{
int Len;
int IsError;
char *retVal = " ";
Len = GetWindowTextLength(itshWnd);
GetWindowText(itshWnd, (LPTSTR) retVal, Len+1);
return retVal;
}
SetText works fine, but as soon as I call GetText:
edVal1->GetText()
It raises a General Protection Fault.
And there was me thinking that the API couldn't actually cause a General Protection Fault because it was self-contained and if there was an error it just returned 0.
And I have checked that it is GetWindowText, because if it comment it out, it works fine, if I change the function to a void so that it just calls it for fun, it still crashes.
Is this a record for the first API that directly causes a General Protection Fault. Should I send this in to the Guinness Book of Records?
Please Help.