Beispiel #1
0
void InsertFile (LPSTR name)
{
    long len;
    LPSTR lp;
    HGLOBAL hMem;
    HFILE hFil;                        

    if (hFil=_lopen(name,OF_READ)) {
        len=_llseek(hFil,0,SEEK_END);
        _llseek(hFil,0,SEEK_SET);
        if ((len+1)<32000l) {
            if (hMem=GlobalAlloc(GMEM_MOVEABLE|GMEM_SHARE,len+1)) {                                 
                lp=GlobalLock(hMem);
                _lread(hFil,lp,(int)len);
                *(lp+len)=0;
                GlobalUnlock(hMem);                 
                if (OpenClipboard(hwndFrame)) {
                    SetClipboardData(CF_TEXT,hMem);
                    CloseClipboard();
                    EditPaste(GetActiveEditWindow(hwndMDIClient));
                }
            }
        }
        _lclose(hFil);
    }    
}
Beispiel #2
0
VOID AutoTest(void){

    static OPENFILENAME ofn;
    static char szFilename[80];
    char szT[80];
    int i, hfile;


	Sleep (5000);

    gfAll = TRUE;

    for (gibmi = 0; gibmi < gcbmi; gibmi++) {
	gabmi[gibmi].pfnBenchmark(gabmi[gibmi].cIterations);
    }


    hfile = _lopen("usrbench.out", OF_READWRITE); //try to open file
    if (hfile == -1){
	hfile = _lcreat("usrbench.out", 0);  //create it if it does not exist
	if (hfile == -1)
	    return;
    }
    else
	_llseek(hfile, 0L, 2);	// go to end of file for append


    WriteResults(hfile);

    _lclose(hfile);


}
Beispiel #3
0
short FAR PASCAL FilHdlOpn (const char far *lpFilNam, unsigned short usOpnFlg)
{
    static  char    szLocNam[FIOMAXNAM];

    /********************************************************************/
    /* Make a local copy of the file name                               */
    /********************************************************************/
    _fstrncpy (szLocNam, lpFilNam, FIOMAXNAM);

#if (defined (W31)) /****************************************************/
    /********************************************************************/
    /* _lopen does not have O_BINARY option                             */
    /********************************************************************/
    usOpnFlg &=  ~O_BINARY;
    /********************************************************************/
    /* _lopen does not have O_CREAT & _O_TRUNC option                   */
    /********************************************************************/
    if ((O_TRUNC & usOpnFlg) || ((O_CREAT & usOpnFlg) && FilGetSta (szLocNam, NULL))) {
        return (FilHdlCre (szLocNam, usOpnFlg, S_IWRITE));
    }
    return (_lopen (szLocNam, usOpnFlg));
#endif /*****************************************************************/

#if (defined (DOS)) /****************************************************/
    return (_open (szLocNam, usOpnFlg));
#endif /*****************************************************************/

}
Beispiel #4
0
/*------------------------------------------------
  "Browse" button
--------------------------------------------------*/
void OnBrowse(HWND hDlg)
{
	const char *filter = "Bitmap, Icon (*.bmp, *.ico)\0*.bmp;*.ico\0"
		"Executable (*.exe, *.dll)\0*.exe;*.dll\0"
		"All (*.*)\0*.*\0\0";
	char deffile[MAX_PATH], fname[MAX_PATH];
	HFILE hf;
	char head[2];
	
	GetDlgItemText(hDlg, IDC_FNAMEICON, deffile, MAX_PATH);
	
	if(!SelectMyFile(m_hInst, hDlg, filter, 2, deffile, fname))
		return;
	
	hf = _lopen(fname, OF_READ);
	if(hf == HFILE_ERROR) return;
	_lread(hf, head, 2);
	_lclose(hf);
	strcpy(m_fname_index, fname);
	
	if(head[0] == 'M' && head[1] == 'Z') // Executable
	{
		if(InitSelectIcon(hDlg))
			PostMessage(hDlg, WM_NEXTDLGCTL,
				(WPARAM)GetDlgItem(hDlg, IDC_LISTICON), TRUE);
	}
	else
	{
		EndSelectIcon(hDlg);
		EndDialog(hDlg, IDOK);
	}
}
Beispiel #5
0
void CJpeg::LoadJPG(LPCSTR FileName)
{
	// File Open & Load Entire Contents //
	HFILE hFile = _lopen(FileName, OF_READWRITE);
	int FileSize = GetFileSize((HANDLE)hFile, NULL);
	m_pBuf = new BYTE[FileSize];
	_lread(hFile, m_pBuf, FileSize);
	_lclose(hFile);
	m_Index = 0;
	int Count=0;

	FindSOI();	
	pByte = &m_pBuf[m_Index];
	while(TRUE)
	{
		FindETC(); // DRI(Define Restart Interval)
		FindDHT(); // Huffman Table Loading
		FindDQT(); // Quantization Table Loading
		FindSOF(); // Frame Header Loading
		FindSOS(); // Scan Header Loading & Decoding
		
		if( (*pByte == 0xff) && (*(pByte+1) == 0xd9) ) // 끝을 만났을 때
			break;
		Count++;
		if(Count > 50) // Loop가 끝날 가능성이 거의 없을 때
			break;		
	}

	delete [] m_pBuf;	
}
Beispiel #6
0
/*------------------------------------------------
  read menu commands from tcmenu*.txt
--------------------------------------------------*/
void LoadMenuFromText(HMENU hmenu,
	const char *fname, const WIN32_FIND_DATA *pfd)
{
	HFILE hf = HFILE_ERROR;
	int size;
	char *pbuf;
	
	if(fname && pfd)
		hf = _lopen(fname, OF_READ);
	if(hf == HFILE_ERROR)
	{
		AppendMenu(hmenu, MF_STRING, IDC_EXIT, "E&xit TClock");
		return;
	}
	
	size = (int)pfd->nFileSizeLow;
	pbuf = malloc(size + 1);
	_lread(hf, pbuf, size);
	pbuf[size] = 0;
	_lclose(hf);
	
	m_numCommands = ReadMenuCommands(NULL, pbuf, NULL);
	
	if(m_pmenuCommands) free(m_pmenuCommands);
	m_pmenuCommands = NULL;
	
	if(m_numCommands > 0)
		m_pmenuCommands = malloc(sizeof(MENUSTRUCT) * m_numCommands);
	ReadMenuCommands(hmenu, pbuf, m_pmenuCommands);
	
	free(pbuf);
}
Beispiel #7
0
FILETIME getBuffModifyTime()
{
	HFILE hFile = _lopen("buff.txt", OF_READ);

	FILETIME fCreateTime, fAccessTime, fWriteTime;
	GetFileTime((HANDLE*)hFile, &fCreateTime, &fAccessTime, &fWriteTime);//获取文件时间
	return fWriteTime;
}
Beispiel #8
0
static HMETAFILE GetPlaceableMetaFile( HWND hwnd, LPCSTR szFileName )
{
  LPBYTE lpData;
  METAHEADER mfHeader;
  APMFILEHEADER	APMHeader;
  HFILE	fh;
  HMETAFILE hmf;
  WORD checksum, *p;
  HDC hdc;
  int i;

  if( (fh = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR ) return 0;
  _llseek(fh, 0, 0);
  if (!_lread(fh, (LPSTR)&APMHeader, sizeof(APMFILEHEADER))) return 0;
  _llseek(fh, sizeof(APMFILEHEADER), 0);
  checksum = 0;
  p = (WORD *) &APMHeader;

  for(i=0; i<10; i++)
    checksum ^= *p++;
  if (checksum != APMHeader.checksum) {
    char msg[128];
    sprintf(msg, "Computed checksum %04x != stored checksum %04x\n",
	   checksum, APMHeader.checksum);
        MessageBox(hwnd, msg, "Checksum failed", MB_OK);
    return 0;
  }

  if (!_lread(fh, (LPSTR)&mfHeader, sizeof(METAHEADER))) return 0;

  if (!(lpData = GlobalAlloc(GPTR, (mfHeader.mtSize * 2L)))) return 0;

  _llseek(fh, sizeof(APMFILEHEADER), 0);
  if (!_lread(fh, lpData, (UINT)(mfHeader.mtSize * 2L)))
  {
    GlobalFree((HGLOBAL)lpData);
    _lclose(fh);
    return 0;
  }
  _lclose(fh);

  if (!(hmf = SetMetaFileBitsEx(mfHeader.mtSize*2, lpData)))
    return 0;


  width = APMHeader.bbox.Right - APMHeader.bbox.Left;
  height = APMHeader.bbox.Bottom - APMHeader.bbox.Top;

  /*      printf("Ok! width %d height %d inch %d\n", width, height, APMHeader.inch);  */
  hdc = GetDC(hwnd);
  width = width * GetDeviceCaps(hdc, LOGPIXELSX)/APMHeader.inch;
  height = height * GetDeviceCaps(hdc,LOGPIXELSY)/APMHeader.inch;
  ReleaseDC(hwnd, hdc);

  deltax = 0;
  deltay = 0 ;
  return hmf;
}
Beispiel #9
0
void DisplayFileInformation( PMODULE_FILE_INFO pModInfo, BOOL bQuiet )
{
    LPCTSTR base = getModuleBase(pModInfo,bQuiet);
    if ( !base ) return ;
    printf( "%-14s", base) ; // ->GetBaseName() );

    PSTR pszFullName = pModInfo->GetFullName();

    if ( g_fShowDateTime )
    {
        HFILE hFile = _lopen( pszFullName, OF_READ );
        if ( HFILE_ERROR != hFile )
        {
            FILETIME ft;

            if ( GetFileTime( (HANDLE)hFile, 0, 0, &ft ) )
            {
                char szFileDate[32] = { 0 };
                char szFileTime[32] = { 0 };

                GetFileDateAsString(&ft, szFileDate, sizeof(szFileDate) );
                GetFileTimeAsString(&ft, szFileTime, sizeof(szFileTime),
                                    TRUE);

                printf( "%s %s  ", szFileDate, szFileTime );
            }

            _lclose( hFile );
        }
    }

    if ( g_fShowLinkDateTime )
    {
        FILETIME ft;
        char szFileDate[32] = { 0 };
        char szFileTime[32] = { 0 };

        PE_EXE exe( pszFullName );

        TimeDateStampToFileTime( exe.GetTimeDateStamp(), &ft );

        GetFileDateAsString(&ft, szFileDate, sizeof(szFileDate) );
        GetFileTimeAsString(&ft, szFileTime, sizeof(szFileTime),
                            TRUE);

        printf( "%s %s  ", szFileDate, szFileTime );
    }

    if ( g_fShowFullPath )
        printf( "(%s)", pszFullName );

    printf( "\n" );

    if ( g_fShowVersion )
        ShowVersionInfo( pszFullName );
}
Beispiel #10
0
bool CFile::Open(int iAccessMode)
{
	m_hFile = _lopen(m_Path, iAccessMode);
	
	// Error?
	if (m_hFile == HFILE_ERROR)
		return FALSE;
	
	return TRUE;
}
Beispiel #11
0
BOOL CopyFile1(
/************************************************************************/
LPSTR 	lpInFile,
LPSTR	lpOutFile,
BOOL 	bClock,
BOOL	bEscapable)
{
int i, ifp, ofp;
char Buffer[2048];
int	nTotal, nCount;

nTotal = FileSize(lpInFile) / 2048;
lstrcpy( Buffer, lpInFile );
if ((ifp = _lopen( Buffer, OF_READ )) < 0)
	return( FALSE );
lstrcpy( Buffer, lpOutFile );
if ((ofp = _lcreat( Buffer, 0 )) < 0)
	{
	_lclose( ifp );
	return( FALSE );
	}

i = sizeof(Buffer);
nCount = 0;
while( 1 )
	{
	if (bClock)
		{
		if (AstralClockCursor(nCount, nTotal, bEscapable))
			{
			_lclose( ifp );
			_lclose( ofp );
			lstrcpy( Buffer, lpOutFile );
			unlink(Buffer);
			return( FALSE );
			}
		}
	if ( (i = _lread(ifp, Buffer, i)) <= 0 )
		{
		_lclose( ifp );
		_lclose( ofp );
		return( i == 0 );
		}
	if ( _lwrite(ofp, Buffer, i) != i )
		{
		_lclose( ifp );
		_lclose( ofp );
		lstrcpy( Buffer, lpOutFile );
		unlink(Buffer);
		return( FALSE );
		}
	++nCount;
	}
}
Beispiel #12
0
int
DIAMONDAPI
SpdFdiOpen(
    IN PSTR FileName,
    IN int  oflag,
    IN int  pmode
    )

/*++

Routine Description:

    Callback used by FDICopy to open files.

Arguments:

    FileName - supplies name of file to be opened.

    oflag - supplies flags for open.

    pmode - supplies additional flags for open.

Return Value:

    Handle to open file or -1 if error occurs.

--*/

{
    HFILE h;
    int OpenMode;

    if(oflag & _O_WRONLY) {
        OpenMode = OF_WRITE;
    } else {
        if(oflag & _O_RDWR) {
            OpenMode = OF_READWRITE;
        } else {
            OpenMode = OF_READ;
        }
    }

    h = _lopen(FileName,OpenMode | OF_SHARE_DENY_WRITE);

    if(h == HFILE_ERROR) {
        DiamondLastIoError = LZERROR_BADINHANDLE;
        return(-1);
    }

    return((int)h);
}
Beispiel #13
0
BOOL ReadObjHeader(LPSTR lpFileName, LPINT lpDataType, LPTIFFHEADER lpHeader )
/************************************************************************/
{
	int ifh;
	LPLONG lngptr;
	LPWORD shtptr;
	int nObjects;
	WORD wBytes, wByteOrder, wVersion;
	long lObjSize, lObjStart;
	LONG lDataOffset;
	BOOL bRet = FALSE;

	if ( (ifh = _lopen(lpFileName, OF_READ)) < 0)
		{
		Message( IDS_EOPEN, lpFileName );
		return( FALSE );
		}

	// Read in header info
	wBytes = OBJ_HDR_SIZE;
	if ( _lread(ifh, LineBuffer[0], wBytes) != wBytes )
		goto BadRead;
	shtptr     = (LPWORD)LineBuffer[0];
	wByteOrder = GetNextWord(&shtptr);	/* byte order is LSB,MSB */
	wVersion   = GetNextWord(&shtptr);	/* Version Number */
	nObjects   = GetNextWord(&shtptr);	/* Number of Objects */
	lngptr     = (LPLONG)shtptr;
	lObjSize   = GetNextLong(&lngptr);	/* size of object data */
	lObjStart  = GetNextLong(&lngptr);	/* start of object data */

	_llseek (ifh, lObjStart, 0);
	wBytes = (WORD)lObjSize;
	if ( _lread(ifh, LineBuffer[0], wBytes) != wBytes )
		goto BadRead;
	shtptr = (LPWORD)LineBuffer[0];

   	shtptr += 8;	// Obj data
   	shtptr++;		// Data type
   	shtptr += 5;	// lpOffsets before lDataOffset
	lngptr = (LPLONG)shtptr;
    lDataOffset = *lngptr;

	_llseek (ifh, lDataOffset, 0);
	bRet = ReadTiffHeader( ifh, lpFileName, -1, lpDataType, NO/*bReadOnly*/,
		lpHeader );

BadRead:
	_lclose(ifh);
	return( bRet );
}
Beispiel #14
0
void dbgv(
/***********************************************************************/
LPSTR 	lpFormat,
LPTR 	lpArguments)
{
char szBuffer[512];
static int hFile, debug;
static BOOL bReopen;

if ( !debug ) // First time in...
	debug = GetDefaultInt( "debug", -1 );
if ( debug <= 0 )
	return;

if ( lpFormat )
	{
	if ( !hFile )
		{
	 	lstrcpy( szBuffer, Control.ProgHome );
		lstrcat( szBuffer, "DEBUG.TXT" );
		if ( bReopen )
			{
			if ( (hFile = _lopen( szBuffer, OF_WRITE )) < 0 )
				hFile = 0;
			else	_llseek( hFile, 0L, 2 );
			}
		else	{
			if ( (hFile = _lcreat( szBuffer, 0 )) < 0 )
				hFile = 0;
			}
		}
	if ( hFile )
		{
 	   	wvsprintf( szBuffer, lpFormat, (LPSTR)lpArguments );
    		lstrcat(szBuffer, "\r\n");
		_lwrite( hFile, szBuffer, lstrlen(szBuffer) );
		if (debug > 1)
			OutputDebugString(szBuffer);
		}
	}
else
if ( hFile )
	{
	lstrcpy( szBuffer, "---------- CLOSED ----------\r\n" );
	_lwrite( hFile, szBuffer, lstrlen(szBuffer) );
	_lclose( hFile );
	bReopen = YES;
	hFile = 0;
	}
}
Beispiel #15
0
LPVOID LoadFile(LPCTSTR szFile, DWORD * pFileLength)
{
    LPVOID pFile;
    HANDLE hFile;
    HANDLE h;
    DWORD  FileLength;

#ifdef WIN32
    hFile = CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL,
        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

    if (hFile == INVALID_HANDLE_VALUE)
        return 0;

    FileLength = (LONG)GetFileSize(hFile, NULL);

    if (pFileLength)
       *pFileLength = FileLength ;

    h = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
    CloseHandle(hFile);

    if (h == INVALID_HANDLE_VALUE)
        return 0;

    pFile = MapViewOfFile(h, FILE_MAP_READ, 0, 0, 0);
    CloseHandle(h);

    if (pFile == NULL)
        return 0;
#else
    hFile = (HANDLE)_lopen(szFile, OF_READ);

    if (hFile == (HANDLE)-1)
        return 0;

    FileLength = _llseek((int)hFile, 0, SEEK_END);
    _llseek((int)hFile, 0, SEEK_SET);

    pFile = GlobalAllocPtr(GHND, FileLength);

    if (pFile && _hread((int)hFile, pFile, FileLength) != FileLength)
    {
        GlobalFreePtr(pFile);
        pFile = NULL;
    }
    _lclose((int)hFile);
#endif
    return pFile;
}
Beispiel #16
0
BOOL CFileSendDlg::IsFileAlreadyOpen(char *filename)
{
    HFILE theFile = HFILE_ERROR;
    DWORD lastErr = NO_ERROR;

    // Attempt to open the file exclusively.
    theFile = _lopen(filename, OF_READ | OF_SHARE_EXCLUSIVE);

    if (theFile == HFILE_ERROR)
        // Save last error...
        lastErr = GetLastError();
    else // If the open was successful, close the file.
        _lclose(theFile);

    // Return TRUE if there is a sharing-violation.
    return ((theFile == HFILE_ERROR) && (lastErr == ERROR_SHARING_VIOLATION));
}
Beispiel #17
0
static BOOL GRPFILE_ReadFileToBuffer(LPCSTR path, HLOCAL *phBuffer,
				     INT *piSize)
{
  UINT    len, size;
  LPSTR  buffer;
  HLOCAL hBuffer, hNewBuffer;
  HFILE  file;

  file=_lopen(path, OF_READ);
  if (file == HFILE_ERROR) return FALSE;

  size = 0;
  hBuffer = LocalAlloc(LMEM_FIXED, MALLOCHUNK + 1);
  if (!hBuffer) return FALSE;
  buffer = LocalLock(hBuffer);

  while ((len = _lread(file, buffer + size, MALLOCHUNK))
	 == MALLOCHUNK)
    {
      size += len;
      hNewBuffer = LocalReAlloc(hBuffer, size + MALLOCHUNK + 1,
				LMEM_FIXED);
      if (!hNewBuffer)
	{
	  LocalFree(hBuffer);
	  return FALSE;
	}
      hBuffer = hNewBuffer;
      buffer = LocalLock(hBuffer);
    }

  _lclose(file);

  if (len == (UINT)HFILE_ERROR)
    {
      LocalFree(hBuffer);
      return FALSE;
    }

  size += len;
  buffer[size] = 0;

  *phBuffer = hBuffer;
  *piSize   = size;
  return TRUE;
}
Beispiel #18
0
BOOL IsFile(char *name)
{
	HFILE h;
	if (name == NULL)
	{
		return FALSE;
	}

	h = _lopen(name, OF_READ);
	if (h == HFILE_ERROR)
	{
		return FALSE;
	}
	_lclose(h);

	return TRUE;
}
Beispiel #19
0
static BOOL FileIsPlaceable( LPCSTR szFileName )
{
  HFILE		hInFile;
  APMFILEHEADER	apmh;

  if( (hInFile = _lopen( szFileName, OF_READ ) ) == HFILE_ERROR )
    return FALSE;

  if( _lread( hInFile, &apmh, sizeof(APMFILEHEADER) )
      != sizeof(APMFILEHEADER) )
    {
      _lclose( hInFile );
      return FALSE;
    }
  _lclose( hInFile );

  /* Is it placeable? */
  return (apmh.key == APMHEADER_KEY);
}
Beispiel #20
0
void WOLog_init(const char *logfile, const char *level)
{
   int i;
   int fd;

   logMutex = WA_createLock("logMutex");

   /*
    *	the file we stat() to see if we should log
    */
#ifndef	ALWAYS_LOG
   sprintf(logFlag,"%s/%s",tmp(),LOG_FLAG);
#endif

   /*
    *	log to file.  we need to make sure it's world writable since
    *	we're likely to fork/exec from root to httpd or something...
    */
   if (logfile != NULL) {
      strcpy(logPath, logfile);
   } else {
      sprintf(logPath,"%s/%s",tmp(),LOG_FILE);
   }
#ifdef	WIN32
   fd = _lopen(logPath, OF_WRITE| OF_SHARE_COMPAT);
   _lclose(fd);
#else
   fd = open(logPath, O_WRONLY, 0644);
   close(fd);		/* create the file if needed */
#endif
   chmod(logPath, 0644);

   if (level) {
      for (i = WO_DBG; i <= WO_USER; i++) {
         if (strcasecmp(WOLogLevel[i], level) == 0) {
            baselevel = i;
            break;
         }
      }
   }

   initialized = 1;
}
Beispiel #21
0
static
void _log_roll_file(flog_file_t* lf)
{
    // 1. generate the rolled filename and move the current file to there
    _log_generate_filename(lf->filename, lf->poutput_filename);
    if (rename(lf->filename, lf->poutput_filename)) {
        printError("rotate file failed: call rename failed");
        abort();
    }
    close(lf->fd);

    // 2. open
    int fd = _lopen(lf->filename);
    if (fd < 0) {
        printError("open file failed");
        abort();
    }

    lf->fd = fd;
    lf->file_size = _log_filesize(lf);
}
Beispiel #22
0
void dbglog ( char* szFormat ... )
{
	va_list ap;
	char str [100000];

	va_start ( ap, szFormat );
	vsprintf ( str, szFormat, ap );
	strcat (str, "\r\n");
	va_end (ap);

	int file = _lopen ( DBGLOG_FILENAME, OF_WRITE );

	if ( file == -1 )
	{
		file = _lcreat ( DBGLOG_FILENAME, 0 );
	}

	_llseek ( file, 0, FILE_END );
	_lwrite ( file, str, lstrlen (str) );
	FlushFileBuffers ((HANDLE)file);
	_lclose ( file );
}
Beispiel #23
0
static void initialize_file_info(PFileVar fv, PYVar yv)
{
	if (yv->YMode == IdYSend) {
		if (fv->FileOpen) {
			_lclose(fv->FileHandle);

			if (fv->FileMtime > 0) {
				SetFMtime(fv->FullName, fv->FileMtime);
			}
		}
		fv->FileHandle = _lopen(fv->FullName,OF_READ);
		fv->FileSize = GetFSize(fv->FullName);
	} else {
		fv->FileHandle = -1;
		fv->FileSize = 0;
		fv->FileMtime = 0;
		yv->RecvFilesize = FALSE;
	}
	fv->FileOpen = fv->FileHandle>0;

	if (yv->YMode == IdYSend) {
		InitDlgProgress(fv->HWin, IDC_PROTOPROGRESS, &fv->ProgStat);
	} else {
		fv->ProgStat = -1;
	}
	fv->StartTime = GetTickCount();
	SetDlgItemText(fv->HWin, IDC_PROTOFNAME, &(fv->FullName[fv->DirLen]));

	yv->PktNumOffset = 0;
	yv->PktNum = 0;
	yv->PktNumSent = 0;
	yv->PktBufCount = 0;
	yv->CRRecv = FALSE;
	fv->ByteCount = 0;
	yv->SendFileInfo = 0;
	yv->SendEot = 0;
	yv->LastSendEot = 0;
	yv->LastMessage = 0;
}
Beispiel #24
0
/*-------------------------------------------
	save log data
---------------------------------------------*/
void Log(const char* msg)
{
	SYSTEMTIME st;
	char s[160];
	int count, index;

	GetLocalTime(&st);
	wsprintf(s, "%02d/%02d %02d:%02d:%02d ",
		st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
	strcat(s, msg);

	// save to listbox
	count = SendMessage(hwndSNTPLog, LB_GETCOUNT, 0, 0);
	if(count > 100)
		SendMessage(hwndSNTPLog, LB_DELETESTRING, 0, 0);
	index = SendMessage(hwndSNTPLog, LB_ADDSTRING, 0, (LPARAM)s);
	SendMessage(hwndSNTPLog, LB_SETCURSEL, index, 0);

	// save to file
	if(GetMyRegLong("SNTP", "SaveLog", TRUE))
	{
		HFILE hf;
		char fname[MAX_PATH];

		strcpy(fname, g_mydir);
		add_title(fname, "SNTP.txt");
		hf = _lopen(fname, OF_WRITE);
		if(hf == HFILE_ERROR)
			hf = _lcreat(fname, 0);
		if(hf == HFILE_ERROR) return;
		_llseek(hf, 0, 2);
		_lwrite(hf, s, strlen(s));
		_lwrite(hf, "\x0d\x0a", 2);
		_lclose(hf);
	}
}
Beispiel #25
0
BOOL    EXTERN LoadCP(LPCSTR filename, HGLOBAL FAR *phMem, LPCHANDLE lpCP)
{
    icHeader    CPHeader;
    HFILE       hFile;
    SINT        Res, CPSize;
    MEMPTR      mpCP;

    *phMem = 0;
    if (lpCP == NULL)
    {
        SetCPLastError(CP_NULL_POINTER_ERR);
        return(FALSE);
    }

    hFile = _lopen(filename, READ );
    if( hFile == HFILE_ERROR )
    {
        SetCPLastError(CP_FILE_OPEN_ERR);
        return(FALSE);
    }
 
    Res = _lread(hFile, (LPVOID) &CPHeader, sizeof(CPHeader));
    if( (Res == HFILE_ERROR) ||
        (Res != sizeof(CPHeader)) )
    {
        _lclose(hFile);
        SetCPLastError(CP_FILE_READ_ERR);
        return(FALSE);
    }

    // Make the initial check for validity of the profile
    if( SigtoCSIG(CPHeader.magic) != icMagicNumber )
    {
        _lclose(hFile);
        SetCPLastError(CP_FORMAT_ERR);
        return(FALSE);
    }

    CPSize = ui32toSINT(CPHeader.size);
    if( MemAlloc(CPSize, phMem, (LPMEMPTR) &mpCP) )
    {

        *lpCP = (CHANDLE) mpCP;  // Put the memory pointer as  handle
        // Read profile into  memory
         _lseek(hFile, 0L, SEEK_SET);

        while(CPSize)
        {
            Res = _lread(hFile, (LPVOID) mpCP, 4096);
            if (Res == HFILE_ERROR) 
            {
                _lclose(hFile);
                SetCPLastError(CP_FILE_READ_ERR);
                return(FALSE);
            }
            mpCP    += Res;
            CPSize  -= Res;
        }
    }else
    {
        *phMem = 0;
        _lclose(hFile);
        return(FALSE);
    }
    _lclose(hFile);
    return (TRUE);
}
Beispiel #26
0
BOOL EXTERN ValidColorSpace(LPPDEVICE lppd, LPICMINFO lpICMI, LPCSIG lpDevCS )
{
    icHeader    CPHeader;
    HFILE       hFile;
    SINT        Res;
    CSIG        CPColorSpaceTag;

    if (NULL == lpICMI)
    {
        return(FALSE);
    }
    hFile = _lopen(lpICMI->lcsDestFilename, READ);
    if( hFile == HFILE_ERROR )
    {
        return(FALSE);
    }

    Res = _lread(hFile, (LPVOID) &CPHeader, sizeof(CPHeader));
    _lclose(hFile);
    if( (Res == HFILE_ERROR) || (Res != sizeof(CPHeader)) )
    {
        return(FALSE);
    }

    // Make the initial check for validity of the profile
    if( SigtoCSIG(CPHeader.magic) != icMagicNumber )
    {
        return(FALSE);
    }
    // Make sure the profile is 'prtr'
    // SRGB98
    // if( SigtoCSIG(CPHeader.deviceClass) != icSigOutputClass )
    // {
    //     return(FALSE);
    // }
    CPColorSpaceTag = SigtoCSIG(CPHeader.colorSpace);
    *lpDevCS = CPColorSpaceTag;             // 247974

    switch ( lppd->lpPSExtDevmode->dm.iColorMatchingMethod )
    {
        case COLOR_MATCHING_ON_HOST:
            if ((CPColorSpaceTag == icSigCmyData))
//                (CPColorSpaceTag == icSigRgbData))
//                (CPColorSpaceTag == icSigGrayData))
            {
                return(FALSE);
            }
            break;
            case COLOR_MATCHING_ON_PRINTER:
            if ((CPColorSpaceTag == icSigCmyData))
//                (CPColorSpaceTag == icSigGrayData))
            {
                return(FALSE);
            }
            break;
        case COLOR_MATCHING_PRINTER_CALIBRATION:
        default:
            break;
    }
    return (TRUE);
}
Beispiel #27
0
//---------------------------------------------------------------------------
// MainWndProc
//
// Main window procedure
//
// RETURNS:     Per Windows Convention....
//---------------------------------------------------------------------------
LONG  APIENTRY MainWndProc (HWND hwnd, WORD message,
                             WPARAM wParam, LPARAM lParam)
{
    FARPROC lpProcAbout;

    switch (message)
        {
        case WM_CREATE:
            {
            RECT    r;

            // Create an edit window for the client area
            //---------------------------------------------------------------
            GetClientRect (hwnd, &r);
            hwndEdit = CreateWindow ("RBEdit", NULL,
            //hwndEdit = CreateWindow ("edit", NULL,
            //                         ES_MULTILINE |
                                     WS_BORDER |
                                     WS_CHILD | WS_CLIPCHILDREN |
                                     WS_VSCROLL | WS_HSCROLL,
                                     0,
                                     20,
                                     r.right,
                                     r.bottom-20,
                                     hwnd,
                                     0xCAC,
                                     hInst,
                                     NULL);
            ShowWindow (hwndEdit, SW_SHOWNORMAL);
            fNotify = FALSE;
            break;
            }

        case WM_SIZE:
            // Move the edit window to fit the new client area
            //---------------------------------------------------------------
            if (IsWindow (hwndEdit))
                MoveWindow (hwndEdit, 0, 20,
                                      LOWORD(lParam), HIWORD(lParam)-20, 1);
            break;

        case WM_PAINT:
            {
            HDC         hdc;
            PAINTSTRUCT ps;

            hdc = BeginPaint (hwnd, &ps);
            PaintStatus (hwnd, hdc);
            EndPaint (hwnd, &ps);
            break;
            }

        case WM_SETFOCUS:
            if (IsWindow (hwndEdit))
                SetFocus (hwndEdit);
            break;

        case WM_SYSCOLORCHANGE:
            SendMessage (hwndEdit, message, wParam, lParam);
            break;

        case WM_COMMAND:
            switch (GET_WM_COMMAND_ID (wParam, lParam))
                {
                case IDM_ABOUT:
                    lpProcAbout = MakeProcInstance ((FARPROC)About, hInst);
                    DialogBox (hInst, "AboutBox", hwnd, (WNDPROC)lpProcAbout);
                    FreeProcInstance (lpProcAbout);
                    break;

                case IDM_CRASH:
                    {
                    INT     l;

                    l = (INT)SendMessage (hwndEdit, EM_LINELENGTH, 0, -1L);
                    SendMessage (hwndEdit, EM_SETSELXY, -1,
                                 MAKELONG (l, l+3));
                    break;
                    }

                case IDM_UNDO:
                    if (!SendMessage (hwndEdit, EM_UNDO, 0, 0L))
                        MessageBeep (0);
                    break;

                case IDM_SETRO:
                    SendMessage (hwndEdit, EM_SETREADONLY, 1, 0L);
                    break;

                case IDM_SETRW:
                    SendMessage (hwndEdit, EM_SETREADONLY, 0, 0L);
                    break;

                case IDM_SETFONT:
                    SendMessage (hwndEdit, EM_SETFONT,
                                 (WORD)GetStockObject (ANSI_FIXED_FONT), 0L);
                    break;

                case IDM_CHGATTR:
                    SendMessage (hwndEdit, EM_SETLINEATTR, -1, oldattr++);

                    if (oldattr == 4)
                        oldattr = 0;
                    break;

                case IDM_NOTIFY:
                    fNotify = !fNotify;
                    SendMessage (hwndEdit, EM_SETNOTIFY, fNotify, 0L);
                    CheckMenuItem (GetMenu (hwnd), IDM_NOTIFY,
                                   fNotify ? MF_CHECKED : MF_UNCHECKED);
                    break;

                case IDM_LOADFILE:
                    {
                    HANDLE  hText;
                    LPSTR   lpText;
                    INT     file;
                    LONG    size;
                    DWORD   l1, l2;
                    CHAR    buf[80];

                    l1 = GetWindowLong (hwndEdit, 0);
                    l2 = GetWindowLong (hwndEdit, 4);
                    wsprintf (buf, "HSTATE: %X  LPSTATE: %x\r\n", l1, l2);
                    Out (buf);

                    hText = GlobalAlloc (GHND, 65536);
                    if (!hText)
                        break;
                    lpText = GlobalLock (hText);

                    l1 = GetWindowLong (hwndEdit, 0);
                    l2 = GetWindowLong (hwndEdit, 4);
                    wsprintf (buf, "HSTATE: %X  LPSTATE: %x\r\n", l1, l2);
                    Out (buf);

                    file = _lopen ("edittest.txt", OF_READ);
                    if (file != -1)
                        {
                        size = _llseek (file, 0, 2);
                        if (size > 0x0000ffff)
                            {
                            size = 0xfe00;
                            Alert (hwnd, "File truncated!");
                            }
                        _llseek(file, 0, 0);
                        lpText[_lread(file, lpText, (UINT)size)] = 0;

                    l1 = GetWindowLong (hwndEdit, 0);
                    l2 = GetWindowLong (hwndEdit, 4);
                    wsprintf (buf, "HSTATE: %X  LPSTATE: %x\r\n", l1, l2);
                    Out (buf);

                        _lclose(file);
                        Out ("Sending SETTEXT... ");

                    l1 = GetWindowLong (hwndEdit, 0);
                    l2 = GetWindowLong (hwndEdit, 4);
                    wsprintf (buf, "HSTATE: %X  LPSTATE: %x\r\n", l1, l2);
                    Out (buf);

                        file = (INT)SendMessage (hwndEdit, EM_RBSETTEXT, 0,
                                                 (LONG)lpText);
                        wsprintf (buf, "file = %d\r\n", file);
                        Out (buf);
                        if (!file)
                            Alert (hwnd, "SETTEXT Failed!");
                        }
                    else
                        Alert (hwnd, "EDITTEST.TXT not found...");
                    GlobalUnlock (hText);
                    GlobalFree (hText);
                    break;
                    }

                case 0xCAC:
                    // These (had better be) notification codes for the
                    // edit window
                    //-------------------------------------------------------
                    switch (HIWORD (lParam))
                        {
                        case EN_ERRSPACE:
                            Alert (hwnd, "Out of edit spce");
                            break;
                        case EN_LINETOOLONG:
                            Alert (hwnd, "Line too long");
                            break;
                        case EN_LINEWRAPPED:
                            Alert (hwnd, "Line too long -- CR inserted");
                            break;
                        case EN_SETCURSOR:
                            {
                            HDC     hdc;

                            hdc = GetDC (hwnd);
                            PaintStatus (hwnd, hdc);
                            ReleaseDC (hwnd, hdc);
                            break;
                            }
                        default:
                            break;
                            //Alert (hwnd, "Unknown notification code");
                        }
                    break;


                default:
                    return (DefWindowProc(hwnd, message, wParam, lParam));
                }
            break;

        case WM_DESTROY:
	    PostQuitMessage(0);
	    break;

        default:
            return (DefWindowProc (hwnd, message, wParam, lParam));
        }
    return (NULL);
}
Beispiel #28
0
/*--------------------------------------------------
  read BMP file and return bitmap handle
----------------------------------------------------*/
HBITMAP ReadBitmap(HWND hwnd, const char* fname, BOOL bTrans)
{
	BITMAPFILEHEADER bmfh;
	BYTE* pDib;
	DWORD size;
	HFILE hf;
	BITMAPINFOHEADER* pbmih;
	BYTE* pDIBits;
	HDC hdc;
	int index;
	HBITMAP hBmp;
	
	hf = _lopen(fname, OF_READ);
	if(hf == HFILE_ERROR) return NULL;
	
	size = _llseek(hf, 0, 2) - sizeof(BITMAPFILEHEADER);
	_llseek(hf, 0, 0);
	
	if(_lread(hf, (LPSTR)&bmfh, sizeof(BITMAPFILEHEADER)) !=
		sizeof(BITMAPFILEHEADER))
	{
		_lclose(hf); return NULL;
	}
	
	if(bmfh.bfType != *(WORD *)"BM")
	{
		_lclose(hf); return NULL;
	}
	
	pDib = malloc(size);
	if(pDib == NULL)
	{
		_lclose (hf); return NULL;
	}
	
	if(_lread(hf, pDib, size) != size)
	{
		_lclose(hf); free(pDib);
		return NULL;
	}
	_lclose(hf);
	
	pbmih = (BITMAPINFOHEADER*)pDib;
	// don't support OS/2 format
	if(pbmih->biSize != sizeof(BITMAPINFOHEADER))
	{
		free(pDib); return NULL;
	}
	// don't support RLE compression
	if(pbmih->biCompression != BI_RGB &&
		pbmih->biCompression != BI_BITFIELDS)
	{
		free(pDib); return NULL;
	}
	
	if(pbmih->biCompression == BI_RGB)
		pDIBits = GetDibBitsAddr(pDib);
	else
		pDIBits = pDib + sizeof(BITMAPINFOHEADER) + 3 * sizeof(DWORD);
	
	if(bTrans) // pseudo transparency
	{
		if(pbmih->biBitCount == 1)
			index = (*pDIBits & 0x80) >> 7;
		else if(pbmih->biBitCount == 4)
			index = (*pDIBits & 0xF0) >> 4;
		else if(pbmih->biBitCount == 8)
Beispiel #29
0
BOOL FAR  MergeFile(LPSTR FileName, int view)
{
    HCURSOR hSaveCursor;
    char line[MAX_USER_LINE + 1];
    int offset; //Current offset of storage in block
    int lineLen; // length of line
    BYTE prevLength; //Previous line size
    LPVIEWREC v = &Views[view];
    WORD res;
    LPDOCREC d =&Docs[v->Doc];
    LPLINEREC pCurLine, pLastLine;
    LPBLOCKDEF pCurBlock, pNewBlock;
    long y;

    Assert( v->Doc >= 0);


    if ((hFileDoc = _lopen(FileName, OF_READ)) == HFILE_ERROR)
          return ErrorBox(ERR_File_Open, (LPSTR)FileName);

    if ((pszBufferDoc = DocAlloc(DISK_BLOCK_SIZE)) == NULL) {
        ErrorBox(SYS_Allocate_Memory);
        goto error1;
    }

    dwBytesReadDoc = DISK_BLOCK_SIZE;
    dwOffsetDoc = DISK_BLOCK_SIZE;
    lineLen = 0;

    //Delete selected text if any
    if (v->BlockStatus) {

        long XR, YR;

        GetBlockCoord (view, &(v->X), &(v->Y), &XR, &YR);
        DeleteStream(view, v->X, v->Y, XR, YR, FALSE);
    }

    //Set the Hour glass cursor
          hSaveCursor = SetCursor(LoadCursor(NULL, IDC_WAIT));

    //Insert first line

    res = LoadLine(line, &lineLen, d->NbLines);
    if (res == END_OF_FILE || res == END_OF_LINE) {

        //Add a CR+LF
        if (res == END_OF_LINE) {
            line[lineLen] = CR;
            line[lineLen + 1] = LF;
            lineLen += 2;
        }
        if (!InsertBlock(v->Doc, v->X, v->Y, (WORD) lineLen, line))
            goto error2;
    }
    else {

        if (res == ERR_File_Read || res == ERR_Not_A_Text_File)
              ErrorBox(res, (LPSTR)FileName);
        goto error2;
    }

    if (res != END_OF_FILE) {

        //Get current line status (we just inserted it)

        y = v->Y;
        if (!FirstLine(v->Doc, &pCurLine, &y, &pCurBlock))
              return FALSE;

        //Get next line (just after the line we just inserted)

        if (!NextLine(v->Doc, &pCurLine, &y, &pCurBlock))
              return FALSE;

        //Set offset to StoreLine start
              offset =  (LPSTR)pCurLine - (LPSTR)pCurBlock->Data;
        prevLength = pCurLine->PrevLength;

        //Split block in 2 blocks by first allocating a new block and then
        //copying right side of block in new block

        if (!AllocateBlock(pCurBlock, pCurBlock->NextBlock, &pNewBlock))
              return FALSE;

        pLastLine = (LPLINEREC)(pCurBlock->Data + pCurBlock->LastLineOffset);
        memmove(pNewBlock->Data, (LPSTR)pCurLine,
              (LPSTR)pLastLine - (LPSTR)pCurLine + pLastLine->Length);

        //Set new old block len and new new block len
              pCurBlock->LastLineOffset = (LPSTR)pCurLine - (LPSTR)pCurBlock->Data - pCurLine->PrevLength;
        pNewBlock->LastLineOffset = (LPSTR)pLastLine - (LPSTR)pCurLine;

        //Backward links next block with new one
        if (pCurBlock->NextBlock == NULL)
              d->LastBlock = pNewBlock;
        else
              (pCurBlock->NextBlock)->PrevBlock = pNewBlock;

        //Forward link current block with new block

        pCurBlock->NextBlock = pNewBlock;

        CloseLine(v->Doc, &pCurLine, y, &pCurBlock);

        //Read and store all lines in new blocks

        res = LoadLine(line, &lineLen, d->NbLines);
        while (res == END_OF_LINE) {

            //Truncate a file too large

            if (d->NbLines >= MAX_LINE_NUMBER - 1) {
                ErrorBox(ERR_Truncate_Doc);
                res = END_OF_FILE;
                break;
            }

            if (!StoreLine(line, lineLen, &offset, &prevLength, &pCurBlock)) {
                res = END_ABORT;
                break;
            }

            res = LoadLine(line, &lineLen, ++d->NbLines);
        }

        //Take decisions
        switch (res) {

          case END_OF_FILE:

            //Store last line
            if (StoreLine(line, lineLen, &offset, &prevLength, &pCurBlock)) {

                d->NbLines++;

                //Forward link of last allocated block with new block

                pCurBlock->NextBlock = pNewBlock;

                //Backward link of new block with last allocated block

                pNewBlock->PrevBlock = pCurBlock;
                ((LPLINEREC)(pNewBlock->Data))->PrevLength = (BYTE)(lineLen + LHD);

                //Free memory

                if (!DocFree(pszBufferDoc))
                      InternalErrorBox(SYS_Free_Memory);

                //Restore cursor

                SetCursor(hSaveCursor);

                //Check syntax if C

                if (d->language == C_LANGUAGE) {
                    d->lineTop = 0;
                    d->lineBottom = d->NbLines;
                    CheckSyntax(v->Doc);
                }
                SetVerticalScrollBar(view, TRUE);

                PosXY(view, v->X, v->Y, FALSE);
                InvalidateRect(v->hwndClient, (LPRECT)NULL, FALSE);

                CloseHandle (hFileDoc);
                return TRUE;
            }
            else
                goto abort;

          case ERR_File_Read:
          case ERR_Not_A_Text_File:
            ErrorBox(res, (LPSTR)FileName);
            //Fall through

          case END_ABORT:
            {

              abort:
                SetCursor(hSaveCursor);
                break;
            }

          default:
            Assert(FALSE);
            break;
        }

    } else
          InvalidateRect(v->hwndClient, (LPRECT)NULL, FALSE);

  error2: {
        SetCursor (hSaveCursor);
        if (!DocFree(pszBufferDoc))
              InternalErrorBox(SYS_Free_Memory);
    }

  error1: {
        CloseHandle (hFileDoc);
    }

    return FALSE;
}                                       /* MergeFile() */
Beispiel #30
-1
/***********************************************************************
 *           DESKTOP_LoadBitmap
 *
 * Load a bitmap from a file. Used by SetDeskWallPaper().
 */
static HBITMAP DESKTOP_LoadBitmap( HDC hdc, const char *filename )
{
    BITMAPFILEHEADER *fileHeader;
    BITMAPINFO *bitmapInfo;
    HBITMAP hbitmap;
    HFILE file;
    LPSTR buffer;
    LONG size;

    /* Read all the file into memory */

    if ((file = _lopen( filename, OF_READ )) == HFILE_ERROR)
    {
        UINT len = GetWindowsDirectoryA( NULL, 0 );
        if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
                                  len + strlen(filename) + 2 )))
            return 0;
        GetWindowsDirectoryA( buffer, len + 1 );
        strcat( buffer, "\\" );
        strcat( buffer, filename );
        file = _lopen( buffer, OF_READ );
        HeapFree( GetProcessHeap(), 0, buffer );
    }
    if (file == HFILE_ERROR) return 0;
    size = _llseek( file, 0, 2 );
    if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
    {
	_lclose( file );
	return 0;
    }
    _llseek( file, 0, 0 );
    size = _lread( file, buffer, size );
    _lclose( file );
    fileHeader = (BITMAPFILEHEADER *)buffer;
    bitmapInfo = (BITMAPINFO *)(buffer + sizeof(BITMAPFILEHEADER));

      /* Check header content */
    if ((fileHeader->bfType != 0x4d42) || (size < fileHeader->bfSize))
    {
	HeapFree( GetProcessHeap(), 0, buffer );
	return 0;
    }
    hbitmap = CreateDIBitmap( hdc, &bitmapInfo->bmiHeader, CBM_INIT,
                                buffer + fileHeader->bfOffBits,
                                bitmapInfo, DIB_RGB_COLORS );
    HeapFree( GetProcessHeap(), 0, buffer );
    return hbitmap;
}