Thread: Yet another Question =)

  1. #1
    Labelizm
    Guest

    Yet another Question =)

    I added a option in the menu to switch text colors betweeen red, green, blue, yellow, and a custom defined hex value, now what i need to do is "refresh" my rect so that the color changes take effect, i am storing the hex valu in an unsigned long, thats value changes when they select a color, and it defaults to green...

    so i just need to refresh this rect and ill be good to go...

    i know im probably asking WAY too many questions, but im somewhat new to the windows API, im used to OpenGL.

  2. #2
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    What rect? a selected color rect? There's a really easy API called FillRect that you can just specify the color and location on a dc. I hope that's what you are looking for.

  3. #3
    Labelizm
    Guest
    the rect thats generated using the Win32 AppWizard in MSVC++ 6

  4. #4
    labelizm
    Guest
    I have color oprion in my menu for the app...

    heres how they work to change the colors, (well they dont work)
    Code:
    case IDM_RTXT:
    				   col=0x00FF0000;
    				   break;
    and that doesnt update the text color from the default green to red, so i tried...

    Code:
    case IDM_RTXT:
    				   col=0x00FF0000;
                                                                       UpdateWindow(hWnd);
    				   break;
    and that dont work either...

    im using MSVC++ on windows98SE and building the application from the Win32 Application AppWizards Simple Application,

    any help is greatly appreciated.

  5. #5
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    so if this is a dialog box then you certainly have the HWND available to you. you can draw directly on it. But that's not what you're looking for. There must be a call you can send the new color into in that control. Sorry, can't help much with MFC.

  6. #6
    Labelizm
    Guest
    its not MFC, its just win32...

  7. #7
    Labelizm
    Guest
    Code:
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	int wmId, wmEvent;
    	PAINTSTRUCT ps;
    	HDC hdc;
    	TCHAR szTest[MAX_LOADSTRING];
    	LoadString(hInst, IDS_ColorTest, szTest, MAX_LOADSTRING);
    
    	switch (message) 
    	{
    		case WM_COMMAND:
    			wmId    = LOWORD(wParam); 
    			wmEvent = HIWORD(wParam); 
    			// Parse the menu selections:
    			switch (wmId)
    			{
    				case IDM_RFNT:
    				   col=0x00FF0000;
    				   break;
    				case IDM_ABOUT:
    				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
    				   break;
    				case IDM_EXIT:
    				   DestroyWindow(hWnd);
    				   break;
    				default:
    				   return DefWindowProc(hWnd, message, wParam, lParam);
    			}
    			break;
    		case WM_PAINT:
    			hdc = BeginPaint(hWnd, &ps);
    			// TODO: Add any drawing code here...
    			RECT rt;
    			GetClientRect(hWnd, &rt);
    			SetBkMode(hdc, TRANSPARENT);
    			SetTextColor(hdc, col);
    			DrawText(hdc, szTest, strlen(szTest), &rt, DT_CENTER);
    			EndPaint(hWnd, &ps);
    			break;
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    		default:
    			return DefWindowProc(hWnd, message, wParam, lParam);
       }
       return 0;
    }

  8. #8
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793
    You have szText as a local variable that you dont seem to be setting....also remember all you your variables will lose scope after each message unless you declare them static

  9. #9
    Labelizm
    Guest
    now im really confused, I know for a fact now that i have to update the view some how... because i added in a lil bit of code to only draw text once a color variable becomes 2, i know the value is changing like it should because i also have a message box pop up to tell me... hertes the code that draws the window...

    Code:
    		case WM_PAINT:
    			hdc = BeginPaint(hWnd, &ps);
    			// TODO: Add any drawing code here...
    			RECT rt;
    			GetClientRect(hWnd, &rt);
    			SetBkMode(hdc, TRANSPARENT);
    			SetTextColor(hdc, col);
    			DrawText(hdc, szTest, strlen(szTest), &rt, DT_CENTER);
    			if (color==2)
    				DrawText(hdc, "\n\nTESTING", strlen("\n\nTESTING"), &rt, DT_CENTER);
    			EndPaint(hWnd, &ps);
    			break;
    when i set the integer to 2 via a menu, it doesnt draw the text like it should... if i taske out the if statement it draws fine... so i have to find a way to update the window so that it draws when ever a change was made...

  10. #10
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    this question is making no sense to me. "col" is the color of the text isn't it? Where the heck is this imaginary rect you're trying to change? are you talking about invalidating the rect that contains the text? if so, InvalidateRect() should do what you're after. Otherwise this doesn't make any sense.

    I am starting to think you're talking about the window client area. if so, MAN you threw me off.

  11. #11
    Unregistered
    Guest
    yes, col is the unsigned long that stores the hex COLORREF, it defaults to 0x0000FF00 (green), when i update col however, the color of the text doesnt update... maybe i should put the entire source on my website.... because im getting confused aswell hehe... ill upload the source in a sec, ill zip it up now

  12. #12
    Registered User
    Join Date
    Jul 2002
    Posts
    273
    ok, in that case it's easy

    ::InvalidateRect(hWnd, NULL, TRUE);

    after you set the col value will force a WM_PAINT to happen

  13. #13
    Labelizm
    Guest
    Thanks, that works good

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM