single instance YET ...

Hi,

I wish to have my MDI based MFC application to be single instance.
Let's assume I use the unique class name method.
When my application starts, I check to see if there's already an instance
running. If so, I set focus to active instance and terminate.

But now I wish this:

When a second instance is started with command line parameters, I wish to
terminate that instance, but pass the command line parameters to the first
instance (a file name, so that it can be openend as another document inside
my MDI application).

How do I pass this info?
Is it possible to pass this via a windows message (is it possible to send a
string via a windows message? Could I use something like this:

TCHAR t[MAX_PATH];
_tcscpy( t, _T("C:\\somepath\\somefile.ext"));
SendMessage(WM_APP + 1, t);

I mean, I know that I must wait for the message to be processed so that my
LPCTSTR is still valid.
But would this work? I mean each app runs in its own virtual memory space ..
WM messages can cross these memory boundaries I assume since I can change
application titles with WM_SETTEXT I think.

An alternative might be via the ClipBoard or something, but I'd have to send
a WM_APP message to notify the instance that there's something available in
the ClipBoard.

Are these possibilities, are there better ways?

Lisa


0
no6060 (315)
10/17/2004 5:29:28 AM
vc.mfc 33608 articles. 0 followers. Follow

5 Replies
546 Views

Similar Articles

[PageSpeed] 19

>But now I wish this:
>
>When a second instance is started with command line parameters, I wish to
>terminate that instance, but pass the command line parameters to the first
>instance (a file name, so that it can be openend as another document inside
>my MDI application).

Lisa,

By default an MFC MDI application should do what you want if you
double click one of your documents from Explorer (or use
ShellExecute(Ex) to "run" one of your registered documents).

How are you starting a second instance?

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
10/17/2004 9:19:12 AM
Startmenu\Run: "myapp.exe c:\file1"
Startmenu\Run: "myapp.exe c:\file2"

This would create 2 instances, first one with file1, second with file2.
I wish the second instance to shut down, set focus to first instance and
pass it c:\file2 path so the first instance can load file2 next to file1 and
have them both open in 1 instance.

Lisa

"David Lowndes" <davidl@example.invalid> wrote in message
news:vvd4n0tgcmeja8ao1p222bnigds8ks4a37@4ax.com...
> >But now I wish this:
> >
> >When a second instance is started with command line parameters, I wish to
> >terminate that instance, but pass the command line parameters to the
first
> >instance (a file name, so that it can be openend as another document
inside
> >my MDI application).
>
> Lisa,
>
> By default an MFC MDI application should do what you want if you
> double click one of your documents from Explorer (or use
> ShellExecute(Ex) to "run" one of your registered documents).
>
> How are you starting a second instance?
>
> Dave
> -- 
> MVP VC++ FAQ: http://www.mvps.org/vcfaq


0
no6060 (315)
10/17/2004 9:52:56 AM
check out q141752 for one method of limiting to a single instance, and
Q243953 for another one.  with either one you could take your command line
and send a message to the other instance to handle to open a file or do
whatever else you need.

"Lisa Pearlson" <no@spam.plz> wrote in message
news:%23wJb9oAtEHA.1336@tk2msftngp13.phx.gbl...
> Hi,
>
> I wish to have my MDI based MFC application to be single instance.
> Let's assume I use the unique class name method.
> When my application starts, I check to see if there's already an instance
> running. If so, I set focus to active instance and terminate.
>
> But now I wish this:
>
> When a second instance is started with command line parameters, I wish to
> terminate that instance, but pass the command line parameters to the first
> instance (a file name, so that it can be openend as another document
inside
> my MDI application).
>
> How do I pass this info?
> Is it possible to pass this via a windows message (is it possible to send
a
> string via a windows message? Could I use something like this:
>
> TCHAR t[MAX_PATH];
> _tcscpy( t, _T("C:\\somepath\\somefile.ext"));
> SendMessage(WM_APP + 1, t);
>
> I mean, I know that I must wait for the message to be processed so that my
> LPCTSTR is still valid.
> But would this work? I mean each app runs in its own virtual memory space
...
> WM messages can cross these memory boundaries I assume since I can change
> application titles with WM_SETTEXT I think.
>
> An alternative might be via the ClipBoard or something, but I'd have to
send
> a WM_APP message to notify the instance that there's something available
in
> the ClipBoard.
>
> Are these possibilities, are there better ways?
>
> Lisa
>
>


0
noone1 (387)
10/17/2004 11:17:41 AM
Lisa Pearlson wrote:

> Hi,
> 
> I wish to have my MDI based MFC application to be single instance.
> Let's assume I use the unique class name method.
> When my application starts, I check to see if there's already an instance
> running. If so, I set focus to active instance and terminate.
> 
> But now I wish this:
> 
> When a second instance is started with command line parameters, I wish to
> terminate that instance, but pass the command line parameters to the first
> instance (a file name, so that it can be openend as another document inside
> my MDI application).
> 
> How do I pass this info?
> Is it possible to pass this via a windows message (is it possible to send a
> string via a windows message? Could I use something like this:
> 
> TCHAR t[MAX_PATH];
> _tcscpy( t, _T("C:\\somepath\\somefile.ext"));
> SendMessage(WM_APP + 1, t);
> 
> I mean, I know that I must wait for the message to be processed so that my
> LPCTSTR is still valid.
> But would this work? I mean each app runs in its own virtual memory space ..
> WM messages can cross these memory boundaries I assume since I can change
> application titles with WM_SETTEXT I think.
> 
> An alternative might be via the ClipBoard or something, but I'd have to send
> a WM_APP message to notify the instance that there's something available in
> the ClipBoard.
> 
> Are these possibilities, are there better ways?
> 
> Lisa
> 
> 

The SendMessage method will work if the message you send is WM_COPYDATA. 
  It is designed for this purpose: the OS copies the parameter memory 
block from one process memory space to the other.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
10/17/2004 1:33:31 PM
>Startmenu\Run: "myapp.exe c:\file1"
>Startmenu\Run: "myapp.exe c:\file2"

Just specify the file name. The shell association will start your
application and use DDE to have any existing instance load the
document.

If you've built your application with VS2003 there's a known bug in
the DDE implementation - search Google groups for references to
OnDDEExecute to find the solution.

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
10/17/2004 3:19:50 PM
Reply:

Similar Artilces:

Save a single worksheet in Excel as a single file.
I have multipe worksheets in a single workbook. I would like to be able to save each worksheet individually. I want to send each worksheet to an individual, I do not want to send the entire workbook. All information must be retained in the one workbook, but as the individual worksheets are updated, the individual worksheet needs to be saved and sent to that individual. Help anyone? Thanks. Linda you can probably find the answer here. http://www.rondebruin.nl/ -- Don Guillett SalesAid Software dguillett1@austin.rr.com "Dakota" <Dakota@discussions.microsoft.com&...

Any USB-3 motherboards or devices out yet?
Just wondering if people have noticed anything on the horizon. I did notice this: http://www.theinquirer.net/inquirer/feature/1563788/usb3-sata3-appear-gigabyte-mainboards There's also Light Peak (10 gb/sec) from Intel that will blow that out of the water but it could be years away. http://www.examiner.com/x-21104-Cleveland-Information-Technology-Examiner~y2009m10d3-Getting-connected-faster-with-USB-3-and-Light-Peak Whoosh wrote: > Just wondering if people have noticed anything on the horizon. I did > notice this: > http://www.theinquirer.net/inquirer/feature/1563...

way to open a form in mutliple instances?
Is there a way to open up a form in more than one instance. i.e. the same form but different data? If so, what is the methos? Thanks for any help. Yes, there is. See the sample code at http://www.daiglenet.com/msaccess.htm The Multi_Instance Forms download is the last one on this page. HTH, Rob "ThorBo" <ThorBo@discussions.microsoft.com> wrote in message news:0296148F-5664-4584-90D6-CDE1BCCC3DED@microsoft.com... > Is there a way to open up a form in more than one instance. i.e. the same > form but different data? If so, what is the methos? > > Thanks for ...

Returning Multiple Values in a Single Cell
Hello, I posted this same question a couple of weeks ago but forgot to mention a key point. My question was as follows: I have read a few posts regarding this subject but am still somewhat lost. I have a two sheet workbook (Excel 2000). On the first sheet is a list of projects that my department will complete during the year. A description of each project is given, a start date, an end date, as well as which crew will be completing the work (Crew 1 or Crew 2). What I am trying to do on the second sheet is to be able to type in any date, and have the description of the project on that da...

rpc-https on Single server
Hi, I am enabling rpc over https on single exchange server, which is also a DC and GC. After installing rpc proxy component on Windows Server 2003, I used ESM to enable rpc-http for Back-End server. Upon doing so, I got a dialog box complaining there is no Front-End server in my environment. However, the rpc-http for Back-End option is still selected. When I open outlook 2003 which is configured to use rpc-http, the connection status still use TCP/IP. I checked the rpcProxy ports in registry, all entries are defined correctly. Do I miss out any important steps or any websites I can refe...

Single Site Single Org Multiple Domains Exchange 5.5
Help anyone.... I have an Exchange 5.5 Server on a AD Domain and an Exchange 5.5 Server on a NT 4 domain. All same site and same org. I have been able to install the Exchange on the AD domain and join it to the existing site and org on the NT domain. My issue is that it will not replicate with any of the Exchange servers on the NT domain. I have a 2 way trust and I have no issues going back and forth between the 2 domains to access shares or any other resources between the two domains. The errors that I am getting in the Event Log are of course 9318 and 9322. I have tried host and lmhos...

Single record
Is it possible to print a single record per page? I have a spreadshee with 240 records and I want to be able to print a single record pe page, preferably with the column headings vertically down the side. have only a short time (about 20 hrs) to acheive this. : -- zigeune ----------------------------------------------------------------------- zigeuner's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=2752 View this thread: http://www.excelforum.com/showthread.php?threadid=47047 How about a small macro to get you started: Option Explicit Sub testme() Dim w...

Two accounts same machine share a single pst file
I have two accounts that I use on my machine each with their own pst file. I would like to have both accounts point to a single pst so that I don't have to use my pda to synch between the two. Any suggestions? John What you mean by "accounts" is not clear. Assuming you mean Internet Mail accounts, just setup both accounts in the same profile. -- Russ Valentine [MVP-Outlook] "dsfds" <dsaf> wrote in message news:422d7b17$0$6967$afc38c87@news.optusnet.com.au... >I have two accounts that I use on my machine each with their own pst file. >I > would like...

is it possible to use F9 to manually calculate in a single sheet or single workbook?
is it possible to use F9 to manually calculate in a single sheet or single workbook? as i have got over 500 cells with vlookup in a single sheet, with more than 50 sheets in a workbook. Thank you!! Shift+F9 will calculate only the active sheet. From the XL Help for XL2003: ----- Press F9 Calculates formulas that have changed since the last calculation, and formulas dependent on them, in all open workbooks. If a workbook is set for automatic calculation, you do not need to press F9 for calculation. Press SHIFT+F9 Calculates formulas that have changed since the last calculation, and fo...

Route all emails to a single SMTP address ?
Hi, Due to severe issue on my BE server, I'm looking for a quick way to redirect all the mails supposed to go to this server to a specific SMTP recipient, whoever was the original recipient. Thanks, Chris On Mon, 8 Nov 2004 14:32:52 +0100, "Chris" <tophe_news@hotmail.com> wrote: >Hi, > >Due to severe issue on my BE server, I'm looking for a quick way to redirect >all the mails supposed to go to this server to a specific SMTP recipient, >whoever was the original recipient. > >Thanks, >Chris > > if your BE is up the creek then you hav...

single instance YET ...
Hi, I wish to have my MDI based MFC application to be single instance. Let's assume I use the unique class name method. When my application starts, I check to see if there's already an instance running. If so, I set focus to active instance and terminate. But now I wish this: When a second instance is started with command line parameters, I wish to terminate that instance, but pass the command line parameters to the first instance (a file name, so that it can be openend as another document inside my MDI application). How do I pass this info? Is it possible to pass this via a window...

Rule Process Instance
I have rules I have created and only the admin user can process the instance. Right now I have a manual rule that waits "if a pick list is changed from yes to no then e-mail manager." If I login to CRM as the admin user and select yes the rule fires fine and e-mail is sent. If I login in as a user the rule stays in a waiting status in the CRM Monitor. I then have to right click on the instance, select properties and then pause and retry and the instance completes. I did login as a user with administrator rights and created a rule and tried to run it but the process will stil...

Yet another picture database question
I currently have a database that loads pictures from a network location; sub Form_current image1.picture = "\\server\share\picture.png" end sub as this enables me (or any user) to open the database from any computer on the network. Is it possible to load pictures from a local intranet http address instead? The pictures I want are accessed in a browser by typing the following: http://address/directory/file.pl?display=chart;number=12345 This would make updating the database easier as I would not have to open and resave every picture to the network share. Forgot to say, I am...

RPC HTTP Single Exchange Server / Seperate DC GC Server
Just a post that may help others trying to achieve the same objective. Single Exchange 2003 SP1 server (no front end server), seperate Domain Controllers (2003, no SP1) Clients, XP SP1 / SP2, O2 XDA via HTTPS There are many thorough Microsoft documents, but as many have found they expect either a single server that hosts all Exchange / AD roles, or a FE/BE setup. What is not easily catered for (at least in SP1) is having a dedicated Exchange server and having AD on dedicated servers (a recommended configuration). I found all the pieces of the puzzle from either the Microsoft Exchange Libra...

OLXP AutoComplete: How to Delete Single Entry
Q289975 mentions "changing" a single entry, but not deleting it. Posts to this list on the same subject mention how to delete entries from the AutoComplete list, but those suggestions will not work to remove a single entry from the cache. Can anyone suggest a procedure to remove a single entry from the AutoComplete list that actually works? OLXP AutoComplete caches resolved addresses into the <profilename>.NK2 file. Deleting the NK2 file removes single instances but that is a rather extreme solution to the problem. Is there an editor that one can use to edit the NK2 file to re...

How to get the COLORREF from a CBrush instance?
Hi, Is there a way to get from a CBrush instance the COLORREF that was used by CBrush::CreateSolidBrush() to create the CBrush? Thanks for your help. Tony May Young <tony@srac.com> schrieb: >Hi, > >Is there a way to get from a CBrush instance the COLORREF that was used >by CBrush::CreateSolidBrush() to create the CBrush? Thanks for your help. Take a look at CBrush::GetLogBrush( LOGBRUSH* pLogBrush ); Hans ...

Single Mailbox Restore, SINGLE server! Exchange 5.5
Hi all I have a 3 server 5.5 organisation. (all 3 servers in different sites connected via a WAN) I do not have a spare server. I realise this is the way to go... but I cant do it this way so if anybody can offer any help? I have a good backup (entire mailbox store NOT individual mailboxes) from Friday night. Today is Monday night. (Veritas Backup Exec 9) I deleted a mailbox accidentialy today. Its gone! - If I restore the server using Firdays backup, It will re-appear I imagine. BUT when all the transaction logs get procesed from them until the time I begin the restore, will the ma...

Recording multiple checks in a single deposit
This seems like it's probably brutally simple, but I can't figure it out: how do I record multiple check numbers in a single deposit? The deposit consists of a couple checks from my primary checking account which I'm depositing, along with some cash, as a single deposit transcation in a different checking account. Using MS Money Deluxe 2003. - sph In microsoft.public.money, hodgdon wrote: >This seems like it's probably brutally simple, but I >can't figure it out: how do I record multiple check >numbers in a single deposit? > >The deposit consist...

Cannot Open Multiple Instances of Excel
I cannot open more than one instance of Excel from my MS Office Shortcut Bar, yet I can open more than one instance if I open Excel from my Programs menu or the Excel shortcut icon on my desktop. Any ideas? Thanks. Randy The one on the Office Shortcut Bar probably has "/recycle" in the command line. Regards, Aaron Queenan. "Randy" <randy.m@emp.com> wrote in message news:08a801c34af4$60e0b280$a001280a@phx.gbl... > I cannot open more than one instance of Excel from my MS > Office Shortcut Bar, yet I can open more than one instance > if I open Excel from ...

Can I divide amount from a single transaction?
Hello. I would like to ask if I can divide amount from one transaction. Let's say that I deposited total of $200 into checking account at bank. The $100 is cash, the other $100 is my paper paycheck. On MS Money screen, it shows "$200" as a single transaction. Can I make this into two transaction, so I can categorize them separately? Thanks. Kay, Set up a new account within Money and set its type to "Cash" (i.e. not a bank account). This cash account is where you will create the $100 paycheck transaction. This account would also include a transaction correspondi...

Exchange 2000:allowing single user larger message send size not working
Ok, I've been through all the knowledgebases, and I'm nearly 100% positive I've got this setup right, but it still doesn't work. I've got a Global Settings/Message Delivery/Sending Message Size Limit of 10MB. There is NO limit set in the SMTP VS. I've got a very small number of users I want to be able to send messages larger than the 10MB limit. So for those individual users, I've increased their individual sending message size limit to 25MB. It still didn't work - the Exchange server rejects the message as too large to send. Everything I find insists that...

Single session only?
Hi group, is there a way to force or throttle outlook 2003 to only make 1 server connection at a time? Currently, it sends and receives together. This is causing problems with my Linux IMAP server. TIA google_groups3@hotmail.com <google_groups3@hotmail.com> wrote: > Hi group, is there a way to force or throttle outlook 2003 to only > make 1 server connection at a time? Currently, it sends and receives > together. This is causing problems with my Linux IMAP server. Create a separate send/receive group for each account. Create separate send/receive intervals for each gr...

single quote xml value
EvtEnrollAttr.Value = "3748" EvtEnrollElem.Attributes.Append(EvtEnrollAttr) i need the attr value to be <stuff ID = '3748'> in single quote how can i do that with visual basic.net? thanks Use EvtEnrollAttr.Value = "'3748'" (single quote's inside double quote) "dotnetnoob" <dotnetnoob@discussions.microsoft.com> wrote in message news:7B2A0B48-6CFD-4868-8D15-4BF9E5C24CA5@microsoft.com... > EvtEnrollAttr.Value = "3748" > EvtEnrollElem.Attributes.Append(EvtEnrollAttr) > > i need the attr value to be <stuff...

Locationwise Sales and Stock in a Single Report at HQ
Hi to all the groupmates Is it possible to have a report from HQ wherein for the sales , the date range validation is given (From date and to date) and only the total sales of an item per location is displayed seperately. Along with this the current stock of the item of the location also to be displayed. hi RK, it is already availble, you can go to HQ> Reports> then click on the Sales and click the Sales Detail Report put the the date range. then from the column selector select the On Hand column which will show you the onhand current qty of particular item. I hope this satisfy y...

Pasting Word table cell with paragraph markers into single Excel c
I have a Microsoft Word document that contains a table, each cell of which may contain paragraph markers. I need to copy and paste this table into Excel. However, whenever a cell from the Word table contains paragraph markers, rather than pasting the contents of the entire cell into a single cell in Excel, the paragraph markers are treated as delimiters, and the data is pasted into multiple Excel cells. If the cell from the table in Word contains one paragraph marker, then when I paste that cell to Excel, it pastes it into two cells. If it contains two paragraph markers, then it pa...