Home > Software engineering >  Question [100], you double-click to open the file operation of multi-process communication process?
Question [100], you double-click to open the file operation of multi-process communication process?

Time:11-09

Recently met a don't know much about business, but I think there should be a lot of people have written and have a relatively common methods to achieve, but I didn't find baidu, so here I ask leaders to guide the younger brother, thank you
Is this
File type has been associated with good, if you don't start the program, double-click the file to start the program,
 int APIENTRY WinMain (HINSTANCE HINSTANCE, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 
{
STD: : string targetfile=lpCmdLine;//registered file type, double click on the corresponding file types, the value will receive the target file

//to find the main form is already running
The HWND HWND=: : FindWindow (NULL, _T (" MainWnd "));
If (HWND!=NULL) {
//if the user open the associated file by double-clicking on, then try to open the file
{if (targetfile. The size ())
//const char * tf="you are a god";//success
//const char * tf=targetfile. Data ();//failure

//MessageBox (HWND, tf, NULL, 0); Display correctly//all successful, double-click the file path
: : SendMessage (HWND, WM_OPENTARGETFILE, 0, (LPARAM) tf);
}
return 0;
}
The else {
//main form didn't run, just run the main form
CMainWnd * pFrame=new CMainWnd;
If (pFrame==NULL) return 0;
PFrame - & gt; Create (NULL, _T (" MainWnd "), UI_WNDSTYLE_FRAME, 0 l, 0, 0, 990, 690);
PFrame - & gt; CenterWindow ();
PFrame - & gt; ShowModal ();
The delete pFrame;

return 0;
}
}


This value, is the path I double click the file to this MainWnd, this step is difficult to me, see the code above, I specific assignment is successful by value, but with targetfile is washed-up, whether c_str () or data () all can not pass, but the pop-up window when it is right, asked a also write code, he than I know a little about, but he didn't write this, he said there should be multiple processes, how many how many files open process, not reach values because across processes, inter-process communication, I want to know, everyone here is how to deal with, is here, double-click the file transfer value is a multi-process communication? Or how to preach, modesty and guidance!

CodePudding user response:

To
//allow the user to through Windows file manager to open data file
EnableShellOpen () :
Then search RegisterShellFileTypes himself

CodePudding user response:

Across processes, can consider to use clipboard

CodePudding user response:

Under the WM_COPYDATA can also refer to
Using the Data Copy


CodePudding user response:

refer to the second floor zgl7903 response:
across processes, can consider to use clipboard
do you mean, is to use multiple processes, open 10 file at the same time, there are 10 process? Do you open the file?

CodePudding user response:

reference 1/f, solitary guest tianya response:
to
//allow the user to through Windows file manager to open data file
EnableShellOpen () :
Then your search RegisterShellFileTypes

Thanks for your reply, I am win32 program, add the header file afxwin. H, still can't use these two functions
There is, the function problem, placed my entry function is APIENTRY WinMain, can change in my code, specifically, if know DragAcceptFiles (), can see change together, more points

CodePudding user response:

reference 4 floor maya8maya85 response:
Quote: refer to the second floor zgl7903 response:

Across processes, can consider to use clipboard
do you mean, is to use multiple processes, open 10 file at the same time, there are 10 process? Do you open the file?


Didn't quite understand what you mean, multiple processes popup file open dialog box?

CodePudding user response:

refer to 6th floor zgl7903 response:
Quote: refer to 4th floor maya8maya85 response:

Quote: refer to the second floor zgl7903 response:

Across processes, can consider to use clipboard
do you mean, is to use multiple processes, open 10 file at the same time, there are 10 process? Do you open the file?


Didn't quite understand what you mean, multiple processes popup file open dialog box?

Actually this kind of situation in reality very much, just pick up a speak, [word, photoshop, too, too much, but it seems that you have never talked about this, may be too simple]
Like. Url file, a url shortcuts, double-click the is to start the browser, and then create a TAB to open, right?
Good, now is the browser has launched, and has opened a url, right?
Now users and another. Double-click the file url, the browser will by opening a new TAB page url, two tabs, two. Url, right?
Ok, problem is,
1, double-click. Url, the browser is how to receive it. The path of the url from the entrance to the processing function of program? SendMessage?
2, between the two tabs, the relationship between process and process? If this is the case, the transfer. The url path should be inter-process communication, rather than the SendMessage? I understand it, right?
3, if it's not that complicated, win32 have own method, strives for the specific code or link

CodePudding user response:

This characteristic, an MDI application MFC wizard generated more than a document, it support,
The main mechanism is the Dynamic Data Exchange, WM_DDE_INITIATE WM_DDE_EXECUTE WM_DDE_TERMINATE

CodePudding user response:

references 9 f zgl7903 response:
this characteristic, an MDI application MFC wizard generated more than a document, support,
The main mechanism is the Dynamic Data Exchange, WM_DDE_INITIATE WM_DDE_EXECUTE WM_DDE_TERMINATE
looks is a very basic thing, how to operate?

CodePudding user response:

Using the Dynamic Data Exchange

CodePudding user response:

MFC single process, to the open source community search MFC single instance can find a lot of sample code, MFC own EnableShellOpen but this is based on outdated DDE, with new code IDropTarget register file association - the user to select multiple files and then select open, your application will only be started once, select the file name of the array will be in a shell data object to your inside, refer to https://devblogs.microsoft.com/oldnewthing/20100503-00/? P=14183

Of course this is only in view of the resource manager to open the file, can use the command line or start multiple instances of your programs, single process control, people like to use Shared memory communication made synchronous Mutex, find the window is too far-fetched, you select the two files open at the same time, can't find the window would happen,

CodePudding user response:

Sharing between the city and address is not enough, need to share memory and value in the past, or remote procedure call (RPC), mobile phone, can't code...

CodePudding user response:

Write before don't know now ok
 
////
BOOL CMainFrame: : GetExeCommand (char * fullname, char * command)
{//"" % 1" 1 * "is for. Bat file
"//" XXX. Exe % 1
//"", a, b, c, yyy. Exe"/p % 1
"Char ext [40].
Char pathname [MAX_PATH];
Char exename [MAX_PATH];
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related