Esempio n. 1
0
VOID
UpdateServiceCount(PMAIN_WND_INFO Info)
{
    LPTSTR lpNumServices;

    if (AllocAndLoadString(&lpNumServices,
                           hInstance,
                           IDS_NUM_SERVICES))
    {
        TCHAR szNumServices[32];

        INT NumListedServ = ListView_GetItemCount(Info->hListView);

        _sntprintf(szNumServices,
                   31,
                   lpNumServices,
                   NumListedServ);

        SendMessage(Info->hStatus,
                    SB_SETTEXT,
                    0,
                    (LPARAM)szNumServices);

        LocalFree(lpNumServices);
    }
}
Esempio n. 2
0
//----------------------------------------------------------------------
//
//Sets flags based on commandline arguments
//
//----------------------------------------------------------------------
BOOL ParseCommandLine(int argc, TCHAR *argv[])
{
	int i;
	LPTSTR lpIllegalMsg;

	//FIXME: Add handling of commandline arguments to select the session number and name, and also name of remote machine
	//Example: logoff.exe 4 /SERVER:Master should logoff session number 4 on remote machine called Master.

	for (i = 1; i < argc; i++) {
		switch(argv[i][0]){
		case '-':
		case '/':
			// -v (verbose)
			if (argv[i][1] == 'v') {
				bVerbose = TRUE;
				break; //continue parsing the arguments
			}
			// -? (usage)
			else if(argv[i][1] == '?') {
				return FALSE; //display the Usage
			}
		default:
			//Invalid parameter detected
			if (AllocAndLoadString(&lpIllegalMsg, GetModuleHandle(NULL), IDS_ILLEGAL_PARAM))
			_putts(lpIllegalMsg);
			return FALSE;
		}
	}

	return TRUE;
}
Esempio n. 3
0
HWND
CreateProgressDialog(HWND hParent,
                     UINT LabelId)
{
    HWND hProgDlg;
    LPWSTR lpProgStr;

    /* open the progress dialog */
    hProgDlg = CreateDialogW(hInstance,
                             MAKEINTRESOURCEW(IDD_DLG_PROGRESS),
                             hParent,
                             ProgressDialogProc);
    if (hProgDlg != NULL)
    {
        /* Load the label Id */
        if (AllocAndLoadString(&lpProgStr,
                               hInstance,
                               LabelId))
        {
            /* Write it to the dialog */
            SendDlgItemMessageW(hProgDlg,
                                IDC_SERVCON_INFO,
                                WM_SETTEXT,
                                0,
                                (LPARAM)lpProgStr);

            HeapFree(GetProcessHeap(),
                     0,
                     lpProgStr);
        }
    }

    return hProgDlg;
}
Esempio n. 4
0
//----------------------------------------------------------------------
//
//Retrieve resource string and output the Usage to the console
//
//----------------------------------------------------------------------
static void PrintUsage() {
	LPTSTR lpUsage = NULL;

	if (AllocAndLoadString(&lpUsage, GetModuleHandle(NULL), IDS_USAGE)) {
		_putts(lpUsage);
	}

}
Esempio n. 5
0
VOID
TV2_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo,
                        HTREEITEM hParent,
                        LPTSTR lpServiceName)
{

    LPENUM_SERVICE_STATUSW lpServiceStatus;
    LPTSTR lpNoDepends;
    DWORD count, i;
    BOOL bHasChildren;

    /* Get a list of service dependents */
    lpServiceStatus = TV2_GetDependants(lpServiceName, &count);
    if (lpServiceStatus)
    {
        for (i = 0; i < count; i++)
        {
            /* Does this item need a +/- box? */
            bHasChildren = TV2_HasDependantServices(lpServiceStatus[i].lpServiceName);

            /* Add it */
            AddItemToTreeView(pDlgInfo->hDependsTreeView2,
                              hParent,
                              lpServiceStatus[i].lpDisplayName,
                              lpServiceStatus[i].lpServiceName,
                              lpServiceStatus[i].ServiceStatus.dwServiceType,
                              bHasChildren);
        }

        HeapFree(GetProcessHeap(),
                 0,
                 lpServiceStatus);
    }
    else
    {
        /* If there is no parent, set the tree to 'no dependencies' */
        if (!hParent)
        {
            /* Load the 'No dependencies' string */
            AllocAndLoadString(&lpNoDepends, hInstance, IDS_NO_DEPENDS);

            AddItemToTreeView(pDlgInfo->hDependsTreeView2,
                              NULL,
                              lpNoDepends,
                              NULL,
                              0,
                              FALSE);

            HeapFree(ProcessHeap,
                     0,
                     lpNoDepends);

            /* Disable the window */
            EnableWindow(pDlgInfo->hDependsTreeView2, FALSE);
        }
    }
}
Esempio n. 6
0
static BOOL
DoCreate(PCREATE_DATA Data)
{
    SC_HANDLE hSCManager;
    SC_HANDLE hSc;
    BOOL bRet = FALSE;

    /* open handle to the SCM */
    hSCManager = OpenSCManager(NULL,
                               NULL,
                               SC_MANAGER_ALL_ACCESS);
    if (hSCManager)
    {
        hSc = CreateService(hSCManager,
                            Data->ServiceName,
                            Data->DisplayName,
                            SERVICE_ALL_ACCESS,
                            SERVICE_WIN32_OWN_PROCESS,
                            SERVICE_DEMAND_START,
                            SERVICE_ERROR_NORMAL,
                            Data->BinPath,
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            NULL);

        if (hSc)
        {
            LPTSTR lpSuccess;

            /* Set the service description as CreateService
               does not do this for us */
            SetServiceDescription(Data->ServiceName,
                                  Data->Description);

            /* report success to user */
            if (AllocAndLoadString(&lpSuccess,
                                   hInstance,
                                   IDS_CREATE_SUCCESS))
            {
                DisplayString(lpSuccess);

                HeapFree(ProcessHeap,
                         0,
                         lpSuccess);
            }

            CloseServiceHandle(hSc);
            bRet = TRUE;
        }

        CloseServiceHandle(hSCManager);
    }

    return bRet;
}
Esempio n. 7
0
static HWND
CreateApplicationWindow(VOID)
{
    HWND hWnd;

    PMIXER_WINDOW MixerWindow = HeapAlloc(hAppHeap,
                                          HEAP_ZERO_MEMORY,
                                          sizeof(MIXER_WINDOW));
    if (MixerWindow == NULL)
    {
        return NULL;
    }

    if (mixerGetNumDevs() > 0)
    {
        hWnd = CreateWindowEx(WS_EX_WINDOWEDGE | WS_EX_CONTROLPARENT,
                              SZ_APP_CLASS,
                              lpAppTitle,
                              WS_DLGFRAME | WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE, 
                              0, 0, 300, 315,
                              NULL,
                              LoadMenu(hAppInstance,
                                       MAKEINTRESOURCE(IDM_MAINMENU)),
                              hAppInstance,
                              MixerWindow);
    }
    else
    {
        LPTSTR lpErrMessage;

        /*
         * no mixer devices are available!
         */

        hWnd = NULL;
        if (AllocAndLoadString(&lpErrMessage,
                               hAppInstance,
                               IDS_NOMIXERDEVICES))
        {
            MessageBox(NULL,
                       lpErrMessage,
                       lpAppTitle,
                       MB_ICONINFORMATION);
            LocalFree(lpErrMessage);
        }
    }

    if (hWnd == NULL)
    {
        HeapFree(hAppHeap,
                 0,
                 MixerWindow);
    }

    return hWnd;
}
Esempio n. 8
0
//----------------------------------------------------------------------
//
//Main entry for program
//
//----------------------------------------------------------------------
int _tmain(int argc, TCHAR *argv[])
{
	LPTSTR lpLogoffRemote, lpLogoffLocal;

	//
	// Parse command line
	//
	if (!ParseCommandLine(argc, argv)) {
		PrintUsage();
		return 1;
	}

	//
	//Should we log off session on remote server?
	//
	if (szRemoteServerName) {
		if (bVerbose) {
			if (AllocAndLoadString(&lpLogoffRemote, GetModuleHandle(NULL), IDS_LOGOFF_REMOTE))
			_putts(lpLogoffRemote);
		}

		//FIXME: Add Remote Procedure Call to logoff user on a remote machine
		_ftprintf(stderr, "Remote Procedure Call in logoff.exe has not been implemented");
	}
	//
	//Perform logoff of current session on local machine instead
	//
	else {
		if (bVerbose) {
			//Get resource string, and print it.
			if (AllocAndLoadString(&lpLogoffLocal, GetModuleHandle(NULL), IDS_LOGOFF_LOCAL))
			_putts(lpLogoffLocal);
		}

		//Actual logoff
		if (!ExitWindows(NULL, NULL)) {
			DisplayLastError();
			return 1;
		}
	}

	return 0;
}
Esempio n. 9
0
int WINAPI
_tWinMain(HINSTANCE hThisInstance,
          HINSTANCE hPrevInstance,
          LPTSTR lpCmdLine,
          int nCmdShow)
{
    LPTSTR lpAppName;
    HWND hMainWnd;
    MSG Msg;
    int Ret = 1;
    INITCOMMONCONTROLSEX icex;

    hInstance = hThisInstance;
    ProcessHeap = GetProcessHeap();

    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
    InitCommonControlsEx(&icex);

    if (!AllocAndLoadString(&lpAppName,
                            hInstance,
                            IDS_APPNAME))
    {
        return 1;
    }

    if (InitMainWindowImpl())
    {
        hMainWnd = CreateMainWindow(lpAppName,
                                    nCmdShow);
        if (hMainWnd != NULL)
        {
            /* pump the message queue */
            while( GetMessage( &Msg, NULL, 0, 0 ) )
            {
                //if(! IsDialogMessage(hProgDlg, &Msg) )
                //{
                    TranslateMessage(&Msg);
                    DispatchMessage(&Msg);
                //}
            }

            Ret = 0;
        }

        UninitMainWindowImpl();
    }

    LocalFree((HLOCAL)lpAppName);

    return Ret;
}
Esempio n. 10
0
static BOOL
DoDeleteService(PMAIN_WND_INFO Info,
                HWND hDlg)
{
    SC_HANDLE hSCManager;
    SC_HANDLE hSc;
    BOOL bRet = FALSE;

    hSCManager = OpenSCManagerW(NULL,
                                NULL,
                                SC_MANAGER_ALL_ACCESS);
    if (hSCManager)
    {
        hSc = OpenServiceW(hSCManager,
                           Info->pCurrentService->lpServiceName,
                           DELETE);
        if (hSc)
        {
            if (DeleteService(hSc))
            {
                LPWSTR lpSuccess;

                /* report success to user */
                if (AllocAndLoadString(&lpSuccess,
                                       hInstance,
                                       IDS_DELETE_SUCCESS))
                {
                    DisplayString(lpSuccess);

                    LocalFree(lpSuccess);
                }

                bRet = TRUE;
            }

            CloseServiceHandle(hSc);
        }

        CloseServiceHandle(hSCManager);
    }

    return bRet;
}
Esempio n. 11
0
VOID
TV1_AddDependantsToTree(PSERVICEPROPSHEET pDlgInfo,
                        HTREEITEM hParent,
                        LPTSTR lpServiceName)
{
    SC_HANDLE hSCManager;
    SC_HANDLE hService;
    LPQUERY_SERVICE_CONFIG lpServiceConfig;
    LPTSTR lpDependants;
    LPTSTR lpStr;
    LPTSTR lpNoDepends;
    BOOL bHasChildren;

    hSCManager = OpenSCManager(NULL,
                               NULL,
                               SC_MANAGER_ALL_ACCESS);
    if (hSCManager)
    {
        hService = OpenService(hSCManager,
                               lpServiceName,
                               SERVICE_QUERY_STATUS | SERVICE_ENUMERATE_DEPENDENTS | SERVICE_QUERY_CONFIG);
        if (hService)
        {
            /* Get a list of service dependents */
            lpDependants = TV1_GetDependants(pDlgInfo, hService);
            if (lpDependants)
            {
                lpStr = lpDependants;

                /* Make sure this isn't the end of the list */
                while (*lpStr)
                {
                    /* Get the info for this service */
                    lpServiceConfig = GetServiceConfig(lpStr);
                    if (lpServiceConfig)
                    {
                        /* Does this item need a +/- box? */
                        if (lpServiceConfig->lpDependencies &&
                            *lpServiceConfig->lpDependencies != '\0')
                        {
                            bHasChildren = TRUE;
                        }
                        else
                        {
                            bHasChildren = FALSE;
                        }

                        /* Add it */
                        AddItemToTreeView(pDlgInfo->hDependsTreeView1,
                                          hParent,
                                          lpServiceConfig->lpDisplayName,
                                          lpStr,
                                          lpServiceConfig->dwServiceType,
                                          bHasChildren);

                        HeapFree(GetProcessHeap(),
                                 0,
                                 lpServiceConfig);
                    }

                    /* Move to the end of the string */
                    while (*lpStr++)
                        ;
                }

                HeapFree(GetProcessHeap(),
                         0,
                         lpDependants);
            }
            else
            {
                /* If there is no parent, set the tree to 'no dependencies' */
                if (!hParent)
                {
                    /* Load the 'No dependencies' string */
                    AllocAndLoadString(&lpNoDepends, hInstance, IDS_NO_DEPENDS);

                    AddItemToTreeView(pDlgInfo->hDependsTreeView1,
                                      NULL,
                                      lpNoDepends,
                                      NULL,
                                      0,
                                      FALSE);

                    LocalFree(lpNoDepends);

                    /* Disable the window */
                    EnableWindow(pDlgInfo->hDependsTreeView1, FALSE);
                }
            }

            CloseServiceHandle(hService);
        }

        CloseServiceHandle(hSCManager);
    }
}
Esempio n. 12
0
int WINAPI
_tWinMain(HINSTANCE hThisInstance,
          HINSTANCE hPrevInstance,
          LPTSTR lpCmdLine,
          int nCmdShow)
{
    LPTSTR lpAppName;
    HWND hMainWnd;
    MSG Msg;
    int Ret = 1;
    INITCOMMONCONTROLSEX icex;
    
    switch (GetUserDefaultUILanguage())
  {
    case MAKELANGID(LANG_HEBREW, SUBLANG_DEFAULT):
      SetProcessDefaultLayout(LAYOUT_RTL);
      break;

    default:
      break;
  }
    
    hInstance = hThisInstance;
    ProcessHeap = GetProcessHeap();

    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
    InitCommonControlsEx(&icex);

    if (!AllocAndLoadString(&lpAppName,
                            hInstance,
                            IDS_APPNAME))
    {
        return 1;
    }

    if (InitMainWindowImpl())
    {
        hMainWnd = CreateMainWindow(lpAppName,
                                    nCmdShow);
        if (hMainWnd != NULL)
        {
            /* pump the message queue */
            while( GetMessage( &Msg, NULL, 0, 0 ) )
            {
                //if ( !hProgDlg || !IsWindow(hProgDlg) || !IsDialogMessage(hProgDlg, &Msg) )
                //{
                    TranslateMessage(&Msg);
                    DispatchMessage(&Msg);
                //}
            }

            Ret = 0;
        }

        UninitMainWindowImpl();
    }

    LocalFree((HLOCAL)lpAppName);

    return Ret;
}
Esempio n. 13
0
static BOOL
TdbInsertToolbar(PTOOLBAR_DOCKS TbDocks,
                 PDOCKBAR_ITEM Item,
                 DOCK_POSITION Position)
{
    LPTSTR lpCaption = NULL;
    REBARBANDINFO rbi = {0};
    BOOL Ret = FALSE;

    rbi.cbSize = sizeof(rbi);
    rbi.fMask = RBBIM_ID | RBBIM_STYLE | RBBIM_LPARAM;
    rbi.wID = Item->DockBar.BarId;
    rbi.fStyle = RBBS_GRIPPERALWAYS;
    rbi.lParam = (LPARAM)Item;

    if (Item->DockBar.DisplayTextId != 0)
    {
        if (AllocAndLoadString(&lpCaption,
                               hInstance,
                               Item->DockBar.DisplayTextId))
        {
            rbi.fMask |= RBBIM_TEXT;
            rbi.lpText = lpCaption;
        }
    }

    if (Item->hWndClient != NULL)
    {
        rbi.fMask |= RBBIM_CHILD;
        rbi.hwndChild = Item->hWndClient;
    }

    switch (Item->DockBar.Position)
    {
        case NO_DOCK:
        {
            POINT pt = {0};

            /* FIXME - calculate size */
            Ret = TbdCreateToolbarWnd(TbDocks,
                                      Item,
                                      Item->DockBar.Position,
                                      (UINT)-1,
                                      &rbi,
                                      pt,
                                      NULL,
                                      (UINT)-1,
                                      FALSE);
            break;
        }

        default:
        {
            UINT Index = -1;
            BOOL AddBand = TRUE;

            if (Item->Callbacks->InsertBand != NULL)
            {
                AddBand = Item->Callbacks->InsertBand(TbDocks,
                                                      &Item->DockBar,
                                                      Item->Context,
                                                      &Index,
                                                      &rbi);
            }

            if (AddBand)
            {
                Item->Callbacks->DockBand(TbDocks,
                                          &Item->DockBar,
                                          Item->Context,
                                          NO_DOCK,
                                          Item->DockBar.Position,
                                          &rbi);

                if (rbi.fMask & RBBIM_CHILD)
                    Item->hWndClient = rbi.hwndChild;
                else
                    Item->hWndClient = NULL;

                Ret = SendMessage(TbDocks->hRebar[Position],
                                  RB_INSERTBAND,
                                  (WPARAM)Index,
                                  (LPARAM)&rbi) != 0;
                if (Ret)
                {
                    Item->PrevDock = Position;
                    Item->PrevBandIndex = (UINT)SendMessage(TbDocks->hRebar[Position],
                                                            RB_IDTOINDEX,
                                                            (WPARAM)Item->DockBar.BarId,
                                                            0);
                }
            }

            break;
        }
    }

    if (lpCaption != NULL)
    {
        LocalFree((HLOCAL)lpCaption);
    }

    return Ret;
}
Esempio n. 14
0
static BOOL
DoInitDependsDialog(PMAIN_WND_INFO pInfo,
                    HWND hDlg)
{
    HWND hServiceListBox;
    LPWSTR lpPartialStr, lpStr;
    DWORD fullLen;
    HICON hIcon = NULL;
    BOOL bRet = FALSE;

    if (pInfo)
    {
        /* Tag the info to the window */
        SetWindowLongPtrW(hDlg,
                          GWLP_USERDATA,
                          (LONG_PTR)pInfo);

        /* Load the icon for the window */
        hIcon = (HICON)LoadImageW(hInstance,
                                  MAKEINTRESOURCE(IDI_SM_ICON),
                                  IMAGE_ICON,
                                  GetSystemMetrics(SM_CXSMICON),
                                  GetSystemMetrics(SM_CXSMICON),
                                  0);
        if (hIcon)
        {
            /* Set it */
            SendMessageW(hDlg,
                         WM_SETICON,
                         ICON_SMALL,
                         (LPARAM)hIcon);
            DestroyIcon(hIcon);
        }

        /* Load the stop depends note */
        if (AllocAndLoadString(&lpPartialStr,
                               hInstance,
                               IDS_STOP_DEPENDS))
        {
            /* Get the length required */
            fullLen = wcslen(lpPartialStr) + wcslen(pInfo->pCurrentService->lpDisplayName) + 1;

            lpStr = HeapAlloc(ProcessHeap,
                              0,
                              fullLen * sizeof(WCHAR));
            if (lpStr)
            {
                /* Add the service name to the depends note */
                _snwprintf(lpStr,
                           fullLen,
                           lpPartialStr,
                           pInfo->pCurrentService->lpDisplayName);

                /* Add the string to the dialog */
                SendDlgItemMessageW(hDlg,
                                    IDC_STOP_DEPENDS,
                                    WM_SETTEXT,
                                    0,
                                    (LPARAM)lpStr);

                HeapFree(ProcessHeap,
                         0,
                         lpStr);

                bRet = TRUE;
            }

            LocalFree(lpPartialStr);
        }

        /* Display the list of services which need stopping */
        hServiceListBox = GetDlgItem(hDlg,
                                     IDC_STOP_DEPENDS_LB);
        if (hServiceListBox)
        {
            AddServiceNamesToStop(hServiceListBox,
                                  (LPWSTR)pInfo->pTag);
        }
    }

    return bRet;
}
Esempio n. 15
0
static
VOID
InitRecoveryPage(
    HWND hwndDlg)
{
    LPWSTR lpAction;
    INT id;

    for (id = IDS_NO_ACTION; id <= IDS_RESTART_COMPUTER; id++)
    {
        if (AllocAndLoadString(&lpAction,
                               hInstance,
                               id))
        {
            SendDlgItemMessageW(hwndDlg,
                                IDC_FIRST_FAILURE,
                                CB_ADDSTRING,
                                0,
                                (LPARAM)lpAction);

            SendDlgItemMessageW(hwndDlg,
                                IDC_SECOND_FAILURE,
                                CB_ADDSTRING,
                                0,
                                (LPARAM)lpAction);

            SendDlgItemMessageW(hwndDlg,
                                IDC_SUBSEQUENT_FAILURES,
                                CB_ADDSTRING,
                                0,
                                (LPARAM)lpAction);

            LocalFree(lpAction);
        }
    }

    SendDlgItemMessageW(hwndDlg,
                        IDC_FIRST_FAILURE,
                        CB_SETCURSEL,
                        0,
                        0);

    SendDlgItemMessageW(hwndDlg,
                        IDC_SECOND_FAILURE,
                        CB_SETCURSEL,
                        0,
                        0);

    SendDlgItemMessageW(hwndDlg,
                        IDC_SUBSEQUENT_FAILURES,
                        CB_SETCURSEL,
                        0,
                        0);

    SendDlgItemMessageW(hwndDlg,
                        IDC_RESET_TIME,
                        WM_SETTEXT,
                        0,
                        (LPARAM)L"0");

    SendDlgItemMessageW(hwndDlg,
                        IDC_RESTART_TIME,
                        WM_SETTEXT,
                        0,
                        (LPARAM)L"1");

    for (id = IDC_RESTART_TEXT1; id <= IDC_RESTART_OPTIONS; id++)
        EnableWindow(GetDlgItem(hwndDlg, id), FALSE);
}
Esempio n. 16
0
int WINAPI
_tWinMain(HINSTANCE hInstance,
          HINSTANCE hPrevInstance,
          LPTSTR lpszCmdLine,
          int nCmdShow)
{
    MSG Msg;
    int Ret = 1;
    INITCOMMONCONTROLSEX Controls;

    UNREFERENCED_PARAMETER(hPrevInstance);
	UNREFERENCED_PARAMETER(lpszCmdLine);
	UNREFERENCED_PARAMETER(nCmdShow);

    hAppInstance = hInstance;
    hAppHeap = GetProcessHeap();

    if (InitAppConfig())
    {
        /* load the application title */
        if (!AllocAndLoadString(&lpAppTitle,
                                hAppInstance,
                                IDS_SNDVOL32))
        {
            lpAppTitle = NULL;
        }

        Controls.dwSize = sizeof(INITCOMMONCONTROLSEX);
        Controls.dwICC = ICC_BAR_CLASSES | ICC_STANDARD_CLASSES;

        InitCommonControlsEx(&Controls);

        if (RegisterApplicationClasses())
        {
            hMainWnd = CreateApplicationWindow();
            if (hMainWnd != NULL)
            {
                BOOL bRet;
                while ((bRet =GetMessage(&Msg,
                                         NULL,
                                         0,
                                         0)) != 0)
                {
                    if (bRet != -1)
                    {
                        TranslateMessage(&Msg);
                        DispatchMessage(&Msg);
                    }
                }

                DestroyWindow(hMainWnd);
                Ret = 0;
            }
            else
            {
                DPRINT("Failed to create application window (LastError: %d)!\n", GetLastError());
            }

            UnregisterApplicationClasses();
        }
        else
        {
            DPRINT("Failed to register application classes (LastError: %d)!\n", GetLastError());
        }

        if (lpAppTitle != NULL)
        {
            LocalFree(lpAppTitle);
        }

        CloseAppConfig();
    }
    else
    {
        DPRINT("Unable to open the Volume Control registry key!\n");
    }

    return Ret;
}
Esempio n. 17
0
int WINAPI
_tWinMain(HINSTANCE hThisInstance,
        HINSTANCE hPrevInstance,
        LPTSTR lpCmdLine,
        int nCmdShow)
{
    LPTSTR lpAppName, lpVersion, lpTitle;
    HWND hMainWnd;
    MSG Msg;
    BOOL bRet;
    int Ret = 1;
    size_t len;
    INITCOMMONCONTROLSEX icex;

    hInstance = hThisInstance;
    ProcessHeap = GetProcessHeap();

    icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
    icex.dwICC = ICC_BAR_CLASSES | ICC_COOL_CLASSES;
    InitCommonControlsEx(&icex);

    if ( !AllocAndLoadString(&lpAppName, hInstance, IDS_APPNAME) ||
         !AllocAndLoadString(&lpVersion, hInstance, IDS_VERSION) )
    {
        return Ret;
    }

    len = _tcslen(lpAppName) + _tcslen(lpVersion);
    lpTitle = HeapAlloc(ProcessHeap,
                        0,
                        (len + 2) * sizeof(TCHAR));
    if (lpTitle == NULL)
    {
        LocalFree((HLOCAL)lpAppName);
        LocalFree((HLOCAL)lpVersion);
        return Ret;
    }

    wsprintf(lpTitle,
             _T("%s %s"),
             lpAppName,
             lpVersion);

    LocalFree((HLOCAL)lpAppName);
    LocalFree((HLOCAL)lpVersion);

    if (TbdInitImpl())
    {
        if (InitMainWindowImpl())
        {
            if (InitImageEditWindowImpl())
            {
                if (InitFloatWndClass())
                {
                    hMainWnd = CreateMainWindow(lpTitle,
                                                nCmdShow);
                    if (hMainWnd != NULL)
                    {
                        /* pump the message queue */
                        while ((bRet = GetMessage(&Msg,
                                                  NULL,
                                                  0,
                                                  0) != 0))
                        {
                            if (bRet != (BOOL)-1)
                            {
                                if (!MainWndTranslateMDISysAccel(hMainWnd,
                                                                 &Msg))
                                {
                                    TranslateMessage(&Msg);
                                    DispatchMessage(&Msg);
                                }
                            }
                        }

                        Ret = 0;
                    }

                    UninitImageEditWindowImpl();
                }

                UninitFloatWndImpl();
            }

            UninitMainWindowImpl();
        }

        TbdUninitImpl();
    }

    HeapFree(GetProcessHeap(),
             0,
             lpTitle);

    return Ret;
}