/************************************************** BOOL CImg::SaveToFile(CFile &file) 功能: 把CImg实例中的图像数据保存到指定的图像文件 限制: 只能处理位图图像 参数: CFile &file 欲保存到的CFile对象 返回值: BYTE类型,TRUE为成功,FALSE为失败 ***************************************************/ BOOL CImg::SaveToFile(CFile &file) { // 判断是否有效 if(!IsValidate()) return FALSE; // 构建BITMAPFILEHEADER结构 BITMAPFILEHEADER bmfHeader = { 0 }; int nWidthBytes = WIDTHBYTES((m_pBMIH->biWidth)*m_pBMIH->biBitCount); bmfHeader.bfType = MAKEWORD('B', 'M'); bmfHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + m_nColorTableEntries*4; bmfHeader.bfSize = bmfHeader.bfOffBits + m_pBMIH->biHeight * nWidthBytes; // 向文件中写入数据 file.Write(&bmfHeader, sizeof(bmfHeader)); file.Write(m_pBMIH, sizeof(BITMAPINFOHEADER) + m_nColorTableEntries*4); for(int i=0; i<m_pBMIH->biHeight; i++) { file.Write(m_lpData[i], nWidthBytes); } return TRUE; }
void CPPNumEdit::OnUpdate() { // TODO: If this is a RICHEDIT control, the control will not // send this notification unless you override the CEdit::OnInitDialog() // function to send the EM_SETEVENTMASK message to the control // with the ENM_UPDATE flag ORed into the lParam mask. // TODO: Add your control notification handler code here TRACE(_T("CPPNumEdit::OnUpdate()\n")); m_bValidValue = IsValidate(); }
BOOL CImg::SaveToFile(LPCTSTR lpcPathName) { if(!IsValidate()) return FALSE; CFile file; if(!file.Open(lpcPathName, CFile::modeRead|CFile::modeWrite|CFile::modeCreate)) { return FALSE; } BOOL bSuc = SaveToFile(file); file.Close(); return bSuc; }
void SocketBase::Close() throw() { if(IsValidate()) { try { #ifdef WIN32 closesocket(_sock); #else close(_sock); #endif } catch(...) { // do nothing } } }
LRESULT CPPNumEdit::SendNotify(UINT uNotifyCode) { TRACE(_T("CPPNumEdit::SendNotify()\t%X\n"), uNotifyCode); if (uNotifyCode >= PPNUMEDIT_MAX_EVENTS) return 0; //If the notification code is not CANCEL or the editing value is not validate //then don't send the notification if ((uNotifyCode != PPNUMEDIT_CANCEL_DATA) && (!IsValidate())) return 0; // Make sure this is a valid window if (!IsWindow(GetSafeHwnd())) return 0; // See if the user wants to be notified if (GetNotify() == FALSE) return 0; NM_PPNUM_EDIT lpnm; lpnm.iValue = GetValue(); lpnm.iEvent = uNotifyCode; lpnm.hdr.hwndFrom = m_hWnd; lpnm.hdr.idFrom = GetDlgCtrlID(); if (uNotifyCode == PPNUMEDIT_CANCEL_DATA) lpnm.hdr.code = UDM_PPNUMEDIT_CANCEL; else if (uNotifyCode == PPNUMEDIT_ENTER_DATA) lpnm.hdr.code = UDM_PPNUMEDIT_ENTER; else if (uNotifyCode < PPNUMEDIT_HOTKEY_HEX) lpnm.hdr.code = UDM_PPNUMEDIT_MOVE; else lpnm.hdr.code = UDM_PPNUMEDIT_HOTKEY; CWnd *pOwner = GetOwner(); if (pOwner && IsWindow(pOwner->m_hWnd)) return pOwner->SendMessage(WM_NOTIFY, lpnm.hdr.idFrom, (LPARAM)&lpnm); else return 0; }