Showing Controls in a Window

I had developed a GUI application based on WIN API. I am calling CreateWindowEx API to create the window (FORM) and then I am handling its OnCreate function in which I am creating the Form's controls (EDIT, BUTTON, LISTVIEW ...).

My problem is that the controls are being drawn or shown one after another while what is needed is to have them all displayed in one shot.

To be more clear, in a certain Form, I have 30 controls (12 Static, 12 Edit and 6 Buttons). Upon creating this Form, it is very clear that the application is showing the FORM window, then showing its controls 1 after another.
Below is a headlines of the create algorithm:
1- Build block: It an array of myItem struct that holds parameters of each control:
1
2
3
4
5
6
7
8
.
.
myItem * ctrl[100];
ctrl[0] = createMyItem (x1, y1, w1, h1, "STATIC", ...);
ctrl[1] = createMyItem (x2, y2, w2, h2, "EDIT", ...);
ctrl[2] = createMyItem (x3, y3, w3, h3, "BUTTON", ...);
ctrl[3] = createMyItem (x4, y4, w4, h4, "LISTVIEW", ...);
ctrl[4] = NULL;

2- Create Form Window:
1
2
3
.
.
CreateWindowEx (...);

3- In OnCreate:
1
2
3
4
5
6
.
.
for (int i = 0; ctrl[i] != NULL; i++) {
	ctrl[i].parent = hWnd;   // hWnd is HWND of Form window
	CreateMyItemControl (ctrl[i]);
}

4- Procedure CreateMyItemControl:
1
2
3
4
5
CreateMyItemControl (myItem ctrl_v) {
	.
	.
	CreateWindowEx(..., ctrl_v.x, ctrl.y, ctrl.w, ctrl.h, .., ctrl.parent, ..);
}

I hope I am clear enough.

Please advise.

Regards,
Are you passing the WS_VISIBLE style to CreateWindowEx when you create the main window? If so, remove this flag so the window is hidden while the child controls are created and show it when CreateWindowEx returns.

Andy
Last edited on
Below are the style passed to CreateWindowEx():
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
wStyle_v = NULL
		 | WS_CAPTION
		 | WS_CHILDWINDOW 
		 | WS_CLIPSIBLINGS
		 | WS_SYSMENU 
		 | WS_THICKFRAME 
		 | WS_MINIMIZEBOX 
		 | WS_MAXIMIZEBOX 
		 ;
wStyle_v = NULL
		 | WS_CHILDWINDOW 
		 | WS_CAPTION
		 | WS_CLIPSIBLINGS
		 | WS_SIZEBOX 
		 ;


However, I was referring to MSDN documentation on WS_VISIBLE bit, they mentioned:
The window is initially visible.
This style can be turned on and off by using the ShowWindow or SetWindowPos function.
(Link is below):
http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx

Alternetivly, I couldn't find any Hide style so I can pass it to CreateWindowEx and then I'll show the window when needed.

Regards,
Ahmad
These are really used on a child window ?
WS_CAPTION
WS_SIZEBOX
WS_SYSMENU
WS_MINIMIZEBOX
WS_MAXIMIZEBOX
????????????????????????????????

And are you serious about OR-ing all these with NULL ?

Please pass only WS_CHILD as the only style for start.

These are really used on a child window ?
WS_CAPTION
WS_SIZEBOX
WS_SYSMENU
WS_MINIMIZEBOX
WS_MAXIMIZEBOX
????????????????????????????????


My Application has a main window which is the parent of all other Forms. Each Form is a window by itself that contains several control (EDIT, BUTTON ...). In my application, I need those Forms to have caption and be maximized, minimized, closed and re-sized. Furthermore, where is the problem if I pass all those into child window? My Application is interpreting them properly.

Please clarify.

And are you serious about OR-ing all these with NULL ?

The NULL was added by mistake.

Regards,
Ahmad
Andy..
Any update on the above?

As per my update, I am not passing WS_VISIBLE for the window and as per MSDN notes, the window is visible by default.

Please help
Regards,
Ahmad

My Application has a main window which is the parent of all other Forms. Each Form is a window by itself that contains several control (EDIT, BUTTON ...). In my application, I need those Forms to have caption and be maximized, minimized, closed and re-sized.


That sounds to me like it should be developed using MDI - Multiple Document Interface architecture. Are you doing that?
As per my update, I am not passing WS_VISIBLE for the window and as per MSDN notes, the window is visible by default.

Windows are hidden by default on creation; a window is initially visible only if you use WS_VISIBLE when you create it (this is what the MSDN entry is saying, though maybe not totally clearly... i.e. when you use the WS_VISIBLE flag then... the window is inititially visible.) And ShowWindow() can be used to show or hide the window as required.

From your description it sounded like the form window was being shown before its children were created. If that's not the case, then the next place to look is there you're making the windows visible (if you're not using WS_VISIBLE when you create the windows then somewhere you must be calling ShowWindow or equivalent??)

Other than that I have no idea...

(But you could use IsWindowVisible() to confirm the window is still hidden when your WM_CREATE handler is run, if you haven't already done so.)

Andy

PS @freddie1

The subject of MDI has already come up... and I agree with you!

Redrawing Over Lapping Windows
http://www.cplusplus.com/forum/windows/109913/#msg601636
Last edited on

My problem is that the controls are being drawn or shown one after another while what is needed is to have them all displayed in one shot.

To be more clear, in a certain Form, I have 30 controls (12 Static, 12 Edit and 6 Buttons). Upon creating this Form, it is very clear that the application is showing the FORM window, then showing its controls 1 after another.


I really don't understand what you are saying and I'm wondering if you could be clearer still. It appears you are storing child window control parameters in an array and creating the controls in a for loop. I personally don't do that but I see nothing wrong with that concept if done properly. So what exactly isn't functioning? When the form becomes visible on the screen are the controls not showing up? Or is there a time lapse until they show up? Or are they showing up one at a time with a second or two delay between the visibility of each control as it is created in the for loop? From your description I simply don't know what you are seeing that you are interpreting as an error or failure condition.
Hi everyone,
Sorry for late reply. I was on mission out of country so I was not able to follow up on my application project.
Anyway, freddie1:
When the form becomes visible on the screen are the controls not showing up? Or is there a time lapse until they show up? Or are they showing up one at a time with a second or two delay between the visibility of each control as it is created in the for loop?

The controls are appearing one after the other with a delay between the visibility of each control although they are created while processing the WM_CREATE of the parent window. Besides, I don't know what bit flag must I use while creating those controls so they wont get visible until the processing of WM_CREATE is done.

I hope I am clearer now. If not please let me know :)

Best Regards,
Ahmad
Perhaps someone can correct me if I'm wrong, but nothing whatsoever of an application becomes visible at all during and right up to the end of WM_CREATE processing. Inevitably, at some point after the WM_CREATE message returns, there will be other messages such as WM_SIZE and most important WM_PAINT. Its only at that point where main program windows and child controls become visible - all at once.

That your application is taking as much time as it is that you can see sequential creation of controls, there is something that isn't right. Since I jumped into this topic somewhat late, and it does appear to have some prior history, I'm not sure what the problem is.
freddie1, thx anyway :)

What would you suggest? Would you like me to post the code of WM_CREATE?
I noticed that WM_SIZE and WM_PAINT are triggered while processing of WM_CREATE. However, I still don't know how to let all the control to appear in 1 shot. It is really not professional to have them appearing in a sequential was one after the other :)

Thanks in advance for your help.

Regards,
Ahmad
1
2
3
4
5
WS_CAPTION
WS_SIZEBOX
WS_SYSMENU
WS_MINIMIZEBOX
WS_MAXIMIZEBOX


You really aren't using those styles on these child window controls such as static controls, text boxes, and buttons, are you? The only styles buttons or static controls should have are WS_CHILD | WS_VISIBLE. Edit controls have a few additional useful ones. If you are using those styles on these child window controls try just using what I stated above. In my opinion using those styles on edit controls, labels, or buttons could put you in the realm of 'undefined behavior', and the slowness of window creation you are seeing could be one manifestation of that. I might add that styles are of critical importance in Windows coding directly to its API. The reason for this is because in C oriented OOP (which is what direct use of the API entails), you are actually setting 'properties' through the use of styles. We think of objects as having properties, oftentimes mutatable through mutators, i.e., Get/Set method calls, but OOP through C works by setting these styles.
freddie1:
1
2
3
4
5
WS_CAPTION
WS_SIZEBOX
WS_SYSMENU
WS_MINIMIZEBOX
WS_MAXIMIZEBOX


You really aren't using those styles on these child window controls such as static controls, text boxes, and buttons, are you?


I am not using those styles for controls (EDIT, BUTTON, STATIC, ...). I am passing those styles ONLY upon creating windows.

Besides, I am NOT using WS_VISIBLE in the whole code. However, I'll recheck again if by mistake I am showing the window before creating its controls.

Regards,
Ahmad
I am not using those styles for controls (EDIT, BUTTON, STATIC, ...). I am passing those styles ONLY upon creating windows.



Why ? These styles should never be used on child controls.
We keep going around and around with this issue of styles here and I think the reason for that is confusion of terminology. What I think Ahmad has here is a main program window, to which such styles as WS_CAPTION,
WS_SIZEBOX, WS_SYSMENU, WS_MINIMIZEBOX, WS_MAXIMIZEBOX, and so on are completely appropriate. But then I believe Ahmad is creating childs of this top level window with these exact same styles. That is, they are not what we think of as 'controls', but rather child windows that really have styles the same as a top level window. And it is upon these 'childs' that Ahmad is placing actual child window controls such as buttons and text boxes. This is more typically done with a Multiple Document Interface architecture, where I believe one of the styles is indeed MDI_CHILD or something like that (I haven't done a MDI app for a few years and I forget - would have to look it up).

Personally, while I have a real lot of experience creating GUI apps with the Windows Api, I have simply never done anything like that. If my experience is anything like others here, that may be the reason we are having a hard time understanding this problem.

What I'd recommend Ahmad, is that you try to remove all data processing code from your app, and attempt to condense it into something that will fit here if posted - I think 8192 bytes is allowed or something like that - and which still shows the problem. At that point I'd be willing to look at it and see what the issue is.
Topic archived. No new replies allowed.