• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            vc相關筆記

            1、隱藏鼠標

            int i = ShowCursor(FALSE);
             for ( i; i >= 0 ;i-- )
             {
              ShowCursor(FALSE);
             }

            2、顯示鼠標

             int i = ShowCursor(TRUE);
             for ( i;i<= 0;i++ )
             {
              ShowCursor(TRUE);
             }

            3、在Picture Control上顯示圖片

            (1)先寫一個類

            //.h

            #pragma once
            using namespace Gdiplus;
            #pragma comment(lib, "gdiplus.lib")
            // CImagePrieviewStatic
            class CImagePreviewStatic : public CStatic
            {
             DECLARE_DYNAMIC(CImagePreviewStatic)
            public:
                 CImagePreviewStatic();
             virtual   ~CImagePreviewStatic();

             virtual BOOL Create();
             virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);

             void   SetFilename(LPCTSTR szFilename);

            protected:
             WCHAR   m_wsFilename[_MAX_PATH];
             Image   *m_img;
             Graphics  *m_graphics;

             DECLARE_MESSAGE_MAP()
            }; 

            //.cpp

            #include "stdafx.h"
            #include "ImagePreviewStatic.h"

            // CImagePrieviewStatic
            IMPLEMENT_DYNAMIC(CImagePreviewStatic, CStatic)

            CImagePreviewStatic::CImagePreviewStatic() : CStatic()
            {
             m_img = (Image *) NULL;
             m_graphics = (Graphics *) NULL;
            }

            CImagePreviewStatic::~CImagePreviewStatic()
            {
             //modified by yangjiaxun @ 200701226
             if( m_img )
              delete m_img;
             if( m_graphics )
              delete m_graphics;
            }

            BOOL CImagePreviewStatic::Create()
            {
             if (GetSafeHwnd() != HWND(NULL))
             {
              if (m_img != NULL)
              {
               delete m_img;
               m_img = (Image *) NULL;
              }
              if (m_graphics != NULL)
              {
               delete m_graphics;
               m_graphics = (Graphics *) NULL;
              }

              m_img = new Image(m_wsFilename);
              m_graphics = new Graphics(GetSafeHwnd());
              return TRUE;
             }

             return FALSE;
            }

            void CImagePreviewStatic::SetFilename(LPCTSTR szFilename)
            {
            #ifndef _UNICODE
             USES_CONVERSION;
            #endif

             ASSERT(szFilename);
             ASSERT(AfxIsValidString(szFilename));

             TRACE("%s\n", szFilename);

            #ifndef _UNICODE
             wcscpy(m_wsFilename, A2W(szFilename));
            #else
             wcscpy_s(m_wsFilename, szFilename);
            #endif

             delete m_img;
             m_img = new Image(m_wsFilename, FALSE);
             Invalidate();
            }

            void CImagePreviewStatic::DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/)
            {
             Unit  units;
             CRect rect;

             if (m_img != NULL)
             {
              GetClientRect(&rect);

              RectF destRect(REAL(rect.left), REAL(rect.top), REAL(rect.Width()), REAL(rect.Height())),
               srcRect;
              m_img->GetBounds(&srcRect, &units);
              m_graphics->DrawImage(m_img, destRect, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, UnitPixel, NULL);
             }
            }

            BEGIN_MESSAGE_MAP(CImagePreviewStatic, CStatic)
            END_MESSAGE_MAP()

            //在另外的.cpp中進行調用

            為該Picture Control添加控件變量 CImagePreviewStatic m_adPic;

             m_adPic.Create();
             m_adPic.SetFilename(theApp.g_szDefaultADPic);

            4、根據屏幕分辨率改變窗體控件的大小

            void xx::StretchControl(UINT uID)
            {
             CRect rcControl;
             CRect rcFrame;
             GetDlgItem( IDC_FRAME )->GetWindowRect( rcFrame );
             ScreenToClient( rcFrame );
             GetDlgItem( uID )->GetWindowRect( rcControl );
             ScreenToClient( rcControl );
             long topRate, leftRate, heightRate, widthRate;
             topRate  = rcControl.top      * GetSystemMetrics( SM_CYSCREEN ) / rcFrame.Height();
             leftRate = rcControl.left     * GetSystemMetrics( SM_CXSCREEN ) / rcFrame.Width();
             heightRate = rcControl.Height() * GetSystemMetrics( SM_CYSCREEN ) / rcFrame.Height();
             widthRate = rcControl.Width()  * GetSystemMetrics( SM_CXSCREEN ) / rcFrame.Width();
             GetDlgItem( uID )->MoveWindow( leftRate, topRate, widthRate, heightRate );
             Invalidate();
            }

            void xx::ShiftControl(UINT uID)
            {
             CRect rcControl;
             CRect rcFrame;

             GetDlgItem( IDC_FRAME )->GetWindowRect( rcFrame );
             ScreenToClient( rcFrame );

             GetDlgItem( uID )->GetWindowRect( rcControl );
             ScreenToClient( rcControl );

             long topRate, leftRate;
             topRate  = rcControl.top  * GetSystemMetrics( SM_CYSCREEN ) / rcFrame.Height();
             leftRate = rcControl.left * GetSystemMetrics( SM_CXSCREEN ) / rcFrame.Width();

             GetDlgItem( uID )->MoveWindow( leftRate, topRate, rcControl.Width(), rcControl.Height() );
             Invalidate();
            }

            5、在listctrl中顯示圖片

            (1)addpicture

            void xx::addPicture(void)
            {
             // TODO: Add your control notification handler code here
             UpdateData(TRUE);

             // validate image directory
             // show hour glass cursor
             BeginWaitCursor();

             // get the names of bitmap files
             if ( !GetImageFileNames() )
             {
              LOG_OUTPUT_WARN(_T("image目錄下沒有圖片。"));
              EndWaitCursor();
              return;
             }
             // draw thumbnail images in list control
             drawPicture();
            // set focus and select the first thumbnail in the list control
             //m_ctrList.SetFocus();
             m_ctrList.SetItemState(0, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); 

             CRect crt;
             int x = 95;
             int y = 120;
             m_ctrList.GetClientRect(&crt);
             x = (crt.Width() - 20)/3;
             y = crt.Height()/3;
             m_ctrList.SetIconSpacing(x,y);
             
             EndWaitCursor();
            }

            (2)GetImageFileNames

            BOOL xx::GetImageFileNames()
            {
             CString strExt;
             CString strName;
             CString strPattern;
             BOOL bRC = TRUE;

             HANDLE     hFind = NULL;
             WIN32_FIND_DATA   FindFileData;
             std::vector<CString> VectorImageNames;

             if ( theApp.g_szPicFilePath[theApp.g_szPicFilePath.GetLength() - 1] == TCHAR(''\\'') ) 
              strPattern.Format( TEXT("%s*.*"), theApp.g_szPicFilePath );
             else
              strPattern.Format( TEXT("%s\\*.*"), theApp.g_szPicFilePath );

             hFind = ::FindFirstFile(strPattern, &FindFileData); // strat search 
             if (hFind == INVALID_HANDLE_VALUE)
             {
              LPVOID  msg;
              ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
               NULL,
               GetLastError(),
               MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
               (LPTSTR)&msg,
               0,
               NULL);
              //  MessageBox((LPTSTR)msg, CString((LPCSTR)IDS_TITLE), MB_OK|MB_ICONSTOP);
              ::LocalFree(msg);
              return FALSE;
             }

             // filter off the system files and directories
             if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)  &&
              !(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)     &&
              !(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)     &&
              !(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY))
             {    
              // test file extension
              strName = FindFileData.cFileName;
              strExt = strName.Right(3);

              if ( strExt.CompareNoCase( TEXT("jpg") ) == 0 )
              {
               // save the image file name
               VectorImageNames.push_back(strName);
              }
             } 

             // loop through to add all of them to our vector 
             while (bRC)
             {
              bRC = ::FindNextFile(hFind, &FindFileData);
              if (bRC)
              {
               // filter off the system files and directories
               if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)  &&
                !(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)     &&
                !(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)     &&
                !(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY))
               {
                // test file extension
                strName = FindFileData.cFileName;
                strExt = strName.Right(3);

                if ( strExt.CompareNoCase( TEXT("jpg") ) == 0)
                {
                 // save the image file name
                 //strName = theApp.g_szPicFilePath + strName;
                 VectorImageNames.push_back(strName);
                }
               }
              } 
              else
              {
               DWORD err = ::GetLastError();
               if (err !=  ERROR_NO_MORE_FILES)
               {
                LPVOID msg;
                ::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
                 NULL, err,
                 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
                 (LPTSTR)&msg, 0, NULL);
                //MessageBox((LPTSTR)msg, CString((LPCSTR)IDS_TITLE), MB_OK|MB_ICONSTOP);
                ::LocalFree(msg);
                ::FindClose(hFind);
                return FALSE;
               }
              }
             } // end of while loop

             // close the search handle
             ::FindClose(hFind);

             // update the names, if any
             if ( !VectorImageNames.empty() )
             {
              // reset the image name vector
              m_VectorImageNames.clear();
              m_VectorImageNames = VectorImageNames;
              return TRUE;
             }

             return FALSE;
            }

            (3)drawPicture

            void xx::drawPicture()
            {
             CBitmap*    pImage = NULL;
             HBITMAP  hBmp = NULL;
             POINT  pt;
             CString  strPath;
             int   i;

             // no images
             if (m_VectorImageNames.empty())
              return;

             // set the length of the space between thumbnails
             // you can also calculate and set it based on the length of your list control
             int nGap = 6;

            // reset our image list
             for (i = 0; i<m_ImageListThumb.GetImageCount(); i++)
              m_ImageListThumb.Remove(i); 

             // remove all items from list view
             if (m_ctrList.GetItemCount() != 0)
              m_ctrList.DeleteAllItems();
             //add 20070809
             // set the size of the image list
             utility uClass;
             int m_iSid;
             m_iSid = theApp.getSidByMenuSname(theApp.m_strMenuSname);
             if (m_iSid == -1)
             {
              return;
             }
             theApp.m_menuInfoVec = uClass.getMenuInfoBySid(m_iSid);
             m_ImageListThumb.SetImageCount((UINT)theApp.m_menuInfoVec.size());//--modify 20070809
             i = 0;

             CRect crt;
             int iWidth = 95;
             int iHeight = 120;
             m_ctrList.GetClientRect(&crt);
             iWidth = (crt.Width() - 20)/3;
             iHeight = (crt.Height() - 20)/3 - 15;

             for (UINT k = 0;k < (UINT)theApp.m_menuInfoVec.size();k++)
             {
              CString strMid;
              CString strJpg = _T(".jpg");
              CString strMj;
              strMid.Format(L"%d",theApp.m_menuInfoVec[k].Mid);
              strMj = strMid + strJpg;
              std::vector<CString>::iterator iter;
              iter = find(m_VectorImageNames.begin(),m_VectorImageNames.end(),strMj);
              if(iter == m_VectorImageNames.end())
              {
               // load the bitmap
               strPath.Format( TEXT("%s\\%s"), theApp.g_szPicFilePath, _T("default.jpg") );

               USES_CONVERSION;
               //Bitmap img( A2W(strPath) );
               Bitmap img( strPath);
               //Bitmap* pThumbnail = static_cast<Bitmap*>(img.GetThumbnailImage(100, 75, NULL, NULL));
               Bitmap* pThumbnail = static_cast<Bitmap*>(img.GetThumbnailImage(iWidth, iHeight, NULL, NULL));

               // attach the thumbnail bitmap handle to an CBitmap object
               pThumbnail->GetHBITMAP(NULL, &hBmp);
               pImage = new CBitmap();  
               pImage->Attach(hBmp);

               // add bitmap to our image list
               m_ImageListThumb.Replace(k, pImage, NULL);

               // put item to display
               // set the image file name as item text
               //m_ctrList.InsertItem(i, m_VectorImageNames[i], i);
               CString strXS = _T("");
               CString strMname = theApp.m_menuInfoVec[k].Mname;
               CString strMprice = theApp.m_menuInfoVec[k].Mprice;
               CString strMmeasure = theApp.m_menuInfoVec[k].Mmeasure;
               LPCTSTR strTemp = LPCTSTR(strMname);
               strMname = strTemp;
               strTemp = LPCTSTR(strMprice);
               strMprice = strTemp;   
               strTemp = LPCTSTR(strMmeasure);
               strMmeasure = strTemp;
               strXS = (strMname + _T("\n") + _T("(") + strMprice + _T("/") + strMmeasure + _T(")"));
               m_ctrList.InsertItem(k,strXS,k);
               // get current item position 
               m_ctrList.GetItemPosition(k, &pt); 

               // shift the thumbnail to desired position
               pt.x = nGap + k*(75 + nGap);
               //m_ctrList.SetItemPosition(k, pt);//delete by wupeng 2007.08.15 for reslove picture''s positon
               //i++;

               delete pImage;
               delete pThumbnail;

              }
              else{
               // load the bitmap
               strPath.Format( TEXT("%s\\%s"), theApp.g_szPicFilePath,*iter );

               USES_CONVERSION;
               //Bitmap img( A2W(strPath) );
               Bitmap img( strPath);
               //Bitmap* pThumbnail = static_cast<Bitmap*>(img.GetThumbnailImage(100, 75, NULL, NULL));
               Bitmap* pThumbnail = static_cast<Bitmap*>(img.GetThumbnailImage(iWidth, iHeight, NULL, NULL));

               // attach the thumbnail bitmap handle to an CBitmap object
               pThumbnail->GetHBITMAP(NULL, &hBmp);
               pImage = new CBitmap();  
               pImage->Attach(hBmp);

               // add bitmap to our image list
               m_ImageListThumb.Replace(k, pImage, NULL);

               // put item to display
               // set the image file name as item text
               //m_ctrList.InsertItem(i, m_VectorImageNames[i], i);
               CString strXS = _T("");
               CString strMname = theApp.m_menuInfoVec[k].Mname;
               CString strMprice = theApp.m_menuInfoVec[k].Mprice;
               CString strMmeasure = theApp.m_menuInfoVec[k].Mmeasure;
               LPCTSTR strTemp = LPCTSTR(strMname);
               strMname = strTemp;
               strTemp = LPCTSTR(strMprice);
               strMprice = strTemp;   
               strTemp = LPCTSTR(strMmeasure);
               strMmeasure = strTemp;
               strXS = (strMname + _T("\n") + _T("(") + strMprice + _T("/") + strMmeasure + _T(")"));
               m_ctrList.InsertItem(k,strXS,

            k);
               // get current item position 
               m_ctrList.GetItemPosition(k, &pt); 

               // shift the thumbnail to desired position
               pt.x = nGap + k*(75 + nGap);
               //m_ctrList.SetItemPosition(k, pt);
               /*i++;*/

               delete pImage;
               delete pThumbnail;
              }
             }
             //end add

             // let''s show the new thumbnails
             m_ctrList.SetRedraw();
            }

            posted on 2008-09-10 18:32 wrh 閱讀(506) 評論(0)  編輯 收藏 引用

            導航

            <2008年10月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            統計

            常用鏈接

            留言簿(19)

            隨筆檔案

            文章檔案

            收藏夾

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            品成人欧美大片久久国产欧美...| 久久久精品人妻一区二区三区四| 久久99热狠狠色精品一区| 久久久九九有精品国产| 三级三级久久三级久久| 久久精品国产亚洲av影院| 国产精品久久一区二区三区| 久久综合色老色| 久久久久亚洲精品中文字幕 | 久久精品国产精品亚洲精品| 国产精品99久久久久久猫咪 | 色综合合久久天天给综看| 久久久久久毛片免费看| 久久精品男人影院| 久久只有这里有精品4| 久久无码av三级| 亚洲人成网亚洲欧洲无码久久 | 97精品伊人久久久大香线蕉| 久久国产精品99国产精| 亚洲伊人久久成综合人影院| 热综合一本伊人久久精品| 精品久久人妻av中文字幕| 久久精品国产亚洲77777| 伊人久久精品影院| 久久国产精品偷99| 99久久免费只有精品国产| 久久久久久亚洲Av无码精品专口 | 国产亚洲综合久久系列| 无码国内精品久久综合88| 久久国产精品国语对白| 久久天天躁狠狠躁夜夜av浪潮| 99久久人妻无码精品系列| 久久精品无码一区二区无码| 久久国内免费视频| 伊人久久大香线蕉无码麻豆| 久久精品无码专区免费| 国产亚洲精久久久久久无码AV| 99久久亚洲综合精品成人| 激情五月综合综合久久69| 国产精品欧美久久久久天天影视| 国产精品成人久久久久三级午夜电影 |