Mercurial > sdl-ios-xcode
comparison src/video/wincommon/SDL_sysevents.c @ 1288:ea3888b472bf
Cleaned up the app registration stuff a bit
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 29 Jan 2006 09:13:36 +0000 |
parents | 15a89a0c52bf |
children | c4a5a772c5d9 |
comparison
equal
deleted
inserted
replaced
1287:15a89a0c52bf | 1288:ea3888b472bf |
---|---|
56 #ifdef _WIN32_WCE | 56 #ifdef _WIN32_WCE |
57 LPWSTR SDL_Appname = NULL; | 57 LPWSTR SDL_Appname = NULL; |
58 #else | 58 #else |
59 LPSTR SDL_Appname = NULL; | 59 LPSTR SDL_Appname = NULL; |
60 #endif | 60 #endif |
61 Uint32 SDL_Appstyle = 0; | |
61 HINSTANCE SDL_Instance = NULL; | 62 HINSTANCE SDL_Instance = NULL; |
62 HWND SDL_Window = NULL; | 63 HWND SDL_Window = NULL; |
63 RECT SDL_bounds = {0, 0, 0, 0}; | 64 RECT SDL_bounds = {0, 0, 0, 0}; |
64 int SDL_windowX = 0; | 65 int SDL_windowX = 0; |
65 int SDL_windowY = 0; | 66 int SDL_windowY = 0; |
691 /* Only do this once... */ | 692 /* Only do this once... */ |
692 if ( app_registered ) { | 693 if ( app_registered ) { |
693 return(0); | 694 return(0); |
694 } | 695 } |
695 | 696 |
696 /* This function needs to be passed the correct process handle | 697 #ifndef CS_BYTEALIGNCLIENT |
697 by the application. | 698 #define CS_BYTEALIGNCLIENT 0 |
698 */ | 699 #endif |
699 if ( ! hInst ) { | 700 if ( ! name && ! SDL_Appname ) { |
700 hInst = SDL_GetModuleHandle(); | 701 name = "SDL_app"; |
701 } | 702 SDL_Appstyle = CS_BYTEALIGNCLIENT; |
702 | 703 SDL_Instance = hInst ? hInst : SDL_GetModuleHandle(); |
703 /* Register the application class */ | 704 } |
704 class.hCursor = NULL; | 705 |
706 if ( name ) { | |
705 #ifdef _WIN32_WCE | 707 #ifdef _WIN32_WCE |
706 { | |
707 /* WinCE uses the UNICODE version */ | 708 /* WinCE uses the UNICODE version */ |
708 int nLen = strlen(name)+1; | 709 int nLen = strlen(name)+1; |
709 SDL_Appname = malloc(nLen*2); | 710 SDL_Appname = malloc(nLen*2); |
710 MultiByteToWideChar(CP_ACP, 0, name, -1, SDL_Appname, nLen); | 711 MultiByteToWideChar(CP_ACP, 0, name, -1, SDL_Appname, nLen); |
711 } | |
712 #else | 712 #else |
713 { | |
714 int nLen = strlen(name)+1; | 713 int nLen = strlen(name)+1; |
715 SDL_Appname = malloc(nLen); | 714 SDL_Appname = malloc(nLen); |
716 strcpy(SDL_Appname, name); | 715 strcpy(SDL_Appname, name); |
717 } | |
718 #endif /* _WIN32_WCE */ | 716 #endif /* _WIN32_WCE */ |
719 class.hIcon = LoadImage(hInst, SDL_Appname, IMAGE_ICON, | 717 SDL_Appstyle = style; |
718 SDL_Instance = hInst ? hInst : SDL_GetModuleHandle(); | |
719 } | |
720 | |
721 /* Register the application class */ | |
722 class.hCursor = NULL; | |
723 class.hIcon = LoadImage(SDL_Instance, SDL_Appname, | |
724 IMAGE_ICON, | |
720 0, 0, LR_DEFAULTCOLOR); | 725 0, 0, LR_DEFAULTCOLOR); |
721 class.lpszMenuName = NULL; | 726 class.lpszMenuName = NULL; |
722 class.lpszClassName = SDL_Appname; | 727 class.lpszClassName = SDL_Appname; |
723 class.hbrBackground = NULL; | 728 class.hbrBackground = NULL; |
724 class.hInstance = hInst; | 729 class.hInstance = SDL_Instance; |
725 class.style = style; | 730 class.style = SDL_Appstyle; |
726 #ifdef HAVE_OPENGL | 731 #ifdef HAVE_OPENGL |
727 class.style |= CS_OWNDC; | 732 class.style |= CS_OWNDC; |
728 #endif | 733 #endif |
729 class.lpfnWndProc = WinMessage; | 734 class.lpfnWndProc = WinMessage; |
730 class.cbWndExtra = 0; | 735 class.cbWndExtra = 0; |
731 class.cbClsExtra = 0; | 736 class.cbClsExtra = 0; |
732 if ( ! RegisterClass(&class) ) { | 737 if ( ! RegisterClass(&class) ) { |
733 SDL_SetError("Couldn't register application class"); | 738 SDL_SetError("Couldn't register application class"); |
734 return(-1); | 739 return(-1); |
735 } | 740 } |
736 SDL_Instance = hInst; | |
737 | 741 |
738 #ifdef WM_MOUSELEAVE | 742 #ifdef WM_MOUSELEAVE |
739 /* Get the version of TrackMouseEvent() we use */ | 743 /* Get the version of TrackMouseEvent() we use */ |
740 _TrackMouseEvent = NULL; | 744 _TrackMouseEvent = NULL; |
741 handle = GetModuleHandle("USER32.DLL"); | 745 handle = GetModuleHandle("USER32.DLL"); |
755 | 759 |
756 app_registered = 1; | 760 app_registered = 1; |
757 return(0); | 761 return(0); |
758 } | 762 } |
759 | 763 |
760 /* | 764 /* Unregisters the windowclass registered in SDL_RegisterApp above. */ |
761 * Unregisters the windowclass registered in SDL_RegisterApp above. | |
762 * Called from DIB_VideoQuit and DX5_VideoQuit when | |
763 * SDL_QuitSubSystem(INIT_VIDEO) is called. | |
764 */ | |
765 void SDL_UnregisterApp() | 765 void SDL_UnregisterApp() |
766 { | 766 { |
767 WNDCLASS class; | 767 WNDCLASS class; |
768 | 768 |
769 /* SDL_RegisterApp might not have been called before */ | 769 /* SDL_RegisterApp might not have been called before */ |
770 if (app_registered) { | 770 if ( app_registered ) { |
771 /* Check for any registered windowclasses. */ | 771 /* Check for any registered window classes. */ |
772 if (GetClassInfo(SDL_Instance, SDL_Appname, &class)) { | 772 if ( GetClassInfo(SDL_Instance, SDL_Appname, &class) ) { |
773 UnregisterClass(SDL_Appname, SDL_Instance); | 773 UnregisterClass(SDL_Appname, SDL_Instance); |
774 } | 774 } |
775 } | 775 app_registered = 0; |
776 app_registered = 0; | 776 } |
777 } | 777 } |
778 | 778 |
779 #ifndef NO_GETKEYBOARDSTATE | 779 #ifndef NO_GETKEYBOARDSTATE |
780 /* JFP: Implementation of ToUnicode() that works on 9x/ME/2K/XP */ | 780 /* JFP: Implementation of ToUnicode() that works on 9x/ME/2K/XP */ |
781 | 781 |