Thread: two child windows, help!!!

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    113

    two child windows, help!!!

    hello,

    I already know how to create MDI child windows, from the WM_COMMAND of the frame window clicking on the "menu new" everytime i need a new child window. but what i need is to have only 2 static child windows , my program should not be able to create more than 2, this 2 windows must be visible from the start of the program, and must have completly different behivor and controls, but of course both are of the same "Class",i cant figure out how can i do that, must i create 2 childProc's? 1 for every window with its own WM_CREATE to add its conotrols? with WindowCreateEx() or from 1 childProc can i define the controls, etc of both windows? ,

    i ask this because if i define just 1 childproc, both windows have exactly the same controls, etc,

    what i need is the theory of this, or whats the general idea to perform this.

    thanks for any help, i really need that
    please excuse my poor enhlish
    Last edited by terracota; 12-07-2004 at 01:32 PM.

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    If the mdi child windows are of the same window 'class' then they'll have the same window procedure, which you can override if you want by subclassing (old article but still useful). Or you could just determine which mdi child window a message is for in the window 'class' mdi child window procedure and forward it to another function which would act as the window procedure. On the other hand, if your intention is to have mdi child windows for different purposes then you should probably register each with a unique window 'class' - which includes providing them with separate window procedures.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    looks like the last option is better for me,

    thanks for reply

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    Quote Originally Posted by Ken Fitlike
    Or you could just determine which mdi child window a message is for in the window 'class' mdi child window procedure and forward it to another function which would act as the window procedure.
    sorry forgot to ask you this:

    how can i determine which mdi child window a message is for?
    ie:
    i have 1 window with a button when clicked displays "hello world" and the other window have a button that displays "bye world" , i can combine both in the same child procedure lik:

    Code:
    switch(LOWORD(wParam)){
    ...
    case IDB_HELLOW://in child window 1 with button id IDB_HELLOW
    ...
    break;
    
    case IDB_BYEWORLD://in child window 2 with button id IDB_BYEWORLD
    ...
    break;
    ...
    }
    can be done that way?
    thanks again for help

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    AFAIK MDI children send WM_COMMAND msg's to thier parent. In some cases it may be WM_NOTIFY.
    The child ID will be the low order word of the wParam, the lParam is the childs HWND.

    I prefer to write each child a callback, easier to debug later.


    //from windowsx.h
    idControl = GET_WM_COMMAND_ID( wParam, lParam) ;
    "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

  6. #6
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    sorry to continue with this but still wont work
    know i have 2 simple mdi childs and the idea is that when u activate one its id is displayed
    Code:
    LRESULT CALLBACK ChildProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
    {
    	HWND buttonHellow = NULL;
    	char cadena[80]="";
    	switch(Msg)
    	{
    		case WM_CREATE:
    			buttonHellow = CreateWindowEx(NULL,"BUTTON","Hola mundo",
    			WS_CHILD | WS_VISIBLE,100,20,92,30,
    				hWnd,(HMENU)ID_BUTTON,GetModuleHandle(NULL),NULL);
    			break;
    		case WM_MDIACTIVATE:
    			sprintf(cadena,"%s",GET_WM_COMMAND_ID(wParam, lParam));
    			MessageBox(hWnd,cadena,"Mensaje",MB_OK);
    			break;
    	}
    
    	return DefMDIChildProc(hWnd,Msg,wParam,lParam);
    }
    
    the problem is that a random id is displayed like 103 and in my .h file the firstid child window is 5000
    any idea?
    im completly lost?
    thanks for your help

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    GET_WM_COMMAND_ID is a macro defined in windowsx.h (look for it in your header files) and should only be used in the context of the parent's WM_COMMAND handler. You can also use LOWORD(wParam) in the same context and with the same result ie to get the identifier for that particular control (provided lParam is non-NULL).

    To get the identifier for the mdi child window in the WM_CREATE handler of the mdi child window as you seem to be trying to do then use GetWindowLongPtr.
    Last edited by Ken Fitlike; 12-08-2004 at 02:47 PM. Reason: edit: clarification, hopefully.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  8. #8
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    ok when i select any child window a WM_COMMAND is sent and i can retrieve the child id by the LOWORD(wParam) as i capture tha clicks of the buttons on a normal window like:
    Code:
    UINT idChild = LOWORD(wParam); 
    case WM_COMMAND:
    switch(LOWORD(wParam)){
            case ID_BUTTONOK:
               ....
            case IdChild:
               ...
    }
    thanks for your help

  9. #9
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    If you want to get the id of the mdi child window in response to a WM_MDI_ACTIVATE message, like in your earlier post then:
    Code:
    case WM_MDIACTIVATE:
      {
      int nID=(int)GetWindowLongPtr(hwnd,GWLP_ID);
      sprintf(cadena,"%d",nID);
      MessageBox(hWnd,cadena,"Mensaje",MB_OK);
      break;
      }
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  10. #10
    Registered User
    Join Date
    Mar 2004
    Posts
    113
    Ken
    a beer foy you!!!
    thanks a lot dude.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can't create child windows
    By OnionKnight in forum Windows Programming
    Replies: 4
    Last Post: 04-10-2011, 04:13 PM
  2. Displaying Text on MDI child windows
    By EmbeddedC in forum Windows Programming
    Replies: 4
    Last Post: 10-30-2008, 12:28 PM
  3. Keeping child windows in their place
    By Smallz in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2006, 06:22 AM
  4. Child Windows and Messages
    By Terrell in forum Windows Programming
    Replies: 10
    Last Post: 09-05-2002, 06:39 AM
  5. child windows
    By face_master in forum Windows Programming
    Replies: 14
    Last Post: 03-01-2002, 07:08 AM