• <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相關(guān)筆記

            1、隱藏鼠標(biāo)

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

            2、顯示鼠標(biāo)

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

            3、在Picture Control上顯示圖片

            (1)先寫一個(gè)類

            //.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中進(jìn)行調(diào)用

            為該P(yáng)icture Control添加控件變量 CImagePreviewStatic m_adPic;

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

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

            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目錄下沒(méi)有圖片。"));
              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) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


            導(dǎo)航

            <2010年4月>
            28293031123
            45678910
            11121314151617
            18192021222324
            2526272829301
            2345678

            統(tǒng)計(jì)

            常用鏈接

            留言簿(19)

            隨筆檔案

            文章檔案

            收藏夾

            搜索

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久人人爽人人爽人人片AV麻烦 | 久久有码中文字幕| 久久午夜伦鲁片免费无码| 久久久久亚洲AV无码专区网站| 国产精品视频久久久| 日产精品99久久久久久| 久久天天躁夜夜躁狠狠躁2022| 无码国内精品久久综合88| 久久www免费人成看片| 久久久久久国产精品美女| AV无码久久久久不卡蜜桃| 国产色综合久久无码有码| 亚洲∧v久久久无码精品| 2022年国产精品久久久久| 91精品久久久久久无码| 老司机午夜网站国内精品久久久久久久久 | 99久久国产综合精品女同图片| 久久精品国产免费观看| 亚洲成色WWW久久网站| 99久久er这里只有精品18| 欧美亚洲另类久久综合| 性做久久久久久免费观看| 日产精品久久久久久久| 久久狠狠高潮亚洲精品| 国内精品久久久久久久影视麻豆| 午夜视频久久久久一区 | 久久AAAA片一区二区| 国产99久久久国产精品小说| 婷婷伊人久久大香线蕉AV| 亚洲欧美精品伊人久久| 日本WV一本一道久久香蕉| 欧美一区二区精品久久| 少妇无套内谢久久久久| 久久无码av三级| 国产精品99久久久精品无码| 久久这里只精品国产99热| 久久久午夜精品福利内容| 99精品久久久久中文字幕| 亚洲午夜精品久久久久久app| 久久国产精品99国产精| 人妻少妇精品久久|