background instance..

Hi All,

I have some problem sharing data between two instances of same
application.Below is the design and the problem.

The requirement is to have one single application running in the
background and with one or many UI windows in the foreground.

Currently iam thinking of using the mutex method to restrict to one
instance of the exe.But the problem is everytime the instance of the
exe can launched with different command line parameters.So based on the
parameters i have to either create a dialog(which can again launch the
UI Windows) or directly create some UI windows.First question is how
can i share the command line info of the new instance of the exe with
the existing one.Secondly is there any better method of handling this
situation(currently the UI windows are on different threads).

Please provide some inputs.

Thanks,
kiran

0
3/28/2006 12:02:57 PM
vc.mfc 33608 articles. 0 followers. Follow

8 Replies
329 Views

Similar Articles

[PageSpeed] 40

kiran.inbng@gmail.com wrote:
> The requirement is to have one single application running in the
> background and with one or many UI windows in the foreground.
> 
> Currently iam thinking of using the mutex method to restrict to one
> instance of the exe.But the problem is everytime the instance of the
> exe can launched with different command line parameters.So based on the
> parameters i have to either create a dialog(which can again launch the
> UI Windows) or directly create some UI windows.First question is how
> can i share the command line info of the new instance of the exe with
> the existing one.Secondly is there any better method of handling this
> situation(currently the UI windows are on different threads).

1. Pass the command line string through a pipe, or as a WM_COPYDATA 
message. I'd go with a pipe, but novice developers may find it hard to 
implement correctly. If you implement a pipe then you don't need a 
mutex; instead CreateNamedPipe with FILE_FLAG_FIRST_PIPE_INSTANCE.

2. Create non-modal windows (Create instead of DoModal). You can have 
them several in the same thread.
0
mac1 (347)
3/28/2006 12:44:55 PM
You may want to check out PJ's classes:

http://www.naughter.com/memmap.html
http://www.naughter.com/sinstance.html

Tom

<kiran.inbng@gmail.com> wrote in message 
news:1143547377.293487.201800@t31g2000cwb.googlegroups.com...
> Hi All,
>
> I have some problem sharing data between two instances of same
> application.Below is the design and the problem.
>
> The requirement is to have one single application running in the
> background and with one or many UI windows in the foreground.
>
> Currently iam thinking of using the mutex method to restrict to one
> instance of the exe.But the problem is everytime the instance of the
> exe can launched with different command line parameters.So based on the
> parameters i have to either create a dialog(which can again launch the
> UI Windows) or directly create some UI windows.First question is how
> can i share the command line info of the new instance of the exe with
> the existing one.Secondly is there any better method of handling this
> situation(currently the UI windows are on different threads).
>
> Please provide some inputs.
>
> Thanks,
> kiran
> 


0
tserface (3860)
3/28/2006 3:58:55 PM
Hi,

Iam not able catch the wm_copydata message,can you please point me the
problem in the code.Below is the InitInstance and OnCopyData code,

BOOL CFVApp::InitInstance()
{

	HWND hWnd;
	m_hMutexOneInstance = CreateMutex( NULL, FALSE, _T("My Mutex"));
	BOOL bAlreadyRunning = FALSE;

	if((GetLastError() == ERROR_ALREADY_EXISTS) || (GetLastError() ==
ERROR_ACCESS_DENIED))
	{
		bAlreadyRunning = TRUE;
	}
	LPCSTR lpszClassName = AfxRegisterWndClass(0, NULL, NULL, NULL);

	if(!bAlreadyRunning)
	{
		hWnd = CreateWindow(
				lpszClassName,        // name of window class
				"Hidden Title",            // title-bar string
				WS_OVERLAPPEDWINDOW, // top-level window
				CW_USEDEFAULT,       // default horizontal position
				CW_USEDEFAULT,       // default vertical position
				CW_USEDEFAULT,       // default width
				CW_USEDEFAULT,       // default height
				NULL,         // no owner window
				(HMENU) NULL,        // use class menu
				AfxGetApp()->m_hInstance,           // handle to application
instance
				(LPVOID) NULL);      // no window-creation data

		if(!hWnd)
		{
			return(FALSE);
		}

	}
	else
	{

		hWnd = FindWindow(lpszClassName, "Hidden Title");

		if (hWnd)
		{
			COPYDATASTRUCT copyData;

			char *pData=new char[20];
			strncpy(pData,"Project1",sizeof("Project1"));

			copyData.dwData=77;
			copyData.cbData=20 * sizeof(char);
			copyData.lpData=pData;

			if(!::SendMessage(hWnd,WM_COPYDATA,NULL,(LPARAM)&copyData))
			{
				delete[]pData;
				return(FALSE);
			}

			delete[]pData;

			return(TRUE);
		}

	}

	AfxEnableControlContainer();

	// Standard initialization

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

	::CoInitialize(NULL);


	if(__argc > 1)
	{
		// Do not show the dialog
                                // Create Window
	}
	else
	{
		CFVDlg dlg;
		int nResponse = dlg.DoModal();
		if (nResponse == IDOK)
		{
		}
		else if (nResponse == IDCANCEL)
		{
		}
	}

	// Since the dialog has been closed, return FALSE so that we exit the
	//  application, rather than start the application's message pump.
	return TRUE;
}

BOOL CFVApp::OnCopyData(CWnd* pWnd,COPYDATASTRUCT* pCopyDataStruct)
{
	AfxMessageBox("In Copy Data");
	return(TRUE);
}

Thanks,
kiran

0
3/29/2006 8:11:02 AM
kiran.inbng@gmail.com wrote:
> Iam not able catch the wm_copydata message,can you please point me the
> problem in the code.Below is the InitInstance and OnCopyData code,

WM_COPYDATA must be handled from a window's message handler (CFVDlg 
instead of CFVApp). Take a look at this:

http://www.codeproject.com/threads/ipc_wmcopy.asp
0
mac1 (347)
3/29/2006 8:53:28 AM
Hi All,

Thanks,Iam able to get the app running.There is one more small
issue.Please suggest me a way to handle this.

Initinstance()
{
      if (first instance)
      {
            create hidden window
      }
      else
      {
             send message to create UI window to the first instance
             return;
      }

      continue if first instance
      based on the command line params create a UI window or dialog

      /// The problem is if the dialog in the  previous line is closed
my app exits..it does not wait for other windows to be closed
      /// Do i need keep track of number of windows opened and exit
from the main instance only all the other windows are closed
     
       return
}

Thanks,
kiran

0
3/31/2006 1:08:35 AM
kiran.inbng@gmail.com wrote:
>       /// The problem is if the dialog in the  previous line is closed
> my app exits..it does not wait for other windows to be closed
>       /// Do i need keep track of number of windows opened and exit
> from the main instance only all the other windows are closed

You can create an invisible main window that will create windows in 
response to WM_COPYDATA messages, but can also create one window during 
its initialization. This window should be handled as all the other 
copydata windows. Main (invisible) window should close when all child 
windows are closed, and then the application may finish.
0
mac1 (347)
3/31/2006 8:40:17 AM
Hi Cvetanovic,

Iam still learning,so please bear me for asking trivial questions.

How will the main window(hidden) know that the child windows are
closed.Currently iam thinking of maintaining a windowcount and
everytime a window is created or closed i will increment or decrement
this count.So if the count reaches zero iam posting wm_quit message.Is
this correct ?

Thanks,
kiran

0
3/31/2006 9:12:30 AM
kiran.inbng@gmail.com wrote:
> Iam still learning,so please bear me for asking trivial questions.

Of course :)

> How will the main window(hidden) know that the child windows are
> closed.Currently iam thinking of maintaining a windowcount and
> everytime a window is created or closed i will increment or decrement
> this count.So if the count reaches zero iam posting wm_quit message.Is
> this correct ?

Yes, that's how I would do it. Child window posts a message saying "I'm 
done" and main window handles it buy decrementing ref count.
0
mac1 (347)
3/31/2006 1:13:10 PM
Reply:

Similar Artilces:

Background Sizing
I am creating an ad in Publisher and I specify the size on the ad on page set up. Everything is fine until I add a background - the ad is then larger than the settings I entered. Backgrounds want to cover the entire page with a little left over. What size is your ad? What happens if you create an autoshape and fill it? -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Jen B" <Jen B@discussions.microsoft.com> wrote in message news:2F093E5C-B689-46DF-BC97-01FD15A2235D@microsoft.com... >I am creating an ad in Publi...

Display random background pics on form loading?
That's a new one to me... I was asked to do this... I put the pics in one directory, tried to mess with On_Load event, Form.picture = "Path", but nothing (do I need UNC path?)... any help with this? "Maarkr" wrote: > That's a new one to me... I was asked to do this... I put the pics in one > directory, tried to mess with On_Load event, Form.picture = "Path", but > nothing (do I need UNC path?)... any help with this? Figured this out... What I did was this... made a table (PicTable) with 2 fields (PicID, PicPath) and put the paths in the pi...

Add background music????
How do I add background music to a email. I want it to play a song when the receiving person opens the email I sent to them. Thanks Doug Answered in the general newsgroup. Do NOT multipost! -- Roady [MVP] www.sparnaaij.net Microsoft Office and Microsoft Office related News Also Outlook FAQ, How To's, Downloads and more... Tips of the month: -Create your own fully customized Toolbar -Creating a Classic View in Outlook 2003 Subscribe to the newsletter to receive news and tips & tricks in your mailbox! www.sparnaaij.net (I changed my reply address; remove all CAPS and _underscores_...

How can I add more background colors or stationary to Outlook temp
How can I add more background colors, stationery, animated watermarks, etc. to Outlood email? I go to Outlook> Actions> New Mail Message Using > More Stationery but there are only a templates as options. I would like to add templates. For example green for St Paddys, bunny backgrounds, animated (moving) hearts, etc. Thank you Create pages in an HTML editor and save to %appdata%\microsoft\stationery -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com/ Outlook Tips by ...

background color for dashed line
Hi, I'm calling CPen::CreatePen() and passing PS_DASH (white color). My background is black BUT the line I draw (using the CPen object) is drawn on an existing WHITE line. As a result, I cannot see the new dashed line (because it doesn't draw anything between the small lines so I see only one solid line). I know that I can draw two lines- one black and one dashed white, but the question is if I can draw only one dashed line so that between the white small lines it will draw black lines? Regards, Ram. Ram, If memory serves, the color set in SetBkColor will be used by the background...

Creating new form instance in Access 2003 SP3
I have had a database working for 3 years that creates multiple instances of a main data form. It uses the idea of: Dim frm as Form set frm = new Form_frmCall and then add the form reference to a collection to keep it active. It worked until SP3. Now the Set statement fails with error 2950, Reserved Error. Is this functionality going away? Thanks, Kevin, I'm not seeing that problem. The sample database in this page still works in A2003 SP3: http://allenbrowne.com/ser-35.html -- Allen Browne - Microsoft MVP. Perth, Western Australia Tips for Access users - http://allenbrown...

Custom Background Issue
First, I am not even close to a professional computer anything! Last week I pulled in picture to use as a background for a flyer that I am doing. Everything was fine- it printed fine and was viewed fine. Yesterday I received a new "template" from our design company and did exactly the same things and when I pull it in to the more backgrounds area it looks fine on the background panel and in the print preview area. Yet the screen where you insert text boxes or design your flyer is black and I can barely see the background. Please help! -- T What happens if you insert the back...

about icon background in vista
hi, all: i meet a curious thing. i make a icon using vc2005, and the backgournd of icon is transparent. i draw it to a dialog. in xp, it is right, the backgournd is transparent. but when aero is enabled in vista, the background is wrong, change into white. i find a way to solve this i get the dialog 's dc ,and create a bitmap. draw icon on the bitmap, and then draw bitmap to dialog's dc. the code like below int lWidth = rtClient.right - rtClient.left; int lHeight = rtClient.bottom - rtClient.top; RECT rcWindow; ::GetWindowRect(hDestWindowOverride, &rcWindow); HDC hDCDisplay = ::Cr...

Button background
Hello, I need to change background color of single button (CButton) in dialog. How can it be easily done? Thank you! >I need to change background color of single button (CButton) in dialog. How >can it be easily done? It can't be easily done. I believe the only option is to make it an owner drawn control. Dave -- MVP VC++ FAQ: http://www.mvps.org/vcfaq ...

Links in Outlook 2007 open new instances of IE instead of a new tab in one IE instance
This is driving me crazy. Each link I click in my email opens a new IE instance instead of adding a tab to one IE instance that I am running. How can I change this??? Thanks, Phil Dear Phil, please, try the following: in Internet Explorer go to Tools - Internet Options, on the bottom of the General tab click Tabs Settings, in the new settings window under "Open links from other programs in" selec "A new tab in the current window". Best regards, _________________ Eugene Grischenko MAPILab Support http://www.mapilab.com "Phil C." <phil@nowhere.com> w...

Messages at the Background
I am relatively new with preparing accounting reports. In the spreadsheet I am working with, I saw that except the print areas, the entire spreadsheet was grayed out. I wonder how that was done. I know how to gray out a range of cells, but don't know how to do it for the entire spreadsheet. The other thing I noticed was that within the printed area, there was the nice information painted at the background indicating page numbers. This page number will not be printed out if I select print. And I don't know how that was done either. Hope someone will help me with these questions. ...

Opening separate instances of Excel
How can I force open new instances of Excel each time I open a new file? Will, This will not open a new instance of Excel each time you open a new file, but it will create a new window in the taskbar. Is that what you are after? Tools | Options | View | Windows in Taskbar Regards, Kevin "Will" <anonymous@discussions.microsoft.com> wrote in message news:03d301c39a7d$cf0003a0$a401280a@phx.gbl... > How can I force open new instances of Excel each time I > open a new file? Thanks Kevin, but I really am looking to open new instances of Excel each time I open a fil...

IXMLDOMDocumentPtr instance destruction
I have created an instance of IXMLDOMDocumentPtr //Create DOM Instance HRESULT hResult = m_plDomDocument.CreateInstance(MSXML2::CLSID_DOMDocument); if (FAILED(hResult)||(NULL == m_plDomDocument)) { bRet = FALSE; LEAVE_BLOCK } After this line gets executed the Handle count ( In Task Manager) gets incremented by 18 ( from 237 to 255). The handle count never gets decremented even after I come out of the dll. How can I release or destroy the DOM instances in the destructor. Is there any alternate way to bring the handle count back to where its started. I would greatly ...

background colour of sheet gone gray need to change to whit
On jst one sheet in my book of several sheets the background has turned gray. I copied it and it was still gray. How do I change it back to white. Try clicking on VIEW > NORMAL Vaya con Dios, Chuck, CABGx3 "Change Background colour of worksheet" <Change Background colour of worksheet@discussions.microsoft.com> wrote in message news:24CA1CF3-AA1C-475A-814B-53023C214675@microsoft.com... > On jst one sheet in my book of several sheets the background has turned > gray. > I copied it and it was still gray. How do I change it back to white. ...

Transferring a Sum total w/o the background formula
"How do I transfer a sum total from one cell to another spreadsheet w/o transferring the formulas behind it? When I paste the sum I usually get !ref because the formulas are related to data in the original spreadsheet. Max Copy the cell but then use PasteSpecial | Values to get the value rather than the formula Regards Trevor "Max in NJ" <anonymous@discussions.microsoft.com> wrote in message news:BA3C77DF-5715-4E62-BA6E-62CDB083FC2E@microsoft.com... > "How do I transfer a sum total from one cell to another spreadsheet w/o transferring the formulas behind it?...

Change background color
Hello, I would like to write a function to change the background color of a range based on the date in the first column. I am not very familiar with VBA's objects though. This is what I had: Private Sub Worksheet_Activate() Dim y As Integer, strRange As String ' Ideally, I would like to go to the last row, but 200 will be ' sufficient for my purposes For y = 0 To 200 If Month(Now) = Month(Worksheets(1).Cells(y, 0)) And _ Year(Now) = Year(Worksheets(1).Cells(y, 0)) Then ' Highlight this row (columns A to L) strRange ...

Background color in Outlook 2007
I know how to change the background color of my own calendar. However, if I have been given access (shared permissions) to another person's calendar, can I change the background color of that calendar on my computer? Thanks. No. Outlook assigns the color. -- Diane Poremsky [MVP - Outlook] Outlook Tips: http://www.outlook-tips.net/ Outlook & Exchange Solutions Center: http://www.slipstick.com/ Outlook Tips by email: mailto:dailytips-subscribe-request@lists.outlooktips.net EMO - a weekly newsletter about Outlook and Exchange: mailto:EMO-NEWSLETTER-SUBSCRIBE-REQUEST...

How to receive email with outlook closed (running in background)?
I have a network of all outlook 2003 users, and 2003 exchange server. My problem is that newer users are not opening outlook when they come in for work - so they are missing all their email (untill they remember to open it). Is there a way to make Outlook run in the background and/ or load when the system boots up? I would like the users to receive email constantly throughout the day, even if they forget to open outlook. Any ideas?? Thank you!! Chris Either put a shortcut to Outlook in their startup folder or train them to open Outlook once they have logged on to Windows. Outlook m...

I want to make a two tone chart background
I am creating a chart and want the chart background above a certain value to be of a different color (to indicate a maximum allowable value has been exceeded). An alternative would be to jus have the gridline & axis value of a different color/thickness/etc Basically, you'll need to create some dummy series. Jon Peltier gives excellent examples of how to create horizontal bands here: http://peltiertech.com/Excel/ChartsHowTo/HorizBands.html Other background fills: http://peltiertech.com/Excel/Charts/BackgroundFill.html -- Best Regards, Luke M *Remember to click "yes"...

How do I isolate my Excel server (automation) from other Excel instances?
Our application uses Excel as a server via the Excel COM interface (automation). However, I'm finding that when the user opens other Excel documents, these documents all share the same Excel window. If the user then hits X to exit their document (this is the normal user approach) this shuts down Excel altogether and my server is gone! Also, our application streamlines the Excel window by removing all toolbars. I'm finding that now when the user opens their own documents, their favorite toolbars are gone. Again, it's the same basic issue. How do I isolate our own Excel serve...

Drawing Backgrounds
I have attempted to put built-in backgrounds into Visio 2003 drawings, and they all have a "washed out" appearance. Is there anyway to enhance the colors? Thank you Marsh On Fri, 29 Feb 2008 11:58:03 -0800, Marsh <Marsh@discussions.microsoft.com> wrote: >I have attempted to put built-in backgrounds into Visio 2003 drawings, and >they all have a "washed out" appearance. Is there anyway to enhance the >colors? That is the colours they are supposed to have, but you can edit them to suit your owen preferences. You can either edit the background shape o...

task background color dont stay intact
Hi i put the background color in task & tried on shell also to blue or any other color and save the project and checkin. when i open the project back clolor is gone ... how can i resolve the issue. Pleaes help its project 2007 with professional 2007. You may be trying to modify an enterprise view. Try making a local copy of the view, and then changing the color. - Andrew Lavinsky Blog: http://blogs.catapultsystems.com/epm > Hi i put the background color in task & tried on shell also to blue or > any other color and save the project and checkin. > >...

Excel attachment in Outlook causing 2nd instance of Excel to open- help!
I just reinstalled ofc2003 on a win xp system and now for some reason when I open an excel attachment in outlook my computer opens a second instance of excel. (I already have excel open before clicking on the outlook attachment.) The only slightly different thing I have going on is that I have all my programs on an solid state drive on C and my data is on a conventional drive on drive E. Any ideas how to troubleshoot or fix this? (When this happens I get a message that Excel is already in use and do i want to cancel to open read-only.). Thanks, Chet Detect and repair from of...

Change Event macro
Hi, I am very new to Excel macro programming, but thanks to Dave McRitchie's code (as well as some contributions from numerous others, I have a macro which works, but not quite as I intended. What I want to do is create a gantt chart in excel 2000. Each altenate row has a project name and details, with a range of columns representing weeks in the financial year. I would like to enter a value into a cell to represent the stage of a project (e.g. sketch scheme, detail design, tender, contruction, post-tender). I would like the macro to change the background colour of the cell to produce t...

label background should be the same as its parent's background
hi all, unfortunately i can not use SetBkMode(TRANSPARENT) to set my labels transparent (for some gui look and feel reasons) so i have to make my label's background identical with its parent's background.. i already tried the following (using VC++ 6.0) : HBRUSH CPgLabel::CtlColor(CDC* pDC, UINT nCtlColor) { static CBrush Bkgnd; CWnd* pParent = GetParent(); ASSERT_VALID(pParent); CDC* pParentDC = pParent->GetDC(); ASSERT_VALID(pParentDC); Bkgnd.DeleteObject(); COLORREF parentBgColour = pParentDC->GetBkColor(); pDC->SetBkColor( parentBgColour); ...