|
Victor,
May i know how can know whether user selected different tabs? I mean my function should know when user selects different tabs, based on that i can refresh my single view. ?
|
|
|
|
|
|
Hi.
In my MFC application, i created a class which is derived from CTabView and created few tabs(views) using AddView(). Now i want to change the color of the tab views. May i know how to change the background color of those views?
Thanks in Advance.
|
|
|
|
|
|
I want the first one i.e., changing the background color of the CView. I tried with below call
SetClassLong(GetActiveView()->GetSafeHwnd(), 0, RGB(255, 0, 0)); but it dint work.
|
|
|
|
|
Sampath579 wrote: I tried with below call
SetClassLong(GetActiveView()->GetSafeHwnd(), 0, RGB(255, 0, 0)); but it dint work.
And how should it "work"? Where did you find this strange code? Did you read the SetClassLong function (Windows) documentation in MSDN?
I posted you a link to the Forum where you can find a working code. Why did you ignore it?
|
|
|
|
|
Thanks. Its working fine.
|
|
|
|
|
|
Hi.
I created a class which is derived from CTabView. In OnCretae() function it created a window with a tab control on window. Later i created few views by calling AddView(). I created 5 view.
Now, when i click on the arrow buttons on the tab control below, my control is not switching the tabs.
May i know which function should i call to switch the tabs on my window?
And also let me know how to disable it?
modified 11-Mar-18 5:13am.
|
|
|
|
|
here in the code below i am trying to print the increment every time the same object is called, but it's giving error.
#include <iostream>
using namespace std;
class Names{
int m;
static int count;
public:
void setcode(void){
m = ++count;
cout<<m<<endl;
}
};
int main(){
Names x;
for(int i=1; i<5; i++){
x.setcode();
}
return 0;
}
Error:
Quote: /tmp/ccDcxr5a.o: In function Names::setcode()': savinglistOfNames.cpp text._ZN5Names7setcodeEv[_ZN5Names7setcodeEv]+0xe): undefined reference toNames::count'
savinglistOfNames.cpp text._ZN5Names7setcodeEv[_ZN5Names7setcodeEv]+0x17): undefined reference to Names::count' savinglistOfNames.cpp text._ZN5Names7setcodeEv[_ZN5Names7setcodeEv]+0x1d): undefined reference toNames::count'
collect2: error: ld returned 1 exit status
Thank you
modified 10-Mar-18 7:44am.
|
|
|
|
|
Tarun Jha wrote: but it's giving error. And we must guess what that error is, and where it occurs?
|
|
|
|
|
|
You have declared the variable count in your Names class, but never defined it in your code. Add the following line after the class declaration:
int Names::count;
|
|
|
|
|
|
1>ModifyDlg.obj : error LNK2001: 无法解析的外部符号 "public: virtual int __thiscall CModifyDlg::OnInitDialog(void)" (?OnInitDialog@CModifyDlg@@UAEHXZ)
1>WorkDlg.obj : error LNK2001: 无法解析的外部符号 "protected: virtual int __thiscall CWorkDlg::OnInitDialog(void)" (?OnInitDialog@CWorkDlg@@MAEHXZ)
|
|
|
|
|
|
Here's what i have tried.
#include <iostream>
#include <cstring>
#define MAX 100
using namespace std;
int m=0;
class Names{
char name[5][30];
public:
void getdata(){
cout<<"Entre name :\t";
cin.ignore(1000, '\n');
cin>>name[m];
m++;
}
void display(void){
for(int i=0; i<m; i++){
cout<<name[i]<<endl;
}
}
};
int main(){
Names x;
for(int i=0; i<5; i++){
x.getdata();
}
x.display();
return 0;
}
i tried getline(), but it was giving error. How do i take a string as a input ?
modified 10-Mar-18 0:37am.
|
|
|
|
|
Please test it and let me know whether it solved your requirement.
#include <iostream>
#include <string>
#define MAX 100
using namespace std;
class Names {
string name[3];
public:
void getdata()
{
for (int i = 0; i < 3; i++)
{
cout << "Enter Names:" << endl;
getline(cin,name[i]);
}
}
void display(void) {
for (int i = 0; i<3; i++) {
cout << name[i] << endl;
}
}
};
void main()
{
Names n;
n.getdata();
n.display();
getchar();
}
|
|
|
|
|
Tarun Jha wrote:
i tried getline(), but it was giving error. Can you make your font size larger? I cannot see the error from here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
i will try .
and thank you
|
|
|
|
|
I am working with an ARM microcontroller and I have kind of a statemachine with several hundred states. In order to be able to overview it, I have written the code so that it has a 1:1 correspondence with a flowchart specification. I have removed irrelevant code, but basically the code works like this:
Bool_t (*returnTrueOrFalseFunctionPtr) (void);
void (*actionFunctionPtr) (int);
struct myStruct_s {
returnTrueOrFalseFunctionPtr trueOrFalse;
struct myStruct_s* whereToGoIfTrue;
struct myStruct_s* whereToGoIfFalse;
actionFunctionPtr actionsToPerformInThisState[5];
int actionArguments[5];
};
static struct myStruct_s myStateMachine1[];
static struct myStruct_s myStateMachine2[];
static struct myStruct_s myStateMachine3[];
static struct myStruct_s myStateMachine4[];
define myStateMachine1 ms1
define myStateMachine2 ms2
define myStateMachine3 ms3
define myStateMachine4 ms4
static struct myStruct_s myStateMachine1[] = {
{evaluateSomething, &ms1[1], &ms1[3], {startMotor,increaseSpeed, NULL, NULL, NULL, 3,5, 0, 0,0},
{evaluateSomething, &ms1[2], &ms2[0], {stopMotor, openExhaust, decreaseSpeed,NULL, NULL, 1,20,13,0,0},
{evaluateSomething, &ms1[0], &ms1[2], {openRelay, writeStatusToLog,increaseSpeed,NULL, NULL, 4,5, 87,0,0},
{evaluateSomething, &ms1[4], &ms2[1], {blah blah blah... },
{evaluateSomething, &ms2[1], &ms2[2], {blah blah blah... },
};
struct myStruct_s myStateMachine2[] = {
{evaluateSomething, &ms2[1], &ms2[3], { blah blah blah... },
{evaluateSomething, &ms2[2], &ms3[0], { blah blah blah... },
{evaluateSomething, &ms3[1], &ms3[3], { blah blah blah... },
{evaluateSomething, &ms2[4], &ms4[1], { blah blah blah... },
{evaluateSomething, &ms4[0], &ms2[2], { blah blah blah... },
};
I am very happy with this code format, it make it very easy for me to follow where I am in the statemachine/flowchart and decide where to go next. My problem is that I need to port this code to a microcontroller that has little memory, so I would like to memory-optimize the code heavily. I have already replaced my action function pointers with an enum instead:
enum actionsToPerformInThisState_e {
startMotor_,
stopMotor_,
openRelay_,
openExhaust_,
writeStatusToLog_,
decreaseSpeed_,
increaseSpeed_,
NULL_
};
struct myStruct_s {
returnTrueOrFalseFunctionPtr trueOrFalse;
struct myStruct_s* whereToGoIfTrue;
struct myStruct_s* whereToGoIfFalse;
actionsToPerformInThisState_e actionToPerformInThisState0 : 3;
actionsToPerformInThisState_e actionToPerformInThisState1 : 3;
actionsToPerformInThisState_e actionToPerformInThisState2 : 3;
actionsToPerformInThisState_e actionToPerformInThisState3 : 3;
actionsToPerformInThisState_e actionToPerformInThisState4 : 3;
int actionArguments[5];
};
What else can I do to reduce memory usage? Since most states don't use all 5 actions, I would like to have variable number of actions, but the elements in the array must be of same size, or can anybody think of a workaround (I can't place the actions outside the array and have a pointer to them because then the nice readability is lost). What about all pointers (each occupy a whopping 4 bytes!!!) to next states, can anybody think of another way to accomplish this linking? Other suggestions?
-- modified 9-Mar-18 15:17pm.
|
|
|
|
|
Can the actionArguments have a narrower type? Maybe 5 chars instead of 5 ints?
The next-state pointers could be integers that index into the array of states instead of direct pointers, that would probably allow them to be uint16_t.
Maybe the pointer to the true/false function can be an enum too?
|
|
|
|
|
harold aptroot wrote:
Can the actionArguments have a narrower type? Maybe 5 chars instead of 5 ints?
No, actionArguments can sometimes use 32 bits.
harold aptroot wrote:
The next-state pointers could be integers that index into the array of states instead of direct pointers, that would probably allow them to be uint16_t.
But how would I index when the pointer is pointing to a different array?
harold aptroot wrote:
Maybe the pointer to the true/false function can be an enum too?
Yes, of course, why didn't I think of that!
|
|
|
|
|
arnold_w wrote: actionArguments can sometimes use 32 bits. OK. How often is that needed? Perhaps you can cheat a bit: allow only a couple of 32bit arguments, and the rest must be small. Then if one "block" of actions does need more 32bit arguments, it can be "split" into two successive states (which costs a lot of space, but if splitting is rare then it can be an overall win)
Or maybe: pack arguments in VLQ, but reserve a fixed amount of space. When it doesn't fit, split the state.
The next-state pointers could be integers that index into the array of states instead of direct pointers, that would probably allow them to be uint16_t.
But how would I index when the pointer is pointing to a different array? OK maybe pack together two parts, some bits that indicate which array to look into, and some bits to indicate the index.
|
|
|
|
|
You can tighten the structure at the cost of a carry an action size count. However it does allow you to use the same actions blocks for multiple states. That may often happen in that you just have things like confirm yes/no actions.
I also changed your pointer definitions to const as you are clearly going to have static tables and it will save compiler type casting errors.
I assume you are going to do this .. see the C11 initializers at code end which uses the standard _countof to autosize the arrays.
on GCC it's ARRAY_SIZE() but I hate the name so always define it _countof same as MSVC because it reflects better what it is IMHO.
typedef bool (*returnTrueOrFalseFunctionPtr) (void);
typedef void (*actionFunctionPtr) (int);
struct myAction_s {
const actionFunctionPtr actionToPerformInThisState;
const uint32_t actionArgument;
};
struct myStruct_s {
returnTrueOrFalseFunctionPtr trueOrFalse;
const struct myStruct_s* whereToGoIfTrue;
const struct myStruct_s* whereToGoIfFalse;
const uint8_t maxActionsInThisState;
const struct myAction_s* actionsListInThisState;
};
static void SomeYesFunc (int) {
}
static void SomeNoFunc(int) {
}
static void SomePerhapsFunc(int) {
}
static bool truefalseFunc(void) {
return true;
}
const struct myAction_s yesNoBlock[2] = { &SomeYesFunc, 1 , &SomeNoFunc, 2 };
const struct myAction_s yesNoPerhapsBlock[3] = { &SomeYesFunc, 1 , &SomeNoFunc, 2, &SomePerhapsFunc, 3};
const struct myStruct_s nullState = { 0, 0, 0, 0, 0};
const struct myStruct_s yesNoState = { &truefalseFunc, &nullState , &nullState, _countof(yesNoBlock), &yesNoBlock[0] };
const struct myStruct_s yesNoPerhapsState = { &truefalseFunc, &nullState , &nullState, _countof(yesNoPerhapsBlock), &yesNoPerhapsBlock[0] };
In vino veritas
modified 9-Mar-18 21:53pm.
|
|
|
|
|