Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. code to disable

code to disable

Scheduled Pinned Locked Moved C / C++ / MFC
announcement
21 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y yogendra kaushik

    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

    V Offline
    V Offline
    Viorel
    wrote on last edited by
    #4

    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 your CMyDialog, of boolean type, initialized to false in CMyDialog constructor. Next, in CMyDialog::OnInitDialog function, check the mDisableSomeControls 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

    Y 1 Reply Last reply
    0
    • Y yogendra kaushik

      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

      H Offline
      H Offline
      Hamid Taebi
      wrote on last edited by
      #5

      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


      1 Reply Last reply
      0
      • V Viorel

        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 your CMyDialog, of boolean type, initialized to false in CMyDialog constructor. Next, in CMyDialog::OnInitDialog function, check the mDisableSomeControls 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

        Y Offline
        Y Offline
        yogendra kaushik
        wrote on last edited by
        #6

        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

        V J 2 Replies Last reply
        0
        • Y yogendra kaushik

          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

          V Offline
          V Offline
          Viorel
          wrote on last edited by
          #7

          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?

          Y 1 Reply Last reply
          0
          • V Viorel

            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?

            Y Offline
            Y Offline
            yogendra kaushik
            wrote on last edited by
            #8

            can i know wat is mDisableSomeControls is thsi variable of edit box Please mail me

            V 1 Reply Last reply
            0
            • Y yogendra kaushik

              can i know wat is mDisableSomeControls is thsi variable of edit box Please mail me

              V Offline
              V Offline
              Viorel
              wrote on last edited by
              #9

              In above solution, mDisableSomeControls is a variable defined by you in your dialog class. Let us say your second dialog class is CMyDialog, so open corresponding MyDialog.h file and add a definition, like this:

              class CMyDialog : public CDialog
              {
              public:
                  bool mDisableSomeControls;
                  . . .
              };
              
              Y 2 Replies Last reply
              0
              • V Viorel

                In above solution, mDisableSomeControls is a variable defined by you in your dialog class. Let us say your second dialog class is CMyDialog, so open corresponding MyDialog.h file and add a definition, like this:

                class CMyDialog : public CDialog
                {
                public:
                    bool mDisableSomeControls;
                    . . .
                };
                
                Y Offline
                Y Offline
                yogendra kaushik
                wrote on last edited by
                #10

                thanks a lot Please mail me

                1 Reply Last reply
                0
                • V Viorel

                  In above solution, mDisableSomeControls is a variable defined by you in your dialog class. Let us say your second dialog class is CMyDialog, so open corresponding MyDialog.h file and add a definition, like this:

                  class CMyDialog : public CDialog
                  {
                  public:
                      bool mDisableSomeControls;
                      . . .
                  };
                  
                  Y Offline
                  Y Offline
                  yogendra kaushik
                  wrote on last edited by
                  #11

                  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

                  V 1 Reply Last reply
                  0
                  • Y yogendra kaushik

                    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

                    V Offline
                    V Offline
                    Viorel
                    wrote on last edited by
                    #12

                    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.

                    Y 1 Reply Last reply
                    0
                    • V Viorel

                      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.

                      Y Offline
                      Y Offline
                      yogendra kaushik
                      wrote on last edited by
                      #13

                      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

                      V 1 Reply Last reply
                      0
                      • Y yogendra kaushik

                        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

                        V Offline
                        V Offline
                        Viorel
                        wrote on last edited by
                        #14

                        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.

                        Y 1 Reply Last reply
                        0
                        • V Viorel

                          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.

                          Y Offline
                          Y Offline
                          yogendra kaushik
                          wrote on last edited by
                          #15

                          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

                          V 1 Reply Last reply
                          0
                          • Y yogendra kaushik

                            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

                            V Offline
                            V Offline
                            Viorel
                            wrote on last edited by
                            #16

                            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 your switch must look like this: switch(**atoi(row[0])**).

                            Y 1 Reply Last reply
                            0
                            • V Viorel

                              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 your switch must look like this: switch(**atoi(row[0])**).

                              Y Offline
                              Y Offline
                              yogendra kaushik
                              wrote on last edited by
                              #17

                              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

                              V 1 Reply Last reply
                              0
                              • Y yogendra kaushik

                                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

                                V Offline
                                V Offline
                                Viorel
                                wrote on last edited by
                                #18

                                Try to put a breakpoint at switch, or use MessageBox, in order to see which value contains row[0]. If it contains an unexpected NULL or a non-numeric string, then atoi returns 0.

                                Y 1 Reply Last reply
                                0
                                • V Viorel

                                  Try to put a breakpoint at switch, or use MessageBox, in order to see which value contains row[0]. If it contains an unexpected NULL or a non-numeric string, then atoi returns 0.

                                  Y Offline
                                  Y Offline
                                  yogendra kaushik
                                  wrote on last edited by
                                  #19

                                  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

                                  Y 1 Reply Last reply
                                  0
                                  • Y yogendra kaushik

                                    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

                                    Y Offline
                                    Y Offline
                                    yogendra kaushik
                                    wrote on last edited by
                                    #20

                                    thanks a lot sir this works very well u r absolutly geneious Please mail me

                                    1 Reply Last reply
                                    0
                                    • Y yogendra kaushik

                                      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

                                      J Offline
                                      J Offline
                                      jhwurmbach
                                      wrote on last edited by
                                      #21

                                      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.

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups