- Picture loading code added
authorVictor Kirhenshtein <victor@netxms.org>
Wed, 19 Apr 2006 22:30:18 +0000 (22:30 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Wed, 19 Apr 2006 22:30:18 +0000 (22:30 +0000)
- Some minor changes

src/console/win32/MapFrame.cpp
src/console/win32/MapView.cpp
src/console/win32/globals.h
src/console/win32/tools.cpp
src/server/core/session.cpp

index 0c78359..20be7ca 100644 (file)
@@ -577,11 +577,19 @@ void CMapFrame::OnMapSetbackground()
                                _T("Uploading new background image to server..."));
       if (dwResult == RCC_SUCCESS)
       {
+         HBITMAP hBitmap;
+
+         hBitmap = LoadPicture((TCHAR *)((LPCTSTR)dlg.m_strFileName));
+         if (hBitmap != NULL)
+         {
+         }
+         else
+         {
+         }
       }
       else
       {
-         theApp.ErrorBox(dwResult, _T("Canot upload background image to server: %s"));
+         theApp.ErrorBox(dwResult, _T("Cannot upload background image to server: %s"));
       }
    }
 }
-CImage
index 3ccfc3c..f153008 100644 (file)
@@ -249,7 +249,7 @@ void CMapView::DrawOnBitmap(CBitmap &bitmap, BOOL bSelectionOnly, RECT *prcSel)
       ptOffset.y = 0;
    }
    bitmap.CreateCompatibleBitmap(pdc, rcBitmap.right, rcBitmap.bottom);
-   ReleaseDC(pdc);
+   //ReleaseDC(pdc);
 
    // Initial DC setup
    pOldBitmap = dc.SelectObject(&bitmap);
index 3b5821c..e6255c0 100644 (file)
@@ -277,6 +277,7 @@ int GetObjectImageIndex(NXC_OBJECT *pObject);
 int GetClassDefaultImageIndex(int iClass);
 CImageList *CreateEventImageList(void);
 void LoadBitmapIntoList(CImageList *pImageList, UINT nIDResource, COLORREF rgbMaskColor);
+HBITMAP LoadPicture(TCHAR *pszFile);
 
 
 //
index d801b95..9f667d1 100644 (file)
@@ -728,3 +728,65 @@ HTREEITEM FindTreeCtrlItemEx(CTreeCtrl &ctrl, HTREEITEM hRoot, DWORD dwData)
    }
    return NULL;
 }
+
+
+//
+// Load graphic file using IPicture interface
+// Will return NULL on error or valid bitmap handle on success
+//
+
+#define HIMETRIC_INCH   2540
+
+HBITMAP LoadPicture(TCHAR *pszFile)
+{
+       IPicture *pPicture = NULL;
+       HBITMAP hBitmap = NULL;
+       HRESULT hRes;
+#ifdef UNICODE
+   hRes = OleLoadPicturePath(pszFile, NULL, 0,
+                             -1, IID_IPicture, (LPVOID *)&pPicture);
+#else
+   WCHAR wszFile[MAX_PATH];
+
+   MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pszFile, -1, wszFile, MAX_PATH);
+   hRes = OleLoadPicturePath(wszFile, NULL, 0,
+                             -1, IID_IPicture, (LPVOID *)&pPicture);
+#endif
+                       
+       if (pPicture != NULL)
+       {
+       CBitmap bmMem, *pOldBM;
+          CDC dcMem, *pDC;
+      
+      pDC = theApp.m_pMainWnd->GetDC();
+          if (dcMem.CreateCompatibleDC(pDC))
+          {
+                  long hmWidth;
+                  long hmHeight;
+
+                  pPicture->get_Width(&hmWidth);
+                  pPicture->get_Height(&hmHeight);
+                  
+                  int nWidth = MulDiv(hmWidth, pDC->GetDeviceCaps(LOGPIXELSX), HIMETRIC_INCH);
+                  int nHeight = MulDiv(hmHeight, pDC->GetDeviceCaps(LOGPIXELSY), HIMETRIC_INCH);
+
+                  if (bmMem.CreateCompatibleBitmap(pDC, nWidth, nHeight))
+                  {
+            // Looks like an overkill, but I've seen that without following
+            // line bitmap of zero size was created
+            bmMem.SetBitmapDimension(nWidth, nHeight);
+            pOldBM = dcMem.SelectObject(&bmMem);
+                          hRes = pPicture->Render(dcMem.m_hDC, 0, 0, nWidth, nHeight, 0,
+                                    hmHeight, hmWidth, -hmHeight, NULL);
+                          dcMem.SelectObject(pOldBM);
+                  }
+          }
+
+          theApp.m_pMainWnd->ReleaseDC(pDC);
+          hBitmap = (HBITMAP)bmMem.Detach();
+      pPicture->Release();
+       }
+
+       return hBitmap;
+}
index fe89192..09f4051 100644 (file)
@@ -6640,7 +6640,7 @@ void ClientSession::SendSubmapBkImage(CSCPMessage *pRequest)
       if (pMap->CheckUserRights(m_dwUserId, MAP_ACCESS_READ))
       {
          _sntprintf(szBuffer, MAX_PATH, 
-                    _T("%s") DDIR_BACKGROUNDS FS_PATH_SEPARATOR _T("%08X_%08X.png"),
+                    _T("%s") DDIR_BACKGROUNDS FS_PATH_SEPARATOR _T("%08X.%08X"),
                     g_szDataDir, dwMapId, dwSubmapId);
          if (_taccess(szBuffer, 4) == 0)
          {
@@ -6702,7 +6702,7 @@ void ClientSession::RecvSubmapBkImage(CSCPMessage *pRequest)
          if (m_hCurrFile == -1)
          {
             _sntprintf(m_szCurrFileName, MAX_PATH, 
-                       _T("%s") DDIR_BACKGROUNDS FS_PATH_SEPARATOR _T("%08X_%08X.png"),
+                       _T("%s") DDIR_BACKGROUNDS FS_PATH_SEPARATOR _T("%08X.%08X"),
                        g_szDataDir, dwMapId, dwSubmapId);
             m_hCurrFile = _topen(m_szCurrFileName, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, S_IRUSR | S_IWUSR);
             if (m_hCurrFile != -1)