Im writing a Eprom Programmer Front End. I have a predefinded window size. I want to display all the messages and text, and eventually the hex file bytes on the main window. So what I did was I wrote two functions.... void DisplayText( void ) and void WrapText( int maxStringLen );
Heres the code:
void DisplayText( void )
{
static TEXTMETRIC textInfo;
HDC hDC = NULL;
static int scrnX = 0; // Used for screen height maximum
static int scrnY = 0; // Used for screen width maximum
//int length; // Used for length of string
RECT windowRect;// Current Window Rect
static int nLine;
hDC = GetDC( G.hWnd ); // Get the current Device Context
GetTextMetrics( hDC, &textInfo ); // Get the text info.
G.length = strlen(G.szBuf ); // Get the length of the string buffer,
GetWindowRect( G.hWnd, &windowRect );
scrnX = (windowRect.right- windowRect.left) / textInfo.tmMaxCharWidth; //Calculate the number of Chars that can fit on a screen
scrnY = windowRect.bottom - windowRect.top; // Calculate the number of lines that can fit on the screen
nLine = textInfo.tmHeight; // Get the Height of the current Font
// Set position to start printing to
G.x = 0; // Always start at the beginning of the line
G.y = ( ( G.Line + 1 ) * nLine ); // Calculate the next line
// Test the length of the string. If the string is longer than the screen
// Wrap the text to the next line.
if( G.length > scrnX )
{
do{
G.length = scrnX;
G.y = ( ( G.Line ) * nLine );
InvalidateRect( G.hWnd, NULL, FALSE );
G.Line++;
//TextOut( hDC, x, y, szBuf, scrnX );
WrapBuffer( scrnX ); // Pass the Buffer, and Crop value
G.length = strlen( G.szBuf );
}while( G.length > scrnX );
G.y = ( ( G.Line ) * nLine );
InvalidateRect( G.hWnd, NULL, FALSE );
G.Line++;
}
else
{
//TextOut( hDC, x, y, szBuf, length );
G.y = ( ( G.Line ) * nLine );
InvalidateRect( G.hWnd, NULL, FALSE );
G.Line++;
}
}
void WrapBuffer( int scrnX )
{
int length = 0;
length = strlen(G.szBuf);
for( int i = 0; i < length; i++ )
{
if( G.szBuf[i+(scrnX+1)] == NULL )
{
G.szBuf[ i ] = NULL;
}
else
G.szBuf[i] = G.szBuf[i+(scrnX+1)];
}
}
And in my WM_PAINT I Have
case WM_PAINT:
HDC hDC;
// Paint the screen
hDC = BeginPaint( hWnd, & ps );
// Dump the contents of the String Buffer to the screen
TextOut( hDC, G.x, G.y, G.szBuf, G.length );
EndPaint( hWnd, & ps );
break;
Now my problem is that the screen keeps refreshing and I only get the last line of text I write to it.....I know there is a way of fixing this by creating a virtual DC to draw too, but Im not exactly sure how to do this.....any help would be well appreciated....its a small but annoying problem Im having. I know the answer is under my nose but I can''t figure it out....maybe I need more coffee..hehe...thnx dudes.
-=Carnage=-
Let the carnage begin...