I have a simple windows application with the winapi. It compiles and runs. The only part I actually wrote myself was WinMain, the rest is from a charles petzold ebook. Anyways it seems as though the window isn't being drawn properly because it 'fuzzes out'...well run it for yourself and see!
btw it may be because some of these methods are old, for example I'm not using any of the 'ex' methods, i.e windowsclassex, createwindowex, etc etc
Also anything you find that isn't used anymore, or just isnt' good, point it out so I can know about it.Code:/*------------------------------------------------------------ HELLOWIN.C -- Displays "Hello, Windows 98!" in client area (c) Charles Petzold, 1998 ------------------------------------------------------------*/ #include <windows.h> LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; //WinMian accepts HINSTANCE, HINSTANCE, LPSTR, INT //does: //declareshwnd, msg, char(for textout), wndclass //set up attributes for window class //register window class //while getmessage translate message, dispatch message int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, INT icmdLine) { char * Message = "Uhh, HI!"; char * ClassName = "Window class"; char * MenuName = "This is the menu"; char * WindowName = "This is the window"; WNDCLASS WindowClass; HWND hWnd; MSG msg; WindowClass.cbClsExtra = 0; WindowClass.cbWndExtra = 0; WindowClass.hbrBackground = (HBRUSH)GetStockObject(HOLLOW_BRUSH); WindowClass.hCursor = LoadCursor(hInstance, IDC_APPSTARTING); WindowClass.hIcon = LoadIcon(hInstance, IDI_WARNING); WindowClass.hInstance = hInstance; WindowClass.lpfnWndProc = WndProc; WindowClass.lpszClassName = ClassName; WindowClass.lpszMenuName = MenuName; WindowClass.style = CS_HREDRAW | CS_VREDRAW; if(!RegisterClass(&WindowClass)) return 0; if(!(hWnd = CreateWindow(ClassName, WindowName, WS_OVERLAPPEDWINDOW,0, 0, 1024, 768, NULL,NULL, hInstance, NULL))) return 0; ShowWindow(hWnd, icmdLine); UpdateWindow(hWnd); while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc ; PAINTSTRUCT ps ; RECT rect ; switch (message) { case WM_CREATE: //PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ; return 0 ; case WM_PAINT: hdc = BeginPaint (hwnd, &ps) ; GetClientRect (hwnd, &rect) ; DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER) ; EndPaint (hwnd, &ps) ; return 0 ; case WM_DESTROY: PostQuitMessage (0) ; return 0 ; } return DefWindowProc (hwnd, message, wParam, lParam) ; }
Thanks



LinkBack URL
About LinkBacks


