code to disable
-
i make a dialog box on which i made edit boxes now i made a menu in another dialog box menu contain two commands add data and update data now i want that when i click on add data menu the dialog box open with all edit boxes enable and when i click on update data menu the dialog box open with some edit boxes disable plz tem me how it could be possible send me code for this Please mail me
Before showing your second dialog, set a boolean flag, for instance:
CMyDialog dlg; dlg.mDisableSomeControls = true; dlg.DoModal();
where
mDisableSomeControls
is a new member of yourCMyDialog
, of boolean type, initialized tofalse
inCMyDialog
constructor. Next, inCMyDialog::OnInitDialog
function, check themDisableSomeControls
value and disable needed controls, for instance:BOOL CMyDialog::OnInitDialog() { . . . m_cMyEditBox1.EnableWindow(! mDisableSomeControls); m_cMyEditBox2.EnableWindow(! mDisableSomeControls); . . . }
Hope it helps. -- modified at 7:26 Monday 12th June, 2006
-
i make a dialog box on which i made edit boxes now i made a menu in another dialog box menu contain two commands add data and update data now i want that when i click on add data menu the dialog box open with all edit boxes enable and when i click on update data menu the dialog box open with some edit boxes disable plz tem me how it could be possible send me code for this Please mail me
if CMainDialog is main dialog and CLocalDialog is another dialog use this code in another dialog
CMainDialog* m_Main = (CMainDialog* )GetParent(); m_Main->m_Youredit.EnableWindow(0);//disable or 1 enable
_**
**_
whitesky
-
Before showing your second dialog, set a boolean flag, for instance:
CMyDialog dlg; dlg.mDisableSomeControls = true; dlg.DoModal();
where
mDisableSomeControls
is a new member of yourCMyDialog
, of boolean type, initialized tofalse
inCMyDialog
constructor. Next, inCMyDialog::OnInitDialog
function, check themDisableSomeControls
value and disable needed controls, for instance:BOOL CMyDialog::OnInitDialog() { . . . m_cMyEditBox1.EnableWindow(! mDisableSomeControls); m_cMyEditBox2.EnableWindow(! mDisableSomeControls); . . . }
Hope it helps. -- modified at 7:26 Monday 12th June, 2006
plz tel me how can i check (mDisableSomeControls ) for updaet menu command how i write if(............) { GetDlgItem(IDC_EDIT1)->EnableWindow(FALSE); } wat i write in if statement Please mail me
-
plz tel me how can i check (mDisableSomeControls ) for updaet menu command how i write if(............) { GetDlgItem(IDC_EDIT1)->EnableWindow(FALSE); } wat i write in if statement Please mail me
As I understand, you have two menu items -- "Add Data and "Update Data", -- and two handler functions for them in first dialog. In these functions, you probably display your second dialog using:
CMyDialog dlg; dlg.DoModal();
If this is true, then you have to make changes. In "Add Data" handler, change to:
CMyDialog dlg; dlg.mDisableSomeControls = false; dlg.DoModal();
In "Update Data" handler, change to:
CMyDialog dlg; dlg.mDisableSomeControls = true; dlg.DoModal();
Then in
CMyDialog::OnInitDialog
, do something like this:if(mDisableSomeControls) { GetDlgItem(IDC_EDIT1)->EnableWindow(FALSE); }
Otherwise your program's flow is probably different. Is the menu and menu’s handlers in first dialog, while the controls needed to be disabled are in the second dialog?
-
As I understand, you have two menu items -- "Add Data and "Update Data", -- and two handler functions for them in first dialog. In these functions, you probably display your second dialog using:
CMyDialog dlg; dlg.DoModal();
If this is true, then you have to make changes. In "Add Data" handler, change to:
CMyDialog dlg; dlg.mDisableSomeControls = false; dlg.DoModal();
In "Update Data" handler, change to:
CMyDialog dlg; dlg.mDisableSomeControls = true; dlg.DoModal();
Then in
CMyDialog::OnInitDialog
, do something like this:if(mDisableSomeControls) { GetDlgItem(IDC_EDIT1)->EnableWindow(FALSE); }
Otherwise your program's flow is probably different. Is the menu and menu’s handlers in first dialog, while the controls needed to be disabled are in the second dialog?
can i know wat is mDisableSomeControls is thsi variable of edit box Please mail me
-
can i know wat is mDisableSomeControls is thsi variable of edit box Please mail me
In above solution,
mDisableSomeControls
is a variable defined by you in your dialog class. Let us say your second dialog class isCMyDialog
, so open corresponding MyDialog.h file and add a definition, like this:class CMyDialog : public CDialog { public: bool mDisableSomeControls; . . . };
-
In above solution,
mDisableSomeControls
is a variable defined by you in your dialog class. Let us say your second dialog class isCMyDialog
, so open corresponding MyDialog.h file and add a definition, like this:class CMyDialog : public CDialog { public: bool mDisableSomeControls; . . . };
thanks a lot Please mail me
-
In above solution,
mDisableSomeControls
is a variable defined by you in your dialog class. Let us say your second dialog class isCMyDialog
, so open corresponding MyDialog.h file and add a definition, like this:class CMyDialog : public CDialog { public: bool mDisableSomeControls; . . . };
i am sorry i an again disturbing u but i have a problem in loging in dialog box ihav dialog cbox which has tow edit boxes one for username and one for password so i want that when i enter username and password the it conform those from mysql table named user and when i enter admin type ysrname and passward it open one form and wheni enter pm username and password it open second dialog box note : mysql database may contain two tables one for users and one for authentication Please mail me
-
i am sorry i an again disturbing u but i have a problem in loging in dialog box ihav dialog cbox which has tow edit boxes one for username and one for password so i want that when i enter username and password the it conform those from mysql table named user and when i enter admin type ysrname and passward it open one form and wheni enter pm username and password it open second dialog box note : mysql database may contain two tables one for users and one for authentication Please mail me
If you are making a database application, you should be able to read from the database and check the type of the user -- simple user or administrator. For instance, the "users" data table may contain a column which describes this type, for instance 0 for simple users or 1 for administrators. After you read the type from the database, you can do something like this:
int type = ... // the user’s type from database switch(type) { case 0: // regular user { CMyDialogForSimpleUsers dlg; dlg.DoModal(); } break; case 1: // administrator { CMyDialogForAdministrators dlg; dlg.DoModal(); } break; }
If you have troubles with databases using C++, I think you can post a separate question to the forum.
-
If you are making a database application, you should be able to read from the database and check the type of the user -- simple user or administrator. For instance, the "users" data table may contain a column which describes this type, for instance 0 for simple users or 1 for administrators. After you read the type from the database, you can do something like this:
int type = ... // the user’s type from database switch(type) { case 0: // regular user { CMyDialogForSimpleUsers dlg; dlg.DoModal(); } break; case 1: // administrator { CMyDialogForAdministrators dlg; dlg.DoModal(); } break; }
If you have troubles with databases using C++, I think you can post a separate question to the forum.
can u tel me how i make table in mysql for 0 and 1 type as u told me i simply create a table which contain username and password but as u told plz tel me abt how i create table for 0 user and 1 for adm Please mail me
-
can u tel me how i make table in mysql for 0 and 1 type as u told me i simply create a table which contain username and password but as u told plz tel me abt how i create table for 0 user and 1 for adm Please mail me
In the same manner as you created your users table containing two columns, you can create a table containing three columns. Just add one more column named "type" and having an integer type. If you use some database tools, like MySQL Query Browser, it is easy to add a new column to an existing table.
-
In the same manner as you created your users table containing two columns, you can create a table containing three columns. Just add one more column named "type" and having an integer type. If you use some database tools, like MySQL Query Browser, it is easy to add a new column to an existing table.
i am sorry for delay i try this code but as value fetched from mysql stored in row which is mysql variable and switch case does not work with this plz tel me . groupid is values 0 and 1 which store in mysql table. if (!mysql_query(myDB,"select groupid from users")) res=mysql_store_result(myDB); row = mysql_fetch_row(res); { i = (int) mysql_num_rows( res ); if (i != 1) { MessageBox("no match"); mysql_free_result( res ) ; goto exit_here; } } //int type = ... // the user's type from database switch(row) { case 0: // regular user { CAfterone dlg; dlg.DoModal(); } break; case 1: // administrator { CAfterone dlg; dlg.DoModal(); } break; } exit_here: mysql_close( myDB); } Please mail me
-
i am sorry for delay i try this code but as value fetched from mysql stored in row which is mysql variable and switch case does not work with this plz tel me . groupid is values 0 and 1 which store in mysql table. if (!mysql_query(myDB,"select groupid from users")) res=mysql_store_result(myDB); row = mysql_fetch_row(res); { i = (int) mysql_num_rows( res ); if (i != 1) { MessageBox("no match"); mysql_free_result( res ) ; goto exit_here; } } //int type = ... // the user's type from database switch(row) { case 0: // regular user { CAfterone dlg; dlg.DoModal(); } break; case 1: // administrator { CAfterone dlg; dlg.DoModal(); } break; } exit_here: mysql_close( myDB); } Please mail me
I am not an expert in databases, but I think your MySQL statement for determining groupid for a user by username should look like this:
"SELECT groupid from users **WHERE username='_the-user-name_'**"
.MYSQL_ROW
contains string, so I think yourswitch
must look like this:switch(**atoi(row[0])**)
. -
I am not an expert in databases, but I think your MySQL statement for determining groupid for a user by username should look like this:
"SELECT groupid from users **WHERE username='_the-user-name_'**"
.MYSQL_ROW
contains string, so I think yourswitch
must look like this:switch(**atoi(row[0])**)
.plz sir i distyurb u again but it gives no error but it does not go to second dialog box plz send me code for this if (!mysql_query(myDB,"SELECT groupid from users WHERE userid= \'" + user + "\' and \'" + pass + "\'")) res=mysql_store_result(myDB); row = mysql_fetch_row(res); { i = (int) mysql_num_rows( res ); if (i != 1) { MessageBox("no match"); mysql_free_result( res ) ; goto exit_here; } } switch(atoi(row[0])) { case 0: // regular user { CAfterone dlg; dlg.DoModal(); } break; case 1: // administrator { CAfterone dlg; dlg.DoModal(); } break; } exit_here: mysql_close( myDB); Please mail me
-
plz sir i distyurb u again but it gives no error but it does not go to second dialog box plz send me code for this if (!mysql_query(myDB,"SELECT groupid from users WHERE userid= \'" + user + "\' and \'" + pass + "\'")) res=mysql_store_result(myDB); row = mysql_fetch_row(res); { i = (int) mysql_num_rows( res ); if (i != 1) { MessageBox("no match"); mysql_free_result( res ) ; goto exit_here; } } switch(atoi(row[0])) { case 0: // regular user { CAfterone dlg; dlg.DoModal(); } break; case 1: // administrator { CAfterone dlg; dlg.DoModal(); } break; } exit_here: mysql_close( myDB); Please mail me
-
Try to put a breakpoint at
switch
, or useMessageBox
, in order to see which value containsrow[0]
. If it contains an unexpectedNULL
or a non-numeric string, thenatoi
returns0
.sir u geneous thanks but sir iwill not display second dialog box as second dialog box has class named CAdmin and first dialog box has class CAfterone case 0: // regular user { CAfterone dlg; dlg.DoModal(); } break; case 1: // administrator { CAdmin dlg; dlg.DoModal(); } break; } Please mail me
-
sir u geneous thanks but sir iwill not display second dialog box as second dialog box has class named CAdmin and first dialog box has class CAfterone case 0: // regular user { CAfterone dlg; dlg.DoModal(); } break; case 1: // administrator { CAdmin dlg; dlg.DoModal(); } break; } Please mail me
thanks a lot sir this works very well u r absolutly geneious Please mail me
-
plz tel me how can i check (mDisableSomeControls ) for updaet menu command how i write if(............) { GetDlgItem(IDC_EDIT1)->EnableWindow(FALSE); } wat i write in if statement Please mail me
Please read this article[^] on why you do not want to use GetDlgItem and how you can avoid it while makeing your code mor readble. The author Joseph M. Newcomer is a old regular here on codeproject. His Page is full of great tips.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.