Thread: Problem with making static text using my class

  1. #1
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034

    Problem with making static text using my class

    Its wierd. It allows me to make the main window, but when I go and make static text (which is also a window of course) using the same class.. it compiles but on running the program it always returns my custom error.

    Code:
    BOOL WinProcedure::Create(DWORD argdwExStyle, LPCTSTR arglpClassName, LPCTSTR arglpWindowName, DWORD argdwStyle, int argx, int argy, int argnWidth, int argnHeight, HWND arghWndParent, HMENU arghMenu, HINSTANCE arghInstance, LPVOID arglpParam)
    {
    
      wHndl = CreateWindowEx(
              argdwExStyle,
              arglpClassName,
              arglpWindowName,
              argdwStyle,
              argx,
              argy,
              argnWidth,
              argnHeight,
              arghWndParent,
              arghMenu,
              arghInstance,
              arglpParam);
        
        
      if(wHndl == NULL) {
        ErrorDef->Exit("!(wHndl == NULL)", arglpWindowName, "window name"); // The error returned
      return false;
      } else {
      return true;
      }
    }
    Code:
      WinProcedure *WinMainDef = new WinProcedure(); // Angel Child :)
      WinProcedure *WinChildDef = new WinProcedure(); // Problem Child ;)
    
      WinMainDef->Register(WndAppName, WndProcessor, CS_VREDRAW | CS_HREDRAW, hThisInstance, LoadIcon(NULL, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW), (HBRUSH)(COLOR_WINDOW), MAKEINTRESOURCE(IDM_MYMENURESOURCE), sizeof(WNDCLASSEX), LoadIcon(NULL, IDI_APPLICATION), 0, 0);
      WinMainDef->Create(0, WndAppName, WndTitle, WS_SYSMENU | WS_OVERLAPPED | WS_CAPTION | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hThisInstance, NULL);
      WinMainDef->Show(nFunsterStil); //WinMainDef is processed fine.
    
      
      WinChildDef->Create(0,"static","Hello World!", WS_CHILD | SS_CENTER | WS_VISIBLE, 120, 130, 135, 28, WinChildDef->retWHndl(), NULL, hThisInstance, NULL); // WinChildDef is not processed. It is returning NULL.
    I'ved tried blocking the WinMainDef code out (and the define of it) to see if its doing this because they share the same class. Nada, still get the error.

    The error returns when Create returns NULL, but why would it have any reason to do that!

    Help a guy out,

  2. #2
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    My guess is that you have to give it a parentHWND and not NULL.

    edit: just ran across this on MSDN:

    A child window must have a parent window. The parent window can be an overlapped window, a pop-up window, or even another child window. You specify the parent window when you call CreateWindowEx. If you specify the WS_CHILD style in CreateWindowEx but do not specify a parent window, the system does not create the window.
    Last edited by Darryl; 06-16-2005 at 01:15 PM.

  3. #3
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Darryl
    My guess is that you have to give it a parentHWND and not NULL.

    edit: just ran across this on MSDN:
    Yes!

    That worked, I wasnt giving it NULL for the parent though.. like an idiot I was saying it was the parent of itself, returning its own HWND, LOL

    Thanks a lot it works now

  4. #4
    Tropical Coder Darryl's Avatar
    Join Date
    Mar 2005
    Location
    Cayman Islands
    Posts
    503
    Oops I was one off in reading your parameters, I was looking at next one over, but still glad that worked out.

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    You should also cast the HMENU param to the controls int ID number if using the child style. Not important if only one control but may be if you have multiple controls of same type on same dlg. (as your code gives them all the same ID number of 0)
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with Free.
    By chakra in forum C Programming
    Replies: 9
    Last Post: 12-15-2008, 11:20 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Linking errors with static var
    By Elysia in forum C++ Programming
    Replies: 8
    Last Post: 10-27-2007, 05:24 PM
  4. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  5. static vector<...> in class problem.
    By alkis_y3k in forum C++ Programming
    Replies: 5
    Last Post: 01-29-2003, 04:13 PM