Jump to content
  • Advertisement
Sign in to follow this  
andyborowicz

Why is the text disappearing?

This topic is 4395 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

I'm learning the WinAPI still... I made an application that contains some edits and buttons. The edits are described with drawn text. It's of course made with the GD initiated. When I run the application everything is OK. But once I put any other window on it, ant go back to it, the text disappears... How can I solve this?

Share this post


Link to post
Share on other sites
Advertisement
Windows doesn't (by default) save the bits inside your window. When you cover up your window and then uncover it again you should get a WM_PAINT message that says it's time to redraw your bits.

Share this post


Link to post
Share on other sites
are you calling InvalidateRect() anywhere? Windows needs to know that the client window should be repainted, Invalidating the client window (or client rectangle) should do the trick :)

Share this post


Link to post
Share on other sites
the first thing in my WinMain is a call to InitWindow. And this is a function that creates my window. Looks like this:

bool initWindow(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "MainWindow";
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
wndHandle = CreateWindowEx(
WS_EX_CONTROLPARENT,
"MainWindow",
"Room Impulse Response",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);
if (!wndHandle)
return false;
hndRLX = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_GROUP | WS_CHILD | WS_TABSTOP | WS_VISIBLE | ES_NUMBER,20,25,30,20,wndHandle,(HMENU)101,hInstance,NULL);
hndRLY = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_TABSTOP | WS_VISIBLE | ES_NUMBER,90,25,30,20,wndHandle,(HMENU)102,hInstance,NULL);
hndRLZ = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,160,25,30,20,wndHandle,(HMENU)103,hInstance,NULL);
hndBX1 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,50,75,30,20,wndHandle,(HMENU)104,hInstance,NULL);
hndBY1 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,130,75,30,20,wndHandle,(HMENU)105,hInstance,NULL);
hndBZ1 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,210,75,30,20,wndHandle,(HMENU)106,hInstance,NULL);
hndBX2 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,50,100,30,20,wndHandle,(HMENU)107,hInstance,NULL);
hndBY2 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,130,100,30,20,wndHandle,(HMENU)108,hInstance,NULL);
hndBZ2 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,210,100,30,20,wndHandle,(HMENU)109,hInstance,NULL);
hndX0 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,270,25,30,20,wndHandle,(HMENU)110,hInstance,NULL);
hndY0 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,340,25,30,20,wndHandle,(HMENU)111,hInstance,NULL);
hndZ0 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,410,25,30,20,wndHandle,(HMENU)112,hInstance,NULL);
hndX = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,270,75,30,20,wndHandle,(HMENU)113,hInstance,NULL);
hndY = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,340,75,30,20,wndHandle,(HMENU)114,hInstance,NULL);
hndZ = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,410,75,30,20,wndHandle,(HMENU)115,hInstance,NULL);
hndN = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,375,100,50,20,wndHandle,(HMENU)116,hInstance,NULL);
hndButton1 = CreateWindowEx(WS_EX_WINDOWEDGE,"Button","Oblicz",WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,490,20,110,30,wndHandle,NULL,hInstance,NULL);
hndButton2 = CreateWindowEx(WS_EX_WINDOWEDGE,"Button","Zapisz dane",WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,490,55,110,30,wndHandle,NULL,hInstance,NULL);
hndButton3 = CreateWindowEx(WS_EX_WINDOWEDGE,"Button","Zapisz wykres",WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,490,90,110,30,wndHandle,NULL,hInstance,NULL);
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
hdc = GetWindowDC(wndHandle);
SetTextColor(hdc,0x00000000);
SetBkColor(hdc,0x00C8D0D4);
TextOut(hdc,10,30,"Rozmiary pomieszczenia",22);
TextOut(hdc,10,50,"X",1);
TextOut(hdc,55,50,"cm",2);
TextOut(hdc,80,50,"Y",1);
TextOut(hdc,125,50,"cm",2);
TextOut(hdc,150,50,"Z",1);
TextOut(hdc,195,50,"cm",2);
TextOut(hdc,10,80,"Współczynniki odbicia",21);
TextOut(hdc,10,100,"X1 0.",7);
TextOut(hdc,90,100,"Y1 0.",7);
TextOut(hdc,170,100,"Z1 0.",7);
TextOut(hdc,10,125,"X2 0.",7);
TextOut(hdc,90,125,"Y2 0.",7);
TextOut(hdc,170,125,"Z2 0.",7);
TextOut(hdc,260,30,"Położenie źródła",16);
TextOut(hdc,260,50,"X",1);
TextOut(hdc,305,50,"cm",2);
TextOut(hdc,330,50,"Y",1);
TextOut(hdc,375,50,"cm",2);
TextOut(hdc,400,50,"Z",1);
TextOut(hdc,445,50,"cm",2);
TextOut(hdc,260,80,"Położenie odbiornika",20);
TextOut(hdc,260,100,"X",1);
TextOut(hdc,305,100,"cm",2);
TextOut(hdc,330,100,"Y",1);
TextOut(hdc,375,100,"cm",2);
TextOut(hdc,400,100,"Z",1);
TextOut(hdc,445,100,"cm",2);
TextOut(hdc,260,125,"Czas odpowiedzi",15);
TextOut(hdc,435,125,"ms",2);
ReleaseDC(wndHandle, hdc);
return true;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by andyborowicz
OMG, my eyes!!

bool initWindow(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = "MainWindow";
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
wndHandle = CreateWindowEx(
WS_EX_CONTROLPARENT,
"MainWindow",
"Room Impulse Response",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
640,
480,
NULL,
NULL,
hInstance,
NULL);
if (!wndHandle)
return false;
hndRLX = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_GROUP | WS_CHILD | WS_TABSTOP | WS_VISIBLE | ES_NUMBER,20,25,30,20,wndHandle,(HMENU)101,hInstance,NULL);
hndRLY = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_TABSTOP | WS_VISIBLE | ES_NUMBER,90,25,30,20,wndHandle,(HMENU)102,hInstance,NULL);
hndRLZ = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,160,25,30,20,wndHandle,(HMENU)103,hInstance,NULL);
hndBX1 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,50,75,30,20,wndHandle,(HMENU)104,hInstance,NULL);
hndBY1 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,130,75,30,20,wndHandle,(HMENU)105,hInstance,NULL);
hndBZ1 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,210,75,30,20,wndHandle,(HMENU)106,hInstance,NULL);
hndBX2 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,50,100,30,20,wndHandle,(HMENU)107,hInstance,NULL);
hndBY2 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,130,100,30,20,wndHandle,(HMENU)108,hInstance,NULL);
hndBZ2 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,210,100,30,20,wndHandle,(HMENU)109,hInstance,NULL);
hndX0 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,270,25,30,20,wndHandle,(HMENU)110,hInstance,NULL);
hndY0 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,340,25,30,20,wndHandle,(HMENU)111,hInstance,NULL);
hndZ0 = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,410,25,30,20,wndHandle,(HMENU)112,hInstance,NULL);
hndX = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,270,75,30,20,wndHandle,(HMENU)113,hInstance,NULL);
hndY = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,340,75,30,20,wndHandle,(HMENU)114,hInstance,NULL);
hndZ = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,410,75,30,20,wndHandle,(HMENU)115,hInstance,NULL);
hndN = CreateWindowEx(WS_EX_CLIENTEDGE,"Edit",NULL,WS_CHILD | WS_VISIBLE | ES_NUMBER,375,100,50,20,wndHandle,(HMENU)116,hInstance,NULL);
hndButton1 = CreateWindowEx(WS_EX_WINDOWEDGE,"Button","Oblicz",WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,490,20,110,30,wndHandle,NULL,hInstance,NULL);
hndButton2 = CreateWindowEx(WS_EX_WINDOWEDGE,"Button","Zapisz dane",WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,490,55,110,30,wndHandle,NULL,hInstance,NULL);
hndButton3 = CreateWindowEx(WS_EX_WINDOWEDGE,"Button","Zapisz wykres",WS_BORDER | WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,490,90,110,30,wndHandle,NULL,hInstance,NULL);
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
hdc = GetWindowDC(wndHandle);
SetTextColor(hdc,0x00000000);
SetBkColor(hdc,0x00C8D0D4);
TextOut(hdc,10,30,"Rozmiary pomieszczenia",22);
TextOut(hdc,10,50,"X",1);
TextOut(hdc,55,50,"cm",2);
TextOut(hdc,80,50,"Y",1);
TextOut(hdc,125,50,"cm",2);
TextOut(hdc,150,50,"Z",1);
TextOut(hdc,195,50,"cm",2);
TextOut(hdc,10,80,"Współczynniki odbicia",21);
TextOut(hdc,10,100,"X1 0.",7);
TextOut(hdc,90,100,"Y1 0.",7);
TextOut(hdc,170,100,"Z1 0.",7);
TextOut(hdc,10,125,"X2 0.",7);
TextOut(hdc,90,125,"Y2 0.",7);
TextOut(hdc,170,125,"Z2 0.",7);
TextOut(hdc,260,30,"Położenie źródła",16);
TextOut(hdc,260,50,"X",1);
TextOut(hdc,305,50,"cm",2);
TextOut(hdc,330,50,"Y",1);
TextOut(hdc,375,50,"cm",2);
TextOut(hdc,400,50,"Z",1);
TextOut(hdc,445,50,"cm",2);
TextOut(hdc,260,80,"Położenie odbiornika",20);
TextOut(hdc,260,100,"X",1);
TextOut(hdc,305,100,"cm",2);
TextOut(hdc,330,100,"Y",1);
TextOut(hdc,375,100,"cm",2);
TextOut(hdc,400,100,"Z",1);
TextOut(hdc,445,100,"cm",2);
TextOut(hdc,260,125,"Czas odpowiedzi",15);
TextOut(hdc,435,125,"ms",2);
ReleaseDC(wndHandle, hdc);
return true;
}



Share this post


Link to post
Share on other sites
:) Why U quote me? These are not my words :D

I'm sorry if the code frightened you, I just copied and pasted the entire code, in disorder.

Share this post


Link to post
Share on other sites
Use [source][/source] tags to enclose long snippets of source code.

Also, you really, really shouldn't be keeping all of those controls as separate global variables, but in some kind of structure. And learn to read configuration data in from a file - instead of putting repeated calls to a function, you make a file where each line has arguments for the function, and then do a loop of reading the line, parsing the arguments out and calling the function. You get much shorter code that's much easier on the eyes, and also doesn't have to be recompiled when you change some text positioning or some stupid thing like that.

Share this post


Link to post
Share on other sites
Thanx for the advice guys. I surely will use it in future. This is my first app in WinAPI, written just for the art of writing :)

Still I need help in the 'disappearing graphics' topic :/ Anyone?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!