コード例 #1
0
ファイル: main.c プロジェクト: songbei6/WinObjEx64
/*
* WinObjExMain
*
* Purpose:
*
* Actual program entry point.
*
*/
void WinObjExMain()
{
    MSG                     msg1;
    WNDCLASSEX              wincls;
    BOOL                    IsFullAdmin = FALSE, IsWine = FALSE, rv = TRUE, cond = FALSE;
    ATOM                    class_atom = 0;
    INITCOMMONCONTROLSEX    icc;   
    LVCOLUMN                col;
    SHSTOCKICONINFO         sii;
    HMENU                   hMenu;
    HACCEL                  hAccTable = 0;
    WCHAR                   szWindowTitle[100];
    HANDLE                  hIcon;
    HIMAGELIST              TreeViewImages;

    if (!WinObjInitGlobals())
        return;

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

    // check compatibility
    IsWine = supIsWine();
    if (IsWine != FALSE) {
        IsFullAdmin = FALSE;
    }

    supInit(IsFullAdmin, IsWine);

    // do not move anywhere
    // g_kdctx variable initialized BEFORE this.
    // if you move these lines anywhere above they will be zeroed during kdInit
    g_kdctx.IsWine = IsWine;
    g_kdctx.IsFullAdmin = IsFullAdmin;

#ifdef _DEBUG
    TestStart();
#endif

    do {
        //
        // 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_WinObj.hInstance;
        wincls.hIcon = (HICON)LoadImage(g_WinObj.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;

        class_atom = RegisterClassEx(&wincls);
        if (class_atom == 0)
            break;
        
        RtlSecureZeroMemory(szWindowTitle, sizeof(szWindowTitle));
        _strcpy(szWindowTitle, PROGRAM_NAME);
        if (IsFullAdmin != FALSE) {
            _strcat(szWindowTitle, L" (Administrator)");
        }

        if (IsWine != FALSE) {
            _strcat(szWindowTitle, L" (Wine emulation)");
        }

        MainWindow = CreateWindowEx(0, MAKEINTATOM(class_atom), szWindowTitle,
            WS_VISIBLE | WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL, g_WinObj.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;

        hwndStatusBar = CreateWindowEx(0, STATUSCLASSNAME, NULL,
            WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, MainWindow, NULL, g_WinObj.hInstance, NULL);

        g_hwndObjectTree = 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_WinObj.hInstance, NULL);

        if (g_hwndObjectTree == NULL)
            break;

        g_hwndObjectList = 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_WinObj.hInstance, NULL);

        if (g_hwndObjectList == NULL)
            break;

        hwndToolBar = CreateWindowEx(0, TOOLBARCLASSNAME, NULL,
            WS_VISIBLE | WS_CHILD | CCS_TOP | TBSTYLE_FLAT | TBSTYLE_TRANSPARENT |
            TBSTYLE_TOOLTIPS, 0, 0, 0, 0, MainWindow, (HMENU)1004, g_WinObj.hInstance, NULL);

        if (hwndToolBar == NULL)
            break;

        hwndSplitter = CreateWindowEx(0, WC_STATIC, NULL,
            WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, MainWindow, (HMENU)1005, g_WinObj.hInstance, NULL);

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

        // set tree imagelist
        TreeViewImages = supLoadImageList(g_WinObj.hInstance, IDI_ICON_VIEW_DEFAULT, IDI_ICON_VIEW_SELECTED);
        if (TreeViewImages) {
            TreeView_SetImageList(g_hwndObjectTree, TreeViewImages, TVSIL_NORMAL);
        }

        //not enough user rights, insert run as admin menu entry and hide admin only stuff
        if ((IsFullAdmin == FALSE) && (g_kdctx.IsWine == 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);
            }
        }

        if (g_kdctx.hDevice == NULL) {
            //require driver usage, remove
            DeleteMenu(GetSubMenu(GetMenu(MainWindow), 4), ID_EXTRAS_SSDT, MF_BYCOMMAND);
            DeleteMenu(GetSubMenu(GetMenu(MainWindow), 4), ID_EXTRAS_PRIVATENAMESPACES, MF_BYCOMMAND);
        }

        //unsupported
        if (g_WinObj.osver.dwBuildNumber > 10240) {
            DeleteMenu(GetSubMenu(GetMenu(MainWindow), 4), ID_EXTRAS_PRIVATENAMESPACES, MF_BYCOMMAND);
        }

        //wine unsupported
        if (g_kdctx.IsWine != FALSE) {
            DeleteMenu(GetSubMenu(GetMenu(MainWindow), 4), ID_EXTRAS_DRIVERS, MF_BYCOMMAND);
        }

        //load listview images
        g_ListViewImages = supLoadImageList(g_WinObj.hInstance, IDI_ICON_DEVICE, IDI_ICON_UNKNOWN);
        if (g_ListViewImages) {
            hIcon = LoadImage(g_WinObj.hInstance, MAKEINTRESOURCE(IDI_ICON_SORTUP), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
            if (hIcon) {
                ImageList_ReplaceIcon(g_ListViewImages, -1, hIcon);
                DestroyIcon(hIcon);
            }
            hIcon = LoadImage(g_WinObj.hInstance, MAKEINTRESOURCE(IDI_ICON_SORTDOWN), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
            if (hIcon) {
                ImageList_ReplaceIcon(g_ListViewImages, -1, hIcon);
                DestroyIcon(hIcon);
            }
            ListView_SetImageList(g_hwndObjectList, g_ListViewImages, LVSIL_SMALL);
        }

        //load toolbar images
        g_ToolBarMenuImages = ImageList_LoadImage(g_WinObj.hInstance, MAKEINTRESOURCE(IDB_BITMAP1),
            16, 7, CLR_DEFAULT, IMAGE_BITMAP, LR_CREATEDIBSECTION);

        if (g_ToolBarMenuImages) {

            supCreateToolbarButtons(hwndToolBar);

            //set menu icons
            hMenu = GetSubMenu(GetMenu(MainWindow), 1);
            if (hMenu) {
                supSetMenuIcon(hMenu, ID_VIEW_REFRESH,
                    (ULONG_PTR)ImageList_ExtractIcon(g_WinObj.hInstance, g_ToolBarMenuImages, 1));
            }
            hMenu = GetSubMenu(GetMenu(MainWindow), 2);
            if (hMenu && g_ListViewImages) {
                supSetMenuIcon(hMenu, ID_OBJECT_PROPERTIES,
                    (ULONG_PTR)ImageList_ExtractIcon(g_WinObj.hInstance, g_ToolBarMenuImages, 0));
                supSetMenuIcon(hMenu, ID_OBJECT_GOTOLINKTARGET,
                    (ULONG_PTR)ImageList_ExtractIcon(g_WinObj.hInstance, g_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_WinObj.hInstance, g_ToolBarMenuImages, 2));
            }

            //set extras-mailslots/pipes menu image
            hMenu = GetSubMenu(GetMenu(MainWindow), 4);
            if (hMenu) {
                supSetMenuIcon(hMenu, ID_EXTRAS_MAILSLOTS,
                    (ULONG_PTR)ImageList_ExtractIcon(g_WinObj.hInstance, g_ToolBarMenuImages, 5));
                supSetMenuIcon(hMenu, ID_EXTRAS_PIPES,
                    (ULONG_PTR)ImageList_ExtractIcon(g_WinObj.hInstance, g_ToolBarMenuImages, 6));
            }

            //set help menu image
            hMenu = GetSubMenu(GetMenu(MainWindow), 5);
            if (hMenu) {
                supSetMenuIcon(hMenu, ID_HELP_HELP,
                    (ULONG_PTR)ImageList_ExtractIcon(g_WinObj.hInstance, g_ToolBarMenuImages, 3));
            }

        }

        hAccTable = LoadAccelerators(g_WinObj.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 = TEXT("Name");
        col.fmt = LVCFMT_LEFT | LVCFMT_BITMAP_ON_RIGHT;
        col.iOrder = 0;
        col.iImage = -1;
        if (g_ListViewImages) {
            col.iImage = ImageList_GetImageCount(g_ListViewImages) - 1;
        }
        col.cx = 300;
        ListView_InsertColumn(g_hwndObjectList, 1, &col);

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

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

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

        TreeView_SelectItem(g_hwndObjectTree, TreeView_GetRoot(g_hwndObjectTree));
        SetFocus(g_hwndObjectTree);

        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_WinObj.hInstance);

    //do not move anywhere

    supShutdown();

#ifdef _DEBUG
    TestStop();
#endif

}
コード例 #2
0
ファイル: ThreadManager.cpp プロジェクト: jssfy/learngit_tcp
	void WorkerTask::Run() {
		while (!TestStop()) {
			printf("WorkerTask::Run\n");
			sleep(10);
		} printf("out of WorkerTask::Run\n");
	}