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:
If you need any more info, please ask.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; }
Thanks for taking the time to read this!!
Cheers,
Jack.



LinkBack URL
About LinkBacks




Still got a blank window...