Displaying Text

This is a discussion on Displaying Text within the C++ Programming forums, part of the General Programming Boards category; Hello all Basically, I'm a PHP coder, and I've decided to take have a bash at C. The two languages ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    3

    Displaying Text

    Hello all

    Basically, I'm a PHP coder, and I've decided to take have a bash at C. The two languages are so similiar, I think I've pretty much picked it up ok. I can handle command line stuff fine, it's just this stupid windows thing that I can't do.

    So, I'm having a bit of a problem with the windows api. I'm just trying to display a window with some text in it...

    But the text just doesn't display!! I'm using DrawTextEx()...I would make a guess it's something to do with that. I'm on windows XP, and using CodeBlocks as my compiler.

    Here's my code:

    Code:
    #include <windows.h>
    
    const char Window_Class[] = "WindowClass";
    
    //window callback handler
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	//switch message...
    	switch(msg)
    	{
    		//close window
    		case WM_CLOSE:
                MessageBox(hwnd, "Bye", ":)", 0);
    			DestroyWindow(hwnd);
    		break;
    		//display window
    		case WM_PAINT:
                RECT rcClient;
    			PAINTSTRUCT ps;
    			HDC hdc = BeginPaint(hwnd, &ps);
    
    			DrawTextEx(hdc, "Hello...world?"+'\0', -1, &rcClient, DT_CENTER, NULL);
    		break;
    		//register window process
    		default:
    			return DefWindowProc(hwnd, msg, wParam, lParam);
    		break;
    	}
    
    	return 0;
    }
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
        char *lpCmdLine, int nCmdShow)
    {
    	//register windows classes
    	WNDCLASSEX  window;
    	HWND        hwnd;
    	MSG         msg;
    
    	//register window with....windows ;)
    	window.cbSize           = sizeof(WNDCLASSEX);
    	window.style		    = 0;
    	window.lpfnWndProc	    = WndProc;
    	window.cbClsExtra	    = 0;
    	window.cbWndExtra	    = 0;
    	window.hInstance	    = hInstance;
    	window.hIcon		    = LoadIcon(NULL, IDI_APPLICATION);
    	window.hCursor		    = LoadCursor(NULL, IDC_ARROW);
    	window.hbrBackground    = (HBRUSH) (COLOR_WINDOW + 1);
    	window.lpszMenuName     = NULL;
    	window.lpszClassName    = Window_Class;
    	window.hIconSm		    = LoadIcon(NULL, IDI_APPLICATION);
    
    	//...
    	RegisterClassEx(&window);
    
    	//create the window
    	hwnd = CreateWindowEx(
    		WS_EX_CLIENTEDGE,
    		Window_Class,
    		"Window!",
    		WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT, CW_USEDEFAULT, 500, 250,
    		NULL, NULL, hInstance, NULL);
    
    	//run...
    	ShowWindow(hwnd, nCmdShow);
    	UpdateWindow(hwnd);
    
    	//run the message loop
    	while(GetMessage(&msg, NULL, 0, 0) > 0)
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	return msg.wParam;
    }
    If you need any more info, please ask.
    Thanks for taking the time to read this!!

    Cheers,
    Jack.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,264
    It's been a long time since I've done Windows programming, but I think you need to call EndPaint() after your DrawText call.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    3
    No...didn't make a difference unfortunately Still got a blank window...

    Thanks for the suggestion anyway.

    Any other ideas...?

    Regards,
    Jack.

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    3
    Aha! After reading a load of MSDN docs, I found TextOut(). Works perfectly. Thanks for your help anyway bithub

    Cheers,
    Jack.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Displaying text in a window
    By thetinman in forum Windows Programming
    Replies: 4
    Last Post: 06-30-2006, 01:11 PM
  2. Help displaying line numbers of a text document
    By Japatron in forum C Programming
    Replies: 4
    Last Post: 05-04-2006, 02:34 PM
  3. displaying text files, wierd thing :(
    By Gades in forum C Programming
    Replies: 2
    Last Post: 11-20-2001, 05:18 PM
  4. Problems displaying content of a text file
    By melissa in forum C++ Programming
    Replies: 5
    Last Post: 11-12-2001, 06:13 PM
  5. displaying text with DirectX
    By MechanicX in forum Game Programming
    Replies: 4
    Last Post: 09-24-2001, 07:28 PM

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