This topic is now archived and is closed to further replies.

Device Context Help

This topic is 5653 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;
	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 -;								// 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 )
			G.length = scrnX;
			G.y = ( ( G.Line ) * nLine );
			InvalidateRect( G.hWnd, NULL, FALSE );
			//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 );
		//TextOut( hDC, x, y, szBuf, length  );

		G.y = ( ( G.Line ) * nLine );
		InvalidateRect( G.hWnd, NULL, FALSE );

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;

			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 );

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...

Share this post

Link to post
Share on other sites