Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.1 KiB

  1. /*----------------------------------------------------------------------------
  2. rnawnd.cpp
  3. Functions to zap the RNA windows
  4. Copyright (C) 1995 Microsoft Corporation
  5. All rights reserved.
  6. Authors:
  7. ArulM
  8. ChrisK Updated for ICW usage
  9. --------------------------------------------------------------------------*/
  10. #include "pch.hpp"
  11. #include "globals.h"
  12. #define SMALLBUFLEN 48
  13. /*******************************************************************
  14. NAME: MinimizeRNAWindow
  15. SYNOPSIS: Finds and minimizes the annoying RNA window
  16. ENTRY: pszConnectoidName - name of connectoid launched
  17. NOTES: Does a FindWindow on window class "#32770" (hard-coded
  18. dialog box class which will never change), with
  19. the title "connected to <connectoid name>" or its
  20. localized equivalent.
  21. ********************************************************************/
  22. static const TCHAR szDialogBoxClass[] = TEXT("#32770"); // hard coded dialog class name
  23. HWND hwndFound = NULL;
  24. DWORD dwRASWndTitleMinLen = 0;
  25. BOOL CALLBACK MyEnumWindowsProc(HWND hwnd, LPARAM lparam)
  26. {
  27. TCHAR szTemp[SMALLBUFLEN+2];
  28. PTSTR pszTitle;
  29. UINT uLen1, uLen2;
  30. if(!IsWindowVisible(hwnd))
  31. return TRUE;
  32. if(GetClassName(hwnd, szTemp, SMALLBUFLEN)==0)
  33. return TRUE; // continue enumerating
  34. if(lstrcmp(szTemp, szDialogBoxClass)!=0)
  35. return TRUE;
  36. if(GetWindowText(hwnd, szTemp, SMALLBUFLEN)==0)
  37. return TRUE;
  38. szTemp[SMALLBUFLEN] = 0;
  39. uLen1 = lstrlen(szTemp);
  40. Assert(dwRASWndTitleMinLen);
  41. if(uLen1 < dwRASWndTitleMinLen)
  42. return TRUE;
  43. // skip last 5 chars of title, but keep length to at least the min len
  44. uLen1 = min(dwRASWndTitleMinLen, (uLen1-5));
  45. pszTitle = (PTSTR)lparam;
  46. Assert(pszTitle);
  47. uLen2 = lstrlen(pszTitle);
  48. Dprintf(TEXT("Title=(%s), len=%d, Window=(%s), len=%d\r\n"), pszTitle, uLen2, szTemp, uLen1);
  49. if(uLen2 < uLen1)
  50. return TRUE;
  51. if(_memicmp(pszTitle, szTemp, uLen1)!=0)
  52. return TRUE;
  53. Dprintf(TEXT("FOUND RNA WINDOW!!!\r\n"));
  54. hwndFound = hwnd;
  55. return FALSE;
  56. }
  57. HWND MyFindRNAWindow(PTSTR pszTitle)
  58. {
  59. DWORD dwRet;
  60. hwndFound = NULL;
  61. dwRet = EnumWindows((WNDENUMPROC)(&MyEnumWindowsProc), (LPARAM)pszTitle);
  62. Dprintf(TEXT("EnumWindows returned %d\r\n"), dwRet);
  63. return hwndFound;
  64. }
  65. DWORD WINAPI WaitAndMinimizeRNAWindow(PVOID pTitle)
  66. {
  67. // starts as a seperate thread
  68. int i;
  69. HWND hwndRNAApp;
  70. Assert(pTitle);
  71. for(i=0; !(hwndRNAApp=MyFindRNAWindow((PTSTR)pTitle)) && i<100; i++)
  72. {
  73. Dprintf(TEXT("Waiting for RNA Window\r\n"));
  74. Sleep(50);
  75. }
  76. Dprintf(TEXT("FindWindow (%s)(%s) returned %d\r\n"), szDialogBoxClass, pTitle, hwndRNAApp);
  77. if(hwndRNAApp)
  78. {
  79. // Hide the window
  80. // ShowWindow(hwndRNAApp,SW_HIDE);
  81. // Used to just minimize, but that wasnt enough
  82. // ChrisK reinstated minimize for ICW
  83. ShowWindow(hwndRNAApp,SW_MINIMIZE);
  84. }
  85. LocalFree(pTitle);
  86. // exit function and thread
  87. return ERROR_SUCCESS;
  88. }
  89. void MinimizeRNAWindow(LPTSTR pszConnectoidName, HINSTANCE hInst)
  90. {
  91. HANDLE hThread;
  92. DWORD dwThreadId;
  93. Assert(pszConnectoidName);
  94. // alloc strings for title and format
  95. TCHAR * pFmt = (TCHAR*)LocalAlloc(LPTR, (SMALLBUFLEN+1) * sizeof(TCHAR));
  96. TCHAR * pTitle = (TCHAR*)LocalAlloc(LPTR, (RAS_MaxEntryName + SMALLBUFLEN + 1) * sizeof(TCHAR));
  97. if (!pFmt || !pTitle)
  98. goto error;
  99. // load the title format ("connected to <connectoid name>" from resource
  100. Assert(hInst);
  101. LoadString(hInst, IDS_CONNECTED_TO, pFmt, SMALLBUFLEN);
  102. // get length of localized title (including the %s). Assume the unmunged
  103. // part of the window title is at least "Connected to XX" long.
  104. dwRASWndTitleMinLen = lstrlen(pFmt);
  105. // build the title
  106. wsprintf(pTitle, pFmt, pszConnectoidName);
  107. hThread = CreateThread(0, 0, &WaitAndMinimizeRNAWindow, pTitle, 0, &dwThreadId);
  108. Assert(hThread!=INVALID_HANDLE_VALUE && dwThreadId);
  109. // dont free pTitle. The child thread needs it!
  110. LocalFree(pFmt);
  111. // free the thread handle or the threads stack is leaked!
  112. CloseHandle(hThread);
  113. return;
  114. error:
  115. if(pFmt) LocalFree(pFmt);
  116. if(pTitle) LocalFree(pTitle);
  117. }