Help, my texts is erased when drag the window..
I just finished searching the threads and I find that I have to use InvalidateRect to repaint the textout, which it works if I have only one line of text displaying, but I have 5lines of texts so when i drag that window displaying texts off the screen or cover it up by another window, my texts get erased except the last text still displaying so does anybody know how can I fix this problem?
[392 byte] By [
mase] at [2007-11-20 11:47:58]

# 1 Re: Help, my texts is erased when drag the window..
Yep I do, in your WM_PAINT handler simply redraw the text using TextOut I guess...
And your welcome. :)
# 2 Re: Help, my texts is erased when drag the window..
Yep I do, in your WM_PAINT handler simply redraw the text using TextOut I guess...
And your welcome. :)
thanks for responding, and yep I use WM_PAINT in my main WndProc then I call TextOut under WM_PAINT. If it only displays one line of text then it works nicely, but when it prints two lines of texts for example, and then I move that window off screen or cover it up by another window, the first line gets erased except the the second line... It seems the first line doesn't get stored or something.
mase at 2007-11-9 13:34:05 >

# 3 Re: Help, my texts is erased when drag the window..
look at this thread:
http://www.dev-archive.com/forum/showthread.php?t=437491
it is the same thing, but you are writing text instead of drawing lines.
you can either store all the text so that you can write it all again for each WM_PAINT message, or you can use a memory DC that is drawn to the screen at each refresh.
# 4 Re: Help, my texts is erased when drag the window..
Give me an example of what's goin' on and I'll help you(well I'll try :)).
# 5 Re: Help, my texts is erased when drag the window..
I didn't copy all the code because it's kind of long, so as you can see if the button, magnifyOn, get clicked then it will output the text. If I keep pressing the same button to print more than one lines of text then I run into problem as I described earlier.
Feel free to ask me any question about my code, and thanks for your guys time looking at it.
//global variables
int textPosition = 350;
const int maxDisplayLine = 5;
int currentDisplayLinePosition = 0;
int textLength = 0;
LPSTR id = NULL;
//this function will update all the values for the global variables so they can
//be used when the WM_PAINT calls
void zoomTextDescription(LPSTR descriptionID, int length, int posY)
{
HWND menuWindow = FindWindow(NULL, TEXT("My Window"));
//display text 5 lines maximum
if(currentDisplayLinePosition < maxDisplayLine)
{
currentDisplayLinePosition +=1;
textPosition = posY;
textLength = length;
id = descriptionID;
InvalidateRect(menuWindow, NULL, FALSE);
}
else //even though the condition is fail, but there is one text description
{ //left of that fail condition need to display
currentDisplayLinePosition = 0;
textPosition = 350;
textLength = length;
id = descriptionID;
InvalidateRect(menuWindow, NULL, FALSE);
}
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_MENU_ZOOMme: //menu command
{
//dialog box
DialogBox(g_hInstance, MAKEINTRESOURCE(IDD_zoomCommand), hwnd, AboutDlgProc);
}
break;
case WM_PAINT:
{
HDC hdc = GetDC(hwnd);
TextOut(hdc, 5, textPosition, (LPCWSTR)id, textLength);
ReleaseDC(hwnd, hdc);
}
break;
case WM_DESTROY:
{
PostQuitMessage(0);
}
break;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}
BOOL CALLBACK AboutDlgProc(HWND dlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_magnifyOn: //magnifyOn button
{
zoomTextDescription((LPSTR)TEXT("Magnify On"), (int)strlen("Magnify On"), textPosition +=18);
}
break;
case SC_CLOSE:
case WM_DESTROY:
//case WM_QUIT:
case WM_CLOSE:
{
EndDialog(dlg, 0);
PostQuitMessage(0);
return TRUE;
}
break;
}//end of COMMAND message switch case
}//end of message switch case
return FALSE;
}
mase at 2007-11-9 13:37:06 >

# 6 Re: Help, my texts is erased when drag the window..
look at this thread:
http://www.dev-archive.com/forum/showthread.php?t=437491
it is the same thing, but you are writing text instead of drawing lines.
you can either store all the text so that you can write it all again for each WM_PAINT message, or you can use a memory DC that is drawn to the screen at each refresh.
I was thinking of doing that too, but I thought maybe there is easier way to do it; maybe just copying that specific window screen then repaint it somehow with the same information.
mase at 2007-11-9 13:38:04 >

# 7 Re: Help, my texts is erased when drag the window..
In your code you haven't added the second piece of text.
# 8 Re: Help, my texts is erased when drag the window..
In your code you haven't added the second piece of text.
I think the text will get added repeatedly if click on the button, IDC_magnifyOn:
case IDC_magnifyOn: //magnifyOn button
{
zoomTextDescription((LPSTR)TEXT("Magnify On"), (int)strlen("Magnify On"), textPosition +=18);
}
Text will be added vertically and line after line until it reaches 5maximum lines then it will reset the position starting from the 350.
mase at 2007-11-9 13:40:10 >

# 9 Re: Help, my texts is erased when drag the window..
I'm sorry I don't know if I can help you because I simply don't understand.
# 10 Re: Help, my texts is erased when drag the window..
I was thinking of doing that too, but I thought maybe there is easier way to do it; maybe just copying that specific window screen then repaint it somehow with the same information.
i'm afraid that using a memory DC is pretty much the easiest way to do it.
i suppose you could do a dirty fix of
case WM_ERASEBKGND :
{
return 0;
}
this will stop the window being erased when you drag it (before it is redrawn with only one text message) but you will still get all sorts of problems when you drag it off of the screen or cover it with another window etc..
you have to keep a record of what you want to draw yourself.
you can do this two ways:
(1) keep a list of all the strings somewhere (e.g. in an array of strings) and then TextOut() ALL of the strings each time you redraw the window.
(2) draw them once to a bitmap in a memory DC, and just draw the memory DC to the screen at each refresh.
it depends what you want the strings for and why you are displaying them as to which option is most appropriate. there are probably other ways, but variations on a theme - the important thing is that windows is not going to remember things for you, if you want to draw something again you have to store the information somewhere.
# 11 Re: Help, my texts is erased when drag the window..
i'm afraid that using a memory DC is pretty much the easiest way to do it.
i suppose you could do a dirty fix of
case WM_ERASEBKGND :
{
return 0;
}
this will stop the window being erased when you drag it (before it is redrawn with only one text message) but you will still get all sorts of problems when you drag it off of the screen or cover it with another window etc..
you have to keep a record of what you want to draw yourself.
you can do this two ways:
(1) keep a list of all the strings somewhere (e.g. in an array of strings) and then TextOut() ALL of the strings each time you redraw the window.
(2) draw them once to a bitmap in a memory DC, and just draw the memory DC to the screen at each refresh.
it depends what you want the strings for and why you are displaying them as to which option is most appropriate. there are probably other ways, but variations on a theme - the important thing is that windows is not going to remember things for you, if you want to draw something again you have to store the information somewhere.
Thanks you for your suggestion. I will create the array and store information just like you suggested in the first option.
mase at 2007-11-9 13:43:05 >

