Dear all,
I understood that I've to use GetDlgItem() API to retrieve the right Windows handle for control when using Non-Modal forms.
Here is my question:
- is-it necessary to use the GetDlgItem() API in the WM_CREATE or only for the other events (WM_SIZE, WM_CLOSE, etc ...) ?
Thanks
Jean-Pierre
You don't have to use GetDlgItem for all non-modal forms, only those that are multiple instances of themselves. If you have a non-modal form that is only ever used by itself then you can access the window/control variables in the same manner as if it was a modal form.
If you do have multiple instances of the same form then you must use GetDlgItem to access the window/control handle variables. I would imagine that you would have to use GetDlgItem in the WM_CREATE handler as well.
Hi Paul,
Thank for your answer; and yes my question was regarding the multiple instances of the same form.
And in this specific case it seems (I'm not 100% sure) that we can get rid of the GetDlgItem() API in the WM_CREATE handler only. It's seem to work pretty well. Again I'm not 100% sure.
Regards,
Jean-Pierre
Quote from: TechSupport on February 01, 2016, 01:32:40 PM
If you do have multiple instances of the same form then you must use GetDlgItem to access the window/control handle variables. I would imagine that you would have to use GetDlgItem in the WM_CREATE handler as well.
Hi Paul,
I've done many tests and put traces in the WM_CREATE Handler. My findings so far is that even for multi instances of the same non-modal form, the value of the handle is exactly the same as the value got via the GetDlgItem function.
Below are my results with a FORM called PROJECT:
- with a BUTTON control OK
- with a TAB control TABCONTROL1
- with a ChildForm PROJECTGOALS on the TABCONTROL1
- with a TEXTBOX Goals on the ChildForm PROJECTGOALS
First instance of the form
HWND_PROJECT_OK =133854 GetDlgItem(hWndForm ,IDC_PROJECT_OK) =133854
HWND_PROJECT_TABCONTROL1=133878 GetDlgItem(hWndForm ,IDC_PROJECT_TABCONTROL1)=133878
HWND_PROJECTGOALS_GOALS =133866 GetDlgItem(hWndFormProjectGoals,IDC_PROJECTGOALS_GOALS) =133866
Second instance of the form
HWND_PROJECT_OK =133976 GetDlgItem(hWndForm ,IDC_PROJECT_OK) =133976
HWND_PROJECT_TABCONTROL1=134000 GetDlgItem(hWndForm ,IDC_PROJECT_TABCONTROL1)=134000
HWND_PROJECTGOALS_GOALS =133988 GetDlgItem(hWndFormProjectGoals,IDC_PROJECTGOALS_GOALS) =133988
Third instance of the form
HWND_PROJECT_OK =134074 GetDlgItem(hWndForm ,IDC_PROJECT_OK) =134074
HWND_PROJECT_TABCONTROL1=134118 GetDlgItem(hWndForm ,IDC_PROJECT_TABCONTROL1)=134118
HWND_PROJECTGOALS_GOALS =134106 GetDlgItem(hWndFormProjectGoals,IDC_PROJECTGOALS_GOALS) =134106
I would like to know if it is safe to do that in the WM_CREATE handler only; from what I see it seems to be ok; I would like to get your confirmation as it is much more easier to code without the GetDlgItem() function (at least in the WM_CREATE handler).
Thanks,
Jean-Pierre
PS: in this example to get the handle of the TabControl child form "hWndFormProjectGoals" I use the function TabControlGetChildFormHandle see http://www.planetsquires.com/protect/forum/index.php?topic=3797.msg27652