The day before yesterday in Brucezhang's blog "Help: How to call the WinForm program in the ASP page?" Replied to his question, but he thought I was mistaken in thinking.
Today in the trial webqq, bored to think of a lot of people on the blog has such a gadget, click on it can and bloggers to engage in dialogue, and no need to Garber the Lord as a friend.
Well, isn't that the way to brucezhang the solution to that problem? So how does Tencent do in the Web page to invoke the QQ program?
Let's look at the code that Tencent gives us:
<a href="tencent://message/? uin=88888888&Site=JooIT.com&Menu=yes">
</a>
Obviously, the secret is "tencent://message/"? Uin=215555521&site=jooit.com&menu=yes "Here, then what is this principle?"
First rip off the topic according to their own ideas to think, to open the local QQ, must be divided into two steps, the first is to navigate to QQ, and then pass to it some parameters, that is, "uin=215555521&site=jooit.com&menu=yes" such things. Positioning, the use of the registry is the most obvious way. But how to run the QQ up? Do we have to start a process on our own? The answer is no, the Windows operating system takes this into account, allowing us to register our application as a protocol processor, as detailed in the article "Registering an application to a URL Protocol" on MSDN
Tencent's Tencent://message protocol registration form is as follows:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOTTencent]
@="TencentProtocol"
"URL Protocol"="D:\Program Files\Tencent\QQ\Timwp.exe"
[HKEY_CLASSES_ROOTTencentDefaultIcon]
@="D:\Program Files\Tencent\QQ\Timwp.exe,1"
[HKEY_CLASSES_ROOTTencentshell]
[HKEY_CLASSES_ROOTTencentshellopen]
[HKEY_CLASSES_ROOTTencentshellopencommand]
@=""D:\Program Files\Tencent\QQ\Timwp.exe" "% 1""
What this registry implements is when the browser (or other) encounters tencent://... When, automatically call Timwp.exe, and put tencent://... The address is passed to the Timwp.exe as the first argument.
Nonsense not to say, the following hands-on experiment a demo to explain everything, the source code please download the article first. A very simple function is to display the parameter values passed to the MFC dialog program. Just analyze the code I added:
First you need to get the parameters passed in, in the console program we know that the main () function of the parameter argv brought in the parameters passed in, and in the MFC program, you need to InitInstance () in the command line parameter parsing.
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
A Setdisplayinfo method is added to pass the dialog box to the parameters to be displayed.
CHelloWorldDlg dlg;
dlg.SetDisplayInfo(cmdInfo.m_strFileName);//设置待显示的信息
void CHelloWorldDlg::SetDisplayInfo(CString& strInfo)
{
this->m_strInfo = strInfo;
}
Finally, the parameter parsing in the OnInitDialog function
//解析传入的完 整地址,e.g "helloworld://hello world/"
int pos = m_strInfo.Find("//");//找到分隔符
m_strInfo = m_strInfo.Mid(pos+2);//取到传入的参数
m_strInfo.Delete(m_strInfo.GetLength()-1);//去掉最后的'/'
m_edit_info.SetWindowText(m_strInfo);