From 56bcac985936580748415c00ba8507933a326d77 Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Wed, 14 Sep 2005 07:30:32 +0000 Subject: WIN32, STR #1007: Added some code that looks a lot, but is actually very littl, that keeps track of all window classes that were registered to avoid registering the same class twice. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4567 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl_win32.cxx | 75 ++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index 266073f12..ebeed9d67 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -1095,6 +1095,38 @@ void Fl_Window::resize(int X,int Y,int W,int H) { //////////////////////////////////////////////////////////////// +/* + * This silly little class remembers the name of all window classes + * we register to avoid double registration. It has the added bonus + * of freeing everything on application colse as well. + */ +class NameList { +public: + NameList() { name = (char**)malloc(sizeof(char**)); NName = 1; nName = 0; } + ~NameList() { + int i; + for (i=0; ixclass(); if (!class_name) class_name = first_class_name; // reuse first class name used @@ -1115,40 +1147,31 @@ Fl_X* Fl_X::make(Fl_Window* w) { first_class_name = class_name; } - const char* message_name = "FLTK::ThreadWakeup"; - - // Register the first (or default FLTK) class only once. - // If the user creates mutiple new windows using other class names, they will - // be registered multiple times. This is not correct and should be fixed by - // keeping a list of registered window classes. Anyway, Windows is - // quite forgiving here, - static int first_time = 1; - if (first_time || strcmp(class_name, first_class_name)) { - WNDCLASSEX lwc; + if (!class_name_list.has_name(class_name)) { + WNDCLASSEX wc; // Documentation states a device context consumes about 800 bytes // of memory... so who cares? If 800 bytes per window is what it // takes to speed things up, I'm game. //wc.style = CS_HREDRAW | CS_VREDRAW | CS_CLASSDC | CS_DBLCLKS; - lwc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS; - lwc.lpfnWndProc = (WNDPROC)WndProc; - lwc.cbClsExtra = wc.cbWndExtra = 0; - lwc.hInstance = fl_display; + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC | CS_DBLCLKS; + wc.lpfnWndProc = (WNDPROC)WndProc; + wc.cbClsExtra = wc.cbWndExtra = 0; + wc.hInstance = fl_display; if (!w->icon()) w->icon((void *)LoadIcon(NULL, IDI_APPLICATION)); - lwc.hIcon = lwc.hIconSm = (HICON)w->icon(); - lwc.hCursor = fl_default_cursor = LoadCursor(NULL, IDC_ARROW); + wc.hIcon = wc.hIconSm = (HICON)w->icon(); + wc.hCursor = fl_default_cursor = LoadCursor(NULL, IDC_ARROW); //uchar r,g,b; Fl::get_color(FL_GRAY,r,g,b); //wc.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(r,g,b)); - lwc.hbrBackground = NULL; - lwc.lpszMenuName = NULL; - lwc.lpszClassName = class_name; - lwc.cbSize = sizeof(WNDCLASSEX); - RegisterClassEx(&lwc); - if (first_time) { - memcpy(&wc, &lwc, lwc.cbSize); - first_time = 0; - } + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = class_name; + wc.cbSize = sizeof(WNDCLASSEX); + RegisterClassEx(&wc); + class_name_list.add_name(class_name); } + + const char* message_name = "FLTK::ThreadWakeup"; if (!fl_wake_msg) fl_wake_msg = RegisterWindowMessage(message_name); HWND parent; -- cgit v1.2.3