|
In a C++ Console Application, I'm looking for some sort of way to give the user a certain amount of time to input a command and if they do nothing in that time, go onto something else.
Essentially, the ideal flow would be something like:
if(SomeFunctionToSeeIfThereIsInputAvailable()) {
cin.getline(someCharArray, 200);
}
I've heard that something like that exists.
I've also heard of something like signals that will wait a while then call a function even while something else is going on or something.
I'm pretty sure my IDE doesn't have any capabilities like that or at least it is poorly documented.
Does anybody know of some library that has a way of doing something like that?
- Makutu
|
|
|
|
|
Hello, all
My project is dealing with DVB-T TV reception based on a piece of hardware. Basically, I am developing a dialog style console (VC++) to control all the signals, MPEG2 data stream etc. As to the functionalities, simply saying, it includes functions like play(), record(), monitoring().Now i want the monitoring() to be running all the time, updating and displaying parameters from hardware for examing purpose. And at the same time, i need to run play() and record(), but they are not accessing the same data. Just for a trial, i use an infinite loop to implement monitoring(), resulting the program hang and with no effect when i try to run play() or record() any more then terminated unexpected. So i just recall the concept of threads,but due to the limited knowledge on them, i even have no idea in this scenario, should i make all the function play(), record() and monitoring() as threads or just make monitoring() as a thread? And how to make it?
Greatly appreciate your help! Thx in advance.
|
|
|
|
|
1. I have a class based on CListCtrl, report style.
I want to prevent the header items from being resized.
So, I declared the OnBegintrack handler to the wrapping class. It does not get control.
Then only for a try I declared the OnBegintrack to the main frame (it's nonsense, I know), it does not get control.
I declared OnNotify to the wrapping class; it does get the control, but no matter what return code I pass, it does not prevent resizing.
What can be wrong?
2. Testwise I created a non-wrapped CListCtrl, like the above.
The parent of the CHeaderCtrl is the CListCtrl. It is not defined in AFXCMN.H.
How can I declare the OnBegintrack to the CListCtrl?
|
|
|
|
|
Vancouver wrote:
declared OnNotify to the wrapping class; it does get the control, but no matter what return code I pass, it does not prevent resizing.
If I remember correctly it's not the return code, but the value LRESULT* pResult is set to. I'm thinking setting this to zero should do the trick, but you'll probably have to play with this a bit.
Hopefully someone else will fill you in more appropriately...I myself am to lazy to fire up VC++ right now to figure it out!!!
Cheers
How do I print my voice mail?
|
|
|
|
|
If I remember correctly it's not the return code, but the value LRESULT* pResult is set to
Thanks, but that's not the issue. I tried with both the return code and pResult.
Btw, another pecularity: I declared an OnNotify for the CListCtrl wrapping class,
and another one for the main frame (the parent of the CListCtrl).
HDN_BEGINTRACK appears only at the OnNotify of the wrapper, and HDN_ITEMCLICK only at the main frame level. Both come from the CHeaderCtrl. What's going on?
|
|
|
|
|
BOOL CTSTListCtrl::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
switch (((NMHDR*)lParam)->code)
{
case HDN_BEGINTRACKW:
case HDN_BEGINTRACKA:
case HDN_DIVIDERDBLCLICKW:
case HDN_DIVIDERDBLCLICKA:
{
*pResult = TRUE; // disable tracking
return TRUE; // Processed message
}
}
return CListCtrl::OnNotify(wParam, lParam, pResult);
}
like in the above fucntion you have to handle all the four events and should not call the parent class's onnotify for the same events...
hope the above helps....
Gudluck
Adi
|
|
|
|
|
I found the error:
this swine of MFC Wizzard generated ON_NOTIFY_REFLECTs in the message map instead of ON_NOTIFY.
Apparently these (and, of course, the corresponding afx_msg's) have to be registered by hand.
Thanks anyway.
|
|
|
|
|
Could you please elaborate on this?
I have an owner-drawn list control, and I need to receive HDN_BEGINTRACK and HDN_ENDTRACK so I can draw the list control differently when the columns are being resized. I read the information on the few posts here on the forum, but I don't even get the OnNotify called into the list control, let alone anything resembling the HDN_ messages.
I do have a derived CHeaderConrol class attached to the header control, but it only overrides the DrawItem function. It does not intercept any messages.
I tried changing the _REFLECT messages to regular ON_NOTIFY, but I still did not get the notifications. Then I took all that out and let ClassWizard add the OnNotify to the list control class, but that did not get called at all either.
Thanks for any help or suggestions.
|
|
|
|
|
Hi,
first of all, if you want to process these messages on the level of the list control, then don't use message reflection, because the list control is the parent of the header control.
Second, the embedded CHeaderCtrl's control id is always zero, so the filter in On_Notify has to be zero as well.
Because the wizard would generate reflecting message mapping, which is wrong here,
you have to record the message handlers by hand between the end of the message map generated by the wizard
//}}AFX_MSG_MAP
and
END_MESSAGE_MAP()
like
ON_NOTIFY(HDN_BEGINTRACKA, 0, Your_Begintrack)
ON_NOTIFY(HDN_BEGINTRACKW, 0, Your_Begintrack)
ON_NOTIFY(HDN_ENDTRACKA, 0, Your_Endtrack)
ON_NOTIFY(HDN_ENDTRACKW, 0, Your_Endtrack)
Furthermore, you have to declare the functions following
//}}AFX_VIRTUAL
in the class definition of your list control:
afx_msg void Your_Begintrack(NMHEADER *nmheader, LRESULT *pResult);
afx_msg void Your_Endtrack(NMHEADER *nmheader, LRESULT *pResult);
(you are free to decide the names of the functions).
This should suffice.
|
|
|
|
|
Thank you very much for the updated information.
It works exactly as desired now.
The class derived from CListCtrl class now gets the begin track and end track messages from the embedded header control, exactly as I had hoped
|
|
|
|
|
Is there any way to copy a vector from one class to another? I have a SDI app, and I am using a UI thread to do some complex operations, right now both the UI thread and my CMainFrame classes have the exact same vector and structure, the vector for both classes contain one structure with multiple variables.. anyway it would be really cool if I could simply copy the mainframe vector over to the UI thread vector.. Any ideas? Right now I have to loop the vector and read everything out, big pain..
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Hello,
You can use a pointer to the vector in on of the classes, so the both use the same one. You must make sure that you use a thread-safe version of the STL or sync access yourself using critical sections and such.
The other thing you can do is:
<br />
copy(source.begin(), source.end(), dest.begin());<br />
Hope this helps...
Multiply it by infinity and take it beyond eternity and you'll still have no idea about what I'm talking about.
|
|
|
|
|
Heck it's even easier!
dest= source;
Assuming of course you're protecting this with a mutex/critical section etc.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
|
|
|
|
|
Am new to C++ and don't know if I'm doing something fundementally wrong. Have a form with a textbox and buttons. When I click on button, I am running a function in my .cpp file. However, in this function I need to update the text box in the form. Have created a public function set_address in the .h file form1 class definition that uses the following code.
public:
void Form1::set_address(char *add)
{
char temp_str[80];
sprintf(temp_str,add);
textBox1->AppendText(temp_str);
}
When I call it from my .cpp file with
Form1* pFm = new Form1;
pFm->set_address(temp_str);
It compiles OK and even runs the code, but the text box is not updated. If however I call the function from a clickbutton
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
char temp_str[80];
sprintf(temp_str,"from button");
set_address(temp_str);
}
It happily updates the text box.
Have been pulling my hair out for 2 days, so any help would be GREATLY appreciated
Thanks
Dave C
|
|
|
|
|
If you are already inside the form1 instead of doing a Form1* pFm = new Form1 etc... just simply call set_address(temp_str);
You should not have to create a new Form1 object..
Another thing.. If you are not in CForm1 lets say you are calling this from CMainFrame you would probably want to do something like this...
CForm1* pForm = (CForm1*)AfxGetActiveView();
ASSERT(pForm);
pForm->set_address(temp_str);
Anyway you get the idea..
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
I am calling from outside the form, this is part of the problem, set_address is not recognised otherwise. When I tried your changes it didn't like ASSERT or AfxGetActiveView. Can't even find AfxGetActiveView on the msdn microsoft website. I am assuming that calling the form as a new form is what's causing my problem, but this is the only way I can get it to compile. Any other ideas?
Using Microsoft Visual C++.net Version 2003
Dave C
|
|
|
|
|
What class are you trying to call that function from? Is your app it a SDI or MDI? If it's a MDI are you trying to call the from another view?
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
V5dave wrote:
When I tried your changes it didn't like ASSERT or AfxGetActiveView
My bad it's GetActiveView() instead of AfxGetActiveView.. didn't check the syntax, was just typing on the fly.. ASSERT should work fine, it's for debugging, if the view doesn't exist it will assert.. anyway for testing you can remove that line..
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
Got the ASSERT to work, needed DEBUG::ASSERT, but doesn't like GetActiveView, says identifier not found. Am calling from a normal function
void Test01(void)
{
// Call is in here
}
The form I'm calling is
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
public:
void Form1::set_address(char *add)
{
char temp_str[80];
sprintf(temp_str,add);
textBox1->AppendText(temp_str);
}
//Loads of other standard definition and click button stuff
}
Is this a problem of calling managed types from unmanged types?
Its an SDI only.
Dave C
|
|
|
|
|
Hello all,
I am working on an editor that automatically applies some formatting as the user types. Among these operations are syntax highlighting and character string insertions. I am currently using the ITextRange interface to apply syntax highlighting since it has been suggested elsewhere that this is the key to maintaining undo/redo ability in this context. Unfortunately I am not having any luck preserving the undo buffer in any useful state! Does anyone have any experience with this? Is it a matter of grouping operations with the (TextDoc) Begin/EndEditCollection functions? So far they have not yielded their secrets to me either
Any advice would be greatly appreciated!
Thanks,
Jon
|
|
|
|
|
Hi I'm having a lot of problems with mouse events. In an MDI application I have a CDialogBar derived class which needs to keep track of mouse movements in the parent frame. Using the ClassWizard I've added the necessary functions but they don't work. Within the CDialogBar derived class there's a CEdit object. Within the WM_NCMOUSEMOVE event handler the CEdit object has it's window text set to the mouse position. Well nothing happens. The application runs, but for whatever reason the dialog bar doesn't get the non-client mouse move event. I've added handlers for WM_NCLBUTTONDOWN and WM_NCLBUTTONUP but nothing happens.
Can anyone tell me what's going on? How do I make my CDialogBar derived class capture mouse events in the parent frame?
|
|
|
|
|
Have you tried to handle these events in CMainFrame and then let CMainFrame call a user defined function in your derived CDialogBar class?
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
I just tried that, and it doesn't work. The code compiles, and application runs but the CFrameWnd derived class still doesn't get any mouse events. I also tried OnNcMouseMove(UINT nHitTest, CPoint point) in the dialog bar, but no dice.
I'm at a total loss...there must be something I'm missing. I can email you the project, maybe you can figure it out.
|
|
|
|
|
I would try to handle the WM_MOUSEMOVE event with in CMainFrame or CFrameWnd (SDI or MDI) what ever the case maybe.. You can even try to do TRACE("Mouse Moving\n"); With in a bunch of functions in the MainFrame or ChildFrame classes to see what window is receiving the messages you are looking for.. here is a example of handling the WM_MOUSEMOVE with in CMainFrame class.. note this is by hand, I havent compiled it.
void CMainFrame::OnMouseMove(UINT nFlags, CPoint point)
{
CFrameWnd::OnMouseMove(nFlags, point);
}
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
I just downloaded the zip and made the adjustments.. I just emailed the project back to you.. Just incase here is the code...
LRESULT CChildView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_MOUSEMOVE)
{
CMainFrame* pMain = (CMainFrame*)AfxGetMainWnd();
ASSERT(pMain);
TRACE("Mouse Movement\n");
CPoint point = (CPoint)lParam;
CString str;
str.Format("OnMouseMove at (%d,%d)",point.x,point.y);
pMain->SetMessageText(_T(str));
}
return CWnd ::WindowProc(message, wParam, lParam);
}
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|