Thread: win32 api MDI windows

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    3

    win32 api MDI windows

    Ok, so basically I got a mdi client area set up. I can create windows, put controls on them yada yada. Now my problem is, my controls dont know which window is which. Is there any method in which mdi windows know which window they are. My current solution is setting a number to the mdi window text then using getmessage to know the window id. Im just wondering if there is a better way to do this since i dont want my windows to have a number in the title. Will provide code if necessary.

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Will 'GetParent()' do what you need?
    "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
    Join Date
    Mar 2009
    Posts
    3
    I dont believe so, I have no hwnd to throw getparent. The mdi's dont have an actuall hwnd declared they have a client area created in which i send messages to create children.


    My mdi Callback.
    Code:
    LRESULT CALLBACK MDIProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
    
      switch(Message) {
        case WM_CREATE: 
            funcs.AddMDI(hwnd, LOWORD(wParam));
          break; 
        case WM_SIZE:
            funcs.SizeMDI(lParam, LOWORD(wParam));
          break;
        case WM_CLOSE:
          break;
      }
          
      return DefMDIChildProc(hwnd, Message, wParam, lParam);
    }

    Creating New MDI window.
    Code:
        mcs.szTitle = text;      
        mcs.szClass = CCMClassName2;              
        mcs.hOwner = MainInst;       
        mcs.x = 1;              
        mcs.y = 1;            
        mcs.cx = 772;             
        mcs.cy = 490;           
        mcs.style = MDIS_ALLCHILDSTYLES; 
    SendMessage(mainCA, WM_MDICREATE, 0, (LONG)(LPMDICREATESTRUCT)&mcs)
    Creating MDI ClientArea
    Code:
    		CLIENTCREATESTRUCT ccs;
            	ccs.hWindowMenu = 0;
                  ccs.idFirstChild = MDISTARTID;
                 
                mainCA = CreateWindowEx(WS_EX_CLIENTEDGE, "MDICLIENT", (LPCTSTR) NULL,	WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE, 
                  105, 20, 782, 500, hwnd, 0, funcs.MainInst, (LPSTR) &ccs);
    Now if my mdi windows had a hwnd handle like mainCA does than I believe I would do something similar to what you said or even more simplistic, but without a stored hwnd how does the mdi know who it is?

    Take note: All this code works perfectly mdi windows are created just fine I edited out a few things because of not related.
    Last edited by TheNewOne; 03-16-2009 at 12:42 AM. Reason: forgot something

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    3
    Ok, So ive did even more research on the subject. I decided to try on WM_CREATE grab the activemdi and add the hwnd, an window count id and a name to a linked list. To attempt to have something to compare with on size.

    A little bit more indepth what im trying to do. The Controls for each mdi window are created outside the mdiproc or create functions and are needed to be accessed outside this function without using sendmessages directly towards the mdiproc. Each mdi window will need to keep vast amount of information specific to it, and resize its controls accordingly when resized when current.

    So on wm_create I would send this.
    Code:
    profiles[windowcount].profile = (HWND)SendMessage(mainCA, WM_MDIGETACTIVE,0,0);
    and on resize I would attempt to do something like this, to check if my identification system would work.

    Code:
          active = (HWND)SendMessage(mainCA, WM_MDIGETACTIVE,0,0)
            for(int x = 0; x <= windowcount; x++) {
              if(profiles[x].profile == active) {
                funcs.SizeMDI(lParam, profiles[x].profileid);
              }
            }
    Now what happened when I did this, the first window wouldnt resize. when i created 5 windows. The first window when resized would resize the 2nd window, than the 2nd window would resize the 3rd. So I assumed my id was just 1 to high this wasnt the case. Anyone have any further idea or suggestions on this topic?

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195
    I belive you can pass a variable to the MDI child on creation, much like you pass to a thread.

  6. #6
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    If you use CreateMDIWindow() the return in the HWND and you can validate the window was created (or call GetLastError on a null HWND) and store this value.

    Use the LPARAM of the MDICREATE as a pointer to an element of an array. The array being a list of structs or classes holding the required data (lets call it ArrayElement for this example).

    Use the MDI HWND as the 'hWndParent' param in the CreateWindow() when creating the controls on the MDI window.

    When you receive a msg in the MDI callback you can get the pointer to the parents element of the array using and

    Code:
    pParentData=(ArrayElement*)GetWindowLongPtr(GetParent() , DWL_USER);
    [Sorry for leaving this half done but very busy with installs before the cyclone season.
    Unluckily someone got killed on-site (not from my company) and we have a week delay.]
    "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. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  2. child windows with win32 API
    By hiya in forum C++ Programming
    Replies: 3
    Last Post: 04-30-2005, 03:08 AM
  3. FILES in WinAPI
    By Garfield in forum Windows Programming
    Replies: 46
    Last Post: 10-02-2003, 06:51 PM
  4. How do you toggle keys like Scroll lock without Windows API?
    By animeaholic in forum C++ Programming
    Replies: 7
    Last Post: 09-15-2002, 07:02 PM
  5. Win32 API Tutorials?
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 05-09-2002, 03:51 PM