|
Generally, if you define a member variable of a class, this variable should only be accessed by member functions of that class (or derived class). This is true both for static and non-static member variables.
If you need to read or change them from outside the class, define accessor member functions as needed.
Any static or non-static function can and may access any member variable. Therefore there is no need to pass it to such a function, unless it is a non-static member variable of a different instance of the class.
Example:
class Vector3i {
private:
std::array<int,3> data;
public:
void fill(const int value) {
data.fill(value);
}
void swap(Vector3i& other) {
std::swap(data, other.data);
}
};
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
I changed the icon and put the following code in
HICON icon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));
SetIcon(icon, FALSE);
in
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
and yet I still have the MFC icon when the Windows is minimized in the task bar
Thanks
|
|
|
|
|
Did you change the .ico file in the res folder?
"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
|
|
|
|
|
In Visual Studio I open up the .ico FILE (which is in the res folder) I erase what there and selecting the TEXT tool I type what I want do a save. However when I go into file explorer it still appear as the original MFC icon/bitmap
|
|
|
|
|
Sounds like you are only changing one resolution.
"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 was able to modify the first 8 resolutions but for the last 5 the drawing tool bar gets grayed out
|
|
|
|
|
My task is to modify selected bits in 8 bit (char) words.
At present I have declared an array of two words.
The array gets "filled" from hardware source - I2C adapter.
I can manage to manipulate required bits using plain Boolean code - KISS.
I have found this template class " bitset " .
I have never used a template class and not sure if using it would be less code or confusion.
Since I need to pass the char pointer of the array I am not sure if changing to template class would be as obvious as passing a char array pointer.
I am open to suggestions.
Cheers
|
|
|
|
|
The problem with a bitset is that you have no control over the internal representation of the bits.
- There is no way to know whether the representation is 1 bit/value or 1 byte/value (this is a quality of implementation issue)
- There is no way to know whether the underlying type is an array of chars, ints, or some other type
- There is no way to know whether bit 0 is the MSB or the LSB of the underlying type
If you are getting data from an external source, the only safe (and portable) way to read the data is as an array of char / unsigned char. Note that std::vector<> and std::array<> guarantee that the allocated memory will be contiguous, so a pointer to the zeroth element of either would be OK as well.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
I suspect what you want to use is bit-field struct members.
e.g. your device sends you 2 bytes, formatted as follows
1-2 op status code 1
3-6 op status code 2
7-12 error code
13-16 unused
You could model that as follows
struct op_status {
unsigned int status_1:2;
unsigned int status_2:2;
unsigned int error:6;
};
If you are unfamiliar with this construct a struct member like unsigned int item:2 defines a member only 2 bits wide. The type of a bit-field member should be integral, (e.g. char, short, int, etc) but can be signed or unsigned as needed.
You can use the struct members as short ints e.g
int devfd = open("/dev/a_device", O_RDWR);
struct op_status i2c_status;
read(devfd, &i2c_status, sizeof(i2c_status));
if(i2c_status.status_1 == 1) {
} else if ( i2c_status.status_1 == 2 && i2c_status.status_2 = 1) {
switch(i2c_status.error) {
case 1:
break;
case 2:
break;
...
default:
}
}
looking a <bitset>, I don't see a nice way to group the bits together to treat them as a single unit, like you can using bit-fields. Usually, bit-fields are packed together, but check your compiler documentation to make sure. Also, don't forget that bit and/or byte order coming from your device might not match your CPU, so you may need to declare various fields out-of-order with respect to the documentation.
|
|
|
|
|
k5054 wrote: looking a <bitset>, I don't see a nice way to group the bits together to treat them as a single unit, like you can using bit-fields.
All the usual logical and shift operators are defined on bitsets. You can also convert a bitset to an integer type, and construct a bitset from an integer type. The major issue is the internal representation, which is implementation-defined. This is why a bitset should not be used to interface to hardware.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Thanks,
this will definitely give me a good start in using bitset, specially when I need to process more than two characters. Appreciate it.
At current I have this code to process single char.
cout << " data 0x" << hex << +data << endl;
data <<= iLSbit;
cout << " shifted data 0x" << hex << +data << endl;
int iDataBit;
for (int iBit = iLSbit; iBit != iMSbit + 1; iBit++) {
#ifdef DEBUG
cout << "processing bit " << dec << +iBit << endl;
buf[0] &= ~(1UL << iBit); #endif
iDataBit = (data >> iBit) & 1U;
#ifdef DEBUG
cout << " iDataBit " << hex << +iDataBit << endl;
#endif
if (iDataBit) {
#ifdef DEBUG
cout << "set bit @ position " << dec << iBit << endl;
#endif
buf[0] |= (1UL << iBit);
} else {
#ifdef DEBUG
cout << "clear bit @ position " << dec << iBit << endl;
#endif
buf[0] &= ~(1UL << iBit);
}
}
Since I need to read the data (hardware register ) before modifying it , then writing it back to hardware it seems simpler than using bitset.
At present I am modifying / checking single register parameter ( A/D converter input MUX ) , but in future I like to modify all parameters in single access. I think that is where bitset will do the job.
Thanks again
Cheers
Vaclav
|
|
|
|
|
Not certain if this is the right place to ask.
A quick look around the office shows that we have different versions of the VC++ 2017 redistributables installed:
14.16.27012
14.12.27012
14.16.2712.6
14.15.26706.0
14.10.25017 (this is the version we install)
The version we install setup a key in the registry :
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall{e9d78d68-c26c-4da7-9158-99355d8ef3ad}
And the installer will check that key when installing (to install or not).
Questions:
Are all VC++2017 redistributables install the same registry key ?
Is there a place where I can see which key are installed for which versions of the redistributable ?
Thanks.
I'd rather be phishing!
|
|
|
|
|
|
holy cow!!!!
That's what I was looking for.
I'd rather be phishing!
|
|
|
|
|
I'm glad it helped you!
|
|
|
|
|
I have to display a Customized list control in a dialog bar and update it frequently.
I am subclassing a custom list control in my application using:
m_cLstCtrl.SubclassDlgItem(IDC_LSTCTRL_ALARM,this);
CSysWindow is the dialog bar class and have created in CMainFrm using:
if (!m_SysWnd.Create(this, IDD_DLGBAR_APPBAR, WS_CHILD | WS_VISIBLE | CBRS_GRIPPER |CBRS_FLYBY|CBRS_TOOLTIPS | CBRS_SIZE_DYNAMIC, IDD_DLGBAR_APPBAR))
{
TRACE0("Failed to create DlgBar\n");
return -1; // fail to create
}
void CSysWindow::RecentAlarms()
{
//I am testing my List control using the below code:
m_cLstCtrl.SetColumnHeader(_T("Student ID, 100; Enroll Date, 150; Score, 80, 2"));
for (int i = 0; i < 10; i++)
{
const int IDX = m_cLstCtrl.InsertItem(0, _T(""));
m_cLstCtrl.SetItemText(IDX, 0, "");
m_cLstCtrl.SetItemText(IDX, 1, "testDate");
m_cLstCtrl.SetItemText(IDX, 2, (rand() % 51) + 50);
for (int j = 0; j < 2; j++)
m_cLstCtrl.SetItemImage(IDX, j, rand() % 5); // subitem images
}
}
When I call this function inside a thread, the application crashes by triggering a breakpoint.
void tUpdateAllViews( CMainFrame *pMainFrm )
{
while( 1 )
{
pMainFrm->UpdateAllViews();
pMainFrm->m_SysWnd.RecentAlarms();
Sleep(500);
}
}
void CMainFrame::UpdateAllViews()
{
//It also crashes when I call here as below.
m_SysWnd.RecentAlarms();
}
Whereas when I Call this function inside OnUpdate, its working
void CMainFrame::OnUpdate()
{
// TODO: Add your command handler code here
m_SysWnd.RecentAlarms();
}
which is the proper way to call this function that is in the dialog bar class "m_SysWnd.RecentAlarms();" where to call this function?
Please advice.
|
|
|
|
|
manoharbalu wrote: When I call this function inside a thread, the application crashes by triggering a breakpoint.
You must not directly access the main GUI thread controls from within a secondary thread!
Instead you should PostMessage a user defined message to the main thread window notifying it that it has to do some operation(s). Within the main thread you handle this message and perform the ordered operation(s).
See also this great J.Newcomer essay: Using Worker Threads
|
|
|
|
|
Good morning everyone.
I am a newbie in c++ coding and recently encountered a problem related to timer.
Note: i am with MFC, so I can use the timer from MFC. but not sure how to about it.
what I have to do is looks something like this;
if (input = 1)
{
start timer for 300ms ;
output = 1 ;
}
if ( new input within 300ms = 1)
{
restart the timer for 300ms;
output = 1;
}
if (input != 1 after 300ms || time elasped > 300ms )
{
output = 0;
}
I have a a stream of input 0 and 1 coming from an array. requirement is that after the program received an input of 1 from the array, it should give output of 1 for 300ms, if it doesn't recieve any other input that is 1 within 300ms, it would set the output to 0 but if it received and input of 1 within 300ms, it would reset the timer and give output as 1 for next 300ms.
I have never worked with timer based programming in c++. so I can't find any ideas about how to do it. If anyone can provide me an answer or point me in right direction, I would be really grateful.
Thank you very much for time replying to my query.
modified 6-Jan-19 21:04pm.
|
|
|
|
|
crucial1953 wrote:
I have never worked with timer based programming in c++ Timers are not part of the native C++ language. You either have to invent your own, or use some third party library that contains one.
On a semi-related note, the clock() function should help to get you started, at last in knowing how many (milli)seconds have elapsed between two points in time.
"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
|
|
|
|
|
To do it by polling which you sort of imply with your pseudocode (It is better with interrupts if possible to trigger the 1 event).
You define an ID for the timer and a timer sample count
#define IDT_TIMER_0 WM_USER + 100
UINT sampleCount = 0;
You set the timer interval
SetTimer(IDT_TIMER_0, 10, NULL);
You do the checks in on_timer call back function and reset the sample count if you find what you wanted
void OnTimer (UINT TimerVal)
{
sampleCount++;
if (sample_whatever == 1)
{
sampleCount = 0;
} else if (sampleCount == 30)
{
sampleCount = 0;
}
}
You can use KillTimer with the id to kill the timer at any time you like
KillTimer(IDT_TIMER_0);
There are more advanced techniques like using WaitForSingleObject but we need to know more about what the 1 is coming from.
In vino veritas
modified 6-Jan-19 22:33pm.
|
|
|
|
|
|
|
If you are asking about compiler theory then in terms of creating a compiler there is often a 'tokenizer' as part of the process and to a certain extent it is often compartmentalized into its own section.
If you are asking for code to do that then I can only suppose it is for a class and I suggest you get writing. Especially since such classes should only be taken by those with a significant technical degree in progress and knowing how to do that would be if not fundamental then at least significant as part of the career for that degree.
|
|
|
|
|
Hi,
I Have Installed A Hook With WH_GETMESSAGE On A DLL Using MFC.But When I Send Postmessage To My Parent Window It Is Not Received...
HWND hwndmain;
static UINT snd=::RegisterWindowMessage(L"mainwnd_msg");
::PostMessage(hwndmain,snd,0,0);
The Same Message Is Declared In The Main Window To Receive The Registered Window Message And Added On register message event also But It Is Not Working Kindly Help Me I'm Not Able To Find What Is Happenning...
|
|
|
|
|