//首先在initinstance()函式中建立乙個同步物件,如果(getlasterror()返回error_already_exists表明存在
//乙個應用例項了,返回false取消
// 建立同步物件
hmutexoneinstantance=createmutex(null,true,_t("preventsecondinstance"));
if(getlasterror()==error_already_exists)
bfound=true;
if(hmutexoneinstantance)
releasemutex(hmutexoneinstantance);
if (bfound==true)
二. 單文件多檢視的切換函式
void cmainframe::changetoform(int nformid)
ccreatecontext context;
context.m_pcurrentdoc = pold->getdocument();
pnew->create(null,
null,
0l,cframewnd::rectdefault,
this,
nformid,
&context);
pnew->oninitialupdate();
}this->setactiveview(pnew);
pnew->showwindow(sw_show);
pold->showwindow(sw_hide);
int id;
if(pold->getruntimeclass()==runtime_class(crmsview))
id = idd_rms_form;
if(pold->getruntimeclass()==runtime_class(cpparameditview))
id = idd_param_form;
if(pold->getruntimeclass()==runtime_class(cpparameditview))
id = idd_otherparam_form;
if(pold->getruntimeclass()==runtime_class(cpuserview))
id = idd_usermanage;
if(pold->getruntimeclass()==runtime_class(cpdeviceedit))
id = idd_device_edit;
if(pold->getruntimeclass()==runtime_class(cpdevicedeleteview))
id = idd_device_delete;
if(pold->getruntimeclass()==runtime_class(cpchanneladdview))
id = idd_channel_add;
if(pold->getruntimeclass()==runtime_class(cpchanneleditview))
id = idd_channel_edit;
if(pold->getruntimeclass()==runtime_class(cdeviceshowview))
id = idd_show_device;
if(pold->getruntimeclass()==runtime_class(cchannelshowview))
id = idd_show_channel;
if(pold->getruntimeclass()==runtime_class(cplogview))
id = idd_log_view;
// 以後繼續新增
pold->setdlgctrlid(id);
pnew->setdlgctrlid(afx_idw_pane_first);
delete pold;
this->recalclayout();
}三. 在指定區域顯示的函式
// lpstrfile:檔名(最好是包含路徑在內)
// hwnd
// nscrwidth:輸出的寬度
// nscrheight:輸出的高度
// nscrwidth、nscrheight是輸出的實際大小,換而言之是指縮放後的尺寸
hresult showpic(char *lpstrfile,hwnd hwnd,int nscrwidth,int nscrheight)
else
//分配全域性儲存空間
hglobal hglobal = globalalloc(gmem_moveable, dwfilesize);
lpvoid pvdata = null;
if (hglobal == null)
return e_fail;
if ((pvdata = globallock(hglobal)) == null)//鎖定分配記憶體塊
return e_fail;
readfile(hfile,pvdata,dwfilesize,&dwbyteread,null);//把檔案讀入記憶體緩衝區
globalunlock(hglobal);
createstreamonhglobal(hglobal, true, &pstm);
//裝入圖形檔案
bresult=oleloadpicture(pstm,dwfilesize,true,iid_ipicture,(lpvoid*)&ppic);
if(failed(bresult))
return e_fail;
ole_xsize_himetric hmwidth;//的真實寬度
ole_ysize_himetric hmheight;//的真實高度
ppic->get_width(&hmwidth);
ppic->get_height(&hmheight);
//將圖形輸出到螢幕上(有點像bitblt)
bresult=ppic->render(hdc_temp,0,0,nscrwidth,nscrheight,
0,hmheight,hmwidth,-hmheight,null);
ppic->release();
closehandle(hfile);//關閉開啟的檔案
if (succeeded(bresult))
else };
四. 呼叫***send指令傳送訊息
header:declared in shellapi.h.
import library:shell32.lib.
void ***send(cstring destip,cstring msg)
{char cwindowdirectory[1024]; //定義路徑名
getwindowsdirectory(cwindowdirectory,1024); //得到windows系統目錄
cstring directory;
directory=cstring(cwindowdirectory)+"
//system32"+"//***
VC程式設計技巧
1.得到程式路徑 tchar exefullpath max path getmodulefilename null,exefullpath,max path 2.從對話方塊得到乙個資料夾 char szdir max path browseinfo bi itemidlist pidl bi.hw...
VC技巧集錦
呵呵,最近在學vc。不過沒有作長遠打算。hangwire發表於2001 12 29 8 39 30 問題一 解決workspace中的classview顯示混亂 解答 即新增的成員變數或函式不能顯示 即使顯示出來了變數或函式,雙擊後不能跳至正確的位置。刪除.ncb檔案,再rebuild all,即可...
VC程式設計技巧
1.得到程式路徑 tchar exefullpath max path getmodulefilename null,exefullpath,max path 2.從對話方塊得到乙個資料夾 char szdir max path browseinfo bi itemidlist pidl bi.hw...