|
hi to all
i have this problem with win32 code. vc++ console based application.
i have a module...where some inputs/messsages keeps coming.....what I want is to....wheneerv a message comes i want to put in a queue..and the reciever function returns the control...now i want to have a thread, which will keep looking onto the queue...if empty, do nothing....if not empty then process the message.... (reason : main reason to do this is...instead of having the while loop in the thread function, which will eat CPU cycle, i want some mechanism to do task only when needed)...
please give me some solution to the problem....or is there anything(funtion/concept) available in win32 (vc++)...
all i need to do is prcess the messages when queue is not empty, otherwise do nothing...
thnaks in advance
|
|
|
|
|
What about documentation: "Multithreading with C and Win32"?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hrishi321 wrote: wheneerv a message comes i want to put in a queue..and the reciever function returns the control...now i want to have a thread, which will keep looking onto the queue...if empty, do nothing....if not empty then process the message....
That's what the UI thread does (if you're using MFC).
hrishi321 wrote: main reason to do this is...instead of having the while loop in the thread function, which will eat CPU cycle, i want some mechanism to do task only when needed)...
WaitForSingleObject[^] could help you do this.
A queued event thread is fairly easy to implement if you're not using MFC as well. All you need is a thread, a message queue and a couple of events that signals if there's more messages to be processed and if the thread should stop execution immediately (app shut down) and a WaitForSingleObject (or multiple objects, depending on how you do it) call that would be used for waiting on the said events.
What have you thought of to solve this?
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Hi!
I have class called CSortedList. I need to implement their member functions using Linked List. I've tried implementing some functions. I am totally lost about the linked list. Can someone please help me out, it would be greatly appreciated. Please point out if I am doing something wrong. I have two files which I am going to post. The first file is CSortedListLLStarterKitSpring2010.cpp and the second file would be CSortedList.h
#include <iostream>
#include <cstdlib>
#include "CSortedList.h"
using namespace std;
void DisplayMenu(void);
void DisplayList(const CSortedList &list);
void FlushInstream(istream &inStream = cin);
int main(void)
{
auto bool bLoop = true;
auto char selection;
auto CSortedList myList;
auto int intVal;
do
{
DisplayMenu();
cout << "Please enter a selection: ";
cin >> selection;
switch (toupper(selection))
{
case 'A':
cout << "Please enter a value to add to the list: ";
if (!(cin >> intVal))
{
cout << "Error reading int, please try again...\n";
FlushInstream();
}
else
{
myList.InsertItem(intVal);
}
break;
case 'R':
cout << "Please enter a value to remove from the list: ";
if (!(cin >> intVal))
{
cout << "Error reading int, please try again...\n";
FlushInstream();
}
else
{
myList.RemoveItem(intVal);
}
break;
case 'D':
cout << "Here is the current list:\n";
DisplayList(myList);
cout << endl;
break;
case 'Q':
bLoop = false;
break;
default:
cout << "Unrecognized selection; please try again...\n";
FlushInstream();
break;
}
cout << endl;
} while (true == bLoop);
return 0;
}
void DisplayMenu(void)
{
cout << "A)dd an item\n";
cout << "R)emove an item\n";
cout << "D)isplay the list\n";
cout << "Q)uit\n";
}
void DisplayList(const CSortedList &list)
{
auto int index;
auto ListItemType listname;
for (index = 0; index < list.GetNumItems(); ++index)
{
list.GetListItem(index, listItem);
cout << listItem << endl;
}
}
void FlushInstream(istream &inStream)
{
auto int inChar;
inStream.clear();
while (false == inStream.eof())
{
inStream.get(inChar);
if ('\n' == inChar)
{
break;
}
}
}
#ifndef CSORTED_LINKED_LIST_HEADER
#define CSORTED_LINKED_LIST_HEADER
#define DEBUG_LIST
typedef int ListItemType;
struct ListItemNode
{
ListItemType value;
ListItemNode *next;
};
enum ListRetVal
{
LIST_FULL
, LIST_EMPTY
,LIST_ERROR
,LIST_SUCCESS
,LIST_INVALID_INDEX
,LIST_DUPLICATE
,LIST_NOT_IN_LIST
};
class CSortedList
{
public:
CSortedList(void) { m_headPtr = NULL; m_numItems = 0; }
CSortedList(const CSortedList &object);
~CSortedList(void) { DestroyList(); }
ListRetVal CreateList(void);
void DestroyList(void);
void DispRetVal(const char* szMessage, ListRetVal value) const;
ListRetVal GetListItem(int index, ListItemType &item) const;
int GetNumItems(void) const { return (m_numItems); }
ListRetVal InsertItem(const ListItemType &newItem);
bool IsListFull(void) const { return (NULL == m_headPtr); }
bool RemoveItem(const ListItemType &targetItem);
CSortedList& operator = (const CSortedList &rhs);
private:
int CopyList(const CSortedList &otherList);
ListItemNode *m_headPtr;
int m_numItems;
};
#endif //CSORTED_LINKED_LIST_HEADER
void DispRetVal(const char* szMessage, ListRetVal value) const
{
#ifdef DEBUG_LIST
cerr << szMessage << ": ";
switch (value)
{
case LIST_Full:
cerr << "LIST_FULL\n";
break;
case LIST_EMPTY:
cerr << "LIST_EMPTY\n";
break;
case LIST_ERROR:
cerr << "LIST_ERROR\n";
break;
case LIST_SUCCESS:
cerr << "LIST_SUCCESS\n";
break;
case LIST_INVALID_INDEX:
cerr << "LIST_INVALID_INDEX\n";
break;
default:
cerr << "Unrecognized error code\n";
break;
}
#endif
}
|
|
|
|
|
I would recommend using the STL list class.
|
|
|
|
|
I can't because this is for my class that I am taking. It's data structures in C++.
|
|
|
|
|
Shah Ravi wrote: I've tried implementing some functions.
I don't see what you have tried for any of the member functions of your Sorted List class, except for DispRetVal. You might want to pick one that you had trouble with, post it, and indicate what problem you are having with it. If you are really lost, first review your notes/textbook about what a linked list is and think about what sorted means.
Regarding your DispRetVal() member function implementation attempt:
1) This belongs in your CSortedList.cpp file, not a header file.
2) In the function definition you need to qualify the function name with the name of the class that it is a part of.
I have looked at the functions that you have written to test your class once you get it written. This is a good thing to do. I see at least one problem that should generate a compiler error. Attempt to compile and clean up the compiler errors. (Ignore linker errors until you get the rest of it written.)
You are currently ignoring return codes from the member functions. You will want to change that.
There are also a number of style issues, but I'll skip those for now.
It looks like you are going to have to roll up your sleeves and get to work.Please do not read this signature.
|
|
|
|
|
Thanks,friends
I loaded 3ds model
But,I have problem :I load 3 file 3ds by glPush...,glMatrix,glTranlated.
desc:
man_3 table_2 floor_1
When i rotate man 3-> normal
When i rotate table 2-> man 3 rotate
When i rotate floor 1->man & table rotate,my gold
This is rotate hand,leg.I want to rotate table then man 3 not rotate,rotate floor 1 then man & table not rotate
thanks
I don't know I not find load animate of 3ds
Thanks
Tuan,College 8,vietnam
|
|
|
|
|
Can you try to make you question clearer? As of now I have no idea what you are trying to say.
-Saurabh
|
|
|
|
|
You might have better luck in the graphics forum but it's been kind of quiet in there lately. You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
But I'm not familiar with Geometric Algebra!
L u n a t i c F r i n g e
|
|
|
|
|
So? When did that ever stop you? You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
|
Wow, I think you should really try to clarify your question because it is really undecipherable.
What is your question exactly ? I don't see any question in your post.
|
|
|
|
|
Hi, this is a main class for a program that I have and I want it to be a multiple run, to ask the user if he wants to enter another number
#include <iostream>
#include <conio.h>
#include "postalobj.cpp"
using namespace std;
int main()
{
int num;
postalclass pobj;
cout<<"Please enter the number of mailboxes for the Postal problem : ";
cin>>num;
pobj.setnumbox(num);
pobj.process();
getch();
}
|
|
|
|
|
zakria81 wrote: I want it to be a multiple run, to ask the user if he wants to enter another number
You need to:
a) Put in a loop. Since it should always execute at least once, a do {} while(); might be appropriate.
b) In the loop ask the user if he wants to enter another number. Based on the response, terminate the loop or continue looping.
This should be straightforward.Please do not read this signature.
|
|
|
|
|
Avi Berger wrote: Please do not read this signature.
My eyes!!!
|
|
|
|
|
Hi I have a CComboBox, I am populating items into that.
But when i run the code, the inserted items are getting sorted in the combo box.
But I want to keep the order of *inertion* in the display. How to do this?
Thanks
JC
CComboBox* comboComSelection;
comboComSelection = ((CComboBox*)GetDlgItem (IDC_COM_COMBO));
comboComSelection->ResetContent();
comboComSelection->AddString (_T ("COM1"));
comboComSelection->AddString (_T ("COM2"));
comboComSelection->AddString (_T ("COM10"));
( I need COM1, COM2, COM10 in the order, when combo box appears)
|
|
|
|
|
Hmm.. I got the answer.. disable the sort property in GUI.
|
|
|
|
|
TechAvtar wrote: How to do this?
By removing the CBS_SORT style. You can do this at design time or at run 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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi,
I met a problem with inserting a ole control into windowless richedit. I want the ole control draw something, and can response to the mouse-move, lbutton-down message and etc. The control has implemented IOleInPlaceObjectWindowless interface, and other necessary interfaces. But "OnWindowMessage" can't be called by richedit itself, so i have to query the IOleInPlaceObjectWindowless interface from IOleObject and call it. I am wondering why should i call the method myself instead of richedit. There is any suggestions from you? I am hoping for it.
|
|
|
|
|
Hi,
Is it possible to gain the style information of the drop down list of a CComboBox object?
I want to use it for reference to determine why a CListBox object I am creating does not behave in the same way.
TIA
Tony
|
|
|
|
|
Use GetWindowLongPtr with the handle of the combo box.
Specify GWL_STYLE as the second parameter.
It will return a LONG_PTR value.
Do a bitwise AND to check for the styles CBS_DROPDOWN and CBS_DROPDOWNLIST .
|
|
|
|
|
maycockt wrote: Is it possible to gain the style information of the drop down list of a CComboBox object?
Strictly speaking, a CComboBox object is not the same as a combobox control.
In any case, see if GetComboBoxInfo() is of any help."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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi,
I have to convert a CString (ie. "5.00" or "5,00") to float using Comma as separator and obtains something like this as result 5,00000 .
Thank you for help.
|
|
|
|