Thread: stuffed up window proc.

  1. #1
    Registered User headexplodes's Avatar
    Join Date
    Aug 2001
    Posts
    26

    Angry stuffed up window proc.

    hi,

    I have a win32 program that creates 3 windows.

    The first window is the parent for the second, and the first one is never displayed and does not need to recieve messages. (the first window is only to stop the second one appearing on the task bar)

    I then create a third window that is a child of the second one.

    Both the second and the third have their own window class and window procedure.

    My problem is that the third window's window procedure never gets called, it all goes to the second window's window procedure as if i had clicked on the second window.

    why is this happending??

    thanks,
    Robert.
    /* MSN and E-Mail - head_explodeshotmail.com */
    If Bill Gates got a dollar for every time windows crahsed... oh... he does.
    I always use MSVC++6.0

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Need to see the code for the creation of the windows winclass.

    Especially

    WndClass.lpfnWndProc = (WNDPROC) MainCallback;

    Are they the right ones? (I think they will both be for window #2)
    "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

  3. #3
    Registered User headexplodes's Avatar
    Join Date
    Aug 2001
    Posts
    26
    well.. thats the thing i first checked and they are different. What i dont get is that when i click on the third window, it goes to the second window and reports the HWND of the SECOND!

    code is below...

    Code:
    	// setup and register window class
      wc.style = CS_HREDRAW | CS_VREDRAW;
      wc.lpfnWndProc = WindowProcI;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon(hInstance, (char*)IDI_MAIN);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = black;  //(HBRUSH)(COLOR_BTNFACE + 1);
      wc.lpszMenuName = NULL;
      wc.lpszClassName = INDCLS;
      RegisterClass(&wc);
      
    	// create indicator window
    	HWND hwnd = CreateWindow(INDCLS, TITLE, WS_POPUP, 0, 0, 
    													400, 24, hParent, NULL, hInstance, NULL);
    thats the 3rd window

    and this is the first and second ones...

    Code:
    	// setup and register window class
      wc.style = CS_HREDRAW | CS_VREDRAW;
      wc.lpfnWndProc = WindowProcM;
      wc.cbClsExtra = 0;
      wc.cbWndExtra = 0;
      wc.hInstance = hInstance;
      wc.hIcon = LoadIcon(hInstance, (char*)IDI_MAIN);
      wc.hCursor = LoadCursor(NULL, IDC_ARROW);
      wc.hbrBackground = black;  //(HBRUSH)(COLOR_BTNFACE + 1);
      wc.lpszMenuName = NULL;
      wc.lpszClassName = NAME;
      RegisterClass(&wc);
      
    	// create host window
    	HWND hmain = CreateWindow(NAME, TITLE, WS_POPUP, 10, 10,
    													400, 300, NULL, NULL, hInstance, NULL);
    
    	// create main window
    	HWND hwnd = CreateWindow(NAME, TITLE, WS_POPUP, 10, 10, 
    													400, 300, hmain, NULL, hInstance, NULL);
    any help would be great.
    /* MSN and E-Mail - head_explodeshotmail.com */
    If Bill Gates got a dollar for every time windows crahsed... oh... he does.
    I always use MSVC++6.0

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    There was no code so I started with the first thing I would have looked at.


    Looks like you have created a child (even though you do not use the WS_CHILD | WS_OVERLAPPED | WS_POPUP ) by specifing the hmain for the HWND PARENT, then failed to have different ID# for the windows.

    Code:
    #define   IDW_SECOND       10001
    #define   IDW_THIRD        10002
    
    HWND hwnd = CreateWindow(NAME, TITLE, WS_POPUP, 10, 10,400, 300, hmain, (HMENU)IDW_SECOND, hInstance, NULL);
    
    HWND hwnd = CreateWindow(INDCLS, TITLE, WS_POPUP, 10, 10,400, 24, hparent, (HMENU)IDW_THIRD, hInstance, NULL);
    "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

  5. #5
    Registered User headexplodes's Avatar
    Join Date
    Aug 2001
    Posts
    26
    i dont get it... how is setting an invalid menu handle to the window changing the id? I tried your code but it just fails to create the window.

    pls explain.
    /* MSN and E-Mail - head_explodeshotmail.com */
    If Bill Gates got a dollar for every time windows crahsed... oh... he does.
    I always use MSVC++6.0

  6. #6
    Registered User
    Join Date
    Aug 2001
    Location
    Melbourne, Australia
    Posts
    92
    hmmm... are you releasing capture after the click? this could be causing one window to send messages back to the other one...?

    -out-
    PsychoBrat
    psychobrat at gmail

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    There is one other error (in my code as well as I cut and pasted) but I thought it was a typo.

    You use HWND hwnd for both main and indicator windows which would explain the problem.

    from MSDN help

    CreateWindow(
    //blah
    //blah
    hWndParent
    //blah
    Although this parameter must specify a valid handle if the dwStyle parameter includes the WS_CHILD style, it is optional if dwStyle includes the WS_POPUP style.

    hMenu
    //blah
    For a child window, hMenu specifies the child-window identifier, an integer value used by a dialog box control to notify its parent about events. The application determines the child-window identifier; it must be unique for all child windows with the same parent window.

    but you don't want to use childs because of the size restrictions (has to be in client area of parent)
    "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. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM