Feedback: How to find the number of current window handles [modified]
-
Hello community, I just wanted to give a feedback, regarding to my question some days ago:My Question from 14. Sept[^] There I was facing a Win32Exception, "Error creating window handle". At this place I want to thank mav.northwind[^] for his great help! He pointed me to the "User32.dll" method "GetGuiResources" (msdn documentation[^]), which was exactly what I was looking for.
/// uiFlags: 0 - Count of GDI objects /// uiFlags: 1 - Count of USER objects /// - Win32 GDI objects (pens, brushes, fonts, palettes, regions, device contexts, bitmap headers) /// - Win32 USER objects: /// - WIN32 resources (accelerator tables, bitmap resources, dialog box templates, font resources, /// menu resources, raw data resources, string table entries, message table entries, cursors/icons) /// - Other USER objects (windows, menus) [DllImport("User32")] extern public static int GetGuiResources(IntPtr hProcess, int uiFlags);
This method is able to return two values as you can see:0 - Count of GDI objects: Is the one you also can watch over the taskmanager.
1 - Count of USER objects: Is not neccessary equal to the GDI Objects
and AFAIK not visible in the taskmanager.An example, how the counting works: If you place a UserControl on a form
- a naked UserControl: GDI +1; User +1
- a UserControl which holds a "PictureBox": GDI +1; User +2
- a UserControl which holds a "System.Drawing.Pen": GDI +2; User +1
-
-
- 3): GDI +3; User +2, ???
sometimes it returns: GDI +2; User +2, which would be expected)
- 3): GDI +3; User +2, ???
-
I knew that there is a limit set in the Registry for the GDI Handle Quota (GDIProcessHandleQuota), and there I also found one for the User Handle Quota (UserProcessHandleQuota). Path: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows NOTE: This
-
Hello community, I just wanted to give a feedback, regarding to my question some days ago:My Question from 14. Sept[^] There I was facing a Win32Exception, "Error creating window handle". At this place I want to thank mav.northwind[^] for his great help! He pointed me to the "User32.dll" method "GetGuiResources" (msdn documentation[^]), which was exactly what I was looking for.
/// uiFlags: 0 - Count of GDI objects /// uiFlags: 1 - Count of USER objects /// - Win32 GDI objects (pens, brushes, fonts, palettes, regions, device contexts, bitmap headers) /// - Win32 USER objects: /// - WIN32 resources (accelerator tables, bitmap resources, dialog box templates, font resources, /// menu resources, raw data resources, string table entries, message table entries, cursors/icons) /// - Other USER objects (windows, menus) [DllImport("User32")] extern public static int GetGuiResources(IntPtr hProcess, int uiFlags);
This method is able to return two values as you can see:0 - Count of GDI objects: Is the one you also can watch over the taskmanager.
1 - Count of USER objects: Is not neccessary equal to the GDI Objects
and AFAIK not visible in the taskmanager.An example, how the counting works: If you place a UserControl on a form
- a naked UserControl: GDI +1; User +1
- a UserControl which holds a "PictureBox": GDI +1; User +2
- a UserControl which holds a "System.Drawing.Pen": GDI +2; User +1
-
-
- 3): GDI +3; User +2, ???
sometimes it returns: GDI +2; User +2, which would be expected)
- 3): GDI +3; User +2, ???
-
I knew that there is a limit set in the Registry for the GDI Handle Quota (GDIProcessHandleQuota), and there I also found one for the User Handle Quota (UserProcessHandleQuota). Path: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows NOTE: This
-
Hello community, I just wanted to give a feedback, regarding to my question some days ago:My Question from 14. Sept[^] There I was facing a Win32Exception, "Error creating window handle". At this place I want to thank mav.northwind[^] for his great help! He pointed me to the "User32.dll" method "GetGuiResources" (msdn documentation[^]), which was exactly what I was looking for.
/// uiFlags: 0 - Count of GDI objects /// uiFlags: 1 - Count of USER objects /// - Win32 GDI objects (pens, brushes, fonts, palettes, regions, device contexts, bitmap headers) /// - Win32 USER objects: /// - WIN32 resources (accelerator tables, bitmap resources, dialog box templates, font resources, /// menu resources, raw data resources, string table entries, message table entries, cursors/icons) /// - Other USER objects (windows, menus) [DllImport("User32")] extern public static int GetGuiResources(IntPtr hProcess, int uiFlags);
This method is able to return two values as you can see:0 - Count of GDI objects: Is the one you also can watch over the taskmanager.
1 - Count of USER objects: Is not neccessary equal to the GDI Objects
and AFAIK not visible in the taskmanager.An example, how the counting works: If you place a UserControl on a form
- a naked UserControl: GDI +1; User +1
- a UserControl which holds a "PictureBox": GDI +1; User +2
- a UserControl which holds a "System.Drawing.Pen": GDI +2; User +1
-
-
- 3): GDI +3; User +2, ???
sometimes it returns: GDI +2; User +2, which would be expected)
- 3): GDI +3; User +2, ???
-
I knew that there is a limit set in the Registry for the GDI Handle Quota (GDIProcessHandleQuota), and there I also found one for the User Handle Quota (UserProcessHandleQuota). Path: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows NOTE: This
Martin# wrote:
NOTE: This limits are System limits, not process limits.
Are you sure about this one? Some time ago I was tracking down a leak of gdi handles and my app crashed when the number of gdi handles for it (watching the gdi handles column in the task manager) reached exactly 10000. Robert
-
Martin# wrote:
NOTE: This limits are System limits, not process limits.
Are you sure about this one? Some time ago I was tracking down a leak of gdi handles and my app crashed when the number of gdi handles for it (watching the gdi handles column in the task manager) reached exactly 10000. Robert
-
Hello community, I just wanted to give a feedback, regarding to my question some days ago:My Question from 14. Sept[^] There I was facing a Win32Exception, "Error creating window handle". At this place I want to thank mav.northwind[^] for his great help! He pointed me to the "User32.dll" method "GetGuiResources" (msdn documentation[^]), which was exactly what I was looking for.
/// uiFlags: 0 - Count of GDI objects /// uiFlags: 1 - Count of USER objects /// - Win32 GDI objects (pens, brushes, fonts, palettes, regions, device contexts, bitmap headers) /// - Win32 USER objects: /// - WIN32 resources (accelerator tables, bitmap resources, dialog box templates, font resources, /// menu resources, raw data resources, string table entries, message table entries, cursors/icons) /// - Other USER objects (windows, menus) [DllImport("User32")] extern public static int GetGuiResources(IntPtr hProcess, int uiFlags);
This method is able to return two values as you can see:0 - Count of GDI objects: Is the one you also can watch over the taskmanager.
1 - Count of USER objects: Is not neccessary equal to the GDI Objects
and AFAIK not visible in the taskmanager.An example, how the counting works: If you place a UserControl on a form
- a naked UserControl: GDI +1; User +1
- a UserControl which holds a "PictureBox": GDI +1; User +2
- a UserControl which holds a "System.Drawing.Pen": GDI +2; User +1
-
-
- 3): GDI +3; User +2, ???
sometimes it returns: GDI +2; User +2, which would be expected)
- 3): GDI +3; User +2, ???
-
I knew that there is a limit set in the Registry for the GDI Handle Quota (GDIProcessHandleQuota), and there I also found one for the User Handle Quota (UserProcessHandleQuota). Path: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows NOTE: This
You reall have to ask yourself, Why is the limit of window handles per process 10,000?[^]
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
You reall have to ask yourself, Why is the limit of window handles per process 10,000?[^]
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Hello Dave,
Dave Kreskowiak wrote:
You reall have to ask yourself, Why is the limit of window handles per process 10,000?[^]
The Short answere is: Because the project needs it! ;) I know that it's "a bad designed GUI" which commes to everybodys mind by reading my post. But I think the application I'm working on is a little bit special. It's is a GUI which does mainly control Process Variables (PV's) of an industrial machine. It's about 20000 PV's (Input and Output) which have to be arranged. Apart from that it has to do some graphical output, charts, ... And the bad thing is, that the pages (UserControl with TabPages) allways have to stay in memory, because of fast reaction time at page change. Good thing is, that the application runs nearly alon on an Industrial PC (XP embedded). So I don't need to share the 32700 maximum of window manager objects. Thanks for the link! It provided some more information about that topic. I'm allways open for suggestions regarding speeding up my application. A big problem is also the time the system needs for the first painting of a Page. Maybe you have some information about that. Thanks again!
All the best, Martin
-
Hello Dave,
Dave Kreskowiak wrote:
You reall have to ask yourself, Why is the limit of window handles per process 10,000?[^]
The Short answere is: Because the project needs it! ;) I know that it's "a bad designed GUI" which commes to everybodys mind by reading my post. But I think the application I'm working on is a little bit special. It's is a GUI which does mainly control Process Variables (PV's) of an industrial machine. It's about 20000 PV's (Input and Output) which have to be arranged. Apart from that it has to do some graphical output, charts, ... And the bad thing is, that the pages (UserControl with TabPages) allways have to stay in memory, because of fast reaction time at page change. Good thing is, that the application runs nearly alon on an Industrial PC (XP embedded). So I don't need to share the 32700 maximum of window manager objects. Thanks for the link! It provided some more information about that topic. I'm allways open for suggestions regarding speeding up my application. A big problem is also the time the system needs for the first painting of a Page. Maybe you have some information about that. Thanks again!
All the best, Martin
Martin# wrote:
Because the project needs it!
No, it doesn't.
Martin# wrote:
I know that it's "a bad designed GUI"
Yeah, it is. And this doesn't excuse it.
Martin# wrote:
It's is a GUI which does mainly control Process Variables (PV's) of an industrial machine. It's about 20000 PV's (Input and Output) which have to be arranged.
There are other ways of doing it beside trying to render 20,000 seperate windows. You can't come up with 20 applications that, COMBINED, use 20,000 handles.
Martin# wrote:
Apart from that it has to do some graphical output, charts, ...
So what?? A single cached bitmap that you do your drawing on, then that gets repainted to the screen.
Martin# wrote:
And the bad thing is, that the pages (UserControl with TabPages) allways have to stay in memory, because of fast reaction time at page change.
So you're telling me that you're storing your apps data in all the controls?? That's a REALLY bad idea and will do nothing other than cause you performance problems. The GUI (and all the controls that make it up) are there to show a visual representation of your apps internal data model. They do a terrible job of actually BEING the data model.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Hello community, I just wanted to give a feedback, regarding to my question some days ago:My Question from 14. Sept[^] There I was facing a Win32Exception, "Error creating window handle". At this place I want to thank mav.northwind[^] for his great help! He pointed me to the "User32.dll" method "GetGuiResources" (msdn documentation[^]), which was exactly what I was looking for.
/// uiFlags: 0 - Count of GDI objects /// uiFlags: 1 - Count of USER objects /// - Win32 GDI objects (pens, brushes, fonts, palettes, regions, device contexts, bitmap headers) /// - Win32 USER objects: /// - WIN32 resources (accelerator tables, bitmap resources, dialog box templates, font resources, /// menu resources, raw data resources, string table entries, message table entries, cursors/icons) /// - Other USER objects (windows, menus) [DllImport("User32")] extern public static int GetGuiResources(IntPtr hProcess, int uiFlags);
This method is able to return two values as you can see:0 - Count of GDI objects: Is the one you also can watch over the taskmanager.
1 - Count of USER objects: Is not neccessary equal to the GDI Objects
and AFAIK not visible in the taskmanager.An example, how the counting works: If you place a UserControl on a form
- a naked UserControl: GDI +1; User +1
- a UserControl which holds a "PictureBox": GDI +1; User +2
- a UserControl which holds a "System.Drawing.Pen": GDI +2; User +1
-
-
- 3): GDI +3; User +2, ???
sometimes it returns: GDI +2; User +2, which would be expected)
- 3): GDI +3; User +2, ???
-
I knew that there is a limit set in the Registry for the GDI Handle Quota (GDIProcessHandleQuota), and there I also found one for the User Handle Quota (UserProcessHandleQuota). Path: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows NOTE: This
Hi Martin! Great, fine you got it to work. You could make an article out of this, so that the information can be found more easily. I guess it could be useful for many developers...
Regards, mav -- Black holes are the places where God divided by 0...
-
Martin# wrote:
Because the project needs it!
No, it doesn't.
Martin# wrote:
I know that it's "a bad designed GUI"
Yeah, it is. And this doesn't excuse it.
Martin# wrote:
It's is a GUI which does mainly control Process Variables (PV's) of an industrial machine. It's about 20000 PV's (Input and Output) which have to be arranged.
There are other ways of doing it beside trying to render 20,000 seperate windows. You can't come up with 20 applications that, COMBINED, use 20,000 handles.
Martin# wrote:
Apart from that it has to do some graphical output, charts, ...
So what?? A single cached bitmap that you do your drawing on, then that gets repainted to the screen.
Martin# wrote:
And the bad thing is, that the pages (UserControl with TabPages) allways have to stay in memory, because of fast reaction time at page change.
So you're telling me that you're storing your apps data in all the controls?? That's a REALLY bad idea and will do nothing other than cause you performance problems. The GUI (and all the controls that make it up) are there to show a visual representation of your apps internal data model. They do a terrible job of actually BEING the data model.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Dave Kreskowiak wrote:
Martin# wrote: Because the project needs it! No, it doesn't.
:| Yes, it does
Dave Kreskowiak wrote:
Martin# wrote: I know that it's "a bad designed GUI" Yeah, it is. And this doesn't excuse it.
:|
Dave Kreskowiak wrote:
Martin# wrote: Apart from that it has to do some graphical output, charts, ... So what?? A single cached bitmap that you do your drawing on, then that gets repainted to the screen.
So nothing! Just wanted to say that apart from >6000 output and input boxes and labels, there are other controls handling some tasks. In fact we are using ZedGraph Control (about 20-30).
Dave Kreskowiak wrote:
Martin# wrote: And the bad thing is, that the pages (UserControl with TabPages) allways have to stay in memory, because of fast reaction time at page change. So you're telling me that you're storing your apps data in all the controls??
:confused: No, not even when I reread my sentence I would come to that idea! I have the feeling you have are lacking of sleep! ;) We just hold the pages in memory, couse the instanciating of the page during runtime (page change) would take too much time.
All the best, Martin
-
Hi Martin! Great, fine you got it to work. You could make an article out of this, so that the information can be found more easily. I guess it could be useful for many developers...
Regards, mav -- Black holes are the places where God divided by 0...
Hello mav, Thanks for youre nice words!
mav.northwind wrote:
You could make an article out of this, so that the information can be found more easily. I guess it could be useful for many developers...
Good idea! Hmm, maybe when I do some more research.
All the best, Martin
-
Dave Kreskowiak wrote:
Martin# wrote: Because the project needs it! No, it doesn't.
:| Yes, it does
Dave Kreskowiak wrote:
Martin# wrote: I know that it's "a bad designed GUI" Yeah, it is. And this doesn't excuse it.
:|
Dave Kreskowiak wrote:
Martin# wrote: Apart from that it has to do some graphical output, charts, ... So what?? A single cached bitmap that you do your drawing on, then that gets repainted to the screen.
So nothing! Just wanted to say that apart from >6000 output and input boxes and labels, there are other controls handling some tasks. In fact we are using ZedGraph Control (about 20-30).
Dave Kreskowiak wrote:
Martin# wrote: And the bad thing is, that the pages (UserControl with TabPages) allways have to stay in memory, because of fast reaction time at page change. So you're telling me that you're storing your apps data in all the controls??
:confused: No, not even when I reread my sentence I would come to that idea! I have the feeling you have are lacking of sleep! ;) We just hold the pages in memory, couse the instanciating of the page during runtime (page change) would take too much time.
All the best, Martin
Martin# wrote:
I have the feeling you have are lacking of sleep!
Guy, you have no idea how true this is. I used to work for a major automaker, and I've seen and supported some huge plant floor control systems that blew my mind in their complexity. But in no case, have I ever seen anything approaching a couple thousand handles, let alone 10's of thousands. There is no reason to have a page full of label controls to show data when your code can be rewritten to paint all the data itself on a single page.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Martin# wrote:
I have the feeling you have are lacking of sleep!
Guy, you have no idea how true this is. I used to work for a major automaker, and I've seen and supported some huge plant floor control systems that blew my mind in their complexity. But in no case, have I ever seen anything approaching a couple thousand handles, let alone 10's of thousands. There is no reason to have a page full of label controls to show data when your code can be rewritten to paint all the data itself on a single page.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Hello Dave,
Dave Kreskowiak wrote:
Guy, you have no idea how true this is.
I'm happy, that you keeped your humor.
Dave Kreskowiak wrote:
I used to work for a major automaker, and I've seen and supported some huge plant floor control systems that blew my mind in their complexity.
And thats the point: You are talking of an application for one task (also if it's a very hughe task). My project needs to fit with all machines our company produces (about 500 per year). They are not all different of course but they differe in some points, sometimes more sometimes less. That means we need a high dynamic GUI, which has to be handled from about 15 people from all over the world.
Dave Kreskowiak wrote:
There is no reason to have a page full of label controls to show data when your code can be rewritten to paint all the data itself on a single page.
This is simply not possible for our project! As the controls provide some userdefined Binding mechanism (sometimes a control is binded to 5 - 10) different PV's, which tells the control for example if an option is set or not. An other reason is that there is a feature where a user of the GUI is able to build his own page by "grapping" controls (plus all bindings) from existing pages, and insert it in his own page.
All the best, Martin
-
Hello Dave,
Dave Kreskowiak wrote:
Guy, you have no idea how true this is.
I'm happy, that you keeped your humor.
Dave Kreskowiak wrote:
I used to work for a major automaker, and I've seen and supported some huge plant floor control systems that blew my mind in their complexity.
And thats the point: You are talking of an application for one task (also if it's a very hughe task). My project needs to fit with all machines our company produces (about 500 per year). They are not all different of course but they differe in some points, sometimes more sometimes less. That means we need a high dynamic GUI, which has to be handled from about 15 people from all over the world.
Dave Kreskowiak wrote:
There is no reason to have a page full of label controls to show data when your code can be rewritten to paint all the data itself on a single page.
This is simply not possible for our project! As the controls provide some userdefined Binding mechanism (sometimes a control is binded to 5 - 10) different PV's, which tells the control for example if an option is set or not. An other reason is that there is a feature where a user of the GUI is able to build his own page by "grapping" controls (plus all bindings) from existing pages, and insert it in his own page.
All the best, Martin
All I can do is smile. Have fun with it!
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007