|
Check this.[^] It might be helpful
-Sarath.
"Great hopes make everything great possible" - Benjamin Franklin
|
|
|
|
|
Hi all,
I am using SetLayeredWindowAttributes in order to create an outlook like message.
I have a special show function which moves (with SetwindowPos) the dialog and changes its opcaity while moving.
The dialog fades in (both by movement and opacity change) around the system tray area, and after 3 seconds fades out.
When i call the show function for the first time, all controls on the dialog (bitmap, static text etc.) appear as black boxes, until the fade in effect is done, then he controls appear properly.
Consequent calls to the show function works properly - it shows the controls through all the fade in and fade out procedure.
If i create a thread and call the show function from it then it works fine for the first call also.
I would appriciate it if someone can explain the differnece between calling the function from another thread or form the window thread, the drawing procedure of a dialog and may be offer a way to solve this problem without creating a new thread.
Thanks
Shimon
|
|
|
|
|
One thing that can be tried first is calling UpdateWindow after the first show function call.
- ns -
|
|
|
|
|
Indeed, calling UpdateWindow after the 1st call fixed the problem
Thanks!
|
|
|
|
|
After setting the layered window style, you should call the SetLayeredWindowAttributes() funcion Immediately. Are you doing so?
<blockquote class="FQ"><div class="FQA">dj4400 wrote:</div>I am using SetLayeredWindowAttributes in order to create an outlook like message.</blockquote>
Also take a look at the AnimateWindow() function. I think you can achive the above effect with a single call to AnimateWindow() function.
|
|
|
|
|
how to duplicate a .mak file with same content but diffrent name
kir_MFC
|
|
|
|
|
can't you just copy the file and rename it ?
This signature was proudly tested on animals.
|
|
|
|
|
Hi everyone,
Here is a problem of mine....
I have a function (threadfunction). And i am creating a thread using Createthread() Function from a buttonClick....I have a local integer value in the threadFunction
Each time I click the button,new thread should create,...Its creting new threads , but its overwriting the local integer value ie it is shared by all the created threads....
Please help me out...
Within the threadfunction, I am decrementing the value after each 200 ms,
DWORD WINAPI personal_recv_fnc_thread( LPVOID lpParam)
{
int i=10;
do
{
Sleep(200);
--i;
}while(i>=0);
return 0;
}
I want to run each thread and decrement the value in all thread separately.....ie each thread should decrement its own local value
modified on Thursday, January 22, 2009 6:05 AM
|
|
|
|
|
Member 4250705 wrote: Its creting new threads , but its overwriting the parameter value ie it is shared by all the created threads....
Well, yes, that's the standard behavior. When you start a new thread, you only create the thread, not duplicate any global value. You will need to make the variable local to your thread function in order to have multiple different variables.
Wait, I misunderstood your question. What are you passing to your thread function ? Could you post the code where you call CreateThread ?
modified on Thursday, January 22, 2009 6:08 AM
|
|
|
|
|
but that will again overwrite by all thread...
|
|
|
|
|
Shouldn't you be casting lpParam to an int pointer rather than an int?
|
|
|
|
|
Indeed it should. Are you sure you are not mistaking? Try the following: use TRACE to display your i variable once before the do and every loop inside the do, then run 3 threads, each with let's say- a 300 ms delay and then check out your output window. You should see that when a new thread is started your already running ones are not affected.
So something like this:
DWORD WINAPI personal_recv_fnc_thread( LPVOID lpParam)
{
int i=10;
TRACE("%X: RUNNING THREAD, starting from %d =====================\n", GetCurrewntThreadId(), i);
do
{
Sleep(200);
--i;
TRACE("%X: %d\n", GetCurrewntThreadId(), i);
}while(i>=0);
return 0;
}
...
CreateThread(...personal_recv_fnc_thread...);
Sleep(300);
CreateThread(...personal_recv_fnc_thread...);
Sleep(300);
CreateThread(...personal_recv_fnc_thread...);
...
To be absolutely sure, i tried this. It works as it should.
p.s: next time you post code, use <pre> and </pre> tags please, makes things easier to read.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
Member 4250705 wrote: Its creting new threads , but its overwriting the local integer value ie it is shared by all the created threads....
That's not true, according to documentation [^]:
All threads of a process share its virtual address space. The local variables of a function are unique to each thread that runs the function.
You may verify with the following simple test program
Please note: fixed to avoid *disaster* [^]
DWORD WINAPI ThreadProc(
LPVOID lpParameter
)
{
int i=10;
const int BUFSIZE = 0x100;
TCHAR szBuf[BUFSIZE];
HRESULT hr;
do
{
Sleep(200);
--i;
printf("%x %d\n", (INT_PTR)lpParameter, i);
hr = StringCchPrintf(szBuf, BUFSIZE, _T("%x %d\n"), (INT_PTR)lpParameter, i);
if ( SUCCEEDED(hr)) OutputDebugString(szBuf);
} while (i>=0) ;
return 0;
}
bool main()
{
for (int i=0; i<10; i++)
{
DWORD dwId;
CreateThread(NULL, 0, ThreadProc, (LPVOID)i, 0, &dwId);
}
Sleep (4000);
return true;
}
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]
modified on Thursday, January 22, 2009 8:07 AM
|
|
|
|
|
Using C-runtime functions in a thread created by a method other than calling _beginthread, _beginthreadex[^] is bad form and a recipe for disaster. The reason the CRT has these functions is that some features of the CRT require thread specific initialisation, which your code is bypassing. The following is quoted from the documentation on CreateThread[^]:
A thread in an executable that calls the C run-time library (CRT) should use the _beginthreadex and _endthreadex functions for thread management rather than CreateThread and ExitThread; this requires the use of the multi-threaded version of the CRT. If a thread created using CreateThread calls the CRT, the CRT may terminate the process in low-memory conditions.
Steve
|
|
|
|
|
You're right, thanks for pointing out.
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]
|
|
|
|
|
Hi,
I want to call a templated function with template parameters chosen at runtime.
for example something like this
func(int x)
{
if( x == 0)
templatedFunction <<int>> y = new templatedFunc<<int>>();
else
templatedFunction <<double>> y = new templatedFunc<<double>>();
}
is this possible in C++?
thx in advance
|
|
|
|
|
You answered your own question i believe. It is possible with switch cases or using if-else.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I tried the code below
switch (pType)
{
case itk::ImageIOBase::IOComponentType::CHAR:
otb::VectorImage<char, 2>::Pointer p = otb::VectorImage<char, 2>::New();
break;
case itk::ImageIOBase::IOComponentType::UCHAR:
otb::VectorImage<unsigned char, 2>::Pointer p = otb::VectorImage<unsigned char, 2>::New();
break;
}
when this code compiles it gives errors
Error 4 error C2360: initialization of 'p' is skipped by 'case' label d:\otb\imageeditorapp\imagetoolbox\imageio.h 44
Error 5 error C2371: 'p' : redefinition; different basic types d:\otb\imageeditorapp\imagetoolbox\imageio.h 45
Error 9 error C2360: initialization of 'p' is skipped by 'case' label d:\otb\imageeditorapp\imagetoolbox\imageio.h 44
Error 10 error C2371: 'p' : redefinition; different basic types d:\otb\imageeditorapp\imagetoolbox\imageio.h 45
I did not understand the mistake, if this is possible :/
|
|
|
|
|
Read this[^], and when you get errors, you can click on them in your output window, on the part after the error word, for example C2360 and press F1 to see what that error means, assuming you are using VS.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
I tried with the code below and it compied without errors
if(pType == itk::ImageIOBase::IOComponentType::CHAR)
otb::VectorImage<char,2>::Pointer p = otb::VectorImage<char,2>::New();
else if(pType == itk::ImageIOBase::IOComponentType::UCHAR)
otb::VectorImage<unsigned>::Pointer p = otb::VectorImage<unsigned>::New();
</unsigned></unsigned>
bu I could not understand why, is there a problem with my switch statement code in the previous message
|
|
|
|
|
You need to define a scope for the memory allocation in the switch statement.
Put the object creation code with parenthesis.
switch (pType)
{
case itk::ImageIOBase::IOComponentType::CHAR:
{
otb::VectorImage<char, 2>::Pointer p = otb::VectorImage<char, 2>::New();
}
break;
case itk::ImageIOBase::IOComponentType::UCHAR:
{
otb::VectorImage<unsigned char, 2>::Pointer p = otb::VectorImage<unsigned char, 2>::New();
}
break;
}
This also means you can use the object only within the parenthesis.
The new lambda functions available in the new C++ standards is what you need.
But unfortunately it is not currently available.
It will be available in VS 2010.
«_Superman_»
|
|
|
|
|
So you mean I can not use this new variable after the switch or if statement
if (x==0)
double y;
else
int y;
y = 0; ERROR // 'y' undeclared identifier
So any of you have a solution for this kind of problem?
What I want to do is this.
I have a parameter, and I want to declare a templated variable according to this parameter(if parameter is 1, it is char, if 2, int etc). and I will use it till the end of the scope of the program.
|
|
|
|
|
Why don't do all processing there itself.
switch (pType)
{
case itk::ImageIOBase::IOComponentType::CHAR:
{
otb::VectorImage<char, 2>::Pointer p = otb::VectorImage<char, 2>::New();
DoAllProcessing(p);
}
break;
case itk::ImageIOBase::IOComponentType::UCHAR:
{
otb::VectorImage<unsigned char, 2>::Pointer p = otb::VectorImage<unsigned char, 2>::New();
DoAllProcessing(p);
}
break;
}
OR
otb::VectorImage&lt;char, 2>::Pointer p1;
otb::VectorImage&lt;unsigned char, 2>::Pointer p2;
int flag = 0;
switch (pType)
{
case itk::ImageIOBase::IOComponentType::CHAR:
{
p1 = otb::VectorImage<char, 2>::New();
flag = 1;
}
break;
case itk::ImageIOBase::IOComponentType::UCHAR:
{
p2 = otb::VectorImage<unsigned char, 2>::New();
flag = 2;
}
break;
}
if (1 == flag)
DoAllProcessing(p1);
else if (2 == flag)
DoAllProcessing(p2);
«_Superman_»
|
|
|
|
|
I'll continue with one of the possibilities, thx for your help, but it is a disappointment not being able to code in a straight manner
|
|
|
|
|
Write a wrapper class (maybe a template) that can hold whatever type of value you wish to use. OR maybe use template methods, am not completely sure what you want to do exactly. You can't declare a variable without explicitly stating a type, so this doesn't work:
if (whatever_condition_is_true) make Y an int;
else make Y a double;
return Y;
BUT you could make a wrapper, something like this, for example:
class CWrapperBase
{
...
};
template <typename typename="">
class CWrapper: public CWrapperBase
{
public:
TypeName m_value;
CWrapper(const TypeName &value)
{
m_value = value;
}
operator =(const TypeName &other)
{
m_value = other;
}
operator TypeName &()
{
return m_value;
}
};
CWrapperBase GetValue(int x)
{
if (x == 0) return CWrapper<double>(1.0);
else return CWrapper<int>(2);
}
</int></double></typename>
This above is far from complete, just a starting point...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|