Can I declare a control based on OS version in .h file?
-
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.
-
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.
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]
-
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.
-
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.
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.
-
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.
-
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]
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.
-
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.
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]
-
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.
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
-
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.
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."
-
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
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."
-
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
i thought of this, but the OP seems to want to determine the OS at runtime...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
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."
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
-
i thought of this, but the OP seems to want to determine the OS at runtime...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
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