|
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...
|
|
|
|
|
|
Thank you For Your Reply,But My Problem Is I Have Installed A WH_GETMESSAGE Hook In a DLL.The DLL Is Loaded On To Notepad Process.The DLL Will Post The Message To Mainwindow When Key 'A' Is Pressed.The Main Window(HWND) Which Has Triggered The Hook Is Unable To Receive The "Postmessage" Posted To It.But Notepad(HWND) Is Able To receive The Postmessage Posted To It...
|
|
|
|
|
I am afraid it is impossible to guess what may be happening. You will need to use your debugger to gather more information.
|
|
|
|
|
First PostMessage returns a result and check the value of the message handle before the dispatch ... act like a programmer, you can easily give us a hell of a lot more information than you have.
At a guess the window you are sending it to is not active or the window you are trying to post from is a dialog in the modal state. Can't tell much beyond that you haven't explained or given us enough detail.
In vino veritas
|
|
|
|
|
Hi,
I am looking for a Basic C or CPP TCP/IP Server Client sample to build around. All I can find is CSS or C# samples. My compiler was born in 1997, but is also my good and trusted friend. Something that it can digest would be appreciated.
Kind Regards,
Bram van Kampen
|
|
|
|
|
There's bunches of stuff out there as a google search for C++ TCP server will show - however if you're using a '97 vintage compiler, then what OS are you using? Anything for Win10 (or even XP) may not be appropriate. If you're looking for DOS, OS/2, or something unixy, then adding those search terms should provide you with something useful.
|
|
|
|
|
|
Well Leon,
About the Machines it will Run On. The Server software will run under WinXP SP2, The Client Software will run on Win7 or above. The software is intended to provide a bridge between the Database running on XP, and an Internet Server, connected to a local data server via an ADSL connection to serve the database. We expect minimal traffic, no pics or films, just text files to tell our clients that their laundry is ready, and, what the bill is.
I am also very concerned about the lack of gravity given in the education system to languages like C and CPP. Many young programmers I speak to consider C and CPP a sort of old fashioned ancient languages, long superseded by Java, JS, JCODE, Perl, C# and CS! Very few of these realize that All these interpreters are ultimately written in 'C' or 'ASM'.
I Despair at this! What percentage of "Software Engineers" understand Assembly Code, never mind Machine Code! The understanding of the Nuts and Bolts of any system, will always remain important!
Kind Regards and Thanks,
Bram van Kampen
|
|
|
|
|
Bram van Kampen wrote: The Server software will run under WinXP SP2
For a business that doesn't sound like a good idea. Even normal databases designed for XP had IP ports so a server could run on a different more modern computer and just communicate with the legacy system. Both could run behind normal security setups.
Bram van Kampen wrote: Many young programmers I speak to consider C and CPP a sort of old fashioned ancient languages, long superseded by Java, JS, JCODE, Perl, C# and CS!
Perl? I haven't seen anyone actively using Perl except me basically ever. In the 90s I worked in a shop that was exclusively Unix programmers and far as I could tell of the 300 developers I was the only one that knew how to use it. And since then even knowing that exists has gone down.
And I have no idea what "CS" would be given that you already referred to C#.
My guess is that embedded programming uses a lot of C. That is the only reason I can see for the popularity in the tiobe index at number 2 for C.
Bram van Kampen wrote: Very few of these realize that All these interpreters are ultimately written in 'C' or 'ASM'.
Nope.
The Java VM is written in Java excluding a very small subset of C++. The Java compiler is written completely in Java - it in fact runs in the Java VM. And that second statement has been true for a very long time probably at least early 2000s. Eclipse and Intellij are both written in java. The very earliest Java compiler might have had ASM in it but at least in about the late 90s it did not (I used to look at the source code quite a bit.)
The current C# compiler is written in C#. I believe it was C++ before that. Visual Studio appears to be written, best as I can tell, mostly in javascript.
GCC has been C++ since 2012. Before that it was C.
There might be some very small niche processors that use an assembler compiler written in assembler. But even back at least in the 80s assemblers were written in languages besides assembler.
|
|
|
|
|
Members of the Jury,
I Rest my Case!
Bram van Kampen
|
|
|
|
|
Well,
The My Program Suite is out in the field since 2005. It runs on XP. It works well, We provide the terminals. built out of recycled computers. Our customers do not view these terminals as computers, but as Tills.
The code is under licence, so I get an annual pay for each license, and everyone is happy. I am in a niche market, without any local competition. The working code base will never be migrated to another Software platform.
Also, because of the persistence of never changing the basic user interface for staff, other than in minimal ways, we have reduced staff training costs for our clients to close to zero.
All Bugs are long resolved, the program works as it states on the Can, so, why should I try to improve.
The Database we use is totally proprietary, developed in our lab. Our Database is hence extremely resistant to Hacking, the format and organisation is private to the company!
We do not use standard software because it is too easy to hack! Our protocols are always non standard, by slightly deviating from the standard, in un expected ways.
Using C#, what you write gets translated to 'Universal Intermediate Code' to run on the Just in Time c# virtual machine. That intermediate code can easily be decompiled to the original source code, with the loss of function and naming conventions We as an organisation will never entertain it as a way to distribute our code!
Bram van Kampen
|
|
|
|
|
Bram van Kampen wrote: The My Program Suite is out in the field since 2005...
That doesn't have anything to do with your statement about modern programming languages.
Bram van Kampen wrote: We do not use standard software because it is too easy to hack!
90% of data loss from companies is due to internal breaches. An employee walks off with the data.
Most of the rest is based on employees doing something wrong - like posting their login on a postit on the box.
Actual technical "hacking" from outside sources is rare (compared to all business losses).
Bram van Kampen wrote: Using C#, what you write gets translated to 'Universal Intermediate Code' to run on the Just in Time c# virtual machine. That intermediate code can easily be decompiled to the original source code, with the loss of function and naming conventions We as an organisation will never entertain it as a way to distribute our code!
First I know exactly how C# works. I also know how java, perl, C++, C, assembler and even SQL on various boxes works. I have in fact written several custom compilers and interpreters and have written an IDE as well.
Secondly I can see how you feel that that protects your IP, but doesn't have much to do with the statement that I originally responded to.
|
|
|
|
|
Lots of samples: sockets c - Google Search[^]. The basics of sockets have not changed for years so you can work from any of the more modern samples in an old compiler: my first sockets program was developed using Visual C++ 6.0 (so long ago).
|
|
|
|
|
I have a task of passing variable values in an array to a function.
Of course compiler cannot reinitialize same array with different values.
Putting the code in a block works.
Awful hack.
So what is "the proper " way to accomplish the task in C++ ?
Multidimensional array is impractical in my case.
Cheers Vaclav
{
int *ipTestValue;
int a[32] = {1,2,3};
ipTestValue =&a[0];
vna.utility.TestArray(ipTestValue);
}
{
int *ipTestValue;
int a[32] = {1,2,3,4,5,6,7};
ipTestValue =&a[0];
vna.utility.TestArray(ipTestValue);
}
|
|
|
|
|
What exactly are you wanting TestArray() to do?
"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
|
|
|
|
|
It does nothing useful, just test prints the values passed to it.
The question is about how to initialize / reinitialize THE ARRAY of the values passed.
|
|
|
|
|