|
Actually, you really don't want to forcibly terminate your thread. You should monitor something in your thread proc that will exit when the state is set by the parent thread.
One way of handling this is to create an event, say, m_hShutdown. At the top of your thread proc loop, do a WaitForSingleObject on m_hShutdown with a short timeout. When the event is set, exit the thread proc and your thread will terminate normally. In your parent code, simply call SetEvent(m_hShutdown) when you're ready to terminate the child thread.
Hope this helps.
|
|
|
|
|
IMO, you can take a global flag variable. In your thread function check for the flag value to be true(The flag value is set to true when you want the thread to end), so gracefully return from the thread function. Using AfxEndThread() , TerminateThread is not suggested. You must always try and return from the thread function whenever you want to end it...
If you are starting a thread in some function and want to instantiate the thread only once then you can use another flag variable. Set it true and check for the validity.
I hope that I understood you correctly...
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
WIr3D 0x90 wrote: i want to know how to terminate child thread from parent thread, any API or tutorials will be helpful,,
I second Mr Duncan's suggestion: Do NOT terminate threads unless you know they are safe to be killed. Should the thread be executing within the C-runtime library for instance, holding a mutex/critical section object, you will effectively cause a dead lock (sooner or later). To only safe way to terminate a thread is to use some form of communication. The absolutely simplest way is to pass a variable through CreateThread/_beginthread which your thread should monitor regularly. As soon as this variable's value becomes true (or whatever variable type you choose), you can then have the thread exit itself. During exit you can then make sure that various locks and resources are released as needed.
Seriously. Do not kill threads by forece. You will regret it later.
--
Mit viel Oktan und frei von Blei, eine Kraftstoff wie Benziiiiiiin!
|
|
|
|
|
Hey, guys.
The image list for a toolbar I'm writing is forced to a 16 color palette regardless of the color depth of the bitmap that I use. In some of the older MFC doc it mentions a 16 color limitation for toolbars. However, this is for an IE toolbar and I can see that others (such as Google) are able to use more color (either 256 or perhaps even true color).
My assumption is that they're doing complete owner draw code for the toolbar buttons, but I'm hoping I'm just missing something obvious. Anyone know how to coerce a toolbar to display the images in greater than 16 color without resorting to an owner draw scenario?
|
|
|
|
|
after creating the tool bar in main class . i.e CMainFrame . add a image list to the tool bar . that imagelist can containe 25 color icons . and we can give three imaage lists for tool bar . 1 for when button is Active . 2 for Wend button is disabled . and 3rd state is grayed. try this. bye
|
|
|
|
|
m_ilToolBar.Create(20,20,ILC_COLOR8,4,4);
Tanvon
the brain behind ...
I Blog here
|
|
|
|
|
after creating the tool bar in main class . i.e CMainFrame . add a image list to the tool bar . that imagelist can containe 256 color icons . and we can give three imaage lists for tool bar . 1 for when button is Active . 2 for Wend button is disabled . and 3rd state is grayed. try this. bye
|
|
|
|
|
sorry I am having today some problem posting answers.
1: load your bitmap
HBITMAP hbm = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_BITMAP,
0,0, LR_CREATEDIBSECTION | LR_LOADMAP3DCOLORS );
CBitmap bm;
bm.Attach(hbm);
2: make a 256 color image list
CImageList m_ilToolBar.Create(20,20,ILC_COLOR8,4,4);
m_ilToolBar.Add(&bm,(CBitmap*)NULL);
3: select that image list in your app toolbar
m_wndToolBar.GetToolBarCtrl().
SetImageList(&m_ilToolBar);
Tanvon
the brain behind ...
I Blog here
|
|
|
|
|
Tanvon (and everyone else), thanks for the help.
I realize now that in using the Create version that takes a mask param, it's defaulting to 16 color. However, the version that accepts the ILC params doesn't include one to set the mask.
If I use ILC_COLOR8 | ILC_MASK, does the first m_ilToolBar.Add() set the bitmap and the second the mask?
|
|
|
|
|
Have you tried creating the image list object manually? See the ILC_XXX flags as well as the MSDN docs for the Create() method.
If you go for true color, and you use 32 bit icons, do use ILC_COLOR32, as it will preserve the alpha channel information. ILC_COLOR24 will strip the alpha channel information, resulting in VERY ugly images.
Another thing: if you use 32 bit icons - DO NOT open them in the IDE icon editor. It will strip away the alpha channel information, rendering the icons ugly. Even if you don't modify and save the icon, the IDE (VS.NET 2k2 and 2k3 - not sure about 2k5) will silently modify your icons.. Took me a while to figure this out.
[edit]I have also noticed that on Windows 2000 and earlier systems, icons and image lists with 256 colors is rendered better than true color image lists. On XP and later, true color looks better. Why this is, I can't really tell. All I've got to back this up are my own subjective opinions - so don't take this statement as scientifically proven. [/edit]
--
Mit viel Oktan und frei von Blei, eine Kraftstoff wie Benziiiiiiin!
|
|
|
|
|
Hey, man.
Thanks for the heads up on this stuff. I'll try the ILC_COLOR32 & see how it does for me.
Turns out it was defaulting to 16 color because I was using the version of Create() that took a mask param. Using the version that takes the ILC flags, I'm assuming I need to or in the ILC_MASK, but I'm not seeing clear doc on how to subsequently set the mask. Any insights would be appreciated.
|
|
|
|
|
Christopher Duncan wrote: I'm assuming I need to or in the ILC_MASK, but I'm not seeing clear doc on how to subsequently set the mask. Any insights would be appreciated.
There are basically two ways to create image lists. One is to use a mask (in some form), and the other is to specify a transparent color. The mask is either explicit (b&w bitmap), or implicit (embedded mask bitmap inside icon and/or alpha transparency). Either way, you will have to specify ILC_MASK.
The transparency color option is simple to use. AFAIK, you don't have to specify ILC_MASK (with MFC you can't I believe). Pixels with this transparent color will be omitted when you draw the image list, giving the transparency effect. When I use this technique, I use a color which is seldom used in the actual image - RGB(0xFF, 0xFF 0) for instance.
So, this is what I'd do if I were to build an image list out of a set of icons:
CImageList lst;
lst.Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 2);
lst.Create(16, 16, ILC_COLOR24 | ILC_MASK, 0, 2);
lst.Add(hIcon1);
lst.Add(hIcon2); With masking bitmaps:
lst.Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 2);
lst.Add(&bmpImage, &bmpMask); And with a transparent pixel and predefined bitmap I'd do this:
lst.Create(MAKEINTRESOURCE(IDB_MYBITMAP), 16, 2, RGB(0xFF, 0xFF, 0));
Of course, ILC_COLOR8 is perfectly valid should you have bitmaps which share the same palette. If your bitmaps have different palettes, the finished image list may look horrible should the bitmaps which you have added to it, have very different palettes.
My rules of thumb are:
- ILC_COLOR24 for all image lists to which I intend to add different bitmaps and use a transparency color
- ILC_COLOR32 for all image lists for which I intend to add 32 bit icons, just to preserve the alpha channel
- ILC_COLORWhatever for static image lists - i.e., image lists which you feed ONE composite bitmap. Such a bitmap will have only one palette, and is therefore not subject to palette freakization.
Basically it boils down to if you want to build the image list at runtime or not. I increase the bit depth for runtime built image lists to guard against ugliness. I am conservative about the bit depth for compile time build image lists, as 24 bits or more for 8 bit images would just be waste of memory.
--
Mit viel Oktan und frei von Blei, eine Kraftstoff wie Benziiiiiiin!
|
|
|
|
|
I'm up and running. Thanks for the help, man!
|
|
|
|
|
You can solve this via creating and filling your own imagelist at first and which you set to the toolbar.
Greetings from Germany
|
|
|
|
|
I'm up and running, just wanted to take a moment to thank all of you who took the time to help out. I do appreciate it.
Have a good week!
|
|
|
|
|
Hi,
Can u plz say how to convert char* variable to char.
I write the code as shown below
struct row{
char name[50];
char sex[5];
};
I am getting text from the edit box and assigning to row.name, I want to insert row.name into the database.
char *CampID=new char[50];
GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50);
row.name=CampID;
But I am getting error saying that "Can not convert from char* to char[50]"
Thanks in advance.
|
|
|
|
|
tejaswini.g wrote: char *CampID=new char[50];
GetDlgItemText (IDC_EDITCAMPAIGNID,CampID,50);
row.name=CampID;
you need to use strcpy here.
strcpy(row.name,CampID);
|
|
|
|
|
Thank you.
Shall I ask you One more doubt.
I have created a propertysheet with two property pages.
In the first property page i displayed 'employee names ' from the database and displayed in the grid lines.
I select on name and activate another property page.Using querysiblings i got the name in the second property page.
And using that ,employeename' i write a query to get the data from the database and displayed in the controls.
First time it is running fine.
Second time if i select another emplyoee name I am getting the correct results from database but the old data is displayed in the controls.
Can u plz say How can I solve this problem?
Thanks in advance.
|
|
|
|
|
|
BOOL CCampaignDataEntryDlg::OnInitDialog()
{
CPropertyPage::OnInitDialog();
setUpODBC();// establish database connection
long x=QuerySiblings(1,(long)&m_querySibling);
CString* pString=(CString*)x;
pStr=*pString;
AfxMessageBox(pStr); //display employee name say 'tejaswini'
SQLRETURN sr;
SQLHSTMT hstmt;
CString campid;
campid.Format("SELECT empName,empID FROM EMPLOYEEDETAILS WHERE EMPNAME= '%s'",pStr);
SQLCHAR* SQL = (SQLCHAR*)(LPCSTR)campid;
}
BOOL CCampaignDataEntryDlg::OnSetActive()
{
if(m_Status!="") //m_Status is to used to know whether the
//property page is activated or not
OnInitDialog();
return CPropertyPage::OnSetActive();
}
BOOL CCampaignDataEntryDlg::OnKillActive()
{
m_Status="abc";
return CPropertyPage::OnKillActive();
}
|
|
|
|
|
tejaswini.g wrote: BOOL CCampaignDataEntryDlg::OnSetActive()
{
if(m_Status!="") //m_Status is to used to know whether the
//property page is activated or not
OnInitDialog();
return CPropertyPage::OnSetActive();
}
dont call OnInitDialog here. Instead write that code in OnSetActive .
|
|
|
|
|
|
tejaswini.g wrote: long x=QuerySiblings(1,(long)&m_querySibling);
CString* pString=(CString*)x;
pStr=*pString;
QuerySiblings() does not return a value that can be cast to a CString .
If page two wants to know the name that was selected on page one, store that name in the sheet (the common link between pages).
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
I would prefer strncpy(...) and set the last char to zero.
Greetings from Germany
|
|
|
|
|
tejaswini.g wrote: saying that "Can not convert from char* to char[50]"
You can also go around with this using CString if you are using MFC
Define the structure as:
struct row{
CString name;
CString sex;
};
// In your code where you are retrieving the string you can write:
char *CampID=new char[50];
GetDlgItemText (IDC_MYEDIT,CampID,50);
row r;
r.name =(CString )CampID;
AfxMessageBox (r.name); // r.name has same string as CampID
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|