Invalid windowhandle

This is a discussion on Invalid windowhandle within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I have done errorchekcing all and that, but at SOME points in my program, MoveWindow() returns error 1400, which ...

  1. #1
    Politics&Cpp geek Da-Nuka's Avatar
    Join Date
    Oct 2004
    Posts
    104

    Invalid windowhandle

    Hi.
    I have done errorchekcing all and that, but at SOME points in my program, MoveWindow() returns error 1400, which is invalid windowhandle. Sometimes, later in the program, it works, even i havent done anything new to the handle!

    I post some relevant code, and the full code included
    The function which creates the window and return a handle
    Code:
    HWND CreateInputWindow(const char* AppName) {
         HWND returnHWND;
         WNDCLASS wndclass;
         wndclass.style         = CS_HREDRAW | CS_VREDRAW;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.lpfnWndProc   = InputProc;
         wndclass.hIcon         = NULL;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.lpszMenuName  = NULL;
         wndclass.lpszClassName = AppName;
         wndclass.hInstance     = g_hInstance ;
         wndclass.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(255,255,255));
    
                if (!RegisterClass (&wndclass)) {
                MessageBox (NULL, TEXT ("Could not register windows class. Shutting down.."), AppName, MB_ICONERROR) ;
                return (HWND)NULL ; // Error, exit and return
         }
    
         returnHWND=CreateWindow(AppName,AppName,WS_CHILD|WS_VISIBLE,0,0,0,0,output_W,(HMENU) ID_INPUT_W,g_hInstance,NULL);
         
                         
    
    
    
                if(returnHWND==NULL) {
                MessageBox(NULL,"Call to CreateWindow() failed", "Error", MB_OK);
                return (HWND) NULL; // Error, exit and return
         }
    
    return returnHWND;
    }
    In the WinMain() function:
    Code:
         input_W=CreateInputWindow(wndClassInput);
         ShowWindow (input_W, g_CmdShow) ;
         UpdateWindow (input_W) ;
    In the MessageProcedure:
    Code:
    case WM_SIZE:
      if(MoveWindow(input_W,0,0,200,200,true)==0) {
         ReportError(GetLastError(),"MoveWindow()"); //This returns 1400...
         }
    return 0;
    Attached Files Attached Files

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Sometimes WM_SIZE messages are issued before WM_CREATE or during system processing of CreateWindowEx, hence the invalid handle error.

    I wouldn't worry about it; if MoveWindow fails in the context you're using it then it's not a problem but, if perfectionism is your thing, then just check for a non-NULL window handle prior to issuing the MoveWindow call.

    edit: Alternatively, set the value of HWND variable, input_W within your WM_CREATE handler; as this message is sent during system processing of CreateWindowEx there's a good chance that handle will be valid for the first WM_SIZE - or just use the window handle delivered to your window procedure as it will be valid.
    Last edited by Ken Fitlike; 03-06-2005 at 05:44 AM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 03:35 PM
  2. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Nested loop frustration
    By caroundw5h in forum C Programming
    Replies: 14
    Last Post: 03-15-2004, 08:45 PM
  5. Flood of errors when include .h
    By erik2004 in forum C++ Programming
    Replies: 14
    Last Post: 12-07-2002, 06:37 AM

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