CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2008
    Posts
    138

    RegisterClassEx and CreateWindowEx fails..

    Hello all..
    I'm trying to make window with specific requirement.. But that's not my issue. It's related to RegisterClassEx and CreateWindowEx.. Both actually fails.. I've no idea why.. I put GetLastError on both.

    After RegisterClassEx it shows Error 6 which means "The handle is invalid."

    After CreateWindowEx it shows Error 203 which means "The system could not find the environment option that was entered."

    Here's code snippet.. Please take a look.

    Code:
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         HWND         hwnd ;
         MSG          msg ;
         WNDCLASSEX   wndclass ;
    	 
    
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) CreateSolidBrush(RGB(255,255,255));
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = "WndProc";
         
         if (!RegisterClassEx (&wndclass))
         {
              DWORD eRR = GetLastError();
              MessageBox (NULL, "Registration Fails","Error", MB_ICONERROR) ;
              return 0 ;
         }
         
         hwnd = CreateWindowEx(WS_EX_TOOLWINDOW |WS_EX_LAYERED| WS_EX_APPWINDOW,
    						  "WndProc",  						
    						   NULL,							
    						   WS_POPUP,						
    						   10,							
    						   10,							
    						   100,							
    						   100,							
    						   NULL,							
    						   NULL,							
    						   hInstance,						
                                                       NULL) ;	
    
    
    	 DWORD eRR1 = GetLastError();
    
         ShowWindow (hwnd, iCmdShow) ;
         SetLayeredWindowAttributes(hwnd, RGB(255,255,255), 255, LWA_COLORKEY|LWA_ALPHA);
    
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }
    It also doesn't get into message loop..

    Thanks..
    Last edited by techie.ashish; November 12th, 2008 at 09:02 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: RegisterClassEx and CreateWindowEx fails..

    From MSDN article "WNDCLASSEX":
    hInstance
    Handle to the instance that contains the window procedure for the class.
    Is hInstance you are assigning to wndclass.hInstance correct/valid?
    Does this module contain the window procedure WndProc ?
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured