PDA

Click to See Complete Forum and Search --> : changng object properties in C


Bad5887
Jun 30th, 2000, 09:59 PM
how do you change a object's properties in 32 bit C? i haev the lcc win32 compiler, it's awesome but i'm still kinda new, please give me an examople how to dothis:

How do you enable/disable a button in C?

Jul 1st, 2000, 09:43 AM
I have Visual C++ and here is how you disable a button. Right-click the Button, select properties, and click on the Disabled Checkbox.

parksie
Jul 1st, 2000, 09:44 AM
What do you mean, enable/disable. Is that a button in a dialogue box? If you are using anything like MFC/OWL then it's different. If you are using 'bare-foot' API, then look up the SendDlgItemMessage function, and send the WM_ENABLE message. Disabling is slightly strange, and you'll need to check MSDN for that. http://msdn.microsoft.com/library

--- one edit later ---
sorry meg, was writing my reply at the same time as you!
...oh well. If he's not using MSVC then that won't work.


[Edited by parksie on 07-01-2000 at 10:47 PM]

Bad5887
Jul 1st, 2000, 01:25 PM
megatron... i ment at runtime, yeah i'm using bare API, cas my compiler is LCC win32 C compiler. i also have vc++ 6 prof edition but lcc makes nice small fast exe's and does all the same things.


i know that is the api call but can u give me and example pleaseeeeeeeee, thanks

Jul 1st, 2000, 02:38 PM
Use the EnableWindow API. I can tell you to do it in VC++. First, when you create your Button, you must add a Member Variable using the Class Wizard. Call it m_bTest.

Put this code in another Button.


void CDialogtestDlg::MyButton()
{
// Disable the Button
m_bTest.EnableWindow(FALSE);
}

Bad5887
Jul 1st, 2000, 02:59 PM
i don't know VC++, i don't even knwo what the heck were thoughs :: for?

parksie
Jul 1st, 2000, 03:54 PM
In C++, when you create an object, by definition it has its own 'namespace'. For example:


namespace A {
int i;
string mystr;
}

namespace B {
int i;
string anotherstring;
}

void function() {
int j;
string x;
j = i; // WRONG: which namespace?
j = A::i; // RIGHT: select from namespace A
j = B::i; // RIGHT: select from namespace B
x = mystr; // RIGHT: no need to select namespace
x = anotherstring; // RIGHT: no need to select namespace
}


So, when you define your class:


class MyClass {
public:
MyClass();
virtual ~MyClass();

void MyFunction(int iParam);
int m_iMyMemberVariable;
}


They are now under the namespace 'MyClass'.

So, to define the functions:


MyClass::MyFunction(int iParam) {
m_iMyMemberVariable = iParam;
}


The '::' selects the namespace, so the compiler knows that you are defining the 'MyFunction' function under namespace 'MyClass'. There is no need to select the namespace for m_iMyMemberVariable because that is the default namespace for that function now.

Back to your original question, though, Megatron was using MFC (Microsoft Foundation Classes) which make Windows programming a lot easier. The CWnd::EnableWindow function is a wrapper for the API EnableWindow function, which can be accessed by ::EnableWindow (::XX means select XX out of the default namespace, which everything which is not already in a namespace ends up in). This is defined as:


void EnableWindow(HWND hWindow, BOOL bEnableFlag);


You need to pass the HWND of the button, and either 1 or 0 for bEnableFlag to enable or disable respectively.



[Edited by parksie on 07-02-2000 at 05:30 AM]