Thread: Window 'disappears' like it isn't being redrawn properly

  1. #1
    Shadow12345
    Guest

    Window 'disappears' like it isn't being redrawn properly

    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

    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) ;
    }
    Also anything you find that isn't used anymore, or just isnt' good, point it out so I can know about it.

    Thanks

  2. #2
    Shadow12345
    Guest
    Okay uhh, nevermind, I'm dumb, I passed in HOLLOW_BRUSH to hbrbackground when I meant WHITE_BRUSH... :O

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Linking OpenGL in Dev-C++
    By linkofazeroth in forum Game Programming
    Replies: 4
    Last Post: 09-13-2005, 10:17 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. opengl code not working
    By Unregistered in forum Windows Programming
    Replies: 4
    Last Post: 02-14-2002, 10:01 PM