|
[Byrne voice]
Well we can't predict the future
But we're trying to do the best that we can
[/Byrne voice]
I suppose 'the best you can' here is: "follow the KISS principle, keep it simple".
Since you cannot predict the future changes, make your overall design simple and well documented.
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]
|
|
|
|
|
In the main thread of my app i do some work and once in a while i create another helper thread to do some job using: AfxBeginThread function which returns me a CWinThread object reference.
But before i will create once again the helper thread i have to be sure that the previous is done.
Now im using the CEvent object to signal from the helper thread that he is done but my app crashes sometimes.
Can i use the CWinThread object to find out whether the previous thread is done?
Thanks.
|
|
|
|
|
Have a look at MSDN documentation: "Multithreading: Terminating Threads"[^].
The "Retrieving the Exit Code of a Thread" section gives all info you need (read carefully the steps needed in order to retrieve the exit status of a CWinThread ).
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]
|
|
|
|
|
Think you probably need to figure out the cause of the crash (that's your main issue), but you can also use the main thread handle in the CWinThread to "wait on" (WaitForSingleObject).
|
|
|
|
|
Can I save drawn rectangle into an bmp image?
|
|
|
|
|
Yes, you may do, see here for a recipe[^], also have a look at this useful sample code[^].
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]
|
|
|
|
|
But how to save drawn rectagle into an image?
|
|
|
|
|
Drawn rectangle (drawn everything) is in 'the content' of current paint HDC (or CDC if you are using MFC ), hence, for instance, inside the WM_PAINT message handler you may copy current paint HDC content into image HDC , using BitBlt function).
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]
|
|
|
|
|
Thanks for reply, but the link you suggested doing the same thing, I am confused to save image on specific path?????
|
|
|
|
|
Well, once you have the bits copied to the bitmap then you may save the bitmap itself. You may use, for instance CImage class (see, for instance "Save CBitmap to File"[^] or, if you want to go to the metal, see "Storing an Image"[^]
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 all,
i have two char buffers char a[1000],char a1[100].
i want to copy 100 value from a to a1, but everytime the index where we should start copying is different i.e. sometime it should start copying from a[100], other time from a[268].
For Copying from one buffer to another we can use function memcpy_s but it starts copying from zero.
Is there any alternate for this.
Thanks in advance
|
|
|
|
|
Just continue using memcpy_s starting from the right address, e.g.:
errno_t result;
result = memcpy_s(a1, sizeof(a1), &a[268], sizeof(a1));
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]
|
|
|
|
|
|
You are welcome.
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]
|
|
|
|
|
Im using CCriticalSection object as a parameter to CSingleLock.
When i try to create the lock object i get the:"Access violation reading location".
Why could it be?
Thnks
|
|
|
|
|
can you show us your code?
|
|
|
|
|
Hello,
I think i know what my mistake was.
I used the same CCriticalSection as a parameter to different CSingleLock objects to synchronize different resources.
I have four threads two of them use one mutual queue and the other two use other queue so i used the same CCriticalSection object as a parameter to two CSingleLocks.
Now i defined seperate lock for each queue and it works fine.
Thanks any way
|
|
|
|
|
Hi! I would like to put a file in the clipboard like when you click on a file and you copy, how can I do that?
I tried in c++ with setclipboarddata() with filename (49158) and filenameW (49159) format but doesn't work, inside the clipboard there are some other formats that I don't know. The complete list of the format is:
49161, 49268, 15, 49349, 49340, 49158, 49159, 49171.
|
|
|
|
|
I've no idea what all these numbers are supposed to mean, but I would suggest you copy the path of the file into the clipboard rather than its content. Perhaps if you show the actual code you are trying to use, someone can help you.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
Ok, thank you, actually to put in the clipboard the path is what I want to do, not the content of the file, in other word I want to do the same thing that you do on windows when you select a file and click on copy.
The code:
(filename format 49158)
char path[]="C:\\file.txt";
int size=strlen(path)+1;
hglbDato = GlobalAlloc(GMEM_MOVEABLE,size);
PVOID pv = (PVOID) GlobalLock(hglbDato);
memcpy(pv,path,size);
GlobalUnlock(hglbDato);
SetClipboardData(49158,hglbDato);
and I do the same for format filenameW (49159) but instead to use a char array I use a wchar array and wcslen() instead of strlen(). Obviously the file.txt exists.
|
|
|
|
|
What is this number 49158 about and where does it come from? The valid values for this parameter are as described here[^].
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
From the file manager I select a file and I copy it in the clipboard than I debug this code and that numbers are the values in the variable format. This code open the clipboard and load every clipboard's format in a list.
struct formato{
UINT tipo;
int dim;
char * dato;
};
listFormati.erase(listFormati.begin(),listFormati.end());
if(!OpenClipboard(hWnd))
MessageBox(hWnd,_T("OpenClipboard"),_T("Error"),MB_OK);
unsigned int countFormat= CountClipboardFormats();
UINT format=0;
for(int i=0;i<countFormat;i++){
format=EnumClipboardFormats(format);
HGLOBAL hglb;
hglb = GetClipboardData(format);
int szhglb;
szhglb = GlobalSize(hglb);
struct formato *f = (struct formato *)malloc(sizeof(formato));
if(hglb != NULL)
{
PVOID pvoid = (PVOID) GlobalLock(hglb);
char *ft = (char *)malloc(szhglb);
memcpy(ft,pvoid,szhglb);
f->dim=szhglb;
f->tipo=format;
f->dato=ft;
listFormati.push_back(f);
GlobalUnlock(hglb);
}
else
{
MessageBox(hWnd,_T("hglb==NULL"),_T("Error"),MB_OK);
}
}
CloseClipboard();
|
|
|
|
|
Those values are used by the FileManager as Registered formats so are not necessarily available for user programs. You should use the standard formats in your own program. unless you have details of the actual content stored by such a format.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
With debug I discover that 49158 is the char path of the file while 49159 wchar path. I tried also save all the formats in my list than to erase the clipboard and reload the formats that I stored in the list and I discover that the formats 49158 and 49159 are not necessary to paste the file (it also works without them). My problem is to understand what format to put in the clipboard to do the same work that the file manager does. Other interesting thing I'm trying it on a virtual machine and seems that when you restart the IDE or maybe the os, there are same format that changes their number idetification of the format while others (49158, 49159 ,etc) have the same number.
|
|
|
|
|
Just use the standard CF_ values as defined in the link I gave you earlier.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|