Exemple #1
0
HRESULT OPEN(PCTSTR ptzDir, PCTSTR ptzFile, BOOL bSubDir = FALSE)
{
	HRESULT hResult = ERROR_FILE_NOT_FOUND;

	// Lookup
	WIN32_FIND_DATA fd;
	TCHAR tzPath[MAX_PATH];
	UStrPrint(tzPath, TEXT("%s\\%s"), ptzDir, ptzFile);
	HANDLE hFind = FindFirstFile(tzPath, &fd);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
			{
				UStrPrint(tzPath, TEXT("%s\\%s"), ptzDir, fd.cFileName);

				// Take action
				PTSTR ptzExt = UStrRChr(fd.cFileName, '.');
				if (ptzExt)
				{
					if ((UStrCmpI(ptzExt, TEXT(".csc")) == 0) || (UStrCmpI(ptzExt, TEXT(".reg")) == 0))
					{
						hResult = LOAD(tzPath);
					}
					else if ((UStrCmpI(ptzExt, TEXT(".dll")) == 0) || (UStrCmpI(ptzExt, TEXT(".ocx")) == 0) || (UStrCmpI(ptzExt, TEXT(".ax")) == 0))
					{
						hResult = CDLL(tzPath);
					}
					else if (UStrCmpI(ptzExt, TEXT(".inf")) == 0)
					{
						TCHAR tzCmd[MAX_PATH];
						UStrPrint(tzCmd, TEXT("DefaultInstall 132 %s"), tzPath);
						InstallHinfSection(NULL, NULL, tzCmd, 0);
						hResult = S_OK;
					}
					else
					{
						// Pass to shell to execute it
						hResult = !ShellOpen(tzPath, NULL, (fd.cFileName[0] == '!') ? SW_HIDE : SW_NORMAL);
					}
				}		
			}
		}
		while (FindNextFile(hFind, &fd));
		FindClose(hFind);
	}

	if (bSubDir)
	{
		UStrPrint(tzPath, TEXT("%s\\*"), ptzDir);
		hFind = FindFirstFile(tzPath, &fd);
		if (hFind != INVALID_HANDLE_VALUE)
		{
			do
			{
				if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (fd.cFileName[0] != '.'))
				{
					UStrPrint(tzPath, TEXT("%s\\%s"), ptzDir, fd.cFileName);
					if (hResult == ERROR_FILE_NOT_FOUND)
					{
						hResult = OPEN(tzPath, ptzFile, bSubDir);
					}
					else
					{
						OPEN(tzPath, ptzFile, bSubDir);
					}
				}
			}
			while (FindNextFile(hFind, &fd));
			FindClose(hFind);
		}
	}
	return hResult;
}
Exemple #2
0
static LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

{
    static int is_running = 0;


    HDC hdc;

    PAINTSTRUCT ps;

#ifndef __MINGW32__
    SHRGINFO rg;
#endif

    int x, y;

    int i;



    switch(msg)

    {

    case WM_CREATE:

        if(hToolTip == NULL) {

            hToolTip = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG_TOOLTIP), NULL, ToolTipProc);

        }

        break;



    case WM_DESTROY:

        DestroyWindow(hToolTip);

        hToolTip = NULL;



        // FileListCnt = 0;

        return 0;



    case WM_TODAYCUSTOM_CLEARCACHE:

        break;



    case WM_TODAYCUSTOM_QUERYREFRESHCACHE:

        if(Refresh) {

            Refresh = FALSE;



            // compute screen extents

            for(x = WinLeftMargin, y = WinTopMargin, i = 0; i < FileListCnt; i++) {

                if((x + IconSizeX + (HMargin * 2)) > GetSystemMetrics(SM_CXSCREEN) - WinRightMargin) {

                    x = WinLeftMargin;

                    y += IconSizeY + (VMargin * 2);

                }

                x += IconSizeX + (HMargin * 2);

            }

            y += IconSizeY + (VMargin * 2) + WinBottomMargin;

            ((TODAYLISTITEM *)(wParam))->cyp = y;



            SetTimer(hWnd, ID_ICON_TIMER, ShowIconSec * 1000, NULL);

            return TRUE;

        }

        return FALSE;



    case WM_LBUTTONDOWN:

        SelItem = Point2Item(LOWORD(lParam), HIWORD(lParam));

        InvalidateRect(hWnd, NULL, FALSE);

        UpdateWindow(hWnd);


#ifndef __MINGW32__
        rg.cbSize = sizeof(SHRGINFO);

        rg.hwndClient = hWnd;

        rg.ptDown.x = LOWORD(lParam);

        rg.ptDown.y = HIWORD(lParam);

#ifdef _WCE_PPC2002

        rg.dwFlags = SHRG_RETURNCMD | SHRG_NOANIMATION;

#else

        rg.dwFlags = SHRG_RETURNCMD;

#endif

        if(SelItem != -1 && SHRecognizeGesture(&rg) == GN_CONTEXTMENU) {

            RECT rect;

            RECT tip_rect;



            SendMessage(hToolTip, WM_SETTEXT, 0, (LPARAM)(FileList + SelItem)->Description);

            GetWindowRect(hWnd, &rect);

            GetWindowRect(hToolTip, &tip_rect);

            tip_rect.left = rect.left + LOWORD(lParam) - (tip_rect.right - tip_rect.left) - 10;

            if(tip_rect.left < 0) tip_rect.left = 0;

            tip_rect.top = rect.top + HIWORD(lParam) - (tip_rect.bottom - tip_rect.top) - 10;

            if(tip_rect.top < 0) tip_rect.top = 0;



            SetWindowPos(hToolTip, HWND_TOPMOST,

                         tip_rect.left, tip_rect.top,

                         0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_SHOWWINDOW);

        }
#endif
        SetCapture(hWnd);

        break;



    case WM_LBUTTONUP:

        ShowWindow(hToolTip, SW_HIDE);

        ReleaseCapture();

        i = Point2Item(LOWORD(lParam), HIWORD(lParam));

        if(i != -1 && i == SelItem) {

            if (!is_running) {
                is_running = 1;
                ShellOpen((FileList + i)->FileName, (FileList + i)->CommandLine);
                Sleep(1000);
                is_running = 0;
            }

        }

        SelItem = -1;

        InvalidateRect(hWnd, NULL, FALSE);

        UpdateWindow(hWnd);

        break;



    case WM_PAINT:

        hdc = BeginPaint(hWnd, &ps);

        OnPaint(hWnd, hdc, &ps);

        EndPaint(hWnd, &ps);

        break;



    case WM_ERASEBKGND:

        return 1;



    case WM_TIMER:

        switch(wParam)

        {

        case ID_ICON_TIMER:



            // JMW maybe break here?



            KillTimer(hWnd, ID_ICON_TIMER);

            InvalidateRect(hWnd, NULL, FALSE);

            UpdateWindow(hWnd);

            break;

        }

        break;



    default:

        return DefWindowProc(hWnd, msg, wParam, lParam);

    }

    return 0;

}