L
Von der aktuellen Methode?
void saveMnd( void )
{
int i,
aktPos,
tmp = 0;
bool isEnd = false;
CHARRANGE myRange;
CHARFORMAT nextFormat = { 0 },
actuallyFormat = { 0 };
TEXTRANGE myTextRange;
char buff[buffSize] = { 0 },
formString[buffSize*22] = { 0 };
FILE *myFile = NULL;
myTextRange.lpstrText = buff;
myTextRange.chrg.cpMax = -1;
myTextRange.chrg.cpMin = 0;
if( NULL != ( myFile = fopen( "./myFile.mnd", "w+" ) ) ) //datei öffnen
{
i = aktPos = 0;
tmp = SendMessage( myPaper, EM_GETTEXTRANGE, 0, (LPARAM)&myTextRange );
myRange.cpMin = aktPos;
myRange.cpMax = aktPos+1;
tmp = GetWindowTextLength( myPaper ); //die anzahl der vorhandenen Buchstaben erhalten
while( aktPos < tmp ) //bis zum letzten Buchstaben alle kopieren
{
memset( buff, 0, sizeof(buff) );
isEnd = false;
i = 0;
while( aktPos < tmp && !isEnd && i < buffSize )
{
myRange.cpMin = aktPos; //den zu selektierenden Bereich setzen
myRange.cpMax = aktPos+1;
actuallyFormat.cbSize = sizeof(CHARFORMAT);
nextFormat.cbSize = sizeof(CHARFORMAT);
SendMessage( myPaper, EM_EXSETSEL, 0, (LPARAM)&myRange ); //text selektieren
SendMessage( myPaper, EM_GETSELTEXT, 0, (LPARAM)(buff+i) ); //selektierten text auslesen
SendMessage( myPaper, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&actuallyFormat );//Charformat auslesen
aktPos++;
myRange.cpMin = aktPos; //den zu selektierenden Bereich setzen
myRange.cpMax = aktPos+1;
SendMessage( myPaper, EM_EXSETSEL, 0, (LPARAM)&myRange ); //text selektieren
SendMessage( myPaper, EM_GETSELTEXT, 0, (LPARAM)(buff+i+1) ); //selektierten text auslesen
SendMessage( myPaper, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&nextFormat ); //Charformat auslesen
if( isEqualCharFormat( &actuallyFormat, &nextFormat ) ) //wenn beide Charformate gleich sind
{
if( 0 == buff[i] && 13 == buff[i+1] ) //RETURN ersetzen
{
buff[i] = 11;
buff[i+1] = 12;
i += 2;
aktPos += 2;
}
else if( 0 != buff[i] || 0 != buff[i+1] )
i++; //i inkrementieren damit dieser Buchstabe nicht mehr überschrieben wird
}
else
isEnd = true;
}
if( '\0' != buff[0] ) //wenn das array nicht leer ist
{
getFormatString( buff, formString, &actuallyFormat ); //Text formatieren
fprintf( myFile, "%s\n", formString ); //formatierten Text in Datei schreiben
}
}
fclose( myFile );
}
}
isEqualCharFormat:
bool isEqualCharFormat( CHARFORMAT *form1, CHARFORMAT *form2 )
//this function checks if the tho CHARFORMATs are equal
{
bool sameBold = false,
sameUnderline = false,
sameItalic = false,
sameColor = false;
sameBold = (form1->dwEffects & CFE_BOLD ) == (form2->dwEffects & CFE_BOLD); //check if the both are BOLD or not BOLD
sameItalic = (form1->dwEffects & CFE_ITALIC) == (form2->dwEffects & CFE_ITALIC); //check if the both are ITALIC or not ITALIC
sameUnderline = (form1->dwEffects & CFE_UNDERLINE) == (form2->dwEffects & CFE_UNDERLINE); //check if the both are UNDERLINE or not UNDERLINE
sameColor = form1->crTextColor == form2->crTextColor; //check if the textcolor is the same
if( sameBold && sameItalic && sameUnderline && sameColor ) //if everything is the same
return true;
return false;
}
getFormatString
void getFormatString( char *text, char *formatText, CHARFORMAT *theFormat )
//This function translate the formated text into normal text, with format-informations
{
bool isItalic = false,
isBold = false,
isUnderline = false;
int R = 0,
G = 0,
B = 0;
R = (int)GetRValue( theFormat->crTextColor ); //Get the red colorvalue of the color
G = (int)GetGValue( theFormat->crTextColor ); //Get the yellow colorvalue of the color
B = (int)GetBValue( theFormat->crTextColor ); //Get the blue colorvalue of the color
isItalic = !( !( theFormat->dwMask & CFM_ITALIC ) || !( theFormat->dwEffects & CFE_ITALIC ) ); //check if its italic
isBold = !( !( theFormat->dwMask & CFM_BOLD ) || !( theFormat->dwEffects & CFE_BOLD ) ); //check if its bold
isUnderline = !( !( theFormat->dwMask & CFM_UNDERLINE ) || !( theFormat->dwEffects & CFM_UNDERLINE ) ); //check if its underline
//set the format-informations in the text
}
Da dieser Code warscheinlich "worst-case" ist brauch ich wohl nciht sagen dass ich ihn selbst geschrieben habe xD
MFG