问题一:如何实现指定盘符的光驱弹出弹入
void ctrl_cdrom_door(
LPCTSTR drivename ,//驱动器的名字如f:等.
bool fOpen file://弹出时用true,弹入时用false
)
{
TCHAR devstr[128],ctrlstr[128];
wsprintf(devstr,_T("open %s type cdaudio alias mycd wait"),drivename);
wsprintf(ctrlstr,_T("set mycd door %s wait"),fOpen _T("open"):_T("closed"));
mciSendString(devstr,NULL,0,NULL);
mciSendString(ctrlstr,NULL,0,NULL);
mciSendString(_T("close mycd wait"),NULL,0,NULL);
}
file://测试的例子代码.
void CMainFrame::OnTestOpen()
{
// TODO: Add your command handler code here
ctrl_cdrom_door("F:",true);
}
void CMainFrame::OnTestClose()
{
// TODO: Add your command handler code here
ctrl_cdrom_door("F:",false);
}
问题二:如何实现繁简体互换?
// j2f.cpp : 简体(gb)==>繁体==>big5的过程
// 反向转换是类似的.
// 注意直接从简体-->big5不能做到一一对应.会有很多 出现,
// 故此需要先转成繁体.再转成big5.
// 我感觉这种方法应当和winnt或office里提供的繁简或字符集互转是一致的.
#include "stdafx.h"
#include
#include
#include
#include
#include
using namespace std;
void j2f(const string &s)
{
int n=s.length ();
int r=LCMapString(
MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRC),
LCMAP_TRADITIONAL_CHINESE,
s.c_str (),s.length (),NULL,0);
if (!r) cout <<"error :"< char *ft=new char[r+1];
r=LCMapString(
MAKELCID(MAKELANGID(LANG_CHINESE,SUBLANG_CHINESE_SIMPLIFIED),SORT_CHINESE_PRC),
LCMAP_TRADITIONAL_CHINESE,
s.c_str (),s.length (),ft,r+1);//这个api搞掂简体转繁体,下面会打印繁体出来
if (r) {
ft[r]=0;
cout< wchar_t *pws=new wchar_t[r+1];
int r1=MultiByteToWideChar(936,0,ft,r,pws,r+1);
BOOL f=FALSE;
r1=WideCharToMultiByte(950,0,pws,r1,ft,r+1," ",&f);//代码页切换搞掂gb->big5
ft[r1]=0;
cout< for (int i=0;i cout<<"";
printf("0x%02x ",(BYTE)ft[i]);
}
cout<<")"< delete [] pws;
}
delete []ft;
}
//从标准输入简体国标-->big5繁体标准输出,输入两个空行退出
int main(int argc, char* argv[])
{
for(;;){
char line[1024];
cin.getline (line,sizeof(line));
string s(line);
if (!cin ||s.length ()==0) break;
j2f(s);
}
_getch();
return 0;
}
问题三:多线程中如何得到视图指针?
有两种方法可以实现你的要求:
1)第一种方法
要是多线程不是在App.cpp里出现,那么要在多线程的.cpp中加上extern CYourApp theApp;
//获得文档模板:
POSITION curTemplatePos = theApp.GetFirstDocTemplatePosition();
CDocTemplate *m_doc=theApp.GetNextDocTemplate(curTemplatePos);
file://获得文档:
curTemplatePos=m_doc->GetFirstDocPosition();
CYourDoc *m_pdoc=(CA8Doc*)m_doc->GetNextDoc(curTemplatePos);
file://获得视图:
curTemplatePos=m_pdoc->GetFirstViewPosition();
CYourView *m_pview=(CYourView*)m_pdoc->GetNextView(curTemplatePos);
file://调用视图函数:
m_pview->Put();