Use DDE to enable an application to add new program groups

Source: Internet
Author: User
Tags tag name

When the application is installed, it is common to set up the program groups, how are they implemented? The following is an example of using DDE to add a new group of programs.

1. Use MFC New Project Pmgroup (dialog form), add three edit box in the dialog box.

2. Using class Wizard, add member variable m_groupname,m_itemname,m_filename, corresponding to the added three edit Box, which will accommodate the input of three entries (group name, tag name, corresponding filename);

3. In the header file STDAFX.H, add the following code:

#include < ddeml.h >

4. In the InitInstance function of the application class Cpgroupapp, add the following code:

BOOL CPMGROUPApp::InitInstance()
{
//...
//Initialze DDEML
DdeInitialize(&dwDDEInst,NULL,APPCMD_CLIENTONLY,0);

if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
if(!AddPMGroup(dlg.m_GroupName,dlg.m_ItemName,dlg.m_FileName))
{
::MessageBox(NULL,"PMGroup:DDE Error","Error
adding group and item.",MB_ICONHAND|MB_OK);
}

}
//...
}

Add a member variable to the Cpgroupapp class Dwddeinst:

DWORD Dwddeinst (with mouse right click on ClassView cpgroupapp, select Add Member Variable in pop-up menu, enter DWORD and Dwddeinst in the dialog respectively)

Because it's a dialog based application, when you click OK, call Addpmgroup to add the new program group. So also to add to the Cpgroupapp class Addpmgroup (with the mouse on the ClassView Cpgroupapp Right-click, in the pop-up menu select the Add Member Function, in the dialogue input int and addpmgroup respectively. Change the resulting int cpmgroupapp::addpmgroup () to int cpmgroupapp::addpmgroup (CString &group,cstring &item,cstring & file) to change int addpmgroup () to int addpmgroup (CString &group,cstring &item,cstring &file) in Cpgroupapp). The contents of the Addpmgroup are:

int CPMGROOPApp::AddPMGroup(CString &group,CString &item,CString &file)
{
HSZ hszService=DdeCreateStringHandle(dwDDEInst,_T("PROGMAN"),CP_WINANSI);
HSZ hszTopic=DdeCreateStringHandle(dwDDEInst,_T("PROGMAN"),CP_WINANSI);
HCONV hConV=DdeConnect(dwDDEInst,hszTopic,hszService,NULL);
DdeFreeStringHandle(dwDDEInst,hszService);
DdeFreeStringHandle(dwDDEInst,hszTopic);
if(!hConV)
{
return FALSE;
}
//主要内容
CString cmd="[CreateGroup("+group+")]";//建立组的命令字
DWORD dwResult;
LPCTSTR data=(LPCTSTR)cmd;
DdeClientTransaction((LPBYTE)data,cmd.GetLength (),
hConV,NULL,CF_TEXT,XTYP_EXECUTE,
1000,&dwResult);
cmd="[AddItem("+file+","+item+")]";
//建立"file"的图标,"item"为标记的命令字
data=(LPCTSTR)cmd;
DdeClientTransaction((LPBYTE)data,cmd.GetLength (),
hConV,NULL,CF_TEXT,XTYP_EXECUTE,
1000,&dwResult);
return TRUE;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.