-
Code:
class Window;
class ComboBox;
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);
}
class ComboBox: public Window
{
public:
//constructors
ComboBox(RECT area, HWND OwnerhWnd, HINSTANCE hStance);
//ComboBox(RECT area, HWND OwnerhWnd);
~ComboBox();
void AddItem(char *NewItem);
int GetItem();
protected:
HWND Owner;
HINSTANCE hIns;
};
ComboBox::ComboBox(RECT area, HWND OwnerhWnd, HINSTANCE hStance)
{
Owner = OwnerhWnd;
//hIns = hStance;
itshWnd = CreateWindowEx(WS_EX_CLIENTEDGE, "ComboBox", "", WS_CHILD | CBS_DROPDOWNLIST , area.left, area.top, area.right - area.left, area.bottom - area.top, Owner, 0, hStance, NULL);
}
/* ComboBox::ComboBox(RECT area, HWND OwnerhWnd)
{
//Assumes that a different Combo (with HINSTANCE) has been created
Owner = OwnerhWnd;
itshWnd = CreateWindowEx(WS_EX_CLIENTEDGE, "ComboBox", "", WS_CHILD | CBS_DROPDOWNLIST , area.left, area.top, area.right - area.left, area.bottom - area.top, Owner, 0, hIns, NULL);
} */
ComboBox::~ComboBox()
{
//Nothing
}
void ComboBox::AddItem(char *NewItem)
{
SendMessage(itshWnd, CB_ADDSTRING, 0, (WPARAM) NewItem);
}
int ComboBox::GetItem()
{
return (int) SendMessage(itshWnd, CB_GETCURSEL, 0, 0);
}
In case you hadn't noticed I'm trying to make my own sort of class for each control, starting with comboboxes.
Now, what I want to do is to be able to access the class
from any part of code module. But if I make a global variable:
Code:
ComboBox cmbOper(WndRect, hWnd, hInst);
It obviously fails miserably because hInst, hWnd and WndRect haven't been created yet.
I tried something to do with the free store, but I couldn't access it outside of the procedure where I created it because the actual memory still existed, but the name I had given it was not declared in the routine I was trying to call it from, and that me... Arrrrgh.
Plain and simple:
How do I create an object that I can access anywhere in my code given that it has its own constructor?
There's got to be a way...
-
How about a global variable that's a pointer?
Code:
ComboBox *gpCombo;
WinMain(...) {
gpCombo = new ComboBox(...);
...
delete gpCombo;
}
-
Thanks soooo much. I really needed that. I'll help you one day.
<ahem>
<ahem>
<ahem><ahem>
<ahem><ahem>
<ahem><ahem><ahem>
*breaks into mad coughing fit*
Sorry. :(
-
Okay...lets see if you can help me with this small query:
Do you know how to use a C++ class from VB???
Hehehe.
PS: This is a genuine question (I just never bothered asking after I only got 2 views, and one was mine)
-
You'd obviously... err ...
<looks through book>
<realises the 'book' is PLAYBOY>
<sees in-depth article in C++-To-VB class porting on page 27>
<Notices they're 'porting' something else on page 28> ;)
<Can't be bothered to answer question now that he's seen page 31 ;) >
<Sorry, parksie, business before pleasure :D >
-
LOL
Hey - you been going through my stuff?