如何用vc来启动其它另外一个程序,比如说记事本,并且传一个信息给启动后的记事本??

coolhealth 2003-12-16 05:43:48
如何用vc来启动其它另外一个程序,比如说记事本,并且传一个信息给启动后的记事本??

谢谢...
...全文
160 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
seilfer2000 2003-12-18
  • 打赏
  • 举报
回复
sendmessage (WM_SETTEXT...) 这个消息可以直接把数据发给别的进程的,建议看一下windows编程
ufocyf 2003-12-18
  • 打赏
  • 举报
回复
//翻
使用ShellExecute,具体的参数可以到msdn中查找,
HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
HWnd,父窗口的窗体句柄。这个窗口接收任何应用程序产生的信息框。例如,应用程序可以通过消息框打印错误。
LpOperation 空指向字符串的地址来说明执行的具体操作。下列操作字符串式有效的:“open”这个函数打开lpFile参数所包含的文件。可以是可执行文件或是文档文件。也可以是层。“print”这个函数打印lpFile所指定的文件。文件必须是文档文件。图国文件是个可执行文件,该函数将打开这个文件,就象“open”所做的。“explore”该函数搜索lpFile所指向的层。这个参数可以为NULL。默认为打开该文件。
LpFile,来说明指向文件地址的字符串,该文件用于打开、打印或是层搜索。这个函数可以打开可执行文件或文档文件。也可打印文件。
LpParameters 如果lpFile参数指定了可执行文件,lpParameters是一个空指向字符串的地址来传递给应用程序参数。如果lpFile指向文档文件,lpParameters应该为NULL。
LpDirectory,空指向字符串地址来说明默认的路径。
NshowCmd,如果lpFile指定了可执行文件,nShowCmd说明在它打开时如何显示。可以为以下值:SW_HIDE
SW_MAXIMIZE
SW_MINIMIZE
SW_RESTORE
SW_SHOW
SW_SHOWDEFAULT
SW_SHOWMAXIMIZED
SW_SHOWMINIMIZED
SW_SHOWMINNOACTION
SW_SHOWNA
SW_SHOWNOACTIVATE
SW_SHOWNORMAL
如果lpFile指向一个文档文件,该参数应为零。
你可用这个函数来打开或搜索层。打开层可用下列应用:
ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);

ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);
搜索层用:
ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL);
如果lpOperation为NULL,该函数将打开lpFile所指向的文件。通过lpOperation时打开或搜索,该函数将试图打开或搜索层。
//end
Goldcastle 2003-12-18
  • 打赏
  • 举报
回复
SendMessage(hwnd,WM_YOUMSG,(LPVOID)para,NULL);

要传的结构体中的数据放到para里,para在发送消息的程序里就要变为真实地址,也就是要做一些转换,或是在消息中把发关消息的进程句柄也传过去,在消息处理中去找数据,数据在发送消息的进程中。
Dephi写的程序和vc程序中的消息ID要一致。比如说都是WM_USER+500;
在接收消息程序中自定义一个消息处理函数就成了。找数据可能要用到物理内存读写函数。



thisisyjs 2003-12-18
  • 打赏
  • 举报
回复
使用内存映象文件。
wy2001wy 2003-12-18
  • 打赏
  • 举报
回复
直接ShellExecute不是挺好的嘛!
coolhealth 2003-12-18
  • 打赏
  • 举报
回复
这个问题是比较常见的一个问题..

难道没有人碰到过??

其实当然可以用写ini文件来解决这个信息传递的问题..

但是除些之外呢??

window的ole也是用于解决程序之间通信的问题.不过他们这个信息量比我们的大得多..

有没有人有好的办法????
lipeng518888 2003-12-18
  • 打赏
  • 举报
回复
ShellExecute
Performs an operation on a specified file.



HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpVerb,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);

coolhealth 2003-12-17
  • 打赏
  • 举报
回复
SendMessage(hwnd,WM_YOUMSG,(LPVOID)para,NULL);

要传的结构体中的数据放到哪里了呢??

如果是记事本..他如何去获取这些信息呢?

其实还有..比如说我用一个Dephi写的程序,传一些信息给一个自己写的vc程序..

然后我们自己写的vc程序中来接收到这个由Dephi程序传过来的信息,,根据传过来的信息做一些要做的事...

这里面就有两个问题:
1.从Dephi中启动我们自己的vc写的程序,并将要传给vc的信息发出....

2.我们自己写的vc程序中如何接收到dephi程序给我们传的那个信息呢??

可不可以用clipboard呢..??
wenzifeifei 2003-12-17
  • 打赏
  • 举报
回复
最好用postthreadmessage函数
iamknight 2003-12-16
  • 打赏
  • 举报
回复
hook拦截相关程序的窗口处理主过程,用自己写的回调函数替换,处理自定义消息,处理完后再替换回原来的主过程函数。
hahu 2003-12-16
  • 打赏
  • 举报
回复
#define WM_YOUMSG WM_USER+2034
HANDLE hwnd=FindWindow(NULL,"title");
//或者使用CreateProcess,里面的PROCESSINFO结构里有hProcess
SendMessage(hwnd,WM_YOUMSG,(LPVOID)para,NULL);
要接收这种信息必须使你自己编的程序
coolhealth 2003-12-16
  • 打赏
  • 举报
回复
这样的方法我知道..

但是如果想传的信息是一个自定义的结构体信息...

如何传给记事本这个信息...并且由启动后的记事本来处理这个信息......
tszzp 2003-12-16
  • 打赏
  • 举报
回复
用WinExec,ShellExecute,CreateProcess都可以做到,相对来说应该时ShellExecute容易用,
具体的用法可看MSDN的例子。
sboom 2003-12-16
  • 打赏
  • 举报
回复
BOOL CreateProcess(
LPCTSTR lpApplicationName,
// pointer to name of executable module
LPTSTR lpCommandLine, // pointer to command line string
LPSECURITY_ATTRIBUTES lpProcessAttributes, // process security attributes
LPSECURITY_ATTRIBUTES lpThreadAttributes, // thread security attributes
BOOL bInheritHandles, // handle inheritance flag
DWORD dwCreationFlags, // creation flags
LPVOID lpEnvironment, // pointer to new environment block
LPCTSTR lpCurrentDirectory, // pointer to current directory name
LPSTARTUPINFO lpStartupInfo, // pointer to STARTUPINFO
LPPROCESS_INFORMATION lpProcessInformation // pointer to PROCESS_INFORMATION
);
返回参数 lpProcessInformation 里面有进程句柄。
wanliduxing 2003-12-16
  • 打赏
  • 举报
回复
winexec也可以。
搜索一下本论坛就行
ross33123 2003-12-16
  • 打赏
  • 举报
回复
CreateProcess
FindWindow
SendMessage
longki 2003-12-16
  • 打赏
  • 举报
回复

有楼上所说也就足够了!
zjp899 2003-12-16
  • 打赏
  • 举报
回复
使用ShellExecute,具体的参数可以到msdn中查找,
HINSTANCE ShellExecute(
HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);

hwnd
Window handle to a parent window. This window receives any message boxes that an application produces. For example, an application may report an error by producing a message box.
lpOperation
Address of a null-terminated string that specifies the operation to perform. The following operation strings are valid: "open" The function opens the file specified by the lpFile parameter. The file can be an executable file or a document file. It can also be a folder.
"print" The function prints the file specified by lpFile. The file should be a document file. If the file is an executable file, the function opens the file, as if "open" had been specified.
"explore" The function explores the folder specified by lpFile.

This parameter can be NULL. In that case, the function opens the file specified by lpFile.

lpFile
Address of a null-terminated string that specifies the file to open or print or the folder to open or explore. The function can open an executable file or a document file. The function can print a document file.
lpParameters
If the lpFile parameter specifies an executable file, lpParameters is an address to a null-terminated string that specifies the parameters to be passed to the application.
If lpFile specifies a document file, lpParameters should be NULL.
lpDirectory
Address of a null-terminated string that specifies the default directory.
nShowCmd
If lpFile specifies an executable file, nShowCmd specifies how the application is to be shown when it is opened. This parameter can be one of the following values: SW_HIDE Hides the window and activates another window.
SW_MAXIMIZE Maximizes the specified window.
SW_MINIMIZE Minimizes the specified window and activates the next top-level window in the z-order.
SW_RESTORE Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT Sets the show state based on the SW_ flag specified in theSTARTUPINFO structure passed to theCreateProcess function by the program that started the application. An application should callShowWindow with this flag to set the initial show state of its main window.
SW_SHOWMAXIMIZED Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE Displays the window as a minimized window. The active window remains active.
SW_SHOWNA Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

If lpFile specifies a document file, nShowCmd should be zero.

You can use this function to open or explore a shell folder. To open a folder, use either of the following calls:

ShellExecute(handle, NULL, path_to_folder, NULL, NULL, SW_SHOWNORMAL);

or

ShellExecute(handle, "open", path_to_folder, NULL, NULL, SW_SHOWNORMAL);

To explore a folder, use the following call:

ShellExecute(handle, "explore", path_to_folder, NULL, NULL, SW_SHOWNORMAL);

If lpOperation is NULL, the function opens the file specified by lpFile. If lpOperation is "open" or "explore", the function will attempt to open or explore the folder.

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧