|
Q1: Yes. Unless you use some kind of thread synchronization you can make no assumptions about what thread finishes when.
Q2: Use synchronization[^]. You need to synchronize access from multiple threads to any objects that aren't specifically thread safe.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
A1. Of course, in the same way your Excel sheet could be recalculating while you are typing text in Word.
A2. Thread synchronization.
You should look at threads in an application like employees in a company; each of them can do as they like or are told, if you don't manage, i.e. organize and synchronize them, a mess will ensue.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Guys,
I have a problem with CDC::DrawText() and I have been sitting here wasting away my Sunday trying to figure it out. The problem is that it does not draw the text in the position I expect it to be. The following code is supposed to draw a rectangle, then draw the text in the box, using the style (DT_LEFT, DT_CENTER or DT_RIGHT).
CBrush brush(m_background[nIndex]);
CBrush* pOldBrush = pDC->SelectObject(&brush);
pDC->SetBkColor(m_background[nIndex]);
pDC->SetBkMode(OPAQUE);
pDC->SelectStockObject(NULL_PEN);
pDC->Rectangle(m_hitRect);
pDC->SelectObject(pOldBrush);
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(txt,m_hitRect, m_nStyle | DT_SINGLELINE | DT_VCENTER);
The text appears in the box (but not in the correct position) when I use DT_CENTER or DT_RIGHT but is not drwn at all with DT_LEFT (I think its outside the rect).
Please help, I really should be cutting the grass!
Tony
|
|
|
|
|
Check the values in m_hitRect , I don't think we can guess what they are.
[edit]It is also worth checking the return value from the DrawText() call to verify that it did what you expect.[/edit]
The best things in life are not things.
|
|
|
|
|
You don't show the values of variables so it's hard to guess.
If you strip it down and hardcode values it works fine...
CString txt = _T("This is the text!");
CRect m_hitRect(10,10,200,40);
dc.Rectangle(m_hitRect);
dc.DrawText(txt,m_hitRect, DT_LEFT | DT_SINGLELINE | DT_VCENTER);
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi thanks for the reply. I figured out what it was, and as usual its something dumb and not in the area I was looking in.
A long, long time ago I had padded out the right hand side of the string with spaces (not sure why I did this). Anyway, as you can imagine, this would totally screw up the justification.
Oh well, that grass wont mow itself
Thanks
|
|
|
|
|
how to create chm file using html help wprkshop
|
|
|
|
|
You may as well ask how to build a car with tools. Try reading the documentation and help, or Google for tutorials or information on MSDN.
The best things in life are not things.
|
|
|
|
|
|
Use help authoring tools like Helpinator[] for example.
|
|
|
|
|
hello guys... I have this array which has 5 elements in it like this.
int arr[] = {1,2,3,4,5};
Now how do I find the length of this array? thnx
|
|
|
|
|
Not completely sure what you mean, but try this:
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
and use it like:
int my_array_len = ARRAY_LENGTH(arr);
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
|
overloaded Name wrote: Now how do I find the length of this array? thnx
The size of the array, or the number of elements?
"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
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
Use sizeof(arr) / 4;
#include <stdio.h>
void main()
{
int arr[] = {1,2,3,4,5};
int x = sizeof(arr)/4;
printf("sizeof(arr) = %d \n", x );
}
|
|
|
|
|
int main()
{
int a[] = {1,2,3,4,5};
printf("%d",sizeof(a)/sizeof(int));
getch();
}
|
|
|
|
|
hi everyone
i have a question
how can I compute space complexity O()?
and is it any already function in C++ to compute it?
|
|
|
|
|
moathyy wrote: hi everyone
i have a question
how can I compute space complexity O()?
Studying the problem.
moathyy wrote: and is it any already function in C++ to compute it?
No.
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]
|
|
|
|
|
The whole point of complexity analysis is finding an estimate based on certain premises, usually the premise that this is a worst-case scenario. The only way to find out about that is knowing the whole program and the algorithms involved in that scenario.
For a full analysis you'd need to find all possible call paths, then start at the lowest level, i. e. functions that do not call any other functions, and analyze their complexity. The you go a level higher and do the same, using the complexity values you've already calculated from the lowest level functions. So you work your way up, until you are able to determine the complexity of main().
Of course, it isn't quite as easy as that: If you use multithreading you will need to consider the cost of synchronisation, and at the same time consider shared resources, and make sure you don't count them multiple times. If you have recursive calls, you need to determine the recursion depth. And worst of all, for every conditional branch, including end-of-loop conditions , you need to estimate the likelyhood for each branch.
Also, space complexity has the added complication that it can be reduced temporarily, making it impossible to determine the complexity of multi-threaded applications.
The biggest problem however is, that even the lowest level functions in your application may need to call system functions, drivers, or other external functionality that you don't possess any complexity information about.
Currently there is no system that can automate this process. And a full-fledged analysis of the whole system as described above is impossible to do manually for all but the most trivial applications. So the only way to do this is by looking at the parts of the system that you think are most critical and important to your users, and manually estimate the complexity for that.
|
|
|
|
|
Hi,
I am developing application which is launched by another application. I wanted to notify the parent application (the launcher) that the task successful or failed. So I need to pass the main window handle of the launcher application to my second application like /CallingProgramWindow="0001009C". Then how can i convert the string back to window handle. And is this method is the right way to do this.? I am using VC++ to develop the application.
Thanks
Nitheesh
Nitheesh George
http://www.simpletools.co.in
|
|
|
|
|
As far as converting to HWND goes, a handle is really a void* , so all you need to do is to parse a HEX number into a void pointer. I do not know if this is the right approach, but I think it has a good chance of working. If it does not work, you could try a less reliable method of passing coordinates of, say, the upper-left corner of the window, and then call WindowFromPoint[^] on it.
|
|
|
|
|
While this may work, I am not sure that it is the 'correct' way to implement what you want. It may be better to use the Process functions (CreateProcess etc) and use the return value form GetExitCodeProcess() [^].
The best things in life are not things.
|
|
|
|
|
There are several ways to make the two processes communicate. The way you depicted is actually feasible, just use the strtoul[^] function to convert the string.
Another simple way would be using the RegisterWindowMessage[^] mechanism.
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]
|
|
|
|
|
Nitheesh George wrote: So I need to pass the main window handle of the launcher application to my second application like /CallingProgramWindow="0001009C". Then how can i convert the string back to window handle. And is this method is the right way to do this.?
Unlikely.
What exactly do you want to do with the handle in the second app?
In general you solve the problem like this.
1. Target app runs
2. Target app gets to point X in app and this is considered 'succcess'
3. Target app 'sends' result to host application.
Step 2 is defined by your application.
There are several ways to do 3, such as stdio or sockets. However if you just need to know if the target ran and the host ran it then the process of actually running it would tell you that.
|
|
|
|
|
Nitheesh George wrote: So I need to pass the main window handle of the launcher application to my second application
Interprocess COmmunication[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|