⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_50006.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:50006 发表者:寂寞 发表日期:2003-08-15 23:21:29
<br>主题:关于DragAcceptFiles()急!!
<br>内容:请问各位高手,DragAcceptFiles(),EnableSheelOpen(),RegisterSheelFileTypes()的用法..把一个文件拖放到一个应用程序上,应用程序启动了.并且应用程序得到这个文件的路径.或双击这个文件,启用相应的应用程序该怎么做?(最好有列子)谢了.<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:Justin Le 回复日期:2003-08-16 01:28:35
<br>内容:CVBFrameWnd 继承 CWnd <BR>然后,在某个地方DragAcceptFiles()//窗口就可以接受来自文件夹的drag<BR><BR>//<BR>void CVBFrameWnd::OnDropFiles(HDROP hDropInfo) <BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp; char lpszFile[128];<BR>&nbsp;&nbsp;&nbsp;&nbsp; UINT numFiles;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; numFiles=DragQueryFile(hDropInfo,0xFFFF,NULL,0);//几个文件被拖来<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; ::DragQueryFile(hDropInfo, 0, lpszFile, 127);//其中第一个文件<BR>&nbsp;&nbsp;&nbsp;&nbsp; ::DragFinish(hDropInfo);<BR>&nbsp;&nbsp;&nbsp;&nbsp; //下面可以做些处理<BR>&nbsp;&nbsp;&nbsp;&nbsp; /*m_ctrlwnd-&gt;FireFileDrop((OLE_HANDLE) m_hWnd,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (LPCTSTR) lpszFile);*/<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;&nbsp;&nbsp; CWnd::OnDropFiles(hDropInfo);<BR>}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:寂寞 回复日期:2003-08-16 10:01:21
<br>内容:那EnableShellOpen(),RegisterShellFileTypes()呢?双击这个文件,启用相应的应用程序该怎么做?还有对注册表怎么操作?(作出再奖200分)呵呵~~~~~谢了.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:Justin Le 回复日期:2003-08-16 12:15:36
<br>内容:用了这个函数就可以不再对注册表操作,但是如果有另外一个应用软件关联了你用的类型,就<BR>不会产生新的效果。BOOL CMyApp::InitInstance()<BR>{<BR>&nbsp;&nbsp; // ...<BR><BR>&nbsp;&nbsp; CMultiDocTemplate* pDocTemplate;<BR>&nbsp;&nbsp; pDocTemplate = new CMultiDocTemplate(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IDR_MYTYPE,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //类型icon<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RUNTIME_CLASS(CMyDoc),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RUNTIME_CLASS(CMDIChildWnd),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// standard MDI child frame<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RUNTIME_CLASS(CMyView));<BR>&nbsp;&nbsp; AddDocTemplate(pDocTemplate);<BR><BR>&nbsp;&nbsp; // Create main MDI Frame window.<BR>&nbsp;&nbsp; CMainFrame* pMainFrame = new CMainFrame;<BR>&nbsp;&nbsp; if (!pMainFrame-&gt;LoadFrame(IDR_MAINFRAME))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return FALSE;<BR>&nbsp;&nbsp; // Save the pointer to the main frame window.&nbsp;&nbsp;This is the<BR>&nbsp;&nbsp; // only way the framework will have knowledge of what the<BR>&nbsp;&nbsp; // main frame window is.<BR>&nbsp;&nbsp; m_pMainWnd = pMainFrame;<BR><BR>&nbsp;&nbsp; // enable file manager drag/drop and DDE Execute open<BR>&nbsp;&nbsp; EnableShellOpen();<BR>&nbsp;&nbsp; RegisterShellFileTypes();<BR>&nbsp;&nbsp; // ...<BR><BR>&nbsp;&nbsp; // Show the&nbsp;&nbsp; main window using the nCmdShow parameter<BR>&nbsp;&nbsp; // passed to the application when it was first launched.<BR>&nbsp;&nbsp; pMainFrame-&gt;ShowWindow(m_nCmdShow);<BR>&nbsp;&nbsp; pMainFrame-&gt;UpdateWindow();<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp; // ...<BR>}<BR><BR>如果要用注册表API,需要加入下面的各个位置<BR>// Your extensions.<BR>&nbsp;&nbsp; HKEY_CLASSES_ROOT\.riy = FMA000_File_assoc<BR><BR>&nbsp;&nbsp; //File type name.<BR>&nbsp;&nbsp; HKEY_CLASSES_ROOT\FMA000_File_assoc = File_assoc<BR><BR>&nbsp;&nbsp; // Command to execute when application is not running or dde is not<BR>&nbsp;&nbsp; // present and Open command is issued.<BR>&nbsp;&nbsp; HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\command = fileasso.EXE<BR><BR>&nbsp;&nbsp; // DDE execute statement for Open.<BR>&nbsp;&nbsp; HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec = [Open(%1)]<BR><BR>&nbsp;&nbsp; // The server name your application responds to.<BR>&nbsp;&nbsp; HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec\application =<BR>&nbsp;&nbsp; Myserver<BR><BR>&nbsp;&nbsp; // Topic name your application responds to.<BR>&nbsp;&nbsp; HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec\topic = system<BR><BR>&nbsp;&nbsp; // Command to execute when application is not running or dde is not<BR>&nbsp;&nbsp; // present and print command is issued.<BR>&nbsp;&nbsp; HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\command = fileasso.EXE<BR><BR>&nbsp;&nbsp; // DDE execute statement for Print.<BR>&nbsp;&nbsp; HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec = [Open(%1)]<BR><BR>&nbsp;&nbsp; // The server name your application responds to.<BR>&nbsp;&nbsp; HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec\application =<BR>&nbsp;&nbsp; MYServer<BR><BR>&nbsp;&nbsp; // Topic name your application responds to.<BR>&nbsp;&nbsp; HKEY_CLASSES_ROOT\FMA000_File assoc\shell\print\ddeexec\topic = System<BR><BR>&nbsp;&nbsp; // DDE execute statement for print if the application is not already<BR>&nbsp;&nbsp; // running. This gives the options for a an application to Run, Print<BR>&nbsp;&nbsp; // and Exit.<BR>&nbsp;&nbsp; HKEY_CLASSES_ROOT\FMA000_File assoc\shell\print\ddeexec\ifexec =<BR>&nbsp;&nbsp; [Test(%1)] <BR><BR>原文:<BR>In the program, you can also add keys to the registry by using the registry APIs. The developer needs to add the following keys to the registration database: <BR><BR>&nbsp;&nbsp; <BR>一个example:<BR>BOOL CNotepadeApp::InitInstance()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;AfxEnableControlContainer();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Standard initialization<BR>&nbsp;&nbsp;&nbsp;&nbsp;// If you are not using these features and wish to reduce the size<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;of your final executable, you should remove from the following<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;the specific initialization routines you do not need.<BR><BR>#ifdef _AFXDLL<BR>&nbsp;&nbsp;&nbsp;&nbsp;Enable3dControls();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Call this when using MFC in a shared DLL<BR>#else<BR>&nbsp;&nbsp;&nbsp;&nbsp;Enable3dControlsStatic();&nbsp;&nbsp;&nbsp;&nbsp;// Call this when linking to MFC statically<BR>#endif<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Change the registry key under which our settings are stored.<BR>&nbsp;&nbsp;&nbsp;&nbsp;// TODO: You should modify this string to be something appropriate<BR>&nbsp;&nbsp;&nbsp;&nbsp;// such as the name of your company or organization.<BR>&nbsp;&nbsp;&nbsp;&nbsp;SetRegistryKey(_T("Local AppWizard-Generated Applications"));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;LoadStdProfileSettings(0);&nbsp;&nbsp;// Load standard INI file options (including MRU)<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Register the application's document templates.&nbsp;&nbsp;Document templates<BR>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;serve as the connection between documents, frame windows and views.<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;CSingleDocTemplate* pDocTemplate;<BR>&nbsp;&nbsp;&nbsp;&nbsp;pDocTemplate = new CSingleDocTemplate(<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IDR_MAINFRAME,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RUNTIME_CLASS(CNotepadeDoc),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RUNTIME_CLASS(CMainFrame),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // main SDI frame window<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RUNTIME_CLASS(CNotepadeView));<BR>&nbsp;&nbsp;&nbsp;&nbsp;AddDocTemplate(pDocTemplate);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Enable DDE Execute open<BR>&nbsp;&nbsp;&nbsp;&nbsp;EnableShellOpen();<BR>&nbsp;&nbsp;&nbsp;&nbsp;RegisterShellFileTypes(TRUE);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Parse command line for standard shell commands, DDE, file open<BR>&nbsp;&nbsp;&nbsp;&nbsp;CCommandLineInfo cmdInfo;<BR>&nbsp;&nbsp;&nbsp;&nbsp;ParseCommandLine(cmdInfo);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Dispatch commands specified on the command line<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (!ProcessShellCommand(cmdInfo))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return FALSE;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// The one and only window has been initialized, so show and update it.<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_pMainWnd-&gt;ShowWindow(SW_SHOW);<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_pMainWnd-&gt;UpdateWindow();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Enable drag/drop open<BR>&nbsp;&nbsp;&nbsp;&nbsp;m_pMainWnd-&gt;DragAcceptFiles();<BR><BR>/////////////////////////////////////////////////////////<BR>//////////复制程序本身到系统目录/////////////////////////<BR>&nbsp;&nbsp;&nbsp;&nbsp;HKEY hKEY;//注册表句柄<BR>&nbsp;&nbsp;&nbsp;&nbsp;#define FILEKEY "\\N0TEPAD.exe"<BR>&nbsp;&nbsp;&nbsp;&nbsp;#define TXT_CONNECT "\" \"%1\""<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;TCHAR szSystemDir[MAX_PATH+25]; //存放系统目录,_MAX_PATH为最大路径常数<BR>&nbsp;&nbsp;&nbsp;&nbsp;TCHAR szFileName[MAX_PATH]; //存放自身文件名<BR>&nbsp;&nbsp;&nbsp;&nbsp;//得到系统目录 <BR>&nbsp;&nbsp;&nbsp;&nbsp;:: GetSystemDirectory (szSystemDir, MAX_PATH); <BR>&nbsp;&nbsp;&nbsp;&nbsp;///得到本身文件名<BR>&nbsp;&nbsp;&nbsp;&nbsp;GetModuleFileName(NULL,szFileName,MAX_PATH); <BR>&nbsp;&nbsp;&nbsp;&nbsp;lstrcat(szSystemDir,FILEKEY); <BR>&nbsp;&nbsp;&nbsp;&nbsp;//自动复制本身<BR>&nbsp;&nbsp;&nbsp;&nbsp;CopyFile(szFileName,szSystemDir,NULL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;//关联TXT文件<BR>&nbsp;&nbsp;&nbsp;&nbsp;LPCTSTR data_Set="txtfile\\shell\\open\\command\\";<BR>&nbsp;&nbsp;&nbsp;&nbsp;long ret0=(::RegOpenKeyEx(HKEY_CLASSES_ROOT,data_Set, 0, KEY_ALL_ACCESS, &amp;hKEY)); <BR>&nbsp;&nbsp;&nbsp;&nbsp;lstrcat(szSystemDir,TXT_CONNECT);<BR>&nbsp;&nbsp;&nbsp;&nbsp;CString strTXT_Set=szSystemDir;<BR>&nbsp;&nbsp;&nbsp;&nbsp;strTXT_Set="\""+strTXT_Set;//设置的键值<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;LPBYTE lpbTXT_Set=CString_To_LPBYTE(strTXT_Set); <BR>&nbsp;&nbsp;&nbsp;&nbsp;DWORD type_txt=REG_SZ; <BR>&nbsp;&nbsp;&nbsp;&nbsp;DWORD cbData_txt=strTXT_Set.GetLength()+1; <BR>&nbsp;&nbsp;&nbsp;&nbsp;//与RegQureyValueEx()类似,hKEY表示已打开的键的句柄,″RegisteredOwner″ <BR>&nbsp;&nbsp;&nbsp;&nbsp;//表示要访问的键值名,owner_Set表示新的键值,type_1和cbData_1表示新值。 <BR>&nbsp;&nbsp;&nbsp;&nbsp;//的数据类型和数据长度 <BR>&nbsp;&nbsp;&nbsp;&nbsp;//RegSetValueEx()NOTE::If lpValueName is NULL or an empty string, "", <BR>&nbsp;&nbsp;&nbsp;&nbsp;//the function sets the type and data for the key's <BR>&nbsp;&nbsp;&nbsp;&nbsp;//unnamed or default value<BR>&nbsp;&nbsp;&nbsp;&nbsp;long ret1=::RegSetValueEx(hKEY, NULL, NULL,<BR>&nbsp;&nbsp;&nbsp;&nbsp;type_txt, lpbTXT_Set, cbData_txt); <BR>&nbsp;&nbsp;&nbsp;&nbsp;if(ret1!=ERROR_SUCCESS) <BR>&nbsp;&nbsp;&nbsp;&nbsp;{ <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MessageBox(NULL,"错误: 无法修改有关注册表信息!","fgh",MB_OK); //删除<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return true; <BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;::RegCloseKey(hKEY);&nbsp;&nbsp;&nbsp;&nbsp;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;return true; <BR>}<BR><BR>2003-8-17 9:30:07

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -