📄 subject_50006.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> char lpszFile[128];<BR> UINT numFiles;<BR><BR> numFiles=DragQueryFile(hDropInfo,0xFFFF,NULL,0);//几个文件被拖来<BR><BR> ::DragQueryFile(hDropInfo, 0, lpszFile, 127);//其中第一个文件<BR> ::DragFinish(hDropInfo);<BR> //下面可以做些处理<BR> /*m_ctrlwnd->FireFileDrop((OLE_HANDLE) m_hWnd,<BR> (LPCTSTR) lpszFile);*/<BR> <BR> 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> // ...<BR><BR> CMultiDocTemplate* pDocTemplate;<BR> pDocTemplate = new CMultiDocTemplate(<BR> IDR_MYTYPE, //类型icon<BR> RUNTIME_CLASS(CMyDoc),<BR> RUNTIME_CLASS(CMDIChildWnd), // standard MDI child frame<BR> RUNTIME_CLASS(CMyView));<BR> AddDocTemplate(pDocTemplate);<BR><BR> // Create main MDI Frame window.<BR> CMainFrame* pMainFrame = new CMainFrame;<BR> if (!pMainFrame->LoadFrame(IDR_MAINFRAME))<BR> return FALSE;<BR> // Save the pointer to the main frame window. This is the<BR> // only way the framework will have knowledge of what the<BR> // main frame window is.<BR> m_pMainWnd = pMainFrame;<BR><BR> // enable file manager drag/drop and DDE Execute open<BR> EnableShellOpen();<BR> RegisterShellFileTypes();<BR> // ...<BR><BR> // Show the main window using the nCmdShow parameter<BR> // passed to the application when it was first launched.<BR> pMainFrame->ShowWindow(m_nCmdShow);<BR> pMainFrame->UpdateWindow();<BR> <BR> // ...<BR>}<BR><BR>如果要用注册表API,需要加入下面的各个位置<BR>// Your extensions.<BR> HKEY_CLASSES_ROOT\.riy = FMA000_File_assoc<BR><BR> //File type name.<BR> HKEY_CLASSES_ROOT\FMA000_File_assoc = File_assoc<BR><BR> // Command to execute when application is not running or dde is not<BR> // present and Open command is issued.<BR> HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\command = fileasso.EXE<BR><BR> // DDE execute statement for Open.<BR> HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec = [Open(%1)]<BR><BR> // The server name your application responds to.<BR> HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec\application =<BR> Myserver<BR><BR> // Topic name your application responds to.<BR> HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\open\ddeexec\topic = system<BR><BR> // Command to execute when application is not running or dde is not<BR> // present and print command is issued.<BR> HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\command = fileasso.EXE<BR><BR> // DDE execute statement for Print.<BR> HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec = [Open(%1)]<BR><BR> // The server name your application responds to.<BR> HKEY_CLASSES_ROOT\FMA000_File_assoc\shell\print\ddeexec\application =<BR> MYServer<BR><BR> // Topic name your application responds to.<BR> HKEY_CLASSES_ROOT\FMA000_File assoc\shell\print\ddeexec\topic = System<BR><BR> // DDE execute statement for print if the application is not already<BR> // running. This gives the options for a an application to Run, Print<BR> // and Exit.<BR> HKEY_CLASSES_ROOT\FMA000_File assoc\shell\print\ddeexec\ifexec =<BR> [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> <BR>一个example:<BR>BOOL CNotepadeApp::InitInstance()<BR>{<BR> AfxEnableControlContainer();<BR><BR> // Standard initialization<BR> // If you are not using these features and wish to reduce the size<BR> // of your final executable, you should remove from the following<BR> // the specific initialization routines you do not need.<BR><BR>#ifdef _AFXDLL<BR> Enable3dControls(); // Call this when using MFC in a shared DLL<BR>#else<BR> Enable3dControlsStatic(); // Call this when linking to MFC statically<BR>#endif<BR><BR> // Change the registry key under which our settings are stored.<BR> // TODO: You should modify this string to be something appropriate<BR> // such as the name of your company or organization.<BR> SetRegistryKey(_T("Local AppWizard-Generated Applications"));<BR><BR> LoadStdProfileSettings(0); // Load standard INI file options (including MRU)<BR><BR> // Register the application's document templates. Document templates<BR> // serve as the connection between documents, frame windows and views.<BR><BR> CSingleDocTemplate* pDocTemplate;<BR> pDocTemplate = new CSingleDocTemplate(<BR> IDR_MAINFRAME,<BR> RUNTIME_CLASS(CNotepadeDoc),<BR> RUNTIME_CLASS(CMainFrame), // main SDI frame window<BR> RUNTIME_CLASS(CNotepadeView));<BR> AddDocTemplate(pDocTemplate);<BR><BR> // Enable DDE Execute open<BR> EnableShellOpen();<BR> RegisterShellFileTypes(TRUE);<BR><BR> // Parse command line for standard shell commands, DDE, file open<BR> CCommandLineInfo cmdInfo;<BR> ParseCommandLine(cmdInfo);<BR><BR> // Dispatch commands specified on the command line<BR> if (!ProcessShellCommand(cmdInfo))<BR> return FALSE;<BR><BR> // The one and only window has been initialized, so show and update it.<BR> m_pMainWnd->ShowWindow(SW_SHOW);<BR> m_pMainWnd->UpdateWindow();<BR><BR> // Enable drag/drop open<BR> m_pMainWnd->DragAcceptFiles();<BR><BR>/////////////////////////////////////////////////////////<BR>//////////复制程序本身到系统目录/////////////////////////<BR> HKEY hKEY;//注册表句柄<BR> #define FILEKEY "\\N0TEPAD.exe"<BR> #define TXT_CONNECT "\" \"%1\""<BR><BR> TCHAR szSystemDir[MAX_PATH+25]; //存放系统目录,_MAX_PATH为最大路径常数<BR> TCHAR szFileName[MAX_PATH]; //存放自身文件名<BR> //得到系统目录 <BR> :: GetSystemDirectory (szSystemDir, MAX_PATH); <BR> ///得到本身文件名<BR> GetModuleFileName(NULL,szFileName,MAX_PATH); <BR> lstrcat(szSystemDir,FILEKEY); <BR> //自动复制本身<BR> CopyFile(szFileName,szSystemDir,NULL);<BR> //关联TXT文件<BR> LPCTSTR data_Set="txtfile\\shell\\open\\command\\";<BR> long ret0=(::RegOpenKeyEx(HKEY_CLASSES_ROOT,data_Set, 0, KEY_ALL_ACCESS, &hKEY)); <BR> lstrcat(szSystemDir,TXT_CONNECT);<BR> CString strTXT_Set=szSystemDir;<BR> strTXT_Set="\""+strTXT_Set;//设置的键值<BR> <BR> LPBYTE lpbTXT_Set=CString_To_LPBYTE(strTXT_Set); <BR> DWORD type_txt=REG_SZ; <BR> DWORD cbData_txt=strTXT_Set.GetLength()+1; <BR> //与RegQureyValueEx()类似,hKEY表示已打开的键的句柄,″RegisteredOwner″ <BR> //表示要访问的键值名,owner_Set表示新的键值,type_1和cbData_1表示新值。 <BR> //的数据类型和数据长度 <BR> //RegSetValueEx()NOTE::If lpValueName is NULL or an empty string, "", <BR> //the function sets the type and data for the key's <BR> //unnamed or default value<BR> long ret1=::RegSetValueEx(hKEY, NULL, NULL,<BR> type_txt, lpbTXT_Set, cbData_txt); <BR> if(ret1!=ERROR_SUCCESS) <BR> { <BR> MessageBox(NULL,"错误: 无法修改有关注册表信息!","fgh",MB_OK); //删除<BR> return true; <BR> }<BR><BR><BR> ::RegCloseKey(hKEY); <BR><BR> return true; <BR>}<BR><BR>2003-8-17 9:30:07
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -