|
-
Sep 30th, 2000, 07:55 AM
#1
Thread Starter
Fanatic Member
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...
-
Sep 30th, 2000, 08:58 AM
#2
Monday Morning Lunatic
How about a global variable that's a pointer?
Code:
ComboBox *gpCombo;
WinMain(...) {
gpCombo = new ComboBox(...);
...
delete gpCombo;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 30th, 2000, 11:38 AM
#3
Thread Starter
Fanatic Member
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. 
-
Sep 30th, 2000, 12:01 PM
#4
Monday Morning Lunatic
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)
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 1st, 2000, 07:57 AM
#5
Thread Starter
Fanatic Member
-
Oct 1st, 2000, 01:43 PM
#6
Monday Morning Lunatic
LOL
Hey - you been going through my stuff?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|