There are no direct APIs or functions to identify which is second instance or third instance and so on.
Why do u need second instance?
What exactly is the problem u r facing?
If something is crashing in the ExistInstance in the second time, you have to find out which statement is crashing.
It may be because, u r trying to access an un initialized variable there which may get initialized in the first instance as InitInstance will execute completely in the first instance.
But in the second instance you may bypass those initializations and exits after the 'previous instance' checking. Then when control reaches ExitInstance it will crash as what ever u r accessing is not initialized. Just a thought. chk it out.
When the first instance starts execution, the very first thing it should do is check for a mutex, if not found it should create one. When the second instance starts, it should check for the mutex, when it finds it it should terminate.
Look at the CreateMutex() and GetLastError() functions.
I'm not sure where to do this in MFC, but in Win32 these routines are the first to be executed in WinMain(). Also note all of this should be done before creating/reading any other variables.
I have a header file containing all these functions and a few more like handling Command line paramaters, and handling MultiUser/MultiDesktop environments. (A modified combination of CP examples). If you like I will send it to you.
Can anyone please help me implement a custom (override) DrawItem method for a multicolumn CListCtrl, in particular for the individual columns / subitems? Here's what I have so far:
void CColoredListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)<br />
CString csItemText = GetItemText(lpDrawItemStruct->itemID, 0);<br />
CDC dc;<br />
// Save these value to restore them when done drawing<br />
COLORREF crOldTextColor = dc.GetTextColor();<br />
COLORREF crOldBkColor = dc.GetBkColor();<br />
if (lpDrawItemStruct->itemData != NULL)<br />
if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED))<br />
dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT));<br />
if ((lpDrawItemStruct->itemID % 2) == 1)<br />
dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_BTNFACE));<br />
dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_WINDOW));<br />
// Draw the text<br />
dc.DrawText(csItemText.GetBuffer(), csItemText.GetLength(), &lpDrawItemStruct->rcItem, DT_LEFT | DT_SINGLELINE | DT_VCENTER);<br />
// Reset the background color and the text color back to their original values<br />
I'm having trouble with the very first line in this method. It always gets the itemtext of the first column, but I'm having a multicolumn listctrl so I also need to know which subitem to get. This method is called from calls to CListCtrl::InsertItem and CListCtrl::SetItemText which get called in a multithreaded context. I was hoping the LPDRAWITEMSTRUCT would have subitem info but it doesn't seem to.
Also, does the lpDrawItemStruct->itemData member contain the info that was set by calls to CListCtrl::SetItemData??
I am verry sorry. I try to create one program and it really worked at only my computer with current user. I could not connect to other computers, even my localhost with other accounts. LogonUser always returned FALSE. Please could you give me some code. Needn't API, non MFCs are OK.
Last Visit: 31-Dec-99 18:00 Last Update: 16-Jun-21 8:18