這些技巧主要是在我的項(xiàng)目中用到的,為了達(dá)到記憶的目的:
1.實(shí)現(xiàn)目錄選擇
使用API
SHBrowseForFolder實(shí)現(xiàn),實(shí)例代碼如下:
1
UpdateData();
2
char Buf[MAX_PATH];
3
LPITEMIDLIST lp;
4
BROWSEINFO bs;
5
bs.hwndOwner=NULL;
6
bs.pidlRoot=NULL;
7
bs.pszDisplayName=Buf;
8
bs.lpszTitle=_T("請選擇存放目錄");
9
bs.ulFlags=BIF_RETURNONLYFSDIRS;//只選擇文件系統(tǒng)目錄
10
bs.lpfn=NULL;
11
bs.iImage=0;
12
lp=SHBrowseForFolder(&bs);
13
if(lp){
15 SHGetPathFromIDList(lp,Buf);
16 m_Path=Buf;//所需的目錄名
17 }
18
UpdateData(FALSE);
19
2.一個(gè)好用的CPiture類
/Files/fenglinuestc/picture.rar示例代碼:
1
UpdateData();//取得圖片路徑,m_Picture 為CPicture對像
2
CFileDialog cfd(TRUE,NULL,NULL,0,"All Image File(*.jpg,*.jpeg,*Gif,*BMP)|*.jpg;*.jpeg;*.gif;*.bmp;||");
3
if(cfd.DoModal()==IDOK)
4
{
5
m_bkPath=cfd.GetPathName();
6
UpdateData(FALSE);
7
m_Picture.Load(m_bkPath);
8
if(m_Picture)//如果可用
9
{
10
GetDlgItem(IDC_FRMAE)->EnableWindow(TRUE);
11
UpdateData(TRUE);
12
BeginWaitCursor();
13
Invalidate();//重畫
14
EndWaitCursor();
15
}
16
}
重畫的時(shí)候只要使用.Render(CDC * dc,Crect rect)定位到一個(gè)rect就可以顯示圖片,接著上邊的重畫消息的示例代碼如下:
1
//WM_PAINT
2
CPaintDC dc(this); // device context for painting
3
if(m_Picture)
4
{
5
CRect rect;
6
CWnd *previewwnd=GetDlgItem(IDC_FRMAE);//IDC_FRAME,通常為一個(gè)Groupbox
7
previewwnd->GetWindowRect(rect);
8
ScreenToClient(rect);
9
//顯示到rect中
10
m_Picture.Render(&dc,rect);
11
}
3.窗口添加ContextMenu的方法
//ON_WM_CONTEXTMENU..
::OnContextMenu(CWnd* pWnd, CPoint point)


{
CMenu menu;
//IDM_CHILDMENU為一ContextMenu
VERIFY(menu.LoadMenu(MAKEINTRESOURCE(IDM_CHILDMENU)));
//Pull out the first popup menu from it
CMenu* pPopup=menu.GetSubMenu(0);
ASSERT(pPopup!=NULL);
CWnd * pWndPopupOwner=this;
while(pWndPopupOwner->GetStyle()&WS_CHILD)
pWndPopupOwner=pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner);
}
Continue..
posted on 2007-09-13 12:26
Lexili 閱讀(447)
評論(0) 編輯 收藏 引用 所屬分類:
Win32