Exemplo n.º 1
0
void DlgPalette::OnSave() 
{
	CString filename;
	if (PromptForFileName(filename, 0,	OFN_HIDEREADONLY | OFN_PATHMUSTEXIST, FALSE, 0)){
		FILE* f;
		f=fopen(filename,"wb");
		if (f) {
			long tmp;
			fwrite("RIFF",4,1,f);
			tmp = 20 + 4*m_numcolors;
			fwrite(&tmp,4,1,f);
			fwrite("PAL data",8,1,f);
			tmp = 8 + 4*m_numcolors;
			fwrite(&tmp,4,1,f);
			tmp=0x0300;
			fwrite(&tmp,2,1,f);
			fwrite(&m_numcolors,2,1,f);
			for(int i=0;i<m_numcolors;i++){
				fwrite(&m_pal[i].rgbRed,1,1,f);
				fwrite(&m_pal[i].rgbGreen,1,1,f);
				fwrite(&m_pal[i].rgbBlue,1,1,f);
				fwrite(&m_pal[i].rgbReserved,1,1,f);
			}
			tmp=0;
			fwrite(&tmp,4,1,f);
			fclose(f);
		}
	}
}
Exemplo n.º 2
0
void CWordPadApp::OnFileOpen()
{
	// prompt the user (with all document templates)
	CString newName;
	int nType = RD_DEFAULT;
	if (!PromptForFileName(newName, AFX_IDS_OPENFILE,
	  OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, TRUE, &nType))
		return; // open cancelled

	if (nType == RD_OEMTEXT)
		m_bForceOEM = TRUE;
	OpenDocumentFile(newName);
	m_bForceOEM = FALSE;
	// if returns NULL, the user has already been alerted
}
Exemplo n.º 3
0
void DlgPalette::OnLoad() 
{
	CString filename;
	if (!PromptForFileName(filename, AFX_IDS_OPENFILE,
	  OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, TRUE, NULL))
		return; // open cancelled
	
	FILE* f;
	f=fopen(filename,"rb");

	if (f==NULL) return;

	char key[5];
	fread(key,4,1,f);
	key[4]=0;

	if (strcmp(key,"JASC")==0){
		long pos,size;
		pos = ftell(f);
		fseek(f, 0, SEEK_END);
		size = ftell(f);
		fseek(f, pos,SEEK_SET);
		char* buffer = (char*)malloc(size);
		fread(buffer,size,1,f);
		fclose(f);
		char* token;
		token = strtok(buffer,"\n");
		if (token){
			token=strtok(NULL,"\n");
			token=strtok(NULL,"\n");
			long numcolors=atol(token);
			if (numcolors>256){
				free(buffer);
				AfxMessageBox("Too much colors!");
				return;
			}
			if (numcolors!=m_numcolors){
				numcolors = min(m_numcolors,numcolors);
				AfxMessageBox("Warning: numcolors doesn't match");
			}
			long i=0;
			while (token && i<numcolors){
				token=strtok(NULL," \n");
				if (token) m_pal[i].rgbRed=atoi(token);
				token=strtok(NULL," \n");
				if (token) m_pal[i].rgbGreen=atoi(token);
				token=strtok(NULL," \n");
				if (token) m_pal[i].rgbBlue=atoi(token);
				i++;
			}
		}
		free(buffer);
		m_changed=1;
		Invalidate(0);
		return;
	}

	if (strcmp(key,"RIFF")==0){
		fseek(f,22,SEEK_SET);
		long numcolors=0;
		fread(&numcolors,2,1,f);
		if (numcolors>256){
			fclose(f);
			AfxMessageBox("Too much colors!");
			return;
		}
		if (numcolors!=m_numcolors){
			numcolors = min(m_numcolors,numcolors);
			AfxMessageBox("Warning: numcolors doesn't match");
		}
		fread(m_pal,numcolors,sizeof(RGBQUAD),f);
		for (int i=0;i<numcolors;i++){
			BYTE tmp = m_pal[i].rgbBlue;
			m_pal[i].rgbBlue = m_pal[i].rgbRed;
			m_pal[i].rgbRed = tmp;
		}
		fclose(f);
		m_changed=1;
		Invalidate(0);
		return;
	}

	fclose(f);
	AfxMessageBox("Unknown contents!");
}