-
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.
-
Will 'GetParent()' do what you need?
-
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.
-
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?
-
I belive you can pass a variable to the MDI child on creation, much like you pass to a thread.
-
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.]