|
If your main thread gets blocked until the worker thread finishes, then I don't see the point of the worker thread. Just put it all on the same thread.
As far as ways of communicating, here's one: create an Event (see CreateEvent or CEvent)in the main thread and pass it to the worker thread. When it's finished, have it signal the event (SetEvent). In the mean time the main thread will be blocked until the event is signaled (WaitForSingleObject). Once that occurs, it will know that it's time to fire the control's event.
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
Hello All!
I have a class derived from CView with a public variable defined like a CListBox m_listbox.
When I try to create this listbox dynamicaly in runtime in ON_COMMAND like :
m_listbox.Create(WS_CHILD|....,CRect(0,0,0,0),this,LDC_LIST)
I recieved an erorr,although build was ok. I recieve an error even befor I come inside of Create
when I override Create(..).
When I declare listbox like local variable in method it is passes Create(..) without any problem but ofcource not shown.
This algorithm was working when I create this Listbox dynamicaly in class derived from Richedit.
Parameter for Create (dwFlags, CRect, CWnd*, ID) but and Richedit and CView were derived from CWnd.
So where can be a problem? I couldnt find any solution all last night ...
Thanks for help
Alex.
Visual C++ .NET
Windows XP Professional
|
|
|
|
|
Just a guess, but is the value of LDC_LIST already used by a different control?
Roger Allen
Sonork 100.10016
WHats brown and sticky?
A stick or some smelly stuff!
|
|
|
|
|
Thanks. No, I have already check this.. And in this way why it was working with local variable..
Alex
|
|
|
|
|
Can you post all the code that does a call to create, the overridden Create function (if you have one) and the declaration of the variable as well. That may help us spot the problem.
Roger Allen
Sonork 100.10016
WHats brown and sticky?
A stick or some smelly stuff!
|
|
|
|
|
So:
*------SampleView.h
CSampleView::CView
public:
CAB4LisBox m_listbox;
*------SampleView.cpp
ON_COMMAND(ID_AUTOCOMPLETE, OnAutocomplete)
void SampleView::OnAutocomplete()
{
.......
if(!m_listbox.hWnd)
m_listbox.Create(CRect(0,0,0,0), this);
}
Where :
bool CAB4LisBox::Create (CRect rect, CWnd* pParentWnd)
{
dwFlags = WS_CHILD|WS_OWNERDRAW|HAS_STRINGS.....; <---- Here Breakpoint => not stop
return CListBox::Create(dwFlags,rect,pParentWnd,IDC_LIST); error befor.
}
In case :
void SampleView::OnAutocomplete()
{
.......
CAB4LisBox m_listbox;
if(!m_listbox.hWnd)
m_listbox.Create(CRect(0,0,0,0), this);
}
working->Have entered into Create,breakpoit works, but list not dispalyed.
Sorry for not full coding, I havent it with me now, so wrote as remember.
Alex
|
|
|
|
|
|
When i disconnect my Networkcable from WindowsXP the Trayicon tolds me that "A Network cable is unplugged".
That is a status that i need in a Dialer with "seamless connectivity function". Does anyone know how to get these status? Doesent find anything about it in MSDN.
Only in MprAdminInterfacGetInfo is something, but that is for Serveradministration by remote connection.
best regards bateman
|
|
|
|
|
REQUIREMENT:: Application shud be sized to full monitor irrespective of the monitor size and current system resolution.
My APPLICATION:: Application is having four formviews in tabcontrol with many controls(AcitveX Lables and Buttons) on each forma view. My application is developed for best view in 15 inch and 800*600 resolution.
MY PROBLEM: i have written code to catch when resolution ic changed.and accorind to the new resolution m changing the each contols's client rect and moving the corresponding control to new client react. but reafreshing si becoming problem and some controls are painting over other controls.
AdiNarayana.vemuru
|
|
|
|
|
can any one send me code/url for DES Encrypyion/Decryption.
|
|
|
|
|
|
HI,
In this piece of code, On button click i disable that button and sleep for some time. But even though the button is disabled, if user clicks on it, the number of clicks are buffered and On button CLick code repeatedly processed.
Sample code :
OnButton1()
{
static int count=0;
this->GetDlgItem(IDC_BUTTON1)->EnableWindow(false);
/* Some print messages*/
sleep(1000); /* in reality this could actually some code*/
/* to access the b ack-end data*./
this->GetDlgItem(IDC_BUTTON1)->EnableWindow(true);
count++;
}
if the buttons is continuously clicked , even if after the button gets disabled, say 5 times, then the OnButton1() code gets processed that many number of times [Count becomes 5].
I don't want the Dialog to process the BN_CLICKED messages from the disabled button.
Could any one help me out.
Thanks.
|
|
|
|
|
You have to look at the problme in the point of view of the thread executing the code. In your case its the user interface thread. This means that during the sleep() command you are not processing any message in the message queue. So what happens in the thread is disable,wait, enable, process other messages.
What you need to do is disable the button and wait in a message processing loop for the time required. Then the additional button presses will be ignored.
A typical way to do this would be to do:
MSG msg ;
while (::PeekMessage(&msg, NULL, 0, 0, PM_NOYIELD | PM_REMOVE))
{
::TranslateMessage(&msg) ;
::DispatchMessage(&msg) ;
}
You will need to setup the correct timing of this to last the time required.
Roger Allen
Sonork 100.10016
WHats brown and sticky?
A stick or some smelly stuff!
|
|
|
|
|
Hi I solved it this way..
Disable the button.
Spawn a thread.. Within that thread do some processing And once its over enable the button back again..
E.G:
On ButtonClick()
{
GetDlgItem(IDC_Button1)-> EnableWindow(falsE);
AfxBeginThread(runThread,this);
}
static UINT runThread(LPVOID param)
{
((Class *)param) ->runFunc();
return 0;
}
void Class::runFunC()
{
// Do proceddgin or Sleep...
GetDlgItem(IDC_BUTTON1)->EnableWindow(true);
}
So no message Loops needed.
But i still don't understand how a button can generate clicks once it is disabled...
|
|
|
|
|
Hi,
I'm trying to use FtpFindFirstFile to know if a file is on server, and FtpGetFile to retrieve it.
The problem is when I try to download or list something that is not there. It just returns me an "operation was completed sucessfully", no matter what I do.
Is there any way of retrieve the error the FTP throws? Any sample?
tia
sms2k
|
|
|
|
|
Try using FtpOpenFile in conjunction with InternetSetStatusCallback to get more infomation.
|
|
|
|
|
dear all,
i want to pass a CArray object (newTask which is an array of a struct TASKS) in a function.
so how do i define a function which takes
1) CArray object (newTask) as parameter.
2)pointer to CArray object (&newTask)
thanx
rishabhs
|
|
|
|
|
Using std::vector this would be easy:
void wobble (const std::vector<TASKS>& tasks);
and
void wobble (const std::vector<TASKS>* pTasks);
but using MFC CArrays, I have not the slightest clue.
My opinions may have changed, but not the fact that I am right.
|
|
|
|
|
[edit] first I'd bartered the function declarations .. but now it's ok
rishabhs wrote:
CArray object (newTask) as parameter.
I think passing as an object won't work. Use references instead:
void MyFunc( CArray(int, int)& array) {...}
...
CArray<int, int> myArray;
myArray.Add(1);
myArray.Add(111);
MyFunc(myArray);
rishabhs wrote:
2)pointer to CArray object (&newTask)
Pass it as you'd do with any other object:
void MyFunc( CArray(int, int)* pArray) {...}
...
CArray<int, int> myArray;
myArray.Add(1);
myArray.Add(111);
MyFunc(&myArray);
|
|
|
|
|
thanx Schlaubi,
but i want to pass my own structure (type) instead of int.
so this is the problem!
any ideas!!!
|
|
|
|
|
rishabhs wrote:
but i want to pass my own structure (type) instead of int.
so this is the problem
Well, the only thing you'd have to do is replacing int by TASKS. The rest wouldn't change. I took int for my example because .... I read over your TASKS - struct;)
|
|
|
|
|
You need to decide if the function will have read/write access to the array or just read access to it.
If it's going to have read/write access, you would just pass it by reference or pointer. By reference is easier since you can use the value semantics (dot notation), however I prefer to pass by pointer since it becomes more obvious that the function is going to change the array.
If it's only going to read the array, then the best way is to pass it by const reference. This gives you the benefits of value semantics while ensuring the array won't be changed (at least not without some ugly casting).
I also recommend creating an alias for the CArray< TASKS, TASKS& >, to make it easier to read (and write). You do that with typedef:
typedef CArray< TASKS, TASKS& > TaskArray;
rishabhs wrote:
1) CArray object (newTask) as parameter
void f1(TaskArray& tasks)
{
}
void f2(TaskArray* pTasks)
{
ASSERT(pTasks);
}
void f3(const TaskArray& tasks)
{
}
rishabhs wrote:
2)pointer to CArray object (&newTask)
TaskArray tasks;
f1(tasks);
f2(&tasks);
f3(tasks);
Regards,
Alvaro
All you need in this life is ignorance and confidence, and then success is sure. -- Mark Twain
|
|
|
|
|
thanx, for a great gesture!
regards
|
|
|
|
|
Hai all
Iam working on a telelcom project...while reading from or wroting to a node we use to show a progress control and a "Cancel" button on it.Focus will be set ot this button while the process goes on in order to give the user to cancel the process at any time.but my button is not working(not responding) for the mouse click and is working fine if we press the space bar.can anybody solve my problem??
ThomasKennedyBose
|
|
|
|
|
Could you give some more information?
Is this a dialog box you are talking about, in which case did you create it using MFC, Class Wizard etc. and using the default id IDCANCEL for it?
Debbie
|
|
|
|