int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	//This UNREFERENCED_PARAMETER macro just suppresses a compiler warning about two parameters being unused in this function.
   UNREFERENCED_PARAMETER(hPrevInstance);
   UNREFERENCED_PARAMETER(lpCmdLine);

   // Show main window 
   DialogBox(hInstance, MAKEINTRESOURCE(IDD_SINGLETON), NULL, Dlg_Proc);

   // Don't forget to clean up and release kernel resources
   if (g_hSingleton != NULL) {
      CloseHandle(g_hSingleton);
   }

   if (g_hNamespace != NULL) {
      if (g_bNamespaceOpened) {  // Open namespace
         ClosePrivateNamespace(g_hNamespace, 0);
      } else { // Created namespace
         ClosePrivateNamespace(g_hNamespace, PRIVATE_NAMESPACE_FLAG_DESTROY);
      }
   }

   if (g_hBoundary != NULL) {
      DeleteBoundaryDescriptor(g_hBoundary);
   }

   return(0);
}
int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
   UNREFERENCED_PARAMETER(hPrevInstance);
   UNREFERENCED_PARAMETER(lpCmdLine);

   /* Show main window */
   DialogBox(hInstance, MAKEINTRESOURCE(IDD_SINGLETON), NULL, Dlg_Proc);

   /* Don't forget to clean up and release kernel resources */
   if (g_hSingleton != NULL) 
   {
       CloseHandle(g_hSingleton);
   }

   if (g_hNamespace != NULL) 
   {
	   /* Open namespace */
       if (g_bNamespaceOpened) 
	   {  
		   /* Open namespace */
           ClosePrivateNamespace(g_hNamespace, 0);
       } 
	   else 
	   {  
		   /* Created namespace */
           ClosePrivateNamespace(g_hNamespace, PRIVATE_NAMESPACE_FLAG_DESTROY);
       }
   }

   if (g_hBoundary != NULL) 
   {
       DeleteBoundaryDescriptor(g_hBoundary);
   }

   return(0);
}
Beispiel #3
0
/*
* WinObjExMain
*
* Purpose:
*
* Actual program entry point.
*
*/
void WinObjExMain()
{
	MSG						msg1;
	WNDCLASSEX				wincls;
	BOOL					IsFullAdmin = FALSE, rv = TRUE, cond = FALSE;
	ATOM					class_atom = 0;
	INITCOMMONCONTROLSEX	icc;
	LVCOLUMNW				col;
	SHSTOCKICONINFO			sii;
	HMENU					hMenu;
	HACCEL					hAccTable = 0;
	WCHAR					szWindowTitle[100];
	HANDLE					tmpb;


#ifdef _DEBUG
	TestPrivateNamespace();
	//TestIoCompletion();
	//TestTimer();
	//TestTransaction();
#endif

	pHtmlHelpW = NULL;
	CurrentObjectPath = NULL;
	bSortInverse = FALSE;
	g_hInstance = GetModuleHandle(NULL);
	RtlSecureZeroMemory(szWindowTitle, sizeof(szWindowTitle));

	//clear dialogs array
	RtlSecureZeroMemory(g_wobjDialogs, sizeof(g_wobjDialogs));

	// do not move anywhere
	IsFullAdmin = supUserIsFullAdmin();
	supInit(IsFullAdmin);

	//create main window and it components
	wincls.cbSize = sizeof(WNDCLASSEX);
	wincls.style = 0;
	wincls.lpfnWndProc = &MainWindowProc;
	wincls.cbClsExtra = 0;
	wincls.cbWndExtra = 0;
	wincls.hInstance = g_hInstance;
	wincls.hIcon = (HICON)LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ICON_MAIN), IMAGE_ICON, 0, 0, LR_SHARED);
	wincls.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(OCR_SIZEWE), IMAGE_CURSOR, 0, 0, LR_SHARED);
	wincls.hbrBackground = NULL;
	wincls.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
	wincls.lpszClassName = MAINWINDOWCLASSNAME;
	wincls.hIconSm = 0;

	do {
		class_atom = RegisterClassEx(&wincls);
		if (class_atom == 0)
			break;

		_strcpy(szWindowTitle, PROGRAM_NAME);
		if (IsFullAdmin != FALSE) {
			_strcat(szWindowTitle, L" (Administrator)");
		}

		MainWindow = CreateWindowEx(0, MAKEINTATOM(class_atom), szWindowTitle,
			WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, g_hInstance, NULL);
		if (MainWindow == NULL)
			break;

		icc.dwSize = sizeof(icc);
		icc.dwICC = ICC_LISTVIEW_CLASSES | ICC_TREEVIEW_CLASSES | ICC_BAR_CLASSES | ICC_TAB_CLASSES;
		if (!InitCommonControlsEx(&icc))
			break;

		StatusBar = CreateWindowEx(0, STATUSCLASSNAME, NULL,
			WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, MainWindow, (HMENU)1001, g_hInstance, NULL);

		ObjectTree = CreateWindowEx(WS_EX_CLIENTEDGE, WC_TREEVIEW, NULL,
			WS_VISIBLE | WS_CHILD | WS_TABSTOP | TVS_DISABLEDRAGDROP | TVS_HASBUTTONS | 
			TVS_HASLINES | TVS_LINESATROOT, 0, 0, 0, 0, MainWindow, (HMENU)1002, g_hInstance, NULL);

		if (ObjectTree == NULL)
			break;

		ObjectList = CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEW, NULL,
			WS_VISIBLE | WS_CHILD | WS_TABSTOP | LVS_AUTOARRANGE | LVS_REPORT | 
			LVS_SHOWSELALWAYS | LVS_SINGLESEL | LVS_SHAREIMAGELISTS, 0, 0, 0, 0, 
			MainWindow, (HMENU)1003, g_hInstance, NULL);

		if (ObjectList == NULL)
			break;

		ToolBar1 = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
			WS_VISIBLE | WS_CHILD | CCS_TOP | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT | 
			TBSTYLE_TOOLTIPS, 0, 0, 0, 0, MainWindow, (HMENU)1004, g_hInstance, NULL);

		if (ToolBar1 == NULL)
			break;

		Splitter = CreateWindowEx(0, WC_STATIC, NULL,
			WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, MainWindow, (HMENU)1005, g_hInstance, NULL);

		// initialization of views
		SendMessage(MainWindow, WM_SIZE, 0, 0);
		ListView_SetExtendedListViewStyle(ObjectList, 
			LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_LABELTIP | LVS_EX_DOUBLEBUFFER);

		// set tree imagelist
		TreeViewImages = supLoadImageList(g_hInstance, IDI_ICON_VIEW_DEFAULT, IDI_ICON_VIEW_SELECTED);
		if (TreeViewImages) {
			TreeView_SetImageList(ObjectTree, TreeViewImages, TVSIL_NORMAL);
		}

		//insert run as admin menu entry
		if (IsFullAdmin == FALSE) {
			hMenu = GetSubMenu(GetMenu(MainWindow), 0);
			InsertMenu(hMenu, 0, MF_BYPOSITION, ID_FILE_RUNASADMIN, T_RUNASADMIN);
			InsertMenu(hMenu, 1, MF_BYPOSITION | MF_SEPARATOR, 0, NULL);
			//set menu shield icon
			RtlSecureZeroMemory(&sii, sizeof(sii));
			sii.cbSize = sizeof(sii);
			if (SHGetStockIconInfo(SIID_SHIELD, SHGSI_ICON | SHGFI_SMALLICON, &sii) == S_OK) {
				supSetMenuIcon(hMenu, ID_FILE_RUNASADMIN, (ULONG_PTR)sii.hIcon);
			}
		}

		//load listview images
		ListViewImages = supLoadImageList(g_hInstance, IDI_ICON_DEVICE, IDI_ICON_UNKNOWN);
		if (ListViewImages) {
			tmpb = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ICON_SORTUP), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
			if (tmpb) {
				ImageList_ReplaceIcon(ListViewImages, -1, tmpb);
				DestroyIcon(tmpb);
			}
			tmpb = LoadImage(g_hInstance, MAKEINTRESOURCE(IDI_ICON_SORTDOWN), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
			if (tmpb) {
				ImageList_ReplaceIcon(ListViewImages, -1, tmpb);
				DestroyIcon(tmpb);
			}
			ListView_SetImageList(ObjectList, ListViewImages, LVSIL_SMALL);
		}

		//load toolbar images
		ToolBarMenuImages = ImageList_LoadImage(g_hInstance, MAKEINTRESOURCE(IDB_BITMAP1), 
			16, 7, CLR_DEFAULT, IMAGE_BITMAP, LR_CREATEDIBSECTION);

		if (ToolBarMenuImages) {

			supCreateToolbarButtons(ToolBar1);

			//set menu icons
			hMenu = GetSubMenu(GetMenu(MainWindow), 1);
			if (hMenu) {
				supSetMenuIcon(hMenu, ID_VIEW_REFRESH,
					(ULONG_PTR)ImageList_ExtractIcon(g_hInstance, ToolBarMenuImages, 1));
			}
			hMenu = GetSubMenu(GetMenu(MainWindow), 2);
			if (hMenu && ListViewImages) {
				supSetMenuIcon(hMenu, ID_OBJECT_PROPERTIES,
					(ULONG_PTR)ImageList_ExtractIcon(g_hInstance, ToolBarMenuImages, 0));
				supSetMenuIcon(hMenu, ID_OBJECT_GOTOLINKTARGET,
					(ULONG_PTR)ImageList_ExtractIcon(g_hInstance, ListViewImages, 
					ID_FROM_VALUE(IDI_ICON_SYMLINK)));
			}

			//set object -> find object menu image
			hMenu = GetSubMenu(GetMenu(MainWindow), 3);
			if (hMenu) {
				supSetMenuIcon(hMenu, ID_FIND_FINDOBJECT,
					(ULONG_PTR)ImageList_ExtractIcon(g_hInstance, ToolBarMenuImages, 2));
			}

			//set extras-pipe menu image
			hMenu = GetSubMenu(GetMenu(MainWindow), 4);
			if (hMenu) {
				supSetMenuIcon(hMenu, ID_EXTRAS_PIPES,
					(ULONG_PTR)ImageList_ExtractIcon(g_hInstance, ToolBarMenuImages, 6));
			}

			//set help menu image
			hMenu = GetSubMenu(GetMenu(MainWindow), 5);
			if (hMenu) {
				supSetMenuIcon(hMenu, ID_HELP_HELP,
					(ULONG_PTR)ImageList_ExtractIcon(g_hInstance, ToolBarMenuImages, 3));
			}

		}

		hAccTable = LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDR_ACCELERATOR1));

		//create ObjectList columns
		RtlSecureZeroMemory(&col, sizeof(col));
		col.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_FMT | LVCF_WIDTH | LVCF_ORDER | LVCF_IMAGE;
		col.iSubItem = 1;
		col.pszText = L"Name";
		col.fmt = LVCFMT_LEFT | LVCFMT_BITMAP_ON_RIGHT;
		col.iOrder = 0;
		col.iImage = -1;
		if (ListViewImages) {
			col.iImage = ImageList_GetImageCount(ListViewImages) - 1;
		}
		col.cx = 300;
		ListView_InsertColumn(ObjectList, 1, &col);

		col.iSubItem = 2;
		col.pszText = L"Type";
		col.iOrder = 1;
		col.iImage = -1;
		col.cx = 100;
		ListView_InsertColumn(ObjectList, 2, &col);

		col.iSubItem = 3;
		col.pszText = L"Additional Information";
		col.iOrder = 2;
		col.iImage = -1;
		col.cx = 170;
		ListView_InsertColumn(ObjectList, 3, &col);

		ListObjectDirectoryTree(L"\\", NULL, NULL);

		TreeView_SelectItem(ObjectTree, TreeView_GetRoot(ObjectTree));
		SetFocus(ObjectTree);

		do {
			rv = GetMessage(&msg1, NULL, 0, 0);

			if (rv == -1)
				break;

			if (MainDlgMsgHandler(msg1)) 
				continue;

			if (IsDialogMessage(MainWindow, &msg1)) {
				TranslateAccelerator(MainWindow, hAccTable, &msg1);
				continue;
			}

			TranslateMessage(&msg1);
			DispatchMessage(&msg1);
		} while (rv != 0);

	} while (cond);

	if (class_atom != 0)
		UnregisterClass(MAKEINTATOM(class_atom), g_hInstance);

	//do not move anywhere
	
	supShutdown();

#ifdef _DEBUG
	if (hObject) NtClose(hObject);

	if (g_hMutex != NULL) {
		CloseHandle(g_hMutex);
	}
	if (g_hNamespace != NULL) {
		ClosePrivateNamespace(g_hNamespace, PRIVATE_NAMESPACE_FLAG_DESTROY);
	}

#endif
}