• Advertisement

Archived

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

Redrawing a Window

This topic is 6551 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 was thinking of an idea for my final project in school, its very simple(but of course i don''t know how to do it) window which when i press tab changes the color, and the text. If someone can point me in the right direction i''d appreciate it. Thanks. - king171@hotmail.com
- http://www.cfxweb.net/mxf/

Share this post


Link to post
Share on other sites
Advertisement
Maybe I''m sleep depped again, but I''m not quite sure I understand what you want.... what needs to be IN the window, text wise? Just some text saying something like "King''s Wonderful Project", a text file, or are you wanting to change the colour of a different applications window?

For the first option, I''d recommend opening up Visual Basic, drawing a simple form with some static text, and writing code that changes the form''s background colour property and the text''s colour property.

For the second, you''d either want to take an existing VB text editor (I''m sure I''ve seen them around) and add colour changing, or use VC++ to quickly create an MFC app that resembles notepad but with trippy colours.

The last option is hard, and I''m not quite sure how I''d go about doing it. There are several window manager programs around that let you hack the way Windows looks - I''m sure that at least one of them must have source code available!

Hope that helps a bit.

Share this post


Link to post
Share on other sites
Bracket i program in C, with the WINDOWS API, but i want to have a window setup(nice and simple like the original "hellow, windows 95" application). Then when I press a button(like Tab) the background changes from white to black, and the text redraws onto the screen saying something different.

hope this clears it up.

- king171@hotmail.com
- http://www.cfxweb.net/mxf/

Share this post


Link to post
Share on other sites
King, since you''re using the windows api all you need to do is add a couple of message handlers WM_KEYDOWN, and WM_PAINT. For WM_KEYDOWN it''s simple just something like:

Share this post


Link to post
Share on other sites
(sorry bout the break (hit tab return, oops))
case WM_KEYDOWN:
switch(wParam){
case VK_TAB: //do something like change bkcolor
}
break;

and the paint function something like:
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
RECT rect;
BeginPaint(hWnd,&ps);
hDC = ps.hdc;
GetClientRect(hWnd,&rect);
FillRect(hDC,&rect,CreateSolidBrush(bkcolor));
//Draw text
ReleaseDC(hWnd,hDC);
EndPaint(hWnd,&ps);
break;

Share this post


Link to post
Share on other sites
Oh, yeah sorry, you do

InvalidateRect(hWnd,NULL,FALSE);

that will redraw the window, but before that you should change the background color and text

Share this post


Link to post
Share on other sites
And in case you don''t know about it, there''s a very useful function when drawing text :

SetBkMode(hDC, TRANSPARENT);

That way the window will only draw the actual text and not that annoying rectangle around it, hope that helps.

Share this post


Link to post
Share on other sites
Well, if I finally get what you mean, to change the background color you can have something like :

DWORD bkcolor = 0x00FFFFFF;

as a global variable and then in the WM_KEYDOWN handler, for VK_TAB put

bkcolor = 0x00FFFFFF - bkcolor;

that will switch the background color from black to white each time you press tab, and if you want it to only change once just put

bkcolor = 0x00000000;

As far as text goes, I made two global LPCSTR''s (text1 and text2) equal to the two different text messages i wanted to display and then made one more LPCSTR called text which was what was displayed and in the VK_TAB handler i put

text = (text==text1)?text2:text1;

I really hope that is what you meant, and that it helps =)

Share this post


Link to post
Share on other sites

  • Advertisement