//CMyNet.cpp #include "stdafx.h" #include "MyNet.h" #include "net.h" #include "MainFrm.h" #include "defines.h" #include "ChildFrm.h" #include "NetDoc.h" #include "NetView.h" #include "MyList.h" #include "ListDlg.h" extern CNetApp theApp; CMyNet::CMyNet() { m_nCounter = 0; } CMyNet::~CMyNet() { } L_VOID CMyNet::UpdateStatusbar(LPCTSTR lpszString) { GETMAINFRAME->UpdateStatusbar(lpszString); } L_VOID CMyNet::UpdateStatusbar(LPCTSTR lpszString, L_INT nRet) { GETMAINFRAME->UpdateStatusbar(lpszString, nRet); } L_INT CMyNet::OnConnect(LInet L_FAR *plConnection, L_INT nError) { L_INT nRet = SUCCESS; L_CHAR *pszHostName; CString strMsg; if(nError != SUCCESS) { strMsg.Format(_T("Error[%d]: OnConnect"), nRet); AfxMessageBox(strMsg); UpdateStatusbar(strMsg); return nError; } // Get the remote computer name if ((pszHostName = plConnection->GetHostName(HOST_NAME_IP)) == NULL) return FAILURE; strMsg.Format( _T("OnConnect: Connected to %hs"), (LPTSTR)pszHostName); theApp.GetMainWnd()->SetWindowText(strMsg); GETMAINFRAME->m_pInetRemoteServer = plConnection; GETMAINFRAME->m_bConnectedToRemoteServer = TRUE; UpdateStatusbar(strMsg); return nRet; } L_INT CMyNet::OnConnectRequest(LInet L_FAR *plConnection, L_INT nError) { L_INT nRet = SUCCESS; CString strMsg; CMainFrame *pMainFrame = GETMAINFRAME; nRet = AcceptConnect(plConnection); if (nRet != SUCCESS) { strMsg.Format(_T("Error[%d]: OnConnectRequest AcceptConnect\n"), nRet); UpdateStatusbar(strMsg); AfxMessageBox(strMsg); return nRet; } //Get remote computer name strMsg = _T("Connection Accepted: "); strMsg += plConnection->GetHostName(HOST_NAME_IP); UpdateStatusbar(strMsg); plConnection->EnableAutoProcess(); return SUCCESS; } L_INT CMyNet::OnClose(LInet L_FAR *plConnection, L_INT nError) { CMainFrame *pMainFrame = GETMAINFRAME; UpdateStatusbar(_T("Connection Closed")); if(!pMainFrame->m_bServerStarted) { GETMAINFRAME->SetWindowText(_T("Connection to Remote Server Closed")); pMainFrame->InitializeVariables(); } return SUCCESS; } /**********************************************************************/ L_INT CMyNet::OnDataReady(LInet L_FAR *plConnection, L_INT nError, L_TCHAR L_FAR *pBuffer, L_UINT32 ulSize) { AfxMessageBox(_T("OnDataReady")); return SUCCESS; } L_INT CMyNet::OnDataSent(LInet L_FAR *plConnection, L_INT nError) { TCHAR szMsg[200]; wsprintf(szMsg, _T("[%d]OnDataSent\n"), m_nCounter++); OutputDebugString(szMsg); return SUCCESS; } L_INT CMyNet::OnDataSending(LInet L_FAR *plConnection, L_INT nError) { TCHAR szMsg[200]; wsprintf(szMsg, _T("[%d]OnDataSending\n"), m_nCounter++); OutputDebugString(szMsg); return SUCCESS; } L_INT CMyNet::OnDataStart(LInet L_FAR *plConnection, L_INT nError) { TCHAR szMsg[200]; wsprintf(szMsg, _T("[%d]OnDataStart\n"), m_nCounter++); OutputDebugString(szMsg); return SUCCESS; } L_INT CMyNet::OnDataReceiving(LInet L_FAR *plConnection, L_INT nError, L_TCHAR L_FAR *pBuffer, L_UINT32 ulSize) { TCHAR szMsg[200]; wsprintf(szMsg, _T("[%d]OnDataReceiving\n"), m_nCounter++); OutputDebugString(szMsg); return SUCCESS; } L_INT CMyNet::OnImageReceived(LInet L_FAR *plConnection, L_INT nError, LBitmapBase L_FAR *pBitmap) { L_INT nRet; if(nError == SUCCESS) { CMainFrame *pMainFrame = GETMAINFRAME; pMainFrame->m_pBitmapBase = pBitmap; pMainFrame->m_pInetRemoteServer = plConnection; if(pMainFrame->pImageListDlg->hCtl && pMainFrame->m_bLoadPathStarted) { AddImage(pBitmap); } else if(!pMainFrame->m_bLoadPathStarted || pMainFrame->m_bServerStarted) theApp.OnFileNew(); UpdateStatusbar(_T("OnImageReceived")); nRet = SUCCESS; } else { UpdateStatusbar(_T("Error[%d]: OnImageReceived"), nError); nRet = FAILURE; } return nRet; } //L_INT CMyNet::OnMMediaReceived(LInet L_FAR *plConnection, L_INT nError, LMultimedia L_FAR *pMedia) //{ // char szMsg[200]; // // wsprintf(szMsg, "[%d]OnMMediaReceived\n", m_nCounter++); // OutputDebugString(szMsg); // return SUCCESS; //} // //L_INT CMyNet::OnSoundReceived(LInet L_FAR *plConnection, L_INT nError, // LPWAVEFORMATDATA pWaveFormatData, L_UINT32 ulWaveFormatSize, // LPWAVEDATA pWaveData) //{ // AfxMessageBox("OnSoundReceived"); // return SUCCESS; //} L_INT CMyNet::OnUser1Received(LInet L_FAR *plConnection, L_INT nError, L_CHAR L_FAR *pBuffer, L_UINT32 ulSize) { CString strMsg; strMsg.Format(_T("%d bytes of data received"), ulSize); UpdateStatusbar(strMsg); return SUCCESS; } L_INT CMyNet::OnUser2Received(LInet L_FAR *plConnection, L_INT nError, L_CHAR L_FAR *pBuffer, L_UINT32 ulSize) { if(lstrcmp((L_TCHAR*)pBuffer, _T("Finish sending dialog data and bitmaps")) == 0) { CMainFrame *pMainFrame = GETMAINFRAME; pMainFrame->m_bLoadPathStarted = FALSE; pMainFrame->pImageListDlg->m_ImgList.EnableKeyboard(TRUE); UpdateStatusbar(_T("Finish loading images to remote path dialog")); } return SUCCESS; } L_INT CMyNet::OnUser3Received(LInet L_FAR *plConnection, L_INT nError, L_CHAR L_FAR *pBuffer, L_UINT32 ulSize) { CMainFrame *pMainFrame = GETMAINFRAME; if(pMainFrame->m_nImageIndex < L_MAXPATH) lstrcpy(pMainFrame->m_ImageNameList[pMainFrame->m_nImageIndex++], (L_TCHAR*)pBuffer); return SUCCESS; } L_INT CMyNet::OnUser4Received(LInet L_FAR *plConnection, L_INT nError, L_CHAR L_FAR *pBuffer, L_UINT32 ulSize) { UpdateStatusbar(_T("OnUser4Received")); return SUCCESS; } //The CommandCallBack() is processed on the server //To process the commands sent to the computer, you must: //1. Derive a class from LInet //2. Override the CommandCallBack member function // //Assume that //1. m_Inet is an object of the class CMyNet (derived from LInet). //2. the network as been started (LInet::StartUp()) //3. a connection has been established with a remote client //4. UpdateStatusbar() displays a message in the status bar //5. m_BitmapList maintains a list of LBitmapWindow objects L_INT CMyNet::CommandCallBack(LInet L_FAR * plConnection, CMDTYPE uCommand, L_UINT uCommandID, L_INT nError, L_UINT uParams, pPARAMETER pParams, L_UINT uExtra, L_CHAR L_FAR*pExtra) { L_INT nStatus = ERROR_FEATURE_NOT_SUPPORTED; L_UINT uBitmapID = (L_UINT)-1; CString strMsg; strMsg.Format(_T("%s, id=%d, nError=%d, uParams=%d%s received"), GetCommandString(uCommand), uCommandID, nError, uParams, uExtra ? _T(", uExtra") : _T("")); UpdateStatusbar(strMsg); CMainFrame *pMain; pMain = GETMAINFRAME; if(nError != SUCCESS) nStatus = ERROR_TRANSFER_ABORTED; else switch(uCommand) { case CMD_LOAD: { L_INT nIndex; nIndex = m_BitmapList.AddBitmap( (L_TCHAR *)pParams[0].pValue, //file name pParams[1].iValue, //nBitsPerPixel pParams[2].iValue //nOrder ); if (nIndex >=0) { nStatus = SUCCESS; pMain->m_uBitmapID = uBitmapID = nIndex; } return pMain->m_Inet.SendLoadRsp(plConnection, uCommandID, uBitmapID, 0, NULL, nStatus); } break; case CMD_CREATE_WIN: { pMain->m_bCreateBitmapWindow = FALSE; //Do not allocate LBitmapWindow pMain->m_pInetRemoteServer = plConnection; memset(theApp.m_szCaption, 0, sizeof(theApp.m_szCaption)); lstrcpy(theApp.m_szCaption, (L_TCHAR *)pParams[1].pValue); theApp.OnFileNew(); pMain->m_bCreateBitmapWindow = TRUE; pMain->m_pInetRemoteServer = NULL; nStatus = SUCCESS; // Get the active MDI child window.CMDIChildWnd CMDIChildWnd *pChild = (CMDIChildWnd *) pMain->GetActiveFrame(); // Get the active view attached to the active MDI child window. CView *pView = pChild->GetActiveView(); WINDOWPLACEMENT lpwndpl; if(pChild->GetWindowPlacement(&lpwndpl)) { if(lpwndpl.showCmd != SW_SHOWMAXIMIZED) { nStatus = pChild->SetWindowPos(NULL, 0, 0, pParams[5].iValue,pParams[6].iValue, SWP_NOOWNERZORDER | SWP_NOMOVE); } } pMain->m_uWindowID = (L_UINT)pView->m_hWnd; return pMain->m_Inet.SendCreateWinRsp( plConnection, uCommandID, (L_UINT)pView->m_hWnd, 0, NULL, nStatus); } break; case CMD_ATTACH_BITMAP: { L_UINT32 uBitmapID = pParams[0].uiValue; HWND uWindowID = (HWND)pParams[1].uiValue; //Need to attach bitmap to BitmapWindow if (IsWndValid((HWND)uWindowID)) { LBitmapWindow *pBitmapWindow; pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { pBitmapWindow->SetWndHandle(uWindowID); CNetDoc *pNetDoc = (CNetDoc*)GetDocFromHWnd((HWND)uWindowID); if (pNetDoc != NULL) { pNetDoc->m_pBitmapWindow = pBitmapWindow; pNetDoc->m_pBitmapWindow->Repaint(); pNetDoc->m_bBitmapWindowInList = TRUE; nStatus = SUCCESS; } } } return pMain->m_Inet.SendAttachBitmapRsp(plConnection, uCommandID, 0, NULL, nStatus); } break; case CMD_FLIP: { uBitmapID = pParams->uiValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->Flip(); } } break; case CMD_SAVE: { uBitmapID = pParams[1].uiValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->Save( (L_TCHAR *)pParams[0].pValue, //pParams[0] file name pParams[2].iValue, //pParams[2] nFormat pParams[3].iValue, //pParams[3] nBitsPerPixel pParams[4].iValue, //pparams[4] nQFactor pParams[5].iValue //pParams[5] uFlags ); if (nStatus != SUCCESS) nStatus = FAILURE; } return pMain->m_Inet.SendSaveRsp(plConnection, uCommandID,0, NULL, nStatus); } break; case CMD_REVERSE: { uBitmapID = pParams->uiValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->Reverse(); } } break; case CMD_90: case CMD_180: { uBitmapID = pParams->uiValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->Rotate((uCommand == CMD_90 ? 9000 : 18000), ROTATE_RESIZE, RGB(255, 0, 0)); } } break; case CMD_SHEAR: { uBitmapID = pParams->uiValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->Shear(4500, TRUE, RGB(255, 255, 255)); } } break; case CMD_RESIZE: { uBitmapID = pParams[0].uiValue; L_INT nWidth = pParams[1].iValue; L_INT nHeight = pParams[2].iValue; L_UINT uResizeMethod = pParams[3].uiValue; L_INT nXResolution = pParams[4].iValue; L_INT nYResolution = pParams[5].iValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { pBitmapWindow->SetXResolution(nXResolution); pBitmapWindow->SetYResolution(nYResolution); nStatus = pBitmapWindow->Size(nWidth, nHeight, uResizeMethod); } } break; case CMD_POSTERIZE: { uBitmapID = pParams[0].uiValue; L_INT nChange = pParams[1].iValue;; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->Posterize(nChange); } } break; case CMD_NOISE: { uBitmapID = pParams[0].uiValue; L_UINT uRange = pParams[1].uiValue; L_UINT uChannel = pParams[2].uiValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->AddNoise(uRange, uChannel); } } break; case CMD_OILIFY: { uBitmapID = pParams[0].uiValue; L_INT nChange = pParams[1].iValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->Oilify(nChange); } } break; case CMD_RESOLUTION: { uBitmapID = pParams[0].uiValue; L_INT nBits = pParams[1].iValue; L_UINT32 uColorResFlags = pParams[2].uiValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->ColorRes(nBits, uColorResFlags); } } break; case CMD_INVERT: { uBitmapID = pParams->uiValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->Invert(); } } break; case CMD_CONTRAST: { uBitmapID = pParams[0].uiValue; L_INT nChange = pParams[1].iValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->ChangeContrast(nChange); } } break; case CMD_SATURATION: { uBitmapID = pParams[0].uiValue; L_INT nChange = pParams[1].iValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pBitmapWindow->ChangeSaturation(nChange); } } break; case CMD_GAMMA: { uBitmapID = pParams[0].uiValue; L_INT nRedValue = pParams[1].iValue; L_INT nGreenValue = pParams[2].iValue; L_INT nBlueValue = pParams[3].iValue; //Make sure bitmap ID is valid LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { LBitmap ColorPlanes[3]; L_INT nBitsPerPixel = pBitmapWindow->GetBitsPerPixel(); L_INT nViewPerspective = pBitmapWindow->GetViewPerspective(); pBitmapWindow->ColorSeparate(ColorPlanes, sizeof(BITMAPHANDLE), COLORSEP_RGB); ColorPlanes[0].GammaCorrect(nBlueValue); ColorPlanes[1].GammaCorrect(nGreenValue); ColorPlanes[2].GammaCorrect(nRedValue); nStatus = pBitmapWindow->ColorMerge(ColorPlanes,sizeof(BITMAPHANDLE), COLORSEP_RGB); pBitmapWindow->ChangeViewPerspective(nViewPerspective); if (nBitsPerPixel <= 16) pBitmapWindow->ColorRes(nBitsPerPixel, CRF_NODITHERING | CRF_OPTIMIZEDPALETTE); ColorPlanes[0].Free(); ColorPlanes[1].Free(); ColorPlanes[2].Free(); } } break; case CMD_LOADPATH: { nStatus = ERROR_NOT_ENOUGH_IMAGES; if(pMain->m_szImageDir[0] == '\0') nStatus = FAILURE; else if(LoadAndSend(plConnection, 1) != 0) { if(LoadAndSend(plConnection, 2) != 0) { nStatus = SUCCESS; L_TCHAR *pBuffer = _T("Finish sending dialog data and bitmaps"); L_UINT32 uBufferLength = (lstrlen(pBuffer) + 1)*sizeof(L_TCHAR); pMain->m_Inet.SendData(plConnection, (L_CHAR*) pBuffer, &uBufferLength, IDATA_USER2); } } } break; case CMD_GET: { L_UINT uBitmapID = pParams->uiValue; OutputDebugStringA(pExtra); //is it a valid bitmap ID? LBitmapWindow *pBitmapWindow = m_BitmapList[uBitmapID]; if (pBitmapWindow != NULL) { nStatus = pMain->m_Inet.SendBitmap(plConnection, pBitmapWindow->GetHandle(), FILE_CMP, 24, QS, NULL); } } break; case CMD_SHOW_WIN: { L_INT nStatus = SUCCESS; L_INT nRet; HWND uWindowID = (HWND)pParams[0].uiValue; L_INT nCmdShow = pParams[1].iValue; if (IsWndValid((HWND)uWindowID)) { nRet = ::ShowWindow( ::GetParent((HWND)uWindowID), nCmdShow ); if (nRet == 0) nStatus = FAILURE; } else { nStatus = ERROR_INV_PARAMETER; } return pMain->m_Inet.SendShowWinRsp(plConnection, uCommandID, 0, NULL, nStatus); } break; case CMD_CLOSE_WIN: { L_INT nStatus = SUCCESS; HWND uWindowID = (HWND)pParams[0].uiValue; if (!CloseDocument((HWND)uWindowID)) { nStatus = ERROR_INV_PARAMETER; } return pMain->m_Inet.SendCloseWinRsp(plConnection, uCommandID, 0, NULL, nStatus); } break; case CMD_FREE_BITMAP: { L_INT nStatus = SUCCESS; L_UINT uBitmapID = pParams[0].uiValue; nStatus = m_BitmapList.DeleteBitmap(uBitmapID); pMain->UpdateWindow(); return pMain->m_Inet.SendFreeBitmapRsp(plConnection, uCommandID, 0, NULL, nStatus); } break; case CMD_SET_RECT: { L_INT nStatus = FAILURE; uBitmapID = pParams->uiValue; CNetDoc *pNetDoc = (CNetDoc*)GetDocFromHWnd(HWND(pParams[0].uiValue)); if (pNetDoc != NULL) { RECT rcRect; rcRect.left = pParams[2].iValue; rcRect.top = pParams[3].iValue; rcRect.right = rcRect.left + pParams[4].iValue; rcRect.bottom = rcRect.top + pParams[5].iValue; pNetDoc->m_pBitmapWindow->EnableCallBack(TRUE); nStatus = pNetDoc->m_pBitmapWindow->ZoomToRect(rcRect); } return pMain->m_Inet.SendSetRectRsp(plConnection, uCommandID,0,0,nStatus); } } return pMain->m_Inet.SendRsp( plConnection, uCommand, uCommandID, NULL, nStatus ); } L_INT CMyNet::ResponseCallBack( LInet L_FAR * plConnection, CMDTYPE uCommand, L_UINT uCommandID, L_INT nError, L_INT nStatus, L_UINT uParams, pPARAMETER pParams, L_UINT uExtra, L_CHAR L_FAR*pExtra ) { CString strMsg; CMainFrame *pMainFrame = GETMAINFRAME; strMsg.Format(_T("Response to %s, id=%d, nError=%d, uParams=%d, nStatus=%d%s received"), GetCommandString(uCommand), uCommandID, nError, uParams, nStatus, uExtra ? _T(", uExtra") : _T("") ); UpdateStatusbar(strMsg); if(nError != SUCCESS) return nError; if(nStatus == SUCCESS) { switch(uCommand) { case CMD_LOAD: { if(pMainFrame->m_uBitmapID != NO_BITMAP) pMainFrame->m_uWindowID = NULL; pMainFrame->m_uBitmapID = pParams->uiValue; pMainFrame->m_bGetBitmap = TRUE; pMainFrame->m_bBitmapAttachedToWindow = FALSE; } break; case CMD_CREATE_WIN: { pMainFrame->m_uWindowID = pParams->uiValue; pMainFrame->m_bBitmapAttachedToWindow = FALSE; } break; case CMD_ATTACH_BITMAP: { pMainFrame->m_bBitmapAttachedToWindow = TRUE; } break; case CMD_CLOSE_WIN: { L_UINT32 uWindowID; sscanf(pExtra, "%ud", &uWindowID); if(uWindowID == pMainFrame->m_uWindowID) pMainFrame->m_uWindowID = NULL; } break; case CMD_GET: { pMainFrame->m_bGetBitmap = FALSE; } break; case CMD_FREE_BITMAP: { pMainFrame->m_uBitmapID = NO_BITMAP; } break; } } else { if(uCommand == CMD_LOADPATH) { strMsg.Format(_T("Error[%d]: %s"), nStatus, (nStatus == FAILURE ? _T("The Server didn't specify an image path") : _T("The Server has no images on its specified image path"))); pMainFrame->m_bLoadPathStarted = FALSE; AfxMessageBox(strMsg, MB_ICONSTOP); pMainFrame->pImageListDlg->EndDialog(-1); } else { strMsg.Format(_T("Error[%d]: %s"), nStatus, GetCommandString(uCommand, TRUE)); AfxMessageBox(strMsg, MB_ICONSTOP); } } return SUCCESS; } L_BOOL CMyNet::IsWndValid(HWND hWnd) { CMainFrame *pMainFrame = GETMAINFRAME; CWnd *pWnd; HWND hWndChildFrame; hWndChildFrame = ::GetParent(hWnd); pWnd = pMainFrame->GetWindow(GW_CHILD); if (pWnd != NULL) { pWnd = pWnd->GetWindow(GW_CHILD); while (pWnd != NULL) { if (pWnd->m_hWnd == hWndChildFrame) { return TRUE; } pWnd = pWnd->GetNextWindow(GW_HWNDNEXT); } } return FALSE; } L_BOOL CMyNet::CloseDocument(HWND hWnd) { CMainFrame *pMainFrame = GETMAINFRAME; CWnd *pWnd; HWND hWndChildFrame; hWndChildFrame = ::GetParent(hWnd); pWnd = pMainFrame->GetWindow(GW_CHILD); if (pWnd != NULL) { pWnd = pWnd->GetWindow(GW_CHILD); while (pWnd != NULL) { if (pWnd->m_hWnd == hWndChildFrame) { pWnd->PostMessage( WM_CLOSE ); return TRUE; } pWnd = pWnd->GetNextWindow(GW_HWNDNEXT); } } return FALSE; } CDocument * CMyNet::GetDocFromHWnd(HWND hWnd) { POSITION pos = theApp.GetFirstDocTemplatePosition(); while (pos) { CDocTemplate* pTemplate = (CDocTemplate*)theApp.GetNextDocTemplate(pos); POSITION pos2 = pTemplate->GetFirstDocPosition(); while (pos2) { CDocument * pDocument; if ((pDocument=pTemplate->GetNextDoc(pos2)) != NULL) { //Get the view POSITION pos = pDocument->GetFirstViewPosition(); if (pos != NULL) { CView* pView = pDocument->GetNextView(pos); if (pView->m_hWnd == hWnd) return pDocument; } } } } return NULL; } L_TCHAR * CMyNet::GetCommandString(CMDTYPE cmd, L_BOOL bError) { L_TCHAR *pszString=_T("INVALID CMD"); switch (cmd) { case CMD_LOAD: pszString = bError ? _T("Failed to load image from server") : _T("CMD_LOAD"); break; case CMD_SAVE: pszString = bError ? _T("Failed to save loaded image on server") : _T("CMD_SAVE"); break; case CMD_CREATE_WIN: pszString = bError ? _T("Failed to create window on server") : _T("CMD_CREATE_WIN"); break; case CMD_CLOSE_WIN: pszString = bError ? _T("Failed to close the created window on server") : _T("CMD_CLOSE_WIN"); break; case CMD_SHOW_WIN: pszString = bError ? _T("Failed to maximize created window on server") : _T("CMD_SHOW_WIN"); break; case CMD_SET_RECT: pszString = bError ? _T("Failed to zoom in the created window on server") : _T("CMD_SET_RECT"); break; case CMD_ATTACH_BITMAP: pszString = bError ? _T("Failed to attach loaded bitmap to created window on server") : _T("CMD_ATTACH_BITMAP"); break; case CMD_FREE_BITMAP: pszString = bError ? _T("Failed to free loaded bitmap on server") : _T("CMD_FREE_BITMAP"); break; case CMD_FLIP: pszString = bError ? _T("Failed to flip loaded bitmap on server") : _T("CMD_FLIP"); break; case CMD_GET: pszString = bError ? _T("Failed to get loaded bitmap from server") : _T("CMD_GET"); break; case CMD_REVERSE: pszString = bError ? _T("Failed to reverse loaded bitmap on server") : _T("CMD_REVERSE"); break; case CMD_90: pszString = bError ? _T("Failed to rotate loaded bitmap by 90° on server") : _T("CMD_90"); break; case CMD_180: pszString = bError ? _T("Failed to rotate loaded bitmap by 180° on server") : _T("CMD_180"); break; case CMD_SHEAR: pszString = bError ? _T("Failed to shear loaded bitmap on server") : _T("CMD_SHEAR"); break; case CMD_RESIZE: pszString = bError ? _T("Failed to resize loaded bitmap on server") : _T("CMD_RESIZE"); break; case CMD_POSTERIZE: pszString = bError ? _T("Failed to posterize loaded bitmap on server") : _T("CMD_POSTERIZE"); break; case CMD_NOISE: pszString = bError ? _T("Failed to add noise to loaded bitmap on server") : _T("CMD_NOISE"); break; case CMD_OILIFY: pszString = bError ? _T("Failed to oilify loaded bitmap on server") : _T("CMD_OILIFY"); break; case CMD_RESOLUTION: pszString = bError ? _T("Failed to process color resolution to the loaded bitmap on server") : _T("CMD_RESOLUTION"); break; case CMD_INVERT: pszString = bError ? _T("Failed to invert colors of the loaded bitmap on server") : _T("CMD_INVERT"); break; case CMD_CONTRAST: pszString = bError ? _T("Failed to change contrast of the loaded bitmap on server") : _T("CMD_CONTRAST"); break; case CMD_SATURATION: pszString = bError ? _T("Failed to change colors saturation of the loaded bitmap on server") : _T("CMD_SATURATION"); break; case CMD_GAMMA: pszString = bError ? _T("Failed to adjust colors intensity of the loaded bitmap on server") : _T("CMD_GAMMA"); break; case CMD_LOADPATH: pszString = _T("CMD_LOADPATH"); break; } return pszString; } L_INT CMyNet::LoadAndSend(LInet L_FAR * plConnection, L_INT nType) { // variables related to searching files HLOCAL InfoHandle; L_INT32 filehandle; FIND_STRUCT *pInfo; L_TCHAR szImageName[L_MAXPATH]; LBitmapWindow BitmapWindow; L_UINT32 uNameLength = sizeof(szImageName); L_INT nRet = 0; // allocate the local memory if(!(InfoHandle = LocalAlloc(LMEM_MOVEABLE, sizeof(FIND_STRUCT)))) return nRet; if(!(pInfo = (FIND_STRUCT*)LocalLock(InfoHandle))) { LocalFree(InfoHandle); return nRet; } // initialize the directory related variables PrepareDirectory(szImageName, _T("*.*")); if((filehandle = FINDFIRST(szImageName, pInfo)) == -1) { LocalFree(InfoHandle); return nRet; } CMainFrame *pMain; pMain = GETMAINFRAME; do { // Prepare image file name memset(szImageName, 0, sizeof(szImageName)); PrepareDirectory(szImageName, pInfo->name); if(BitmapWindow.Load(szImageName) == SUCCESS) { if(nType == 1) { if(pMain->m_Inet.SendData(plConnection, (L_CHAR*) szImageName, &uNameLength, IDATA_USER3) == SUCCESS) nRet++; } else { if(pMain->m_Inet.SendBitmap(plConnection, BitmapWindow.GetHandle(), FILE_CMP, 24, QS, NULL) == SUCCESS) nRet++; BitmapWindow.Free(); } } } while(FINDNEXT(filehandle, pInfo) != -1 && nRet < 80); FINDCLOSE(filehandle); LocalUnlock(InfoHandle); LocalFree(InfoHandle); return nRet; } L_VOID CMyNet::PrepareDirectory(L_TCHAR L_FAR *pszDirName, L_TCHAR L_FAR *pszInit) { CMainFrame *pMainFrame = GETMAINFRAME; lstrcpy(pszDirName, pMainFrame->m_szImageDir); pszDirName += lstrlen(pszDirName) - 1; if(*pszDirName != '\\' && *pszDirName != ':') { pszDirName[1] = '\\'; pszDirName[2] = 0; } lstrcat(pszDirName, pszInit); } L_VOID CMyNet::AddImage(LBitmapBase L_FAR *pBitmap) { LILITEM Item; CMainFrame *pMainFrame = GETMAINFRAME; memset(&Item, 0, sizeof(Item)); Item.uStructSize = sizeof(LILITEM); Item.uMask = LILITEM_BITMAP | LILITEM_TEXT | LILITEM_DATA | LILITEM_SELECTED; Item.pBitmap = pBitmap->GetHandle(); Item.pText = (L_TCHAR L_FAR *)(LPCTSTR)pMainFrame->m_ImageNameList[pMainFrame->pImageListDlg->m_ImgList.GetItemCount()]; Item.lData = 1; Item.bSelected = FALSE; if(pMainFrame->pImageListDlg->m_ImgList.Insert(&Item) != SUCCESS) { SendMessage((pMainFrame->pImageListDlg->hCtl), LB_DELETESTRING, (WPARAM)(int)(SendMessage((pMainFrame->pImageListDlg->hCtl), CB_GETCOUNT, 0L, 0L)), 0L); } else pMainFrame->pImageListDlg->m_ImgList.EnsureVisible(pMainFrame->pImageListDlg->m_ImgList.GetItemCount() - 1); }