2 questions

This is a discussion on 2 questions within the Windows Programming forums, part of the Platform Specific Boards category; 1. In textout(), what do I use to do line breaks (like \n in cout) 2. my program has an ...

  1. #1
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110

    2 questions

    1. In textout(), what do I use to do line breaks (like \n in cout)
    2. my program has an very annoying glitch, when you hit north you must close the command toolbar to actually go north (for text-based rpg)
    Code:
    long room = 1;
    long _north = 1;
    long _south;
    
    BOOL CALLBACK ToolDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	switch(Message)
    	{
    		case WM_COMMAND:
    			switch(LOWORD(wParam))
    			{
    				case IDC_NORTH:
    					room = _north;
    				break;
    				case IDC_SOUTH:
    					room = _south;
    				break;
    				
    			}
    		break;
    		default:
    			return FALSE;
    	}
    	return TRUE;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
    	char buff[2560] = {0}; // A character string for "filling" with text to print
    	
    	HDC hdc = NULL; // An hdc to be "filled" if printing text to screen
    
    	RECT rect = {0}; // This will be used to "paint the window" to white
    					// (we need a RECT defining the windows dimensions to do this)
    
    	switch(Message)
    	{
    		case WM_CREATE:
    			g_hToolbar = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_TOOLBAR),
    				hwnd, ToolDlgProc);
    			if(g_hToolbar != NULL)
    			{
    				ShowWindow(g_hToolbar, SW_SHOW);
    			}
    			else
    			{
    				MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",	
    					MB_OK | MB_ICONINFORMATION);
    			}
    		break;
    		case WM_COMMAND:
    			switch(LOWORD(wParam))
    			{
    				case ID_FILE_EXIT:
    					PostMessage(hwnd, WM_CLOSE, 0, 0);
    				break;
    				case ID_DIALOG_SHOW:
    					ShowWindow(g_hToolbar, SW_SHOW);
    				break;
    				case ID_DIALOG_HIDE:
    					ShowWindow(g_hToolbar, SW_HIDE);
    				break;
    			}
    		break;
    		case WM_CLOSE:
    			DestroyWindow(hwnd);
    		break;
    		case WM_DESTROY:
    			DestroyWindow(g_hToolbar);
    			PostQuitMessage(0);
    		break;
    		default:
    			return DefWindowProc(hwnd, Message, wParam, lParam);
    	}
       while (room != 0) {
    	   if (room == 1) {
    			hdc = GetDC(hwnd);
    			GetClientRect(hwnd,&rect);
    			FillRect(hdc,&rect,(HBRUSH)GetStockObject(WHITE_BRUSH));
    			sprintf(buff,"Your head...\r\nIt hurts, you can\'t feel your fingers, everything feels so numb, so cold...\r\nYou feel dizzy and sick, you wonder where you are...\r\nAll around you is white, it\'s cold, is this snow?  You\'re surrounded by snow!\r\nYou can\'t remember mutch, all you remember is pain, a powerful pain in your back.\r\nWhy do you hurt so much, where you left here?  Or are you travelling on your own?\r\nBut now is not the time to ponder, perhaps you should travel somewhere...\r\n");
    			SetTextColor(hdc,RGB(0,0,0));
    			TextOut(hdc,0,0,buff,istrlen(buff));
    			ReleaseDC(hwnd,hdc);
    		}
    		room = 0;
    	}
    
    	return 0;
    }

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Trying using DrawText instead of TextOut. I personally perfer using static multiline edit boxes when I'm dealing with a bunch of text. With DrawText I think \n is enough, but in the edit box you need \r\n.

    About the glitch, I have no idea since I haven't been successful when it comes to dialog boxes.

  3. #3
    Spaced Cadet
    Join Date
    Aug 2003
    Posts
    110
    how do I use drawtext()?
    same way or what? I only saw examples of textout()

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    >>long _south;

    No definition to south so i assume the problem will occur with south as well.

    The reason you have to close the tool dlg (I think) is so the messages to the app will then (again) be routed to the WndProc() callback instead of the ToolDlgProc() .
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 08:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21