|
Use ShowWindow(SW_SHOW) and ShowWindow(SW_HIDE) to show and hide controls on a dialog.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Use CreateWindow() or CreateWindowEx() with "EDIT" as classname and with the WS_CHILD windowstyle to create the editbox.
Read about CreateWindowEx here.
Sprudling
|
|
|
|
|
Add CEdit member variables to your dialog class and call Create on them when you want to.
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|
|
Poor bloke. He got three equally accurate, but totally different, answers...
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
Hi,
Given: a multithreaded app with a worker threadfunction as below:
UINT TreadFunction(...)
{
Sleep(nDuration);
}
Sleep(nDuration) tries to model a data read operation of unpredictable length from an external device. The read in operation blocks the execution of the thread just like Sleep does. nDuration depends on the actual speed of the device.
Usually, nDuration is < 1 sec, which is quite acceptable for displaying the data afterwards. However, when shi#t happens it might even take up to 1 min for all the data to be read in which is unacceptable because my other threads cannot access the device in the meantime in order to retrieve other kind of data (concurrent access of device is not allowed)
In case of slowed down read I would like to terminate the execution of the above treadfunction after a pre-defined amount of time has elapsed REGARDLESS of the data having been completely read in or not. Of course, partial data could only be displayed in this case.
E.g:
Protection (let's call it so): tread can execute not more than 5 secs.
in 95% nDuration < 5 sec. (Protection does nothing, threadfunc terminates normally, full data is displayed)
in 5% nDuration > 5 sec. (Protection makes the threadfunc terminate prematurely, partial data is displayed)
Do you have an idea how to do that?
Thanks
Pepe
|
|
|
|
|
Hmmm... well, I'm not sure that Sleep is conceptually the same as a blocking fn, but I see your point.
Is there any way to use a non-blocking call, or perhaps set a read timeout on the operation (is this a socket or serial device?)
If not, the only thing I can think of is a TerminateThread issued by a controlling thread when a timer expires - a muchly to be avoided construct. However, if you know that termination is safe (nothing to cleanup) and there's only ever one thread reading (meaning only one timer to set up) it might not be too bad... (no flames please! )
|
|
|
|
|
The serial port is concerned.
Non-blocking calls are not possible because the device manufacturer supplied an ActiveX to be used.
TerminateThread sounds not bad because there is nothing to clean up. I will definitely try it.
But could you please clarify what you meant by setting a read timout?
Thanks for your help.
Pepe
|
|
|
|
|
PPM wrote:
But could you please clarify what you meant by setting a read timout?
Well, on a blocking socket you can use a setsockopt option to specify a timeout for a read or a write operation - not sure how reliable this is in windows, but supposedly works for winsock2. Haven't used it myself, obviously
|
|
|
|
|
TerminateThread is a VERY agressive function and I would aviod using it AT ALL COSTS.
TerminateThread is used to cause a thread to exit. When this occurs, the target thread has no chance to execute any user-mode code and its initial stack is not deallocated. DLLs attached to the thread are not notified that the thread is terminating.
TerminateThread is a dangerous function that should only be used in the most extreme cases. You should call TerminateThread only if you know exactly what the target thread is doing, and you control all of the code that the target thread could possibly be running at the time of the termination. For example, TerminateThread can result in the following problems:
If the target thread owns a critical section, the critical section will not be released.
If the target thread is allocating memory from the heap, the heap lock will not be released.
If the target thread is executing certain kernel32 calls when it is terminated, the kernel32 state for the thread's process could be inconsistent.
If the target thread is manipulating the global state of a shared DLL, the state of the DLL could be destroyed, affecting other users of the DLL.
A thread cannot protect itself against TerminateThread, other than by controlling access to its handles. The thread handle returned by the CreateThread and CreateProcess functions has THREAD_TERMINATE access, so any caller holding one of these handles can terminate your thread.
If the target thread is the last thread of a process when this function is called, the thread's process is also terminated.
The state of the thread object becomes signaled, releasing any other threads that had been waiting for the thread to terminate. The thread's termination status changes from STILL_ACTIVE to the value of the dwExitCode parameter.
Terminating a thread does not necessarily remove the thread object from the system. A thread object is deleted when the last thread handle is closed.
As you can see, using TerminateThread is just asking for problems.
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
Did you think about asynchronous I/O? It is intended to solve exactly such type of problems.
|
|
|
|
|
Asynchronous I/O is unfortunately not possible because all the communication protocol is packaged up into an ActiveX which cannot be changed.
And the reason for several worker threads is:
1.responsiveness of GUI to be preserved
2.queue requests for other data retrieval during the blocked period of time
The worker threads themselves are meant to play the role of asynchronous calls.
Thanks
Pepe
|
|
|
|
|
I dynamic created a CEdit window, and it doesn't handle all the short cut keys ..
so I decide to handle those ctrl+c, ctrl+v etc.
maybe there is an easier way, please tell me.
created it..
dwStyle = WS_CHILD|ES_AUTOHSCROLL;
Create(dwStyle, m_rc, m_pProp->GetCtrlParent(), GetCtrlID());
and want all keys ...
UINT CPropTreeItemEdit::OnGetDlgCode()
{
return CEdit::OnGetDlgCode()|DLGC_WANTALLKEYS;
}
override OnChar function...
void CPropTreeItemEdit::OnChar( UINT nChar, UINT nRepCnt, UINT nFlags )
BOOL bControl = GetKeyState(VK_CONTROL) & 0x8000;
if (bControl)
{
TRACE("%c",nChar);
switch (nChar)
{
case 'a':
{
SetSel(0,-1);
}
break;
case 'x':
Cut();
break;
case VK_INSERT:
case 'c':
Copy();
break;
case 'v':
Paste();
break;
}
}
but when i hit key control key, the character value is always 17 which is probably the control key value,
How can I get a 'a' or 'x'?
|
|
|
|
|
I think you've probably missed a flag or something for the keys to not just work, but in answer to the question, under each case statement, use
if (GetAsynchKeyState(VK_CONTROL))
to find out if the control key is also down. Do a GetAsynchKeyState(VK_CONTROL); before the switch to clear the buffer.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Can anybody show me the way to create image file in memory with GDI+?
thanks
Mazy
Don't Marry a Person You Can Live With...
Marry Someone You Can Not Live Without
|
|
|
|
|
Have you considered reading the docs at the URL I gave you ?
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/gdip_cpp_classes_01b_0nw3.asp
Bitmap bitmap (1024, 768,PixelFormat24bppRGB );
Last time I looked only one of the pixel formats worked, it was either this one, or 32bppRGB, but accessing hte individual bits still returned BGR.
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
This problem involves floating point variables. When ever I add or subtract to a floating point variable I get strange numbers. For example if I add 0.5f to 5.0f, I get 5.499999999999 instead of 5.5. Here is an example:
float fExample = 5.0f;
fExample = fExample + 0.5f;
// fExample is now 5.499999999 !!!!
Is there something I am doing wrong, or is there a way of doing this without getting those ridiculous values.
Thanks in advance,
James Bird
|
|
|
|
|
Floating point is not entirely accurate. Doubles are more accurate than floats.
Why do you need 5.5 instead of 5.499999 ?
Christian
I have come to clean zee pooollll. - Michael Martin Dec 30, 2001
Picture the daffodil. And while you do that, I'll be over here going through your stuff.
|
|
|
|
|
Christian Graus wrote:
Why do you need 5.5 instead of 5.499999 ?
Thats what i was thinking...are they calculating the trajectory of a missle or something...? Maybe you shouldn't say anything..;P
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
If its just the display output that is the problem, you might want to have a look at this thread: here
|
|
|
|
|
Floating point is stored in base 2 and thus can have trouble representing numbers that look perfectly normal to us. Also, addition is inherently poor in floating point while multiplication works much better. If you can avoid repeatedly adding small numbers to a large number and instead perform a single add, the quality of the floating point number is much better.
For example:
float a = 1000;
for (int i = 0; i < 10000; i++)
{
a += 0.5;
}
float a = 1000;
for (int i = 0; i < 10000; i++)
{
float b = a + (float) i * 0.5;
}
Tim Smith
Descartes Systems Sciences, Inc.
|
|
|
|
|
I know what a heap is, I know what a stack is but how do they relate to each other? I'm trying to reach a better understanding of memory management and not being able to put them in context is really throwing me.I know the question is a bit vague but so is my understanding at this point.
To overcome everything is to reach an invisible height where users cease to exist
|
|
|
|
|
Stack works on a push pop concept, heap is random.
stack is used for temporary static variables, heap is used to create dynamic variables.
Thats why you get mem leaks with:
Blah* blah = new Blah;
if no delete follows
but never with
Blah blah;
whatever is pushed onto the stack at startup is removed automatically at the end of the current scope, block, function thingy.
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
HockeyDude wrote:
stack is used for temporary static variables, heap is used to create dynamic variables.
Thank you that clarifies everything!
To overcome everything is to reach an invisible height where users cease to exist
|
|
|
|
|
No worries be happy!
*dances like Harry Bellafonte*
Daaaaaaaaao
DaaaaaaaaaOh..
DB developer and me want to go home.
Left key, right key, left key type!!!
It's almost daylight here, so i'm gonna quit singing...
Nite'
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
HockeyDude wrote:
current scope, block, function thingy
Nish
Nish was here, now Nish has gone;
He left his soul, to turn you on;
Those who knew Nish, knew him well;
Those who didn't, can go to hell.
I like to on the Code Project
Sonork ID 100.9786 voidmain
www.busterboy.org
|
|
|
|