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. Can I declare a control based on OS version in .h file?

Can I declare a control based on OS version in .h file?

Scheduled Pinned Locked Moved C / C++ / MFC
questionannouncement
13 Posts 5 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.
  • J Offline
    J Offline
    Joe Smith IX
    wrote on last edited by
    #1

    Hi all, I wonder if this doable. I have 2 CButton-derived classes (I don't have the source code for any of them): CButton1 and CButton2. Now I want to use CButton1 for XP or later, and use CButton2 for Win2k or older. Since controls are declared in the .h file, how do we differentiate the OS version (if feasible). I want to achieve the following (pseudo-code):

    class CMyDlg : public CDialog
    {
    ...
    // Dialog Data
    //{{AFX_DATA(CLoginDlg)
    enum { IDD = IDD_MYDLG };

    if(RunningWindowsVersion>=XP)
    CButton1 m_btn1;
    else
    CButton2 m_btn1;

    ...
    //}}AFX_DATA
    ...
    }

    If I can do this, I don't have to compile 2 versions of my program. I would appreciate it if anyone has any pointer on this matter. Thanks.

    T K D 3 Replies Last reply
    0
    • J Joe Smith IX

      Hi all, I wonder if this doable. I have 2 CButton-derived classes (I don't have the source code for any of them): CButton1 and CButton2. Now I want to use CButton1 for XP or later, and use CButton2 for Win2k or older. Since controls are declared in the .h file, how do we differentiate the OS version (if feasible). I want to achieve the following (pseudo-code):

      class CMyDlg : public CDialog
      {
      ...
      // Dialog Data
      //{{AFX_DATA(CLoginDlg)
      enum { IDD = IDD_MYDLG };

      if(RunningWindowsVersion>=XP)
      CButton1 m_btn1;
      else
      CButton2 m_btn1;

      ...
      //}}AFX_DATA
      ...
      }

      If I can do this, I don't have to compile 2 versions of my program. I would appreciate it if anyone has any pointer on this matter. Thanks.

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      not like this... but you can use polymorphism. say, in your header file, you use a CButton*, and in the constructor, you detect the os, and allocate the whether a CButton1* or a CButton2* as you like. the only condition for this to work is that CButton1 and CButton2 classes must inherit from CButton base class


      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      J 1 Reply Last reply
      0
      • J Joe Smith IX

        Hi all, I wonder if this doable. I have 2 CButton-derived classes (I don't have the source code for any of them): CButton1 and CButton2. Now I want to use CButton1 for XP or later, and use CButton2 for Win2k or older. Since controls are declared in the .h file, how do we differentiate the OS version (if feasible). I want to achieve the following (pseudo-code):

        class CMyDlg : public CDialog
        {
        ...
        // Dialog Data
        //{{AFX_DATA(CLoginDlg)
        enum { IDD = IDD_MYDLG };

        if(RunningWindowsVersion>=XP)
        CButton1 m_btn1;
        else
        CButton2 m_btn1;

        ...
        //}}AFX_DATA
        ...
        }

        If I can do this, I don't have to compile 2 versions of my program. I would appreciate it if anyone has any pointer on this matter. Thanks.

        K Offline
        K Offline
        khb
        wrote on last edited by
        #3

        Determining the OS is not so hard. Take a look at the article "XWinVer - Simple class to get windows OS version" by Hans Dietrich. Regards, Marcus.

        J S 2 Replies Last reply
        0
        • K khb

          Determining the OS is not so hard. Take a look at the article "XWinVer - Simple class to get windows OS version" by Hans Dietrich. Regards, Marcus.

          J Offline
          J Offline
          Joe Smith IX
          wrote on last edited by
          #4

          I think you missed my point. My problem is not in determining the OS version, i know it's pretty easy. What I need to know is how to declare a control differently based on the os version.

          K 1 Reply Last reply
          0
          • J Joe Smith IX

            I think you missed my point. My problem is not in determining the OS version, i know it's pretty easy. What I need to know is how to declare a control differently based on the os version.

            K Offline
            K Offline
            khb
            wrote on last edited by
            #5

            I'm sorry, I got your sentence "how do we differentiate the OS version (if feasible)" wrong :-O Regards Marcus

            1 Reply Last reply
            0
            • T toxcct

              not like this... but you can use polymorphism. say, in your header file, you use a CButton*, and in the constructor, you detect the os, and allocate the whether a CButton1* or a CButton2* as you like. the only condition for this to work is that CButton1 and CButton2 classes must inherit from CButton base class


              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              J Offline
              J Offline
              Joe Smith IX
              wrote on last edited by
              #6

              Does this mean I have create the button dynamically during run time, not thru ClassWizard? Do you have any sample code or snippet on how exactly to use your approach? Thanks.

              T 1 Reply Last reply
              0
              • J Joe Smith IX

                Does this mean I have create the button dynamically during run time, not thru ClassWizard? Do you have any sample code or snippet on how exactly to use your approach? Thanks.

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                in the .h :

                // class CButton1 : public CButton { ... }
                // class CButton2 : public CButton { ... }

                class CWatever {
                //...
                CButton\* m\_button;
                //...
                

                public:
                CWatever();
                ~CWatever();
                };

                in the .cpp :

                CWatever::CWatever() {
                //...
                if (OSType() == "XP") {
                m_button = new CButton1();
                }
                else {
                m_button = new CButton2();
                }
                //...
                }

                ~CWatever::CWatever() {
                //...
                delete m_button;
                m_button = NULL;
                //...
                }

                then you use the m_button as if it was a simple button pointer...

                m_button->SetWindowText(_T("Push Me !"));


                [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                1 Reply Last reply
                0
                • J Joe Smith IX

                  Hi all, I wonder if this doable. I have 2 CButton-derived classes (I don't have the source code for any of them): CButton1 and CButton2. Now I want to use CButton1 for XP or later, and use CButton2 for Win2k or older. Since controls are declared in the .h file, how do we differentiate the OS version (if feasible). I want to achieve the following (pseudo-code):

                  class CMyDlg : public CDialog
                  {
                  ...
                  // Dialog Data
                  //{{AFX_DATA(CLoginDlg)
                  enum { IDD = IDD_MYDLG };

                  if(RunningWindowsVersion>=XP)
                  CButton1 m_btn1;
                  else
                  CButton2 m_btn1;

                  ...
                  //}}AFX_DATA
                  ...
                  }

                  If I can do this, I don't have to compile 2 versions of my program. I would appreciate it if anyone has any pointer on this matter. Thanks.

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  For a compile-time version, how about something like:

                  #if _WIN32_WINNT >= 0x0501
                  CButton1 m_btn1;
                  #else
                  CButton2 m_btn1;
                  #endif


                  "A good athlete is the result of a good and worthy opponent." - David Crow

                  "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                  S T 2 Replies Last reply
                  0
                  • K khb

                    Determining the OS is not so hard. Take a look at the article "XWinVer - Simple class to get windows OS version" by Hans Dietrich. Regards, Marcus.

                    S Offline
                    S Offline
                    sps itsec46
                    wrote on last edited by
                    #9

                    Obey clickety! It's the law! ;P XWinVer - Simple class to get Windows OS version[^]

                    cheers, mykel OMM: "Let us be thankful we have an occupation to fill. Work hard, increase production, prevent accidents and be happy."

                    1 Reply Last reply
                    0
                    • D David Crow

                      For a compile-time version, how about something like:

                      #if _WIN32_WINNT >= 0x0501
                      CButton1 m_btn1;
                      #else
                      CButton2 m_btn1;
                      #endif


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      S Offline
                      S Offline
                      sps itsec46
                      wrote on last edited by
                      #10

                      I guess he wants the decision about the used button class during runtime and not during compile time... ;)

                      cheers, mykel OMM: "Let us be thankful we have an occupation to fill. Work hard, increase production, prevent accidents and be happy."

                      D 1 Reply Last reply
                      0
                      • D David Crow

                        For a compile-time version, how about something like:

                        #if _WIN32_WINNT >= 0x0501
                        CButton1 m_btn1;
                        #else
                        CButton2 m_btn1;
                        #endif


                        "A good athlete is the result of a good and worthy opponent." - David Crow

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        T Offline
                        T Offline
                        toxcct
                        wrote on last edited by
                        #11

                        i thought of this, but the OP seems to want to determine the OS at runtime...


                        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                        D 1 Reply Last reply
                        0
                        • S sps itsec46

                          I guess he wants the decision about the used button class during runtime and not during compile time... ;)

                          cheers, mykel OMM: "Let us be thankful we have an occupation to fill. Work hard, increase production, prevent accidents and be happy."

                          D Offline
                          D Offline
                          David Crow
                          wrote on last edited by
                          #12

                          See here.


                          "A good athlete is the result of a good and worthy opponent." - David Crow

                          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                          1 Reply Last reply
                          0
                          • T toxcct

                            i thought of this, but the OP seems to want to determine the OS at runtime...


                            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

                            D Offline
                            D Offline
                            David Crow
                            wrote on last edited by
                            #13

                            Which is why I specifically stated "compile-time version." :rolleyes:


                            "A good athlete is the result of a good and worthy opponent." - David Crow

                            "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                            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