display_res_icon.cpp

本文介绍了一个基于Windows的应用程序编程实例,包括窗口类注册、消息处理、图标资源加载等关键步骤,并针对Windows 95进行了特别适配。

  
#include <windows.h> 
#include "Display_Res_Icon.h"


#if defined (WIN32)
 #define IS_WIN32 TRUE
#else
 #define IS_WIN32 FALSE
#endif

#define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
#define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
#define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32

HINSTANCE hInst;   // current instance

LPCTSTR lpszAppName  = "MyApp";
LPCTSTR lpszTitle    = "My Application";

BOOL RegisterWin95( CONST WNDCLASS* lpwc );

int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
                      LPTSTR lpCmdLine, int nCmdShow)
{
   MSG      msg;
   HWND     hWnd;
   WNDCLASS wc;

   // Register the main application window class.
   //............................................
   wc.style         = CS_HREDRAW | CS_VREDRAW;
   wc.lpfnWndProc   = (WNDPROC)WndProc;      
   wc.cbClsExtra    = 0;                     
   wc.cbWndExtra    = 0;                     
   wc.hInstance     = hInstance;             
   wc.hIcon         = LoadIcon( hInstance, lpszAppName );
   wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
   wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
   wc.lpszMenuName  = lpszAppName;             
   wc.lpszClassName = lpszAppName;             

   if ( IS_WIN95 )
   {
      if ( !RegisterWin95( &wc ) )
         return( FALSE );
   }
   else if ( !RegisterClass( &wc ) )
      return( FALSE );

   hInst = hInstance;

   // Create the main application window.
   //....................................
   hWnd = CreateWindow( lpszAppName,
                        lpszTitle,   
                        WS_OVERLAPPEDWINDOW,
                        CW_USEDEFAULT, 0,
                        CW_USEDEFAULT, 0, 
                        NULL,             
                        NULL,             
                        hInstance,        
                        NULL              
                      );

   if ( !hWnd )
      return( FALSE );

   ShowWindow( hWnd, nCmdShow );
   UpdateWindow( hWnd );        

   while( GetMessage( &msg, NULL, 0, 0) )  
   {
      TranslateMessage( &msg );
      DispatchMessage( &msg ); 
   }

   return( msg.wParam );
}


BOOL RegisterWin95( CONST WNDCLASS* lpwc )
{
   WNDCLASSEX wcex;

   wcex.style         = lpwc->style;
   wcex.lpfnWndProc   = lpwc->lpfnWndProc;
   wcex.cbClsExtra    = lpwc->cbClsExtra;
   wcex.cbWndExtra    = lpwc->cbWndExtra;
   wcex.hInstance     = lpwc->hInstance;
   wcex.hIcon         = lpwc->hIcon;
   wcex.hCursor       = lpwc->hCursor;
   wcex.hbrBackground = lpwc->hbrBackground;
   wcex.lpszMenuName  = lpwc->lpszMenuName;
   wcex.lpszClassName = lpwc->lpszClassName;

   // Added elements for Windows 95.
   //...............................
   wcex.cbSize = sizeof(WNDCLASSEX);
   wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName,
                            IMAGE_ICON, 16, 16,
                            LR_DEFAULTCOLOR );
   
   return RegisterClassEx( &wcex );
}

LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
   switch( uMsg )
   {
      case WM_COMMAND :
              switch( LOWORD( wParam ) )
              {
                 case IDM_TEST :
                        {
                           HICON hIcon;      
                           HRSRC hResource;   
                           HRSRC hMem;        
                           BYTE *lpResource;  
                           int   nID;                                                          
                           HDC   hDC;       

                           // Find the icon directory
                           // whose identifier is MYAPP.
                           //...........................
                           hResource = FindResource(hInst, "MYAPP",
                                                    RT_GROUP_ICON);

                           // Load and lock the icon directory.
                           //..................................
                           hMem = LoadResource(hInst, hResource);
                           lpResource = LockResource(hMem);

                           // Get the identifier of the icon that is most
                           // appropriate for the video display.
                           //............................................
                           nID = LookupIconIdFromDirectory((PBYTE)lpResource,
                                                            TRUE);

                           // Find the bits for the nID icon.
                           //................................
                           hResource = FindResource( hInst,
                                                   MAKEINTRESOURCE(nID),
                                                   MAKEINTRESOURCE(RT_ICON));

                           // Load and lock the icon.
                           //........................
                           hMem = LoadResource(hInst, hResource);
                           lpResource = LockResource(hMem);

                           // Create a handle to the icon.
                           //.............................
                           hIcon = CreateIconFromResource((PBYTE)lpResource,
                                           SizeofResource(hInst, hResource),
                                           TRUE,
                                           0x00030000);

                           // Draw the icon in the client area.
                           //..................................
                           hDC = GetDC( hWnd );
                           DrawIcon(hDC, 10, 20, hIcon);
                           ReleaseDC( hWnd, hDC );

                           DestroyIcon( hIcon );
                        }
                        break;

                 case IDM_ABOUT :
                        DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
                        break;

                 case IDM_EXIT :
                        DestroyWindow( hWnd );
                        break;
              }
              break;
     
      case WM_DESTROY :
              PostQuitMessage(0);
              break;

      default :
            return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
   }

   return( 0L );
}


LRESULT CALLBACK About( HWND hDlg,          
                        UINT message,       
                        WPARAM wParam,      
                        LPARAM lParam)
{
   switch (message)
   {
       case WM_INITDIALOG:
               return (TRUE);

       case WM_COMMAND:                             
               if (   LOWORD(wParam) == IDOK        
                   || LOWORD(wParam) == IDCANCEL)   
               {
                       EndDialog(hDlg, TRUE);       
                       return (TRUE);
               }
               break;
   }

   return (FALSE);
}

// ToolBoxBar.cpp: implementation of the CToolBoxBar class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "ToolBoxBar.h" #include "resource.h" #include "grouptybase.h" #include "Sp_drawView.h" #include "sp_draw.h" #include "group_doc.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif const COLORREF clrList = RGB (0, 204, 153); ///////////////////////////////////////////////////////////////////////////// // CToolBoxBar BEGIN_MESSAGE_MAP(CToolBoxBar, CBCGPDockingControlBar) //{{AFX_MSG_MAP(CToolBoxBar) ON_WM_CREATE() ON_WM_SIZE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CToolBoxBar construction/destruction CToolBoxBar::CToolBoxBar() { // TODO: add one-time construction code here m_grouptype.Empty(); } CToolBoxBar::~CToolBoxBar() { } ///////////////////////////////////////////////////////////////////////////// // CWorkspaceBar message handlers int CToolBoxBar::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CBCGPDockingControlBar::OnCreate(lpCreateStruct) == -1) return -1; CRect rectDummy; rectDummy.SetRectEmpty (); // m_images.Create (IDB_SHORTCUTS, 32, 0, RGB (255, 0, 255)); // CBitmap bmpIcons; // bmpIcons.LoadBitmap (IDB_SHORTCUTS); m_images.Create (48, 64, ILC_COLOR32 | ILC_MASK, 0, 10); m_images.SetImageCount(10); // m_images.Add (&bmpIcons, RGB (255, 0, 255)); // Create CListCtrl windows. // TODO: create your own tab windows here: const DWORD dwStyle = LVS_ICON | LBS_NOINTEGRALHEIGHT | WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL; m_wndList.Create (dwStyle, CRect (0, 0, 0, 0), this, (UINT)-1); m_wndList.SetBkColor (clrList); m_wndList.SetTextBkColor (clrList); m_wndList.m_pBar=this; // Setup list content: m_wndList.SetImageList (&m_images, LVSIL_NORMAL); //m_wndList.InsertItem (0,_T("One"),0); //m_wndList.InsertItem (1,_T("Two"),1); //m_wndList.InsertItem (2,_T("Three"),2); //m_wndList.InsertItem (3,_T("Four"),3); return 0; } void CToolBoxBar::OnSize(UINT nType, int cx, int cy) { CBCGPDockingControlBar::OnSize(nType, cx, cy); // List control should cover a whole client area: m_wndList.SetWindowPos (NULL, 0, 0, cx, cy, SWP_NOACTIVATE | SWP_NOZORDER); } bool SaveBitmapToFile(HBITMAP hBitmap , CString lpFileName) { HDC hDC; //设备描述表 int iBits; //当前显示分辨率下每个像素所占字节数 WORD wBitCount=16; //位图中每个像素所占字节数 DWORD dwPaletteSize=0, //定义调色板大小, 位图中像素字节大小 ,位图文件大小 , 写入文件字节数 dwBmBitsSize, dwDIBSize, dwWritten; BITMAP Bitmap; BITMAPFILEHEADER bmfHdr; //位图属性结构 BITMAPINFOHEADER bi; //位图文件头结构 LPBITMAPINFOHEADER lpbi; //位图信息头结构 HANDLE fh, hDib, hPal,hOldPal=NULL; //指向位图信息头结构,定义文件,分配内存句柄,调色板句柄 //计算位图文件每个像素所占字节数 hDC = CreateDC("DISPLAY",NULL,NULL,NULL); iBits = GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES); DeleteDC(hDC); if (iBits <= 1) wBitCount = 1; else if (iBits <= 4) wBitCount = 4; else if (iBits <= 8) wBitCount = 8; else if (iBits <= 24) wBitCount = 24; //计算调色板大小 if (wBitCount <= 8) dwPaletteSize = (1 << wBitCount) *sizeof(RGBQUAD); //设置位图信息头结构 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&Bitmap); bi.biSize = sizeof(BITMAPINFOHEADER); bi.biWidth = Bitmap.bmWidth; bi.biHeight = Bitmap.bmHeight; bi.biPlanes = 1; bi.biBitCount = wBitCount; bi.biCompression = BI_RGB; bi.biSizeImage = 0; bi.biXPelsPerMeter = 0; bi.biYPelsPerMeter = 0; bi.biClrUsed = 0; bi.biClrImportant = 0; dwBmBitsSize = ((Bitmap.bmWidth * wBitCount+31)/32)* 4 *Bitmap.bmHeight ; //为位图内容分配内存 hDib = GlobalAlloc(GHND,dwBmBitsSize+ dwPaletteSize+sizeof(BITMAPINFOHEADER)); lpbi = (LPBITMAPINFOHEADER)GlobalLock(hDib); *lpbi = bi; // 处理调色板 hPal = GetStockObject(DEFAULT_PALETTE); if (hPal) { hDC = ::GetDC(NULL); hOldPal = SelectPalette(hDC, (HPALETTE)hPal, FALSE); RealizePalette(hDC); } // 获取该调色板下新的像素值 GetDIBits(hDC, hBitmap, 0, (UINT) Bitmap.bmHeight, (LPSTR)lpbi + sizeof(BITMAPINFOHEADER)+dwPaletteSize, (LPBITMAPINFO)lpbi, DIB_RGB_COLORS); //恢复调色板 if (hOldPal) { SelectPalette(hDC, (HPALETTE)hOldPal, TRUE); RealizePalette(hDC); DeleteDC(hDC); } //创建位图文件 fh = CreateFile(lpFileName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (fh == INVALID_HANDLE_VALUE) return FALSE; // 设置位图文件头 bmfHdr.bfType = 0x4D42; // "BM" dwDIBSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwPaletteSize + dwBmBitsSize; bmfHdr.bfSize = dwDIBSize; bmfHdr.bfReserved1 = 0; bmfHdr.bfReserved2 = 0; bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER) + dwPaletteSize; // 写入位图文件头 WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL); // 写入位图文件其余内容 WriteFile(fh, (LPSTR)lpbi, dwDIBSize, &dwWritten, NULL); //消除内存分配 GlobalUnlock(hDib); GlobalFree(hDib); CloseHandle(fh); return TRUE; } void CToolBoxBar::UpdateData() { m_images.SetImageCount(0); m_wndList.DeleteAllItems();//清空 CString filepath; filepath=m_dir+"*.grp"; CFileFind ff; BOOL res = ff.FindFile(filepath); float vX0,vX1,vY0,vY1; int w=48,h=64; int num=0; while(res) { res = ff.FindNextFile(); if((!ff.IsDirectory()) && (!ff.IsDots())) { CString strFile = ff.GetFilePath(); CString strTitle=ff.GetFileTitle(); CGroupTyBase grp(strFile); CDC dc; HDC hdc = ::GetWindowDC(this->GetSafeHwnd()); dc.Attach(hdc); CDC memDC;//创建内存DC memDC.CreateCompatibleDC(&dc); CBitmap bm;//位图 CSize sz(w, h); bm.CreateCompatibleBitmap(&dc, sz.cx, sz.cy); CBitmap * oldbm = memDC.SelectObject(&bm); CBrush brush;//绘制背景 brush.CreateSolidBrush(clrList); CRect rt; rt.SetRect(0,0,sz.cx,sz.cy); memDC.FillRect(&rt,&brush); grp.GetGroupRect(&vX0,&vY0,&vX1,&vY1); CDrawInfoData drawinfo(vX0,vY0,vX1,vY1,h,w); grp.DrawGroup(&memDC,&drawinfo);//文件内容绘制到缩略图。 //SaveBitmapToFile((HBITMAP)(bm->m_hObject),m_dir+strTitle+".bmp"); //m_images.Add(bm,RGB (255, 0, 255)); //m_images.Replace(num,bm,NULL); memDC.SelectObject(oldbm); //bm->DeleteObject(); memDC.DeleteDC(); dc.DeleteDC(); //m_images.Replace(num,bm,NULL); m_images.Add(&bm,RGB (255, 0, 255)); //SaveBitmapToFile((HBITMAP)(bm->m_hObject),m_dir+strTitle+".bmp"); //m_wndList.InsertItem (num,strTitle,num); num++; } } //m_wndList.SetImageList (&m_images, LVSIL_NORMAL); //CString outstr; //outstr.Format("count=%d",m_images.GetImageCount()); //TRACE(outstr); res = ff.FindFile(filepath); num=0; while(res) { res = ff.FindNextFile(); if((!ff.IsDirectory()) && (!ff.IsDots())) { CString strTitle=ff.GetFileTitle(); m_wndList.InsertItem (num,strTitle,num); num++; } } } ///////////////////////////////////////////////////////////////////////////// // CToolBoxList CToolBoxList::CToolBoxList() { m_nDragIndex=-1; m_bDragging=false; m_pBar=NULL; } CToolBoxList::~CToolBoxList() { } BEGIN_MESSAGE_MAP(CToolBoxList, CListCtrl) //{{AFX_MSG_MAP(CToolBoxList) ON_WM_ERASEBKGND() //}}AFX_MSG_MAP ON_NOTIFY_REFLECT(LVN_BEGINDRAG, OnLvnBegindrag) ON_WM_MOUSEMOVE() ON_WM_LBUTTONUP() ON_NOTIFY_REFLECT(NM_DBLCLK, OnNMDblclk) ON_COMMAND(ID_GROUP_NEW, OnGroupNew) ON_UPDATE_COMMAND_UI(ID_GROUP_NEW, OnUpdateGroupNew) ON_COMMAND(ID_GROUP_DEL, OnGroupDel) ON_UPDATE_COMMAND_UI(ID_GROUP_DEL, OnUpdateGroupDel) ON_WM_CONTEXTMENU() ON_COMMAND(ID_GROUP_MODIFY, OnGroupModify) ON_UPDATE_COMMAND_UI(ID_GROUP_MODIFY, OnUpdateGroupModify) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CToolBoxList message handlers BOOL CToolBoxList::OnEraseBkgnd(CDC* pDC) { CRect rectClient; GetClientRect (rectClient); pDC->FillSolidRect (rectClient, clrList); return TRUE; } void CToolBoxList::OnLvnBegindrag(NMHDR *pNMHDR, LRESULT *pResult) { LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); // TODO: 在此添加控件通知处理程序代码 if(GetSelectedCount() > 1) return; m_nDragIndex = pNMLV->iItem; CImageList* pImageList=GetImageList(LVSIL_NORMAL); POINT pt; GetItemPosition(m_nDragIndex, &pt); pImageList->BeginDrag(m_nDragIndex,CPoint(-8,-10)); pImageList->DragEnter(GetDesktopWindow(),pNMLV->ptAction); m_bDragging=true; SetCapture (); *pResult = 0; } void CToolBoxList::OnMouseMove(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (m_bDragging) { //// Move the drag image CPoint pt(point); //get our current mouse coordinates ClientToScreen(&pt); //convert to screen coordinates CImageList* pImageList=GetImageList(LVSIL_NORMAL); pImageList->DragMove(pt); //move the drag image to those coordinates } CListCtrl::OnMouseMove(nFlags, point); } void CToolBoxList::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (m_bDragging) { // Release mouse capture, so that other controls can get control/messages ReleaseCapture (); // Note that we are NOT in a drag operation m_bDragging = FALSE; CImageList* pImageList=GetImageList(LVSIL_NORMAL); // End dragging image pImageList->DragLeave (GetDesktopWindow ()); pImageList->EndDrag (); CPoint pt (point); //Get current mouse coordinates ClientToScreen (&pt); //Convert to screen coordinates // Get the CWnd pointer of the window that is under the mouse cursor CWnd* pDropWnd = WindowFromPoint (pt); ASSERT (pDropWnd); //make sure we have a window pointer // If window is CListCtrl, we perform the drop if (pDropWnd->IsKindOf (RUNTIME_CLASS (CTysView))) { tagDragDropInfo* pRec= new tagDragDropInfo; memset(pRec,0,sizeof(tagDragDropInfo)); CString filepath; filepath.Format("%s%s.grp",m_pBar->m_dir,GetItemText(m_nDragIndex,0)); strcpy(pRec->filepath,filepath); pRec->posX=pt.x; pRec->posY=pt.y; pDropWnd->SendMessage(CM_DRAGDROP,0,(LPARAM)pRec); } } CListCtrl::OnLButtonUp(nFlags, point); } void CToolBoxList::OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: 在此添加控件通知处理程序代码 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR); int index = pNMLV->iItem; if(GetItemText(index,0) == "") return; CString filepath; filepath.Format("%s%s.grp",m_pBar->m_dir,GetItemText(index,0)); CGroup_Doc* pDoc=NULL; POSITION pos=theApp.m_GroupTempDoc->GetFirstDocPosition(); while (pos!=NULL) { pDoc=(CGroup_Doc*)theApp.m_GroupTempDoc->GetNextDoc(pos); if (pDoc==NULL) continue; CString str=pDoc->GetPathName(); if (stricmp(str,filepath)==0) { POSITION pos2=pDoc->GetFirstViewPosition( ); if (pos2!=NULL) { CView* pView =pDoc->GetNextView(pos2); if (pView!=NULL) pView->GetParentFrame()->ActivateFrame(); return; } } } CSp_drawApp* pApp=(CSp_drawApp*)AfxGetApp(); if (!pApp->GetPermit()) { return; } pDoc=(CGroup_Doc* )theApp.m_GroupTempDoc->OpenDocumentFile(NULL); if (pDoc==NULL) { assert(false); AfxMessageBox("组合图元无法打开!"); return; } pDoc->OpenGrpFile(filepath); *pResult = 0; } void CToolBoxBar::PostNcDestroy() { // TODO: 在此添加专用代码和/或调用基类 //if (m_pBarList!=NULL) //{ // POSITION pos=m_pBarList->Find(this); // if (pos!=NULL) // m_pBarList->RemoveAt(pos); //} CBCGPDockingControlBar::PostNcDestroy(); } BOOL CToolBoxBar::DestroyWindow() { // TODO: 在此添加专用代码和/或调用基类 CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd(); if (pFrame!=NULL) { POSITION pos=pFrame->m_BarList.Find(this); if (pos!=NULL) return false; else return true; } return CBCGPDockingControlBar::DestroyWindow(); } void CToolBoxList::OnGroupNew() { // TODO: 在此添加命令处理程序代码 CSp_drawApp* pApp=(CSp_drawApp*)AfxGetApp(); //if (!pApp->GetPermit()) //{ // return; //} CGroup_Doc* pDoc=NULL; pDoc=(CGroup_Doc* )theApp.m_GroupTempDoc->OpenDocumentFile(NULL); if (pDoc==NULL) { assert(false); AfxMessageBox("组合图元无法打开!"); return; } if (pDoc->NewGrpFile(m_pBar->m_grouptype)==false) { POSITION pos=pDoc->GetFirstViewPosition(); while (pos!=NULL) { CView * pView= pDoc->GetNextView(pos); CFrameWnd* pWnd=pView->GetParentFrame(); //pWnd->CloseWindow(); pWnd->DestroyWindow(); //pView->DestroyWindow(); //pView->CloseWindow(); } //pDoc->DeleteContents(); } } void CToolBoxList::OnUpdateGroupNew(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 pCmdUI->Enable(); } void CToolBoxList::OnGroupDel() { // TODO: 在此添加命令处理程序代码 CString filepath; // filepath.Format("%s%s.grp",m_pBar->m_dir,GetItemText(index,0)); POSITION pos =GetFirstSelectedItemPosition(); int hItem; if (pos!=NULL) hItem=GetNextSelectedItem(pos); else return; CSp_drawApp* pApp=(CSp_drawApp*)AfxGetApp(); if (!pApp->GetPermit()) { return; } CString str; str.Format("确定要删除类型[%s] 中的组合模版:%s",m_pBar->m_grouptype,GetItemText(hItem,0)); if (AfxMessageBox(str,MB_OKCANCEL)==IDOK) { filepath.Format("%s%s.grp",m_pBar->m_dir,GetItemText(hItem,0)); DeleteFile(filepath); } CMainFrame* pFrame=(CMainFrame*)AfxGetMainWnd(); if (pFrame!=NULL) pFrame->UpdateBarList(); } void CToolBoxList::OnUpdateGroupDel(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 POSITION pos =GetFirstSelectedItemPosition(); if (pos!=NULL) { pCmdUI->Enable(true); } else pCmdUI->Enable(false); } void CToolBoxList::OnContextMenu(CWnd* pWnd, CPoint point) { // TODO: 在此添加消息处理程序代码 if ((point.x<0)||(point.y<0)) return; CMenu menu; BOOL bSucc=menu.CreatePopupMenu(); if (!bSucc) return; OnUpdataPopMenu(&menu); menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x,point.y,this); menu.DestroyMenu(); } void CToolBoxList::OnUpdataPopMenu(CMenu *pMenu) { pMenu->AppendMenu(MF_ENABLED|MF_STRING,ID_GROUP_NEW,"新增"); POSITION pos =GetFirstSelectedItemPosition(); if (pos!=NULL) { pMenu->AppendMenu(MF_ENABLED|MF_STRING,ID_GROUP_DEL,"删除"); pMenu->AppendMenu(MF_ENABLED|MF_STRING,ID_GROUP_MODIFY,"修改"); } } void CToolBoxList::OnGroupModify() { // TODO: 在此添加命令处理程序代码 CSp_drawApp* pApp=(CSp_drawApp*)AfxGetApp(); if (!pApp->GetPermit()) { return; } POSITION pos =GetFirstSelectedItemPosition(); int index; if (pos!=NULL) index=GetNextSelectedItem(pos); else return; CString filepath; filepath.Format("%s%s.grp",m_pBar->m_dir,GetItemText(index,0)); CGroup_Doc* pDoc=NULL; pos=theApp.m_GroupTempDoc->GetFirstDocPosition(); while (pos!=NULL) { pDoc=(CGroup_Doc*)theApp.m_GroupTempDoc->GetNextDoc(pos); if (pDoc==NULL) continue; CString str=pDoc->GetPathName(); if (stricmp(str,filepath)==0) { POSITION pos2=pDoc->GetFirstViewPosition( ); if (pos2!=NULL) { CView* pView =pDoc->GetNextView(pos2); if (pView!=NULL) pView->GetParentFrame()->ActivateFrame(); return; } } } pDoc=(CGroup_Doc* )theApp.m_GroupTempDoc->OpenDocumentFile(NULL); if (pDoc==NULL) { assert(false); AfxMessageBox("组合图元无法打开!"); return; } pDoc->OpenGrpFile(filepath); } void CToolBoxList::OnUpdateGroupModify(CCmdUI *pCmdUI) { // TODO: 在此添加命令更新用户界面处理程序代码 POSITION pos =GetFirstSelectedItemPosition(); if (pos!=NULL) { pCmdUI->Enable(true); } else pCmdUI->Enable(false); }
07-17
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值