導航:首頁 > 文件教程 > mfc簡易教程

mfc簡易教程

發布時間:2024-07-14 11:23:07

① vc++ mfc 鍓璐存澘鎿嶄綔鏁欑▼


鏈鏂囦富瑕佷粙緇嶄簡VC++/MFC涓濡備笅鍐呭圭殑鍓璐存澘鎿嶄綔錛
1銆佹枃鏈鍐呭圭殑鎿嶄綔
2銆乄MF鏁版嵁鐨勬搷浣
3銆佷綅鍥劇殑鎿嶄綔
4銆佽劇疆浣跨敤鑷瀹氫箟鏍煎紡
5銆佹劅鐭ュ壀璐存澘鍐呭圭殑鏀瑰彉
6銆佽嚜鍔ㄥ皢鏁版嵁綺樿創鍒板彟涓搴旂敤紼嬪簭紿楀彛
涓銆佹枃鏈鍐呭圭殑鎿嶄綔
涓嬮潰鐨勪唬鐮佺ず鑼冧簡濡備綍灝嗘枃鏈鍐呭瑰嶅埗鍒板壀璐存澘(Unicode緙栫爜鐨勫厛杞鍖栦負ASCII)錛
CString source;
//鏂囨湰鍐呭逛繚瀛樺湪source鍙橀噺涓
if( OpenClipboard() )
{
HGLOBAL clipbuffer;
char * buffer;
EmptyClipboard();
clipbuffer = GlobalAlloc(GMEM_DDESHARE, source.GetLength()+1);
buffer = (char*)GlobalLock(clipbuffer);
strcpy(buffer, LPCSTR(source));
GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT,clipbuffer);
CloseClipboard();
}
涓嬮潰鐨勪唬鐮佹樉紺轟簡濡備綍浠庡壀璐存澘涓婅幏寰楁枃鏈鍐呭癸細
char * buffer = NULL;
//鎵撳紑鍓璐存澘
CString fromClipboard;
if ( OpenClipboard() )
{
HANDLE hData = GetClipboardData(CF_TEXT);
char * buffer = (char*)GlobalLock(hData);
fromClipboard = buffer;
GlobalUnlock(hData);
CloseClipboard();
}
浜屻乄MF鏁版嵁鐨勬搷浣
鍦ㄥ壀璐存澘涓婅誨啓鍥捐薄鏁版嵁鏄闈炲父鏈夌敤鐨勫姛鑳斤紝騫朵笖瀹炵幇璧鋒潵涔熷緢綆鍗曘備笅闈㈢殑浠g爜鏄劇ず浜嗗備綍灝嗘墿灞曞浘鍏冩枃浠跺嶅埗鍒板壀璐存澘錛
if(OpenClipboard());
{
EmptyClipboard();
//鍒涘緩鍥懼厓鏂囦歡DC
CMetaFileDC * cDC = new CMetaFileDC();
cDC-CreateEnhanced(GetDC(),NULL,NULL,"the_name");
//璋冪敤緇樺浘渚嬬▼
//鍏抽棴CMetafileDC騫惰幏寰楀畠鐨勫彞鏌
HENHMETAFILE handle = cDC-CloseEnhanced();
//澶嶅埗鍒板壀璐存澘
SetClipBoardData(CF_ENHMETAFILE,handle);
CloseClipboard();
//鍒犻櫎dc
delete cDC;
}
涓嬮潰鐨勪唬鐮佹紨紺轟簡浠庡壀璐存澘鑾峰緱鍥懼厓鏂囦歡騫跺皢鍏剁粯鍒跺埌client DC涓婏細
if(OpenClipboard())
{
//鑾峰緱鍓璐存澘鏁版嵁
HENMETAFILE handle = (HENMETAFILE)GetClipboardData(CF_ENHMETAFILE);
//鏄劇ず
CClientDC dc(this);
CRect client(0,0,200,200);
dc.PlayMetaFile(handle,client);
//鍏抽棴鍓璐存澘
CloseClipboard();
}
涓夈佷綅鍥劇殑鎿嶄綔
浣嶅浘鐨勬搷浣滅◢寰澶嶆潅涓鐐癸紝涓嬮潰榪欎釜渚嬪瓙鏄劇ず浜嗗備綍鍦ㄥ壀璐存澘淇濆瓨浣嶅浘錛
if(OpenClipboard())
{
EmptyClipboard();
CBitmap * junk = new CBitmap();
CClientDC cdc(this);
CDC dc;
dc.CreateCompatibleDC(cdc);
CRect client(0,0,200,200);
junk-CreateCompatibleBitmap(cdc,client.Width(),client.Height());
dc.SelectObje
ct(junk);
DrawImage(dc,CString("Bitmap"));
//澶嶅埗鏁版嵁鍒板壀璐存澘
SetClipboardData(CF_BITMAP,junk-m_hObject);
CloseClipboard();
delete junk;
}
涓嬮潰鐨勪唬鐮佹樉紺轟簡濡備綍浠庡壀璐存澘涓婅幏寰椾綅鍥炬暟鎹錛
if(OpenClipboard())
{
//鑾峰緱鍓璐存澘鏁版嵁
HBITMAP handle = (HBITMAP)GetClipboardData(CF_BITMAP);
CBitmap * bm = CBitmap::FromHandle(handle);
CClientDC cdc(this);
CDC dc;
dc.CreateCompatibleDC(cdc);
dc.SelectObject(bm);
cdc.BitBlt(0,0,200,200,dc,0,0,SRCCOPY);
CloseClipboard();
}
鍥涖佽劇疆騫朵嬌鐢ㄨ嚜瀹氫箟鏍煎紡
浣跨敤RegisterClipboardFormat()鍑芥暟錛屽彲浠ュ嶅埗鍜岀矘璐翠換浣曚綘闇瑕佺殑鏁版嵁綾誨瀷銆傛瘮濡傛垜浠鏈変互涓嬩竴涓鏁版嵁綾誨瀷錛
struct MyFormatData
{
long val1;
int val2;
};
鎴戜滑瑕佹妸瀹冨嶅埗鍒板壀璐存澘錛屽彲浠ヤ嬌鐢ㄥ備笅鐨勪唬鐮侊細
UINT format = RegisterClipBoardFormat("MY_CUSTOM_FORMAT");
if(OpenClipboard())
{
MyFormatData data;
data.val1 = 100;
data.val2 = 200;
HGLOBAL clipbuffer;
EmptyClipboard();
clipbuffer = GlobalAlloc(GMEM_DDESHARE, sizeof(MyFormatData));
MyFormatData * buffer = (MyFormatData*)GlobalLock(clipbuffer);
//淇濆瓨鍒板唴瀛
*buffer = data;
//淇濆瓨鍒板壀璐存澘
GlobalUnlock(clipbuffer);
SetClipboardData(format,clipbuffer);
CloseClipboard();
}
璇誨彇鏁版嵁浣跨敤浠ヤ笅浠g爜錛
UINT format = RegisterClipboardFormat("MY_CUSTOM_FORMAT");
MyFormatData data;
if(Openclipboard())
{
HANDLE hData =GetClipboardData(format);
MyFormatData * buffer = (MyFormatData*)GlobalLock(hData);
data = *buffer;
GlobalUnlock(hData);
CloseClipboard();
}
浜斻佹劅鐭ュ壀璐存澘鍐呭圭殑鏀瑰彉
閫氳繃Windows娑堟伅鍙浠ユ劅鐭ュ壀璐存澘鍐呭規槸鍚﹀彂鐢熸敼鍙橈紝浠g爜濡備笅錛
//In your initialization code call:
SetClipboardViewer(); //灝嗘垜浠鐨勭▼搴忔坊鍔犲埌鍓璐存澘瑙傚療閾
//In your message map add:
ON_MESSAGE(WM_DRAWCLIPBOARD, OnClipChange) //娣誨姞Message handle
//Which is declared as:
afx_msg void OnClipChange();
Finally implement:
void CDetectClipboardChangeDlg::OnClipChange()
{
CTime time = CTime::GetCurrentTime();
SetDlgItemText(IDC_CHANGED_DATE,time.Format("%a, %b %d, %Y -- %H:%M:%S"));
DisplayClipboardText();
}
鍏銆佽嚜鍔ㄥ皢鏁版嵁綺樿創鍒板彟涓搴旂敤紼嬪簭紿楀彛
鍙闇鑾峰緱鐩稿簲紿楀彛鐨勫彞鏌勶紝騫跺彂閫佷竴涓娑堟伅灝卞彲浠ヤ簡

閱讀全文

與mfc簡易教程相關的資料

熱點內容
win10攝像頭不能拍照 瀏覽:56
雲陽數控編程培訓哪裡學 瀏覽:519
文件的存放路徑怎麼改 瀏覽:583
cad字體文件如何導出 瀏覽:236
cs16需要cdkey哪個文件里 瀏覽:817
如何讓另一個表格的數據關聯 瀏覽:368
來自app的快捷指令是怎麼有的 瀏覽:844
保留文件的原始文字圖片 瀏覽:385
國外網站的店怎麼看呢 瀏覽:56
ps入門必備文件 瀏覽:348
以前的相親網站怎麼沒有了 瀏覽:15
蘋果6耳機聽歌有滋滋聲 瀏覽:768
怎麼徹底刪除linux文件 瀏覽:379
編程中字體的顏色是什麼意思 瀏覽:534
網站關鍵詞多少個字元 瀏覽:917
匯川am系列用什麼編程 瀏覽:41
筆記本win10我的電腦在哪裡打開攝像頭 瀏覽:827
醫院單位基本工資去哪個app查詢 瀏覽:18
css源碼應該用什麼文件 瀏覽:915
編程ts是什麼意思呢 瀏覽:509

友情鏈接