Beispiel #1
0
INT_PTR CALLBACK device_list_wndproc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	TCHAR tipText[80];
	POINT pt;
	static int oldX, oldY;
	int newX, newY;
	LVHITTESTINFO hitTestInfo;
	LVITEM lvitem;
	device_context_t* dev_context;
	BOOL ignored;

	switch(message)
	{
	case WM_MOUSELEAVE:
		// The mouse pointer has left our window.
		// Deactivate the tooltip.
		SendMessage(g_hwndTrackingTT, TTM_TRACKACTIVATE, (WPARAM)FALSE, (LPARAM)&g_toolItem);
		g_TrackingMouse = FALSE;
		return FALSE;

	case WM_MOUSEMOVE:

		if (!g_TrackingMouse)
		{
			// The mouse has just entered the window.

			// Request notification when the mouse leaves.
			TRACKMOUSEEVENT tme = { sizeof(TRACKMOUSEEVENT) };
			tme.hwndTrack = hDlg;
			tme.dwFlags = TME_LEAVE;
			TrackMouseEvent(&tme);

			// Activate the tooltip.
			SendMessage(g_hwndTrackingTT, TTM_TRACKACTIVATE,
				(WPARAM)TRUE, (LPARAM)&g_toolItem);
			g_TrackingMouse = TRUE;
		}

		newX = LOWORD(lParam);
		newY = HIWORD(lParam);

		// Make sure the mouse has actually moved. The presence of the tooltip
		// causes Windows to send the message continuously.
		if ((newX != oldX) || (newY != oldY))
		{
			oldX = newX;
			oldY = newY;

			memset(&hitTestInfo,0,sizeof(hitTestInfo));
			hitTestInfo.pt.x = newX;
			hitTestInfo.pt.y = newY;

			if ((ListView_HitTest(hDlg, &hitTestInfo) == -1) || newX > ListView_GetColumnWidth(hDlg, 0))
			{
				safe_sprintf(tipText, sizeof(tipText) - 1, TEXT("%s"), TEXT(""));
				SendMessage(g_hwndTrackingTT, TTM_TRACKACTIVATE,FALSE, (LPARAM)&g_toolItem);
			}
			else
			{
				SendMessage(g_hwndTrackingTT, TTM_SETDELAYTIME,TTDT_INITIAL, 1000);

				memset(&lvitem, 0 , sizeof(lvitem));

				lvitem.iItem = hitTestInfo.iItem;
				lvitem.mask =  LVIF_PARAM;
				ignored = ListView_GetItem(hDlg,&lvitem);

				dev_context = (device_context_t*)lvitem.lParam;
				// Update the text.
				safe_sprintf(tipText, sizeof(tipText)-1 , TEXT("%s"), wdi_get_vendor_name(dev_context->wdi->vid));
				SendMessage(g_hwndTrackingTT, TTM_TRACKACTIVATE,TRUE, (LPARAM)&g_toolItem);

			}
			g_toolItem.lpszText = tipText;
			SendMessage(g_hwndTrackingTT, TTM_SETTOOLINFO, 0, (LPARAM)&g_toolItem);

			// Position the tooltip.
			// The coordinates are adjusted so that the tooltip does not
			// overlap the mouse pointer.
			pt.x = newX;
			pt.y = newY;

			ClientToScreen(hDlg, &pt);
			SendMessage(g_hwndTrackingTT, TTM_TRACKPOSITION,
				0, (LPARAM)MAKELONG(pt.x + 10, pt.y - 20));
		}
		break;
	}
	return CallWindowProc(device_list_wndproc_orig, hDlg, message, wParam, lParam);
}
static INT_PTR CALLBACK DlgProfileSelect(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	DlgProfData *dat = (struct DlgProfData *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
	HWND hwndList = GetDlgItem(hwndDlg, IDC_PROFILELIST);

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		EnsureCheckerLoaded(true);
		{
			dat = (DlgProfData*)lParam;
			SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat);

			// set columns
			LVCOLUMN col;
			col.mask = LVCF_TEXT | LVCF_WIDTH;
			col.pszText = TranslateT("Profile");
			col.cx = 100;
			ListView_InsertColumn(hwndList, 0, &col);

			col.pszText = TranslateT("Driver");
			col.cx = 150 - GetSystemMetrics(SM_CXVSCROLL);
			ListView_InsertColumn(hwndList, 1, &col);

			col.pszText = TranslateT("Size");
			col.cx = 60;
			ListView_InsertColumn(hwndList, 2, &col);

			// icons
			HIMAGELIST hImgList = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 2, 1);
			ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_USERDETAILS));
			ImageList_AddIcon_NotShared(hImgList, MAKEINTRESOURCE(IDI_DELETE));

			// LV will destroy the image list
			SetWindowLongPtr(hwndList, GWL_STYLE, GetWindowLongPtr(hwndList, GWL_STYLE) | LVS_SORTASCENDING);
			ListView_SetImageList(hwndList, hImgList, LVSIL_SMALL);
			ListView_SetExtendedListViewStyle(hwndList,
				ListView_GetExtendedListViewStyle(hwndList) | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT);

			// find all the profiles
			ProfileEnumData ped = { hwndDlg, dat->pd->szProfile };
			findProfiles(dat->pd->szProfileDir, EnumProfilesForList, (LPARAM)&ped);
			PostMessage(hwndDlg, WM_FOCUSTEXTBOX, 0, 0);

			dat->hFileNotify = FindFirstChangeNotification(dat->pd->szProfileDir, TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_LAST_WRITE);
			if (dat->hFileNotify != INVALID_HANDLE_VALUE)
				SetTimer(hwndDlg, 0, 1200, NULL);
			return TRUE;
		}

	case WM_DESTROY:
		KillTimer(hwndDlg, 0);
		FindCloseChangeNotification(dat->hFileNotify);
		break;

	case WM_TIMER:
		if (WaitForSingleObject(dat->hFileNotify, 0) == WAIT_OBJECT_0) {
			ListView_DeleteAllItems(hwndList);
			ProfileEnumData ped = { hwndDlg, dat->pd->szProfile };
			findProfiles(dat->pd->szProfileDir, EnumProfilesForList, (LPARAM)&ped);
			FindNextChangeNotification(dat->hFileNotify);
		}
		break;

	case WM_FOCUSTEXTBOX:
		SetFocus(hwndList);
		if (dat->pd->szProfile[0] == 0 || ListView_GetSelectedCount(hwndList) == 0)
			ListView_SetItemState(hwndList, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
		break;

	case WM_SHOWWINDOW:
		if (wParam) {
			SetWindowText(dat->hwndOK, TranslateT("&Run"));
			EnableWindow(dat->hwndSM, TRUE);
			EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1);
		}
		break;

	case WM_CONTEXTMENU:
		{
			LVHITTESTINFO lvht = { 0 };
			lvht.pt.x = GET_X_LPARAM(lParam);
			lvht.pt.y = GET_Y_LPARAM(lParam);
			ScreenToClient(hwndList, &lvht.pt);

			if (ListView_HitTest(hwndList, &lvht) < 0) {
				if (lParam != -1)
					break;

				lvht.iItem = ListView_GetSelectionMark(hwndList);
				RECT rc = { 0 };
				if (!ListView_GetItemRect(hwndList, lvht.iItem, &rc, LVIR_LABEL))
					break;
				
				lvht.pt.x = rc.left;
				lvht.pt.y = rc.bottom;
				ClientToScreen(hwndList, &lvht.pt);
			}
			else {
				lvht.pt.x = GET_X_LPARAM(lParam);
				lvht.pt.y = GET_Y_LPARAM(lParam);
			}

			HMENU hMenu = CreatePopupMenu();
			AppendMenu(hMenu, MF_STRING, 1, TranslateT("Run"));
			AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
			if (ServiceExists(MS_DB_CHECKPROFILE)) {
				AppendMenu(hMenu, MF_STRING, 2, TranslateT("Check database"));
				AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
			}
			AppendMenu(hMenu, MF_STRING, 3, TranslateT("Delete"));
			int index = TrackPopupMenu(hMenu, TPM_RETURNCMD, lvht.pt.x, lvht.pt.y, 0, hwndDlg, NULL);
			switch (index) {
			case 1:
				SendMessage(GetParent(hwndDlg), WM_COMMAND, IDOK, 0);
				break;

			case 2:
				CheckProfile(hwndList, lvht.iItem, dat);
				break;

			case 3:
				DeleteProfile(hwndList, lvht.iItem, dat);
				break;
			}
			DestroyMenu(hMenu);
		}
		break;

	case WM_NOTIFY:
		LPNMHDR hdr = (LPNMHDR)lParam;
		if (hdr && hdr->code == PSN_INFOCHANGED)
			break;

		if (hdr && hdr->idFrom == IDC_PROFILELIST) {
			switch (hdr->code) {
			case LVN_ITEMCHANGED:
				EnableWindow(dat->hwndOK, ListView_GetSelectedCount(hwndList) == 1);

			case NM_DBLCLK:
				if (dat != NULL) {
					TCHAR profile[MAX_PATH];
					LVITEM item = { 0 };
					item.mask = LVIF_TEXT;
					item.iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL);
					item.pszText = profile;
					item.cchTextMax = SIZEOF(profile);

					if (ListView_GetItem(hwndList, &item)) {
						// profile is placed in "profile_name" subfolder
						TCHAR tmpPath[MAX_PATH];
						mir_sntprintf(tmpPath, SIZEOF(tmpPath), _T("%s\\%s.dat"), dat->pd->szProfileDir, profile);
						HANDLE hFile = CreateFile(tmpPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
						if (hFile == INVALID_HANDLE_VALUE)
							mir_sntprintf(dat->pd->szProfile, MAX_PATH, _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, profile, profile);
						else
							_tcscpy(dat->pd->szProfile, tmpPath);
						CloseHandle(hFile);
						if (hdr->code == NM_DBLCLK) EndDialog(GetParent(hwndDlg), 1);
					}
				}
				return TRUE;

			case LVN_KEYDOWN:
				if (((LPNMLVKEYDOWN)lParam)->wVKey == VK_DELETE)
					DeleteProfile(hwndList, ListView_GetNextItem(hwndList, -1, LVNI_SELECTED | LVNI_ALL), dat);
				break;

			case LVN_GETINFOTIP:
				NMLVGETINFOTIP *pInfoTip = (NMLVGETINFOTIP *)lParam;
				if (pInfoTip != NULL) {
					TCHAR profilename[MAX_PATH], fullpath[MAX_PATH];
					struct _stat statbuf;
					ListView_GetItemText(hwndList, pInfoTip->iItem, 0, profilename, MAX_PATH);
					mir_sntprintf(fullpath, SIZEOF(fullpath), _T("%s\\%s\\%s.dat"), dat->pd->szProfileDir, profilename, profilename);
					_tstat(fullpath, &statbuf);
					mir_sntprintf(pInfoTip->pszText, pInfoTip->cchTextMax, _T("%s\n%s: %s\n%s: %s"), fullpath, TranslateT("Created"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_ctime))), TranslateT("Modified"), rtrimt(NEWTSTR_ALLOCA(_tctime(&statbuf.st_mtime))));
				}
			}
		}
		break;
	}

	return FALSE;
}
Beispiel #3
0
BOOL TreeList_ProcessMessage(HWND hwnd, UINT msg, WPARAM, LPARAM lparam, UINT idc, BOOL* )
{
	LVITEM lvi = {0};

	switch (msg) {
	case WM_NOTIFY:
	{
		if (((LPNMHDR)lparam)->idFrom != idc)
			break;

		TTreeList_Data *data = (TTreeList_Data *)sttTreeList_GeWindowData(GetDlgItem(hwnd, idc));
		switch (((LPNMHDR)lparam)->code) {
		case LVN_COLUMNCLICK:
			{
				LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)lparam;
				TreeList_SetSortMode(lpnmlv->hdr.hwndFrom, lpnmlv->iSubItem, FALSE);
			}
			break;

		case LVN_ITEMACTIVATE:
			if (data->mode == TLM_REPORT) {
				LPNMITEMACTIVATE lpnmia = (LPNMITEMACTIVATE)lparam;
				lvi.mask = LVIF_PARAM;
				lvi.iItem = lpnmia->iItem;
				ListView_GetItem(lpnmia->hdr.hwndFrom, &lvi);
				
				HTREELISTITEM hItem = (lvi.iItem < 0) ? data-> root : (HTREELISTITEM)lvi.lParam;
				if (!hItem->subItems.getCount() && !(hItem->flags & TLIF_FAKEPARENT)) break;
				data->hItemSelected = hItem;

				NMTREEVIEW nmtv;
				nmtv.hdr.code = TVN_ITEMEXPANDED;
				nmtv.hdr.hwndFrom = lpnmia->hdr.hwndFrom;
				nmtv.hdr.idFrom = lpnmia->hdr.idFrom;
				nmtv.itemNew.hItem = (HTREEITEM)lvi.lParam;
				SendMessage(hwnd, WM_NOTIFY, lpnmia->hdr.idFrom, (LPARAM)&nmtv);

				if (data->mode == TLM_REPORT)
				{
					ListView_DeleteAllItems(lpnmia->hdr.hwndFrom);
					TreeList_Update(lpnmia->hdr.hwndFrom);
				}
			}
			break;

		case LVN_KEYDOWN:
			if (data->mode == TLM_TREE) {
				LPNMLVKEYDOWN lpnmlvk = (LPNMLVKEYDOWN)lparam;

				lvi.mask = LVIF_PARAM|LVIF_INDENT;
				lvi.iItem = ListView_GetNextItem(lpnmlvk->hdr.hwndFrom, -1, LVNI_SELECTED);
				if (lvi.iItem < 0) return FALSE;
				lvi.iSubItem = 0;
				ListView_GetItem(lpnmlvk->hdr.hwndFrom, &lvi);
				HTREELISTITEM hItem = (HTREELISTITEM)lvi.lParam;

				switch (lpnmlvk->wVKey) {
				case VK_SUBTRACT:
				case VK_LEFT:
				{
					if ( hItem->subItems.getCount() && (hItem->flags & TLIF_EXPANDED )) {
						hItem->flags &= ~TLIF_EXPANDED;
						hItem->flags |= TLIF_MODIFIED;
						TreeList_Update( lpnmlvk->hdr.hwndFrom );
					} 
					else if ( hItem->indent && (lpnmlvk->wVKey != VK_SUBTRACT )) {
						for ( int i = lvi.iItem; i--; ) {
							lvi.mask = LVIF_INDENT;
							lvi.iItem = i;
							lvi.iSubItem = 0;
							ListView_GetItem(lpnmlvk->hdr.hwndFrom, &lvi);
							if (lvi.iIndent < hItem->indent) {
								lvi.mask = LVIF_STATE;
								lvi.iItem = i;
								lvi.iSubItem = 0;
								lvi.state = lvi.stateMask = LVIS_FOCUSED|LVNI_SELECTED;
								ListView_SetItem(lpnmlvk->hdr.hwndFrom, &lvi);
								break;
					}	}	}
					break;
				}

				case VK_ADD:
				case VK_RIGHT:
					if ( (hItem->subItems.getCount() || (hItem->flags & TLIF_FAKEPARENT)) &&
						!( hItem->flags & TLIF_EXPANDED ))
					{
						hItem->flags |= TLIF_EXPANDED;
						hItem->flags |= TLIF_MODIFIED;

						NMTREEVIEW nmtv;
						nmtv.hdr.code = TVN_ITEMEXPANDED;
						nmtv.hdr.hwndFrom = lpnmlvk->hdr.hwndFrom;
						nmtv.hdr.idFrom = lpnmlvk->hdr.idFrom;
						nmtv.itemNew.hItem = (HTREEITEM)hItem;
						SendMessage(hwnd, WM_NOTIFY, lpnmlvk->hdr.idFrom, (LPARAM)&nmtv);
						TreeList_Update( lpnmlvk->hdr.hwndFrom );
					}
					break;
			}	}
			break;

		case NM_CLICK:
			if (data->mode == TLM_TREE) {
				LPNMITEMACTIVATE lpnmia = (LPNMITEMACTIVATE)lparam;
				LVHITTESTINFO lvhti = {0};
				lvi.mask = LVIF_PARAM;
				lvi.iItem = lpnmia->iItem;
				ListView_GetItem(lpnmia->hdr.hwndFrom, &lvi);
				lvhti.pt = lpnmia->ptAction;
				ListView_HitTest(lpnmia->hdr.hwndFrom, &lvhti);

				HTREELISTITEM ptli = ( HTREELISTITEM )lvi.lParam;
				if ((lvhti.iSubItem == 0) && ( (lvhti.flags&LVHT_ONITEM) == LVHT_ONITEMSTATEICON ) &&
					(ptli->subItems.getCount() || ptli->flags & TLIF_FAKEPARENT))
				{
					if ( ptli->flags & TLIF_EXPANDED )
						ptli->flags &= ~TLIF_EXPANDED;
					else {
						ptli->flags |= TLIF_EXPANDED;

						NMTREEVIEW nmtv;
						nmtv.hdr.code = TVN_ITEMEXPANDED;
						nmtv.hdr.hwndFrom = lpnmia->hdr.hwndFrom;
						nmtv.hdr.idFrom = lpnmia->hdr.idFrom;
						nmtv.itemNew.hItem = (HTREEITEM)lvi.lParam;
						SendMessage(hwnd, WM_NOTIFY, lpnmia->hdr.idFrom, (LPARAM)&nmtv);
					}
					ptli->flags |= TLIF_MODIFIED;
					TreeList_Update( lpnmia->hdr.hwndFrom );
			}	}
			break;
		}
		break;
	}	}
	return FALSE;
}
Beispiel #4
0
/*-------------------------------*/
LRESULT CALLBACK WndProc(HWND hWnd, UINT komunikat, WPARAM wParam, LPARAM lParam)
{
    static BOOL bDragging;
    static int poz;
    POINT pkt;
    HIMAGELIST hDragImgList;
    static NOTIFYICONDATA nim;

    switch (komunikat)
    {
        case WM_CREATE:
            HWND hToolTip;
            HFONT hFont;
            TOOLINFO tinf;
            RECT rect;

            /*-----tworzenie kontrolek-----*/
            hList = CreateWindow("SysListView32", "lista_przyciskow", WS_VISIBLE | WS_CHILD | WS_BORDER |
                                 LVS_REPORT | LVS_SINGLESEL,0,0,493,230,hWnd,NULL,hInst, NULL);
            hRefresh = CreateWindow("button", "Odœwie¿ listê", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                                    135, 232, 100, 20, hWnd, NULL, hInst, NULL);
            hShow = CreateWindow("button", "Poka¿ przycisk", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                                 15, 232, 100, 20,/*255, 232, 100, 20,*/ hWnd, NULL, hInst, NULL);
            hInfo = CreateWindow("button", "O programie...", WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,
                                 375, 232, 100, 20, hWnd, NULL, hInst, NULL);

            /*-----tworzenie i ustawianie czcionki dla przycisków-----*/
            hFont = CreateFont(14, 0, 0, 0, 0, false, false, false, DEFAULT_CHARSET,
                               OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
                               DEFAULT_PITCH, NULL);

            SendMessage(hRefresh, WM_SETFONT, (WPARAM) hFont, true);
            SendMessage(hShow, WM_SETFONT, (WPARAM) hFont, true);
            SendMessage(hInfo, WM_SETFONT, (WPARAM) hFont, true);

            ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);

            /*-----ustawianie tooltipów-----*/
            hToolTip = CreateWindow(TOOLTIPS_CLASS, NULL, TTS_ALWAYSTIP | TTS_BALLOON, 0,0,0,0, hWnd, NULL, hInst, NULL);

            //Ustawianie parametrów wspó³nych dla ka¿dego tooltipa: tytu³, kolor.
            SendMessage(hToolTip, TTM_SETTITLE, TTI_INFO, (LPARAM)"Skrót");
            SendMessage(hToolTip, TTM_SETTIPTEXTCOLOR, (LPARAM)RGB(0, 0, 100), 0);
            SendMessage(hToolTip, TTM_SETTIPBKCOLOR, (LPARAM)RGB(250, 250, 250), 0);

            GetClientRect (hWnd, &rect);
            tinf.cbSize = sizeof(TOOLINFO);
            tinf.uFlags = TTF_SUBCLASS;
            tinf.hinst = hInst;
            tinf.uId = 0;
            tinf.rect.left = rect.left;
            tinf.rect.top = rect.top;
            tinf.rect.right = rect.right;
            tinf.rect.bottom = rect.bottom;

            tinf.hwnd = hRefresh;
            tinf.lpszText = "F5";
            SendMessage(hToolTip, TTM_ADDTOOL, 0, (LPARAM)&tinf);
            tinf.hwnd = hShow;
            tinf.lpszText = "dwuklik LPM";
            SendMessage(hToolTip, TTM_ADDTOOL, 0, (LPARAM)&tinf);
            tinf.hwnd = hInfo;
            tinf.lpszText = "F1";
            SendMessage(hToolTip, TTM_ADDTOOL, 0, (LPARAM)&tinf);

            /*-----ustawianie ikony programu w zasobniku systemowym-----*/
            nim.cbSize = sizeof(NOTIFYICONDATA);
            nim.hWnd = hWnd;
            nim.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
            nim.hIcon = ikona;
            nim.uCallbackMessage = WM_TRAY;
            nim.uID = 7;
            lstrcpyn(nim.szTip, "Manipulator by FeniX", sizeof(nim.szTip));
            Shell_NotifyIcon(NIM_ADD, &nim);
            refresh();
            break;
        case WM_KEYUP:  //obs³uga skrótów klawiaturowych dla konkretnych akcji
            switch (wParam)
            {
                case VK_F5:
                    SendMessage(hRefresh, BM_CLICK, 0, 0);
                    break;
                case VK_F1:
                    SendMessage(hInfo, BM_CLICK, 0, 0);
                    break;
                case VK_SPACE:
                    SendMessage(hShow, BM_CLICK, 0, 0);
                    break;
                case VK_ESCAPE:
                    ShowWindow(hWnd, SW_MINIMIZE);
                    break;
            }
            break;
        case WM_COMMAND:    //obs³uga zdarzeñ okien pochodnych okna g³ównego
            switch (HIWORD(wParam))
            {
                case BN_CLICKED:    //komunikat klikniêcia przycisku
                    if ((HWND)lParam == hRefresh)
                    {
                        refresh();
                        SetFocus(hList);
                    }
                    else if ((HWND)lParam == hInfo)
                    {
                        MessageBox(hWnd, "Autor:\nKonrad Gadzina <*****@*****.**>\n"
                                         "Grupa 1131, Informatyka, rok akad. 2008/2009"
                                         "\nPracownia In¿ynierii Oprogramowania M-74\n"
                                         "Instytut Informatyki Stosowanej\n"
                                         "Wydzia³ Mechaniczny, Politechnika Krakowska\nJêzyki i Techniki Programowania",
                                         "O programie", MB_OK);
                    }
                    else if ((HWND)lParam == hShow)
                    {
                        int poz;
                        char buf[10];
                        bool hidden;
                        TBBUTTON *ptbb, tbb;
                        NOTIFYICONDATA fake;  //potrzebne do "odswiezania" paska zadan i dopasowywania szerokosci przyciskow

                        ptbb = (TBBUTTON*)VirtualAllocEx(proces, NULL, sizeof(TBBUTTON), MEM_COMMIT, PAGE_READWRITE);
                        poz = ListView_GetNextItem(hList, (WPARAM)-1, LVNI_SELECTED);

                        SendMessage(hPasek, TB_GETBUTTON, (WPARAM)poz, (LPARAM)ptbb);
                        ReadProcessMemory(proces, (void*)ptbb, (void*)&tbb, sizeof(TBBUTTON), NULL);

                        hidden = SendMessage(hPasek, TB_ISBUTTONHIDDEN, (WPARAM)tbb.idCommand, 0);
                        SendMessage(hPasek, TB_HIDEBUTTON, (WPARAM)tbb.idCommand, (LPARAM)!hidden);

                        if (hidden)
                            SendMessage(hShow, WM_SETTEXT, 0, (LPARAM)"Ukryj przycisk");
                        else
                            SendMessage(hShow, WM_SETTEXT, 0, (LPARAM)"Poka¿ przycisk");

                        /*---dodawanie i usuwanie ikony do zasobnika, by pasek zadañ siê "odœwie¿y³"---*/
                        fake.cbSize = sizeof(NOTIFYICONDATA);
                        fake.hWnd = hWnd;
                        fake.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
                        fake.hIcon = ikona;
                        fake.uCallbackMessage = WM_TRAY;
                        fake.uID = 19;
                        lstrcpyn(fake.szTip, "Manipulator by FeniX", sizeof(fake.szTip));
                        Shell_NotifyIcon(NIM_ADD, &fake);
                        Shell_NotifyIcon(NIM_DELETE, &fake);

                        for (int i = 0; i<ile; i++)
                        {
                            SendMessage(hPasek, TB_GETBUTTON, (WPARAM)i, (LPARAM)ptbb);
                            ReadProcessMemory(proces, (void*)ptbb, (void*)&tbb, sizeof(TBBUTTON), NULL);
                            hidden = SendMessage(hPasek, TB_ISBUTTONHIDDEN, (WPARAM)tbb.idCommand, 0);

                            if (!hidden)
                                strcpy(buf, "[widoczny]");
                            else
                                strcpy(buf, "[ukryty]");
                            ListView_SetItemText(hList, i, 1, buf);
                        }
                        SetFocus(hList);

                        VirtualFreeEx(proces, ptbb, 0, MEM_RELEASE);
                    }
                    break;
            }
            break;
        case WM_TRAY:   //obs³uga klikniêcia na ikonkê programu w zasobniku systemowym
            switch ((UINT)lParam)
            {
                case WM_LBUTTONDOWN:
                    if (!IsWindowVisible(hWnd))
                    {
                        if (IsZoomed(hWnd))
                            ShowWindow(hWnd, SW_MAXIMIZE);
                        else
                            ShowWindow(hWnd, SW_RESTORE);
                        SetForegroundWindow(hWnd);
                    }
                    else if (GetForegroundWindow() == hWnd)
                        ShowWindow(hWnd, SW_HIDE);
                    else
                        SetForegroundWindow(hWnd);
                    break;
            }
            break;
        case WM_ACTIVATE:
            if (LOWORD(wParam) != WA_INACTIVE)
                refresh();
            break;
        case WM_SIZE:   //zdarzenie zmienienia rozmiaru
            int szer, wys;

            if (wParam & SIZE_MINIMIZED)
                ShowWindow(hWnd, SW_HIDE);

            szer = (int)LOWORD(lParam);
            wys = (int)HIWORD(lParam );

            /*
               Poni¿ze linijki pozwalaj¹ przestawiaæ kontrolki tak, by
               dopasowa ich pozycjê/rozmiar do rozmiaru okna g³ównego
            */
            MoveWindow(hList, 0, 0, szer, wys-23, false);
            MoveWindow(hShow, 20, wys-21, 120, 20, false);
            MoveWindow(hRefresh, szer-310, wys-21, 120, 20, false);
            MoveWindow(hInfo, szer-140, wys-21, 120, 20, false);
            break;
        case WM_SIZING: //zdarzenie zmieniania rozmiaru
            RECT* rc;
            rc = (RECT*)lParam;
            /*
               Poni¿sze linie pozwalaj¹ ograniczyc rozmiar okna - jako, ¿e to zdarzenie jest
               wywo³ywane w trakcie zmiany rozmiaru, warunki s¹ sprawdzane nie po puszczeniu
               przycisku myszy, a jeszcze w trakcie jego trzymania. Dziêki temu okno nie
               nigdy nie bêdzie mia³o rozmiarów mniejszych ni¿ 500x100 pikseli.
            */
            if (rc->right - rc->left <= 500)
                rc->right = rc->left + 500;
            if (rc->bottom - rc->top <= 100)
                rc->bottom = rc->top + 100;
            break;
        case WM_DESTROY:    //zdarzenie niszczenia okna
            CloseHandle(proces);
            Shell_NotifyIcon(NIM_DELETE, &nim);
            PostQuitMessage(0);
            break;

        case WM_NOTIFY: //obs³uga komunikatów od kontrolki ListView
            if (((LPNMHDR)lParam)->hwndFrom == hList && ((LPNMHDR)lParam)->code == (unsigned int)NM_DBLCLK)
                SendMessage(hShow, BM_CLICK, 0, 0);
            else if (((LPNMHDR)lParam)->hwndFrom == hList && ((LPNMHDR)lParam)->code == (unsigned int)NM_CLICK)
            {
                char buf[10];
                int poz = ListView_GetNextItem(hList, (WPARAM)-1, LVNI_SELECTED);

                ListView_GetItemText(hList, poz, 1, buf, 50);
                if (!strcmp(buf, "[ukryty]"))
                    SendMessage(hShow, WM_SETTEXT, 0, (LPARAM)"Poka¿ przycisk");
                else
                    SendMessage(hShow, WM_SETTEXT, 0, (LPARAM)"Ukryj przycisk");
            }
            else if (((LPNMHDR)lParam)->hwndFrom == hList && ((LPNMHDR)lParam)->code == LVN_KEYDOWN)
            {
                switch (((LV_KEYDOWN*)lParam)->wVKey)
                {
                case VK_F5:
                    SendMessage(hRefresh, BM_CLICK, 0, 0);
                    break;
                case VK_F1:
                    SendMessage(hInfo, BM_CLICK, 0, 0);
                    break;
                case VK_SPACE:
                    SendMessage(hShow, BM_CLICK, 0, 0);
                    break;
                case VK_ESCAPE:
                    ShowWindow(hWnd, SW_MINIMIZE);
                    break;
                }
            }
            /*------------------- obs³uga drag & drop na liœcie z przyciskami -------------------*/
            else if (((LPNMHDR)lParam)->hwndFrom == hList && ((LPNMHDR)lParam)->code == LVN_BEGINDRAG)
            {
                //wiadomoœæ wysy³ana do okna g³ównego, gdy rozpoczynamy drag & drop na liœcie
                //czyli ³apiemy element lewym przyciskiem myszy
                HIMAGELIST hOneImageList, hTempImageList;
                IMAGEINFO imginf;
                int x = 0, wys;
                pkt.x = 1;
                pkt.y = 1;

                poz = ListView_GetNextItem(hList, (WPARAM)-1, LVNI_SELECTED);  //pobieranie indexu zaznaczonego elementu
                item.iItem = poz;
                item.mask = LVIF_IMAGE | LVIF_INDENT | LVIF_PARAM; //ustawienie maski elementu listy do pobrania
                ListView_GetItem(hList, &item);    //pobieranie danego elementu do zmiennej item

                if (item.iIndent) //element z wciêciem nas nie interesuje
                    break;

                hDragImgList = ListView_CreateDragImage(hList, poz, &pkt); //tworzenie "duszka" do d&d
                ImageList_GetImageInfo(hDragImgList, 0, &imginf);
                wys = imginf.rcImage.bottom;

                while(true)    //dodawanie elementów danej grupy do "duszka" w pêtli
                {
                    if (++item.iItem >= ile)
                        break;
                    item.mask = LVIF_IMAGE | LVIF_INDENT | LVIF_PARAM; //ustawianie maski pobierania danych elementu
                    ListView_GetItem(hList, &item);
                    if(item.iIndent == 0) //je¿eli napotkano kolejny przycisk grupowy trzeba przerwaæ
                        break;

                    hOneImageList = ListView_CreateDragImage(hList, item.iItem, &pkt);
                    hTempImageList = ImageList_Merge(hDragImgList, 0, hOneImageList, 0, 0, wys);
                    ImageList_Destroy(hDragImgList);
                    ImageList_Destroy(hOneImageList);
                    hDragImgList = hTempImageList;
                    ImageList_GetImageInfo(hDragImgList, 0, &imginf);
                    wys = imginf.rcImage.bottom;
                }

                item.iItem = poz;
                item.mask = LVIF_IMAGE | LVIF_INDENT | LVIF_PARAM;
                ListView_GetItem(hList, &item);

                ImageList_BeginDrag(hDragImgList, 0, x, 0);
                pkt = ((NM_LISTVIEW*) ((LPNMHDR)lParam))->ptAction;
                ClientToScreen(hList, &pkt);
                ImageList_DragEnter(GetDesktopWindow(), pkt.x, pkt.y);
                bDragging = true;

                SetCapture(hWnd);
            }
            break;
        case WM_MOUSEMOVE:  //zdarzenie ruchu kursora myszy
            if (!bDragging) //je¿eli nie obs³gujemy akurat d&d na liœcie to nie trzeba nic robiæ
                break;

            pkt.x = LOWORD(lParam);
            pkt.y = HIWORD(lParam);
            ClientToScreen(hWnd, &pkt);
            ImageList_DragMove(pkt.x, pkt.y);
            break;
        case WM_LBUTTONUP:  //zdarzenie puszczenia lewego przycisku myszy
            if (!bDragging) //je¿eli nie obs³gujemy akurat d&d na liœcie to nie trzeba nic robiæ
                break;

            LVHITTESTINFO lvhti;
            char buf[256], sub[12];

            /*---puszczamy przycisk, wiêc przeci¹ganie siê koñczy---*/
            bDragging = false;
            ImageList_DragLeave(hList);
            ImageList_EndDrag();
            //ImageList_Destroy(hDragImgList);  //nie wiem czemu, ale ta linia wywo³uje b³¹d segfault przy uruchomieniu debuggera
            ReleaseCapture();


            /*---sprawdzanie, czy przeci¹gany element zosta³ upuszczony na inny element listy---*/
            lvhti.pt.x = LOWORD(lParam);
            lvhti.pt.y = HIWORD(lParam);
            ClientToScreen(hWnd, &lvhti.pt);
            ScreenToClient(hList, &lvhti.pt);
            ListView_HitTest(hList, &lvhti);
            if (lvhti.iItem == -1)
                break;
            if ((lvhti.flags & LVHT_ONITEMLABEL == 0) && (lvhti.flags & LVHT_ONITEMSTATEICON == 0))
                break;

            if (!item.iIndent) //je¿eli wciêcie = 0, to znaczy ¿e zajmujemy siê przyciskiem "grupowym"
            {
                poz = ListView_GetNextItem(hList, (WPARAM)-1, LVNI_SELECTED);

                if (lvhti.iItem > poz)
                    lvhti.iItem++;

                while (true)
                {
                    if (lvhti.iItem == poz || lvhti.iItem > ile-1 || lvhti.iItem < 0)
                        break;
                    item.iItem = lvhti.iItem;
                    item.iSubItem = 0;
                    item.mask = LVIF_STATE | LVIF_IMAGE | LVIF_INDENT | LVIF_TEXT | LVIF_PARAM;
                    item.stateMask = LVIS_SELECTED;
                    ListView_GetItem(hList, &item);
                    if (item.iIndent)
                    {
                        if (lvhti.iItem > poz)
                            lvhti.iItem++;
                        else if (lvhti.iItem < poz)
                            lvhti.iItem--;
                    }
                    else
                    {
                        if (lvhti.iItem > poz)
                            lvhti.iItem--;
                        break;
                    }
                }

                ListView_GetItemText(hList, poz, 0, buf, 256); //pobieranie tekstu danego elementu listy
                while (true)
                {
                    int tmp = poz;

                    item.iItem = poz;
                    item.iSubItem = 0;
                    item.cchTextMax = 256;
                    item.pszText = buf;
                    item.stateMask = ~LVIS_SELECTED;
                    item.mask = LVIF_STATE | LVIF_IMAGE | LVIF_INDENT | LVIF_TEXT | LVIF_PARAM;
                    ListView_GetItem(hList, &item);
                    ListView_GetItemText(hList, poz, 1, sub, 12);

                    SendMessage(hPasek, TB_MOVEBUTTON, (WPARAM)poz, (LPARAM)lvhti.iItem);
                    if (lvhti.iItem > poz && lvhti.iItem < ile)
                        lvhti.iItem++;
                    item.iItem = lvhti.iItem;

                    ListView_InsertItem(hList, &item);
                    ListView_SetItemText(hList, item.iItem, 1, sub);
                    if (lvhti.iItem < poz)
                        poz++;
                    ListView_DeleteItem(hList, poz);
                    if (lvhti.iItem > tmp)
                        lvhti.iItem--;
                    if (lvhti.iItem < tmp)
                        lvhti.iItem++;
                    ListView_GetItemText(hList, poz, 0, buf, 256);
                    item.iItem = poz;
                    item.iSubItem = 0;
                    item.cchTextMax = 256;
                    item.pszText = buf;
                    ListView_GetItem(hList, &item);
                    if (!item.iIndent || poz > ile-1)  //je¿eli
                        break;
                }
            }
            break;
        default:
            return DefWindowProc(hWnd, komunikat, wParam, lParam);
    }
    return 0;
}
Beispiel #5
0
void VDUIListViewW32::OnNotifyCallback(const NMHDR *pHdr) {
   	if (pHdr->code == LVN_ITEMCHANGED) {
   		const NMLISTVIEW *plvn = (const NMLISTVIEW *)pHdr;
   
   		if ((plvn->uOldState|plvn->uNewState) & LVIS_SELECTED) {
   			int iSel = (int)SendMessage(mhwnd, LVM_GETNEXTITEM, -1, LVNI_ALL|LVNI_SELECTED);
   
   			if (iSel != mSelected) {
   				mSelected = iSel;
   
				mpBase->ProcessValueChange(this, mID);
   				mpBase->DispatchEvent(this, mID, IVDUICallback::kEventSelect, mSelected);
   			}
   		}
	} else if (pHdr->code == LVN_GETDISPINFO) {
		NMLVDISPINFOA& lvdi = *(NMLVDISPINFOA *)pHdr;
		LVITEMA& lvi = lvdi.item;

		VDASSERTCT(sizeof(NMLVDISPINFOW) == sizeof(NMLVDISPINFOA));

		if (mpListCB && (lvi.mask & LVIF_TEXT)) {
			if (mpListCB->GetListText(lvi.iItem, lvi.iSubItem, mListTextW[mListTextIndex])) {
				if (VDIsWindowsNT()) {
					NMLVDISPINFOW& lvdiw = *(NMLVDISPINFOW *)pHdr;
					LVITEMW& lviw = lvdiw.item;

					lviw.pszText = const_cast<WCHAR *>(mListTextW[mListTextIndex].c_str());
				} else {
					mListTextA[mListTextIndex] = VDTextWToA(mListTextW[mListTextIndex]);

					lvi.pszText = const_cast<CHAR *>(mListTextA[mListTextIndex].c_str());
				}

				if (++mListTextIndex >= 3)
					mListTextIndex = 0;
			}
		}
	} else if (mbCheckable) {
		if (pHdr->code == LVN_KEYDOWN && ((const NMLVKEYDOWN *)pHdr)->wVKey == VK_SPACE) {
			int idx = -1;
			bool first = true;
			bool select = false;

			while((idx = ListView_GetNextItem(mhwnd, idx, LVNI_SELECTED)) >= 0) {
				if (first) {
					UINT oldState = ListView_GetItemState(mhwnd, idx, -1);

					select = !(oldState & INDEXTOSTATEIMAGEMASK(1));
					first = false;
				}

				ListView_SetItemState(mhwnd, idx, select ? INDEXTOSTATEIMAGEMASK(1) : 0, LVIS_STATEIMAGEMASK);
				ListView_RedrawItems(mhwnd, idx, idx);
			}
		} else if (pHdr->code == NM_CLICK || pHdr->code == NM_DBLCLK) {
 			DWORD pos = GetMessagePos();

			LVHITTESTINFO lvhi = {0};

			lvhi.pt.x = (SHORT)LOWORD(pos);
			lvhi.pt.y = (SHORT)HIWORD(pos);

			ScreenToClient(mhwnd, &lvhi.pt);

			int idx = ListView_HitTest(mhwnd, &lvhi);

			if (idx >= 0) {
				UINT oldState = ListView_GetItemState(mhwnd, idx, -1);

				ListView_SetItemState(mhwnd, idx, oldState ^ INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK);
				ListView_RedrawItems(mhwnd, idx, idx);
			}
		}
	}
}
Beispiel #6
0
static INT_PTR CALLBACK LangOptDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	HWND hwndList = GetDlgItem(hwndDlg, IDC_LANGLIST);
	LVITEM lvi;

	switch(msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		hwndLangOpt = hwndDlg;
		ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT|LVS_EX_LABELTIP);
		ListView_SetImageList(hwndList, CreateRadioImages(ListView_GetBkColor(hwndList), ListView_GetTextColor(hwndList)), LVSIL_STATE); /* auto-destroyed */
		{	
			LVCOLUMN lvc;
			lvc.mask = LVCF_TEXT;
			lvc.pszText = TranslateT("Installed Languages");
			ListView_InsertColumn(hwndList, 0, &lvc);
		}
		if ( ServiceExists(MS_FLAGS_LOADFLAGICON))
			ListView_SetImageList(hwndList, ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR24, 8, 8), LVSIL_SMALL); 
		
		TCHAR szPath[MAX_PATH];
		GetPackPath(szPath, SIZEOF(szPath), FALSE, _T(""));
		SetDlgItemText(hwndDlg, IDC_SKINROOTFOLDER, szPath);

		SendMessage(hwndDlg, M_RELOADLIST, 0, 0);
		SendMessage(hwndDlg, M_SHOWFILECOL, 0, 1);
		return TRUE;

	case M_RELOADLIST:
		/* init list */
		ListView_DeleteAllItems(hwndList);
		ListView_DeleteColumn(hwndList, 1); /* if present */
		{
			HIMAGELIST himl = ListView_GetImageList(hwndList, LVSIL_SMALL);
			ImageList_RemoveAll(himl);
			/* enum all packs */
			EnumPacks(InsertPackItemEnumProc, _T("langpack_*.txt"), "Miranda Language Pack Version 1", (WPARAM)hwndList, (LPARAM)himl);
			/* make it use current langpack locale for sort */
			ListView_SortItems(hwndList, CompareListItem, CallService(MS_LANGPACK_GETLOCALE, 0, 0));
			//CheckDlgButton(hwndDlg, IDC_ENABLEAUTOUPDATES, db_get_b(NULL, "LangMan", "EnableAutoUpdates", SETTING_ENABLEAUTOUPDATES_DEFAULT) != 0);
			/* show selection */
			int iItem = ListView_GetNextItem(hwndList, -1, LVNI_SELECTED);
			if (iItem != -1)
				ListView_EnsureVisible(hwndList, iItem, FALSE);
		}
		return TRUE;

	case M_SHOWFILECOL:
		if ((BOOL)lParam && ListView_GetItemCount(hwndList) > 1) {
			/* add column */
			LVCOLUMN lvc;
			ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE_USEHEADER);
			lvc.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
			lvc.pszText = TranslateT("File");
			lvc.cx = 160;
			ListView_InsertColumn(hwndList, lvc.iSubItem = 1, &lvc);
			ListView_SetColumnWidth(hwndList, 0, ListView_GetColumnWidth(hwndList, 0) - lvc.cx);

			/* add text */
			lvi.mask = LVIF_PARAM;
			lvi.iSubItem = 0;
			for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) {
				LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
				ListView_SetItemText(hwndList, lvi.iItem, 1, (pack->flags&LPF_DEFAULT) ? TranslateT("built-in") : pack->szFileName);
			}
		}
		else {
			ListView_DeleteColumn(hwndList, 1);
			ListView_SetColumnWidth(hwndList, 0, LVSCW_AUTOSIZE_USEHEADER);
		}
		return TRUE;

	case WM_DESTROY:
		ListView_DeleteAllItems(GetDlgItem(hwndDlg, IDC_LANGLIST));
		return TRUE;

	case WM_THEMECHANGED:
	case WM_SETTINGCHANGE:
		{
			HIMAGELIST himl = ListView_SetImageList(hwndList, CreateRadioImages(ListView_GetBkColor(hwndList), ListView_GetTextColor(hwndList)), LVSIL_STATE); /* auto-destroyed */
			if (himl != NULL)
				ImageList_Destroy(himl);
		}
		break;

	case WM_CTLCOLORLISTBOX: /* mimic readonly edit */
		return (BOOL)SendMessage(hwndDlg, WM_CTLCOLORSTATIC, wParam, lParam);

	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case IDC_LANGEMAIL:
			{
				char buf[512];
				lstrcpyA(buf, "mailto:");
				if (GetWindowTextA(GetDlgItem(hwndDlg, LOWORD(wParam)), &buf[7], sizeof(buf)-7))
					CallService(MS_UTILS_OPENURL, FALSE, (LPARAM)buf);
				return TRUE;
			}

		case IDC_MORELANG:
			CallService(MS_UTILS_OPENURL, TRUE, (LPARAM)"http://miranda-ng.org/");
			return TRUE;
		}
		break;

	case WM_CONTEXTMENU:
		if (GetDlgCtrlID((HWND)wParam) == IDC_LANGLIST) {
			/* get item */
			LVHITTESTINFO hti;
			POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
			if (hti.pt.x == -1 && hti.pt.y == -1) {
				/* keyboard invoked */
				hti.iItem = ListView_GetNextItem((HWND)wParam, -1, LVNI_SELECTED);
				if (hti.iItem != -1)
					break;

				RECT rc;
				if (!ListView_GetItemRect((HWND)wParam, hti.iItem, &rc, LVIR_SELECTBOUNDS))
					break;

				hti.pt.x = rc.left + (rc.right - rc.left) / 2;
				hti.pt.y = rc.top + (rc.bottom - rc.top) / 2;
				ClientToScreen((HWND)wParam, &hti.pt);
			}
			else {
				ScreenToClient((HWND)wParam, &hti.pt);
				if (ListView_HitTest((HWND)wParam, &hti) == -1 || !(hti.flags&LVHT_ONITEM))
					break;
				POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
			}

			/* param */
			lvi.iItem = hti.iItem;
			lvi.iSubItem = 0;
			lvi.mask = LVIF_PARAM;
			if (!ListView_GetItem((HWND)wParam, &lvi))
				break;

			/* context menu */
			LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
			if (!(pack->flags & LPF_DEFAULT)) {
				HMENU hContextMenu = CreatePopupMenu();
				if (hContextMenu != NULL) {
					AppendMenu(hContextMenu, MF_STRING, 2, TranslateT("&Remove..."));
					if (TrackPopupMenuEx(hContextMenu, TPM_RETURNCMD | TPM_NONOTIFY | TPM_TOPALIGN | TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_HORPOSANIMATION | TPM_VERPOSANIMATION, hti.pt.x, hti.pt.y, (HWND)wParam, NULL))
						DeletePackFile(hwndDlg, (HWND)wParam, hti.iItem, pack);
					DestroyMenu(hContextMenu);
				}
			}
			return TRUE;
		}
		break;

	case WM_NOTIFYFORMAT:
		SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, NFR_UNICODE);
		return TRUE;

	case WM_NOTIFY:
		NMHDR *nmhdr = (NMHDR*)lParam;
		switch (nmhdr->idFrom) {
		case IDC_LANGLIST:
			switch (nmhdr->code) {
			case LVN_DELETEITEM:
				lvi.iItem = ((NMLISTVIEW*)lParam)->iItem; /* nmlv->lParam is invalid */
				lvi.iSubItem = 0;
				lvi.mask = LVIF_PARAM;
				if (ListView_GetItem(nmhdr->hwndFrom, &lvi))
					mir_free((LANGPACK_INFO*)lvi.lParam);
				break;

			case LVN_ITEMCHANGED:
				{
					NMLISTVIEW *nmlv = (NMLISTVIEW*)lParam;
					if (!(nmlv->uChanged&LVIF_STATE))
						break;

					/* display info and check radio item */
					if (nmlv->uNewState&LVIS_SELECTED && !(nmlv->uOldState&LVIS_SELECTED)) {
						ListView_SetItemState(nmhdr->hwndFrom, nmlv->iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
						DisplayPackInfo(hwndDlg, (LANGPACK_INFO*)nmlv->lParam);
					}
					/* disable all other radio items */
					else if (nmlv->uNewState&INDEXTOSTATEIMAGEMASK(2)) {
						for (int iItem = ListView_GetItemCount(nmhdr->hwndFrom) - 1; iItem != -1; --iItem)
							if (iItem != nmlv->iItem)
								ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(1), LVIS_STATEIMAGEMASK);

						/* enable apply */
						if (nmlv->uOldState) {
							SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
							ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), SW_SHOW);
						}
					}
				}
				break;

			case LVN_KEYDOWN:
				{
					int iItem = ListView_GetNextItem(nmhdr->hwndFrom, -1, LVNI_SELECTED);
					switch (((NMLVKEYDOWN*)lParam)->wVKey) {
					case VK_SPACE:
						ListView_SetItemState(nmhdr->hwndFrom, iItem, INDEXTOSTATEIMAGEMASK(2), LVIS_STATEIMAGEMASK);
						break;

					case VK_DELETE:
						lvi.iItem = iItem;
						lvi.iSubItem = 0;
						lvi.mask = LVIF_PARAM;
						if (ListView_GetItem(nmhdr->hwndFrom, &lvi)) {
							LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
							if (!(pack->flags&LPF_DEFAULT))
								DeletePackFile(hwndDlg, nmhdr->hwndFrom, iItem, pack);
						}
						break;
					}
				}
				break;

			case NM_CLICK:
				LVHITTESTINFO hti;
				lParam = GetMessagePos();
				POINTSTOPOINT(hti.pt, MAKEPOINTS(lParam));
				ScreenToClient(nmhdr->hwndFrom, &hti.pt);
				if (ListView_HitTest(nmhdr->hwndFrom, &hti) != -1)
					if (hti.flags&(LVHT_ONITEMSTATEICON | LVHT_ONITEMICON)) /* one of them */
						ListView_SetItemState(nmhdr->hwndFrom, hti.iItem, LVIS_SELECTED, LVIS_SELECTED);
			}
			break;

		case 0:
			switch (nmhdr->code) {
			case PSN_APPLY:
				lvi.mask = LVIF_STATE | LVIF_PARAM;
				lvi.stateMask = LVIS_STATEIMAGEMASK;
				lvi.iSubItem = 0;
				for (lvi.iItem = 0; ListView_GetItem(hwndList, &lvi); ++lvi.iItem) {
					LANGPACK_INFO *pack = (LANGPACK_INFO*)lvi.lParam;
					if (lvi.state&INDEXTOSTATEIMAGEMASK(2) && !(pack->flags & LPF_ENABLED)) {
						if(!(pack->flags & LPF_DEFAULT))
							db_set_ws(NULL, "LangMan", "Langpack", pack->szFileName);
						else
							db_unset(NULL, "LangMan", "Langpack");
						TCHAR szPath[MAX_PATH];
						GetPackPath(szPath, SIZEOF(szPath), FALSE, pack->szFileName);
						CallService(MS_LANGPACK_RELOAD, 0, (LPARAM)szPath);
						pack->flags |= LPF_ENABLED;
						CloseWindow(GetParent(hwndDlg));
						DestroyWindow(GetParent(hwndDlg));
					}
					else pack->flags &= ~LPF_ENABLED;
				}
				return TRUE;
			}
		}
		break;
	}
	return FALSE;
}
Beispiel #7
0
/*
================
rvGENavigator::WndProc

Window Procedure 
================
*/
LRESULT CALLBACK rvGENavigator::WndProc ( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	rvGENavigator* nav = (rvGENavigator*) GetWindowLong ( hWnd, GWL_USERDATA );

	switch ( msg )
	{
		case WM_INITMENUPOPUP:
			return SendMessage ( gApp.GetMDIFrame ( ), msg, wParam, lParam );
	
		case WM_ACTIVATE:
			common->ActivateTool( LOWORD( wParam ) != WA_INACTIVE );
			break;

		case WM_ERASEBKGND:
			return TRUE;
		
		case WM_DESTROY:
			gApp.GetOptions().SetWindowPlacement ( "navigator", hWnd );
			break;
		
		case WM_CLOSE:		
			gApp.GetOptions().SetNavigatorVisible ( false );
			nav->Show ( false );
			return 0;

		case WM_DRAWITEM:
		{		
			DRAWITEMSTRUCT*	dis = (DRAWITEMSTRUCT*) lParam;
			idWindow*		window = (idWindow*)dis->itemData;
			
			if ( window )
			{
				rvGEWindowWrapper*	wrapper	= rvGEWindowWrapper::GetWrapper ( window );
				idStr				name    = window->GetName();
				RECT				rDraw;
				float				offset;
				bool				disabled;

				idWindow* parent = window;
				offset = 1;
				disabled = false;
				while ( parent = parent->GetParent ( ) )
				{
					if ( rvGEWindowWrapper::GetWrapper ( parent )->IsHidden ( ) )
					{
						disabled = true;
					}
					
					offset += 10;
				}
				
				CopyRect ( &rDraw, &dis->rcItem );
				rDraw.right = rDraw.left + GENAV_ITEMHEIGHT;
				rDraw.top ++;

				rDraw.right ++;
				FrameRect ( dis->hDC, &rDraw, (HBRUSH)GetStockObject ( BLACK_BRUSH ) );
				rDraw.right --;
			
				FillRect ( dis->hDC, &rDraw, GetSysColorBrush ( COLOR_3DFACE ) );

				Draw3dRect ( dis->hDC, &rDraw, GetSysColorBrush ( COLOR_3DHILIGHT ), GetSysColorBrush ( COLOR_3DSHADOW ) );

				InflateRect ( &rDraw, -3, -3 );
				Draw3dRect ( dis->hDC, &rDraw, GetSysColorBrush ( COLOR_3DSHADOW ), GetSysColorBrush ( COLOR_3DHILIGHT ) );
				
				if ( !wrapper->IsHidden ( ) )
				{
					DrawIconEx ( dis->hDC, rDraw.left, rDraw.top, disabled?nav->mVisibleIconDisabled:nav->mVisibleIcon, 16, 16,0, NULL, DI_NORMAL );
				}

				CopyRect ( &rDraw, &dis->rcItem );
				rDraw.left += GENAV_ITEMHEIGHT;
				rDraw.left += 1;
			
				if ( dis->itemState & ODS_SELECTED )
				{
					FillRect ( dis->hDC, &rDraw, GetSysColorBrush ( COLOR_HIGHLIGHT ) );			
				}
				else
				{
					FillRect ( dis->hDC, &rDraw, GetSysColorBrush ( COLOR_WINDOW ) );
				}

				if ( wrapper->CanHaveChildren ( ) && window->GetChildCount ( ) )
				{
					if ( wrapper->IsExpanded ( ) )
					{
						DrawIconEx ( dis->hDC, rDraw.left + offset, rDraw.top + 3, nav->mCollapseIcon, 16, 16,0, NULL, DI_NORMAL );								
					}
					else
					{
						DrawIconEx ( dis->hDC, rDraw.left + offset, rDraw.top + 3, nav->mExpandIcon, 16, 16,0, NULL, DI_NORMAL );								
					}
				}
			
				HPEN pen = CreatePen ( PS_SOLID, 1, GetSysColor ( COLOR_3DSHADOW ) );
				HPEN oldpen = (HPEN)SelectObject ( dis->hDC, pen );
				MoveToEx ( dis->hDC, rDraw.left, dis->rcItem.top, NULL );
				LineTo ( dis->hDC, dis->rcItem.right, dis->rcItem.top );
				MoveToEx ( dis->hDC, rDraw.left, dis->rcItem.bottom, NULL );
				LineTo ( dis->hDC, dis->rcItem.right, dis->rcItem.bottom);
				SelectObject ( dis->hDC, oldpen );
				DeleteObject ( pen );			

				rDraw.left += offset;
				rDraw.left += 20;
											
				int colorIndex = ( (dis->itemState & ODS_SELECTED ) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT );
				SetTextColor ( dis->hDC, GetSysColor ( colorIndex ) );
				DrawText ( dis->hDC, name, name.Length(), &rDraw, DT_LEFT|DT_VCENTER|DT_SINGLELINE );
							
				if ( wrapper->GetVariableDict().GetNumKeyVals ( ) || wrapper->GetScriptDict().GetNumKeyVals ( ) )
				{
					DrawIconEx ( dis->hDC, dis->rcItem.right - 16, (dis->rcItem.bottom+dis->rcItem.top)/2-6, (dis->itemState & ODS_SELECTED)?nav->mScriptsLightIcon:nav->mScriptsIcon, 13, 13,0, NULL, DI_NORMAL );
				}
			}
			
			break;
		}
	
		case WM_MEASUREITEM:
		{
			MEASUREITEMSTRUCT* mis = (MEASUREITEMSTRUCT*) lParam;
			mis->itemHeight = 22;
			break;
		}
	
		case WM_CREATE:
		{
			LPCREATESTRUCT	cs;
			LVCOLUMN		col;
			
			// Attach the class to the window first
			cs = (LPCREATESTRUCT) lParam;
			nav = (rvGENavigator*) cs->lpCreateParams;
			SetWindowLong ( hWnd, GWL_USERDATA, (LONG)nav );

			// Create the List view
			nav->mTree = CreateWindowEx ( 0, "SysListView32", "", WS_VSCROLL|WS_CHILD|WS_VISIBLE|LVS_REPORT|LVS_OWNERDRAWFIXED|LVS_NOCOLUMNHEADER|LVS_SHOWSELALWAYS, 0, 0, 0, 0, hWnd, (HMENU)IDC_GUIED_WINDOWTREE, win32.hInstance, 0 );
			ListView_SetExtendedListViewStyle ( nav->mTree, LVS_EX_FULLROWSELECT );
			ListView_SetBkColor ( nav->mTree, GetSysColor ( COLOR_3DFACE ) );
			ListView_SetTextBkColor ( nav->mTree, GetSysColor ( COLOR_3DFACE ) );
			nav->mListWndProc = (WNDPROC)GetWindowLong ( nav->mTree, GWL_WNDPROC );
			SetWindowLong ( nav->mTree, GWL_USERDATA, (LONG)nav );
			SetWindowLong ( nav->mTree, GWL_WNDPROC, (LONG)ListWndProc );

			// Insert the only column
			col.mask = 0;	
			ListView_InsertColumn ( nav->mTree, 0, &col );
							
			break;
		}
	
		case WM_SIZE:
		{
			RECT rClient;
			MoveWindow ( nav->mTree, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE );
			GetClientRect ( nav->mTree, &rClient );		
			ListView_SetColumnWidth ( nav->mTree, 0, rClient.right-rClient.left-1 );
			break;
		}

		case WM_NCACTIVATE:
			return gApp.ToolWindowActivate ( gApp.GetMDIFrame(), msg, wParam, lParam );
				
		case WM_NOTIFY:
		{
			LPNMHDR nh;
			
			nh = (LPNMHDR) lParam;
			
			switch ( nh->code )
			{				
				case NM_CLICK:
				case NM_DBLCLK:
				{
					DWORD dwpos = GetMessagePos(); 
					LVHITTESTINFO info;
					info.pt.x = LOWORD(dwpos);
					info.pt.y = HIWORD(dwpos);		
					MapWindowPoints(HWND_DESKTOP, nh->hwndFrom, &info.pt, 1);      
					int index = ListView_HitTest ( nav->mTree, &info );
					if ( index != -1 )
					{
						RECT	rItem;
						int		offset;
						ListView_GetItemRect ( nav->mTree, index, &rItem, LVIR_BOUNDS );
						LVITEM item;
						item.mask = LVIF_PARAM;
						item.iItem = index;
						ListView_GetItem ( nav->mTree, &item );
						idWindow* window = (idWindow*)item.lParam;
						rvGEWindowWrapper* wrapper = rvGEWindowWrapper::GetWrapper(window);

						offset = wrapper->GetDepth ( ) * 10 + 1;

						if ( info.pt.x < GENAV_ITEMHEIGHT )
						{
							if ( !rvGEWindowWrapper::GetWrapper(window)->IsHidden ( ) )
							{
								nav->mWorkspace->HideWindow ( window );
							}
							else
							{
								nav->mWorkspace->UnhideWindow ( window );
							}
						}						
						else if ( info.pt.x > GENAV_ITEMHEIGHT + offset && info.pt.x < GENAV_ITEMHEIGHT + offset + 16 )
						{
							if ( wrapper->CanHaveChildren ( ) && window->GetChildCount ( ) )
							{
								if ( wrapper->IsExpanded ( ) )
								{
									wrapper->Collapse ( );
									nav->Update ( );
								}
								else
								{
									wrapper->Expand ( );
									nav->Update ( );
								}
							}
						}
						else if ( nh->code == NM_DBLCLK )
						{
							SendMessage ( gApp.GetMDIFrame ( ), WM_COMMAND, MAKELONG(ID_GUIED_ITEM_PROPERTIES,0), 0 );
						}											
					}
					
					break;
				}
				
				case NM_RCLICK:
				{
					DWORD dwpos = GetMessagePos(); 
					LVHITTESTINFO info;
					info.pt.x = LOWORD(dwpos);
					info.pt.y = HIWORD(dwpos);		
					MapWindowPoints(HWND_DESKTOP, nh->hwndFrom, &info.pt, 1);      
					int index = ListView_HitTest ( nav->mTree, &info );
					
					if ( index != -1 )
					{				
						ClientToScreen ( hWnd, &info.pt );
						HMENU menu = GetSubMenu ( LoadMenu ( gApp.GetInstance(), MAKEINTRESOURCE(IDR_GUIED_ITEM_POPUP) ), 0 );
						TrackPopupMenu ( menu, TPM_RIGHTBUTTON|TPM_LEFTALIGN, info.pt.x, info.pt.y, 0, gApp.GetMDIFrame ( ), NULL );
						DestroyMenu ( menu );
					}
					
					break;					
				}
								
				case LVN_ITEMCHANGED:
				{
					NMLISTVIEW* nml = (NMLISTVIEW*) nh;
					if ( (nml->uNewState & LVIS_SELECTED) != (nml->uOldState & LVIS_SELECTED) )
					{
						LVITEM item;
						item.iItem = nml->iItem;
						item.mask = LVIF_PARAM;
						ListView_GetItem ( nav->mTree, &item );
						
						if ( nml->uNewState & LVIS_SELECTED )
						{
							nav->mWorkspace->GetSelectionMgr().Add ( (idWindow*)item.lParam, false );
						}
						else
						{
							nav->mWorkspace->GetSelectionMgr().Remove ( (idWindow*)item.lParam );
						}	
					}
					break;
				}
			}
			
			break;
		}	
	}

	return DefWindowProc ( hWnd, msg, wParam, lParam );
}
BOOL CTaskListDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pObject, DROPEFFECT /*dropEffect*/, CPoint point)
{
	CString sFilePath;

	if (GetDroppedFilePath(pObject, sFilePath))
	{
		CString sClass = CWinClasses::GetClass(*pWnd);

		m_pParent->SetForegroundWindow();

		if (IS_WND_TYPE(pWnd, CTreeCtrl, WC_TREEVIEW))
		{
			TVHITTESTINFO tvhti = { { point.x, point.y }, 0, 0 };

			TreeView_HitTest(pWnd->GetSafeHwnd(), &tvhti);
			TreeView_SelectDropTarget(pWnd->GetSafeHwnd(), NULL);

			if (tvhti.hItem)
			{
				m_pParent->SendMessage(WM_TLDT_DROPFILE, (WPARAM)tvhti.hItem, (LPARAM)(LPCTSTR)sFilePath);
			}
		}
		else if (IS_WND_TYPE(pWnd, CListCtrl, WC_LISTVIEW))
		{
			LVHITTESTINFO lvhti = { { point.x, point.y }, 0 };

			ListView_HitTest(pWnd->GetSafeHwnd(), &lvhti);

			if (m_nLVPrevHilite != -1)
			{
				ListView_SetItemState(pWnd->GetSafeHwnd(), m_nLVPrevHilite, 0, LVIS_DROPHILITED); // all items
				m_nLVPrevHilite = -1;
			}

			if (lvhti.iItem != -1)
			{
				m_pParent->SendMessage(WM_TLDT_DROPFILE, (WPARAM)lvhti.iItem, (LPARAM)(LPCTSTR)sFilePath);
			}
		}
		else if (IS_WND_TYPE(pWnd, CEdit, WC_EDIT))
		{
			if (!(pWnd->GetStyle() & ES_READONLY))
			{
				m_pParent->SendMessage(WM_TLDT_DROPFILE, (WPARAM)0, (LPARAM)(LPCTSTR)sFilePath);
			}
		}
		else if (pWnd->IsKindOf(RUNTIME_CLASS(CDialog)) ||
			pWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)))
		{
			// allow dropping only on titlebar
			if ((pWnd->GetStyle() & WS_CAPTION) && point.y < 0)
			{
				m_pParent->SendMessage(WM_TLDT_DROPFILE, (WPARAM)0, (LPARAM)(LPCTSTR)sFilePath);
			}
		}
	}
	else // cleanup
	{
		if (IS_WND_TYPE(pWnd, CTreeCtrl, WC_TREEVIEW))
		{
			TreeView_SelectDropTarget(pWnd->GetSafeHwnd(), NULL);
		}

		else if (IS_WND_TYPE(pWnd, CListCtrl, WC_LISTVIEW))
		{
			if (m_nLVPrevHilite != -1)
			{
				ListView_SetItemState(pWnd->GetSafeHwnd(), m_nLVPrevHilite, 0, LVIS_DROPHILITED);   // all items
			}

			m_nLVPrevHilite = -1;
		}
	}

	return FALSE; // because we handle it
}
Beispiel #9
0
/*
 * VerbAliasDialogProc:  Dialog procedure for command verb alias dialog.
 */
BOOL CALLBACK VerbAliasDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
   switch (message)
   {
   case WM_INITDIALOG:

      SendDlgItemMessage(hDlg, IDC_VERB, EM_LIMITTEXT, MAX_VERBLEN, 0L);
      SendDlgItemMessage(hDlg, IDC_EXPANSION, EM_LIMITTEXT, MAX_ALIASLEN, 0L);

      // Prepare list of aliases currently defined.
      {
	 LV_COLUMN lvcol;
	 HWND hList;
	 int i;

	 // Prepare list of aliases.
	 hList = GetDlgItem(hDlg, IDC_COMMAND_LIST);
	 SetWindowFont(hList, GetFont(FONT_LIST), FALSE);
	 SetWindowLong(hList, GWL_STYLE, GetWindowLong(hList, GWL_STYLE) | LVS_SHOWSELALWAYS);

	 // Add column headings
	 lvcol.mask = LVCF_TEXT | LVCF_WIDTH;
	 lvcol.pszText = GetString(hInst, IDS_AHEADER0);
	 lvcol.cx = 60;
	 ListView_InsertColumn(hList, 0, &lvcol);
	 lvcol.pszText = GetString(hInst, IDS_AHEADER1);
	 lvcol.cx = 220;
	 ListView_InsertColumn(hList, 1, &lvcol);

	 // Add aliases
	 for (i = 0; i < _nVerbAliases; i++)
	 {
	    if (_apVerbAliases[i].verb[0])
	    {
	       LV_ITEM lvitem;

	       // Add item for verb.
	       lvitem.mask = LVIF_TEXT;
	       lvitem.iItem = ListView_GetItemCount(hList);
	       lvitem.iSubItem = 0;
	       lvitem.pszText = _apVerbAliases[i].verb;
	       lvitem.iItem = ListView_InsertItem(hList, &lvitem);

	       // Add subitem for command.
	       lvitem.mask = LVIF_TEXT;
	       lvitem.iSubItem = 1;
	       lvitem.pszText = _apVerbAliases[i].text;
	       ListView_SetItem(hList, &lvitem);
	    }
	 }
      }

      // Dialog is up.
      hAliasDialog = hDlg;
      hAliasDialog2 = hDlg;
      if (hAliasDialog1)
	 DestroyWindow(GetDlgItem(hDlg, IDC_TUNNEL));

      CenterWindow(hDlg, GetParent(hDlg));
      return TRUE;

   case WM_NOTIFY:
      if (wParam != IDC_COMMAND_LIST)
      {
	 return TRUE;
      }
      else
      {
	 NM_LISTVIEW* pnm = (NM_LISTVIEW*)lParam;
	 LV_HITTESTINFO lvhit;
	 LV_KEYDOWN* plvkey;
	 HWND hList;
	 int i;

	 if (!pnm)
	    break;

	 // Prepare list of aliases.
	 hList = GetDlgItem(hDlg, IDC_COMMAND_LIST);

	 switch (pnm->hdr.code)
	 {
	 case NM_CLICK:
	    {
	       VerbAlias alias;
	       LV_ITEM lvitem;
	       HWND hList;

	       hList = GetDlgItem(hDlg, IDC_COMMAND_LIST);

	       // If you click anywhere on an item.
	       GetCursorPos(&lvhit.pt);
	       ScreenToClient(hList, &lvhit.pt);
	       lvhit.pt.x = 3;
	       i = ListView_HitTest(hList, &lvhit);
	       if (i < 0)
		  break;

	       // Get our current definition.
	       lvitem.mask = LVIF_TEXT;
	       lvitem.iItem = i;
	       lvitem.iSubItem = 0;
	       lvitem.pszText = alias.verb;
	       lvitem.cchTextMax = sizeof(alias.verb);
	       ListView_GetItem(hList, &lvitem);
	       lvitem.iSubItem = 1;
	       lvitem.pszText = alias.text;
	       lvitem.cchTextMax = sizeof(alias.text);
	       ListView_GetItem(hList, &lvitem);

	       // Put it up for editing.
	       SetDlgItemText(hDlg, IDC_VERB, alias.verb);
	       SetDlgItemText(hDlg, IDC_EXPANSION, alias.text);

	       // Select and focus the item in the list.
	       ListView_SetItemState(hList, i, 
				     LVIS_SELECTED | LVIS_FOCUSED,
				     LVIS_SELECTED | LVIS_FOCUSED);
	    }
	    break;

	 case LVN_KEYDOWN:
	    plvkey = (LV_KEYDOWN*)pnm;
	    if (plvkey->wVKey == VK_DELETE)
	    {
//	       for (i = 0; i < nItems; i++)
//		  if (is selected i)
//		     ListView_DeleteItem(hList, i);
	    }
	    break;
	 }
      }
      return TRUE;

   case WM_COMMAND:
      switch(GET_WM_COMMAND_ID(wParam, lParam))
      {
      case IDOK:
	 // Erase current set and redefine words in the dialog.
	 {
	    int i, nItems;
	    HWND hList;
	    hList = GetDlgItem(hDlg, IDC_COMMAND_LIST);

	    // Simulate a last click of 'Define' in case they forgot.
	    // Does no harm if they left the boxes empty after their
	    // last 'Define'.
	    //
	    ListView_ClearSelection(hList);
	    SendMessage(hDlg, WM_COMMAND,
	       (WPARAM)MAKELONG(IDC_DEFINE, BN_CLICKED),
	       (LPARAM)GetDlgItem(hDlg, IDC_DEFINE));

	    // Clear our real aliases and rebuild them from our listbox.
	    //
	    FreeVerbAliases();
	    nItems = ListView_GetItemCount(hList);
	    for (i = 0; i < nItems; i++)
	    {
	       VerbAlias alias;
	       LV_ITEM lvitem;

	       lvitem.mask = LVIF_TEXT;
	       lvitem.iItem = i;
	       lvitem.iSubItem = 0;
	       lvitem.pszText = alias.verb;
	       lvitem.cchTextMax = sizeof(alias.verb);
	       ListView_GetItem(hList, &lvitem);
	       lvitem.iSubItem = 1;
	       lvitem.pszText = alias.text;
	       lvitem.cchTextMax = sizeof(alias.text);
	       ListView_GetItem(hList, &lvitem);

	       AddVerbAlias(alias.verb, alias.text);
	    }
	 }
	 EndDialog(hDlg, IDOK);
	 return TRUE;

      case IDCANCEL:
	 EndDialog(hDlg, IDCANCEL);
	 return TRUE;

      case IDC_DEFINE:
	 {
	    VerbAlias alias;
	    LV_ITEM lvitem;
	    HWND hList;

	    hList = GetDlgItem(hDlg, IDC_COMMAND_LIST);

	    // Get our new definition.
	    GetDlgItemText(hDlg, IDC_VERB, alias.verb, sizeof(alias.verb));
	    GetDlgItemText(hDlg, IDC_EXPANSION, alias.text, sizeof(alias.text));
	    if (!alias.verb[0])
	    {
	       SetFocus(GetDlgItem(hDlg, IDC_VERB));
	       return TRUE;
	    }
	    if (!alias.text[0])
	    {
	       SetFocus(GetDlgItem(hDlg, IDC_EXPANSION));
	       return TRUE;
	    }

	    // Simulate a remove so we don't have to hunt and modify existing entry.
	    ListView_ClearSelection(hList);
	    SendMessage(hDlg, WM_COMMAND,
	       (WPARAM)MAKELONG(IDC_REMOVE, BN_CLICKED),
	       (LPARAM)GetDlgItem(hDlg, IDC_REMOVE));

	    // Add item for verb.
	    lvitem.mask = LVIF_TEXT;
	    lvitem.iItem = ListView_GetItemCount(hList);
	    lvitem.iSubItem = 0;
	    lvitem.pszText = alias.verb;
	    lvitem.iItem = ListView_InsertItem(hList, &lvitem);

	    // Add subitem for command.
	    lvitem.mask = LVIF_TEXT;
	    lvitem.iSubItem = 1;
	    lvitem.pszText = alias.text;
	    ListView_SetItem(hList, &lvitem);

	    // Clear the fields to try another.
	    SetDlgItemText(hDlg, IDC_VERB, "");
	    SetDlgItemText(hDlg, IDC_EXPANSION, "");
	    SetFocus(GetDlgItem(hDlg, IDC_VERB));
	 }
	 return TRUE;

      case IDC_REMOVE:
	 {
	    char verb[MAX_VERBLEN+1];
	    LV_FINDINFO lvfind;
	    HWND hList;
	    int i;

	    hList = GetDlgItem(hDlg, IDC_COMMAND_LIST);

	    // Get our new definition.
	    GetDlgItemText(hDlg, IDC_VERB, verb, sizeof(verb));
	    if (!verb[0])
	    {
	       LV_ITEM lvitem;

	       i = ListView_GetSelection(hList);
	       if (i < 0)
	       {
		  SetFocus(GetDlgItem(hDlg, IDC_VERB));
		  return TRUE;
	       }

	       lvitem.mask = LVIF_TEXT;
	       lvitem.iItem = i;
	       lvitem.iSubItem = 0;
	       lvitem.pszText = verb;
	       lvitem.cchTextMax = sizeof(verb);
	       ListView_GetItem(hList, &lvitem);
	       if (!verb[0])
	       {
		  SetFocus(GetDlgItem(hDlg, IDC_VERB));
		  return TRUE;
	       }
	    }

	    // Find item for verb.
	    lvfind.flags = LVFI_STRING | LVFI_WRAP; // not LVFI_PARTIAL
	    lvfind.psz = verb;
	    lvfind.lParam = 0;
	    i = ListView_FindItem(hList, -1, &lvfind);
	    if (i < 0)
	    {
	       SetFocus(GetDlgItem(hDlg, IDC_VERB));
	       Edit_SetSel(GetDlgItem(hDlg, IDC_VERB), 0, -1);
	       return TRUE;
	    }

	    // Remove item.
	    ListView_DeleteItem(hList, i);

	    // Clear the fields to try another.
	    SetDlgItemText(hDlg, IDC_VERB, "");
	    SetDlgItemText(hDlg, IDC_EXPANSION, "");
	    SetFocus(GetDlgItem(hDlg, IDC_VERB));
	 }
	 return TRUE;

      case IDC_TUNNEL:
	 if (!hAliasDialog1 &&
	     IDOK == DialogBox(hInst, MAKEINTRESOURCE(IDD_ALIAS), hDlg, AliasDialogProc))
	 {
	    AliasSave();
	    SetFocus(GetDlgItem(hDlg, IDOK));
	 }
	 return TRUE;
      }
      break;

   case WM_DESTROY:
      hAliasDialog = NULL;
      hAliasDialog2 = NULL;
      return TRUE;
   }
   
   return FALSE;
}
DROPEFFECT CTaskListDropTarget::OnDragOver(CWnd* pWnd, COleDataObject* pObject, DWORD /*dwKeyState*/, CPoint point)
{
	if (!pWnd->IsWindowEnabled())
	{
		return DROPEFFECT_NONE;
	}

	BOOL bFilename = pObject->IsDataAvailable((CLIPFORMAT)::RegisterClipboardFormat(_T("FileName")));
	BOOL bFileDrop = pObject->IsDataAvailable(CF_HDROP);

	if (bFilename || bFileDrop)
	{
		if (IS_WND_TYPE(pWnd, CTreeCtrl, WC_TREEVIEW))
		{
			TVHITTESTINFO tvhti = { { point.x, point.y }, 0, 0 };

			TreeView_HitTest(pWnd->GetSafeHwnd(), &tvhti);
			TreeView_SelectDropTarget(pWnd->GetSafeHwnd(), tvhti.hItem);

			if (tvhti.hItem)
			{
				return bFilename ? DROPEFFECT_LINK : DROPEFFECT_COPY;
			}
		}
		else if (IS_WND_TYPE(pWnd, CListCtrl, WC_LISTVIEW))
		{
			LVHITTESTINFO lvhti = { { point.x, point.y }, 0 };
			ListView_HitTest(pWnd->GetSafeHwnd(), &lvhti);

			// remove previous highlighting
			if (m_nLVPrevHilite != -1 && m_nLVPrevHilite != lvhti.iItem)
			{
				ListView_SetItemState(pWnd->GetSafeHwnd(), m_nLVPrevHilite, 0, LVIS_DROPHILITED);
			}

			if (lvhti.iItem != -1)
			{
				ListView_SetItemState(pWnd->GetSafeHwnd(), lvhti.iItem, LVIS_DROPHILITED, LVIS_DROPHILITED);
				m_nLVPrevHilite = lvhti.iItem;

				return bFilename ? DROPEFFECT_LINK : DROPEFFECT_COPY;
			}
		}
		else if (IS_WND_TYPE(pWnd, CEdit, WC_EDIT))
		{
			if (!(pWnd->GetStyle() & ES_READONLY))
			{
				return DROPEFFECT_COPY;
			}
		}
		else if (pWnd->IsKindOf(RUNTIME_CLASS(CDialog)) ||
			pWnd->IsKindOf(RUNTIME_CLASS(CFrameWnd)))
		{
			// allow dropping only on titlebar
			if ((pWnd->GetStyle() & WS_CAPTION) && point.y < 0)
			{
				return DROPEFFECT_COPY;
			}
		}
	}
	else
	{
		if (IS_WND_TYPE(pWnd, CTreeCtrl, WC_TREEVIEW))
		{
			TreeView_SelectDropTarget(pWnd->GetSafeHwnd(), NULL);
		}

		else if (IS_WND_TYPE(pWnd, CListCtrl, WC_LISTVIEW))
		{
			if (m_nLVPrevHilite != -1)
			{
				ListView_SetItemState(pWnd->GetSafeHwnd(), m_nLVPrevHilite, 0, LVIS_DROPHILITED);   // all items
			}

			m_nLVPrevHilite = -1;
		}
	}

	// else
	return DROPEFFECT_NONE;
}
Beispiel #11
0
INT_PTR CALLBACK DlgProcIconImport(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	static HWND hwndParent, hwndDragOver;
	static int dragging;
	static int dragItem, dropHiLite;
	static HWND hPreview = NULL;

	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		hwndParent = (HWND)lParam;
		hPreview = GetDlgItem(hwndDlg, IDC_PREVIEW);
		dragging = dragItem = 0;
		ListView_SetImageList(hPreview, ImageList_Create(GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), ILC_COLOR32|ILC_MASK, 0, 100), LVSIL_NORMAL);
		ListView_SetIconSpacing(hPreview, 56, 67);
		{
			RECT rcThis, rcParent;
			int cxScreen = GetSystemMetrics(SM_CXSCREEN);

			GetWindowRect(hwndDlg, &rcThis);
			GetWindowRect(hwndParent, &rcParent);
			OffsetRect(&rcThis, rcParent.right-rcThis.left, 0);
			OffsetRect(&rcThis, 0, rcParent.top-rcThis.top);
			GetWindowRect(GetParent(hwndParent), &rcParent);
			if (rcThis.right > cxScreen) {
				OffsetRect(&rcParent, cxScreen-rcThis.right, 0);
				OffsetRect(&rcThis, cxScreen-rcThis.right, 0);
				MoveWindow(GetParent(hwndParent), rcParent.left, rcParent.top, rcParent.right-rcParent.left, rcParent.bottom-rcParent.top, TRUE);
			}
			MoveWindow(hwndDlg, rcThis.left, rcThis.top, rcThis.right-rcThis.left, rcThis.bottom-rcThis.top, FALSE);
			GetClientRect(hwndDlg, &rcThis);
			SendMessage(hwndDlg, WM_SIZE, 0, MAKELPARAM(rcThis.right-rcThis.left, rcThis.bottom-rcThis.top));
		}

		SHAutoComplete( GetDlgItem(hwndDlg, IDC_ICONSET), 1);

		SetDlgItemText(hwndDlg, IDC_ICONSET, _T("icons.dll"));
		return TRUE;

	case DM_REBUILDICONSPREVIEW:
		{
			MySetCursor(IDC_WAIT);
			ListView_DeleteAllItems(hPreview);
			HIMAGELIST hIml = ListView_GetImageList(hPreview, LVSIL_NORMAL);
			ImageList_RemoveAll(hIml);

			TCHAR filename[MAX_PATH], caption[64];
			GetDlgItemText(hwndDlg, IDC_ICONSET, filename, SIZEOF(filename));
			{
				RECT rcPreview, rcGroup;

				GetWindowRect(hPreview, &rcPreview);
				GetWindowRect( GetDlgItem(hwndDlg, IDC_IMPORTMULTI), &rcGroup);
				//SetWindowPos(hPreview, 0, 0, 0, rcPreview.right-rcPreview.left, rcGroup.bottom-rcPreview.top, SWP_NOZORDER|SWP_NOMOVE);
			}

			if ( _taccess(filename, 0) != 0) {
				MySetCursor(IDC_ARROW);
				break;
			}

			LVITEM lvi;
			lvi.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
			lvi.iSubItem = 0;
			lvi.iItem = 0;
			int count = (int)_ExtractIconEx(filename, -1, 16, 16, NULL, LR_DEFAULTCOLOR);
			for (int i=0; i < count; lvi.iItem++, i++) {
				mir_sntprintf(caption, SIZEOF(caption), _T("%d"), i+1);
				lvi.pszText = caption;

				HICON hIcon;
				_ExtractIconEx(filename, i, 16, 16, &hIcon, LR_DEFAULTCOLOR);
				lvi.iImage = ImageList_AddIcon(hIml, hIcon);
				DestroyIcon(hIcon);
				lvi.lParam = i;
				ListView_InsertItem(hPreview, &lvi);
			}
			MySetCursor(IDC_ARROW);
		}
		break;

	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case IDC_BROWSE:
			{
				TCHAR str[MAX_PATH], *file;
				GetDlgItemText(hwndDlg, IDC_ICONSET, str, SIZEOF(str));
				if (!(file = OpenFileDlg(GetParent(hwndDlg), str, TRUE)))
					break;
				SetDlgItemText(hwndDlg, IDC_ICONSET, file);
				SAFE_FREE((void**)&file);
			}
			break;

		case IDC_GETMORE:
			OpenIconsPage();
			break;

		case IDC_ICONSET:
			if (HIWORD(wParam) == EN_CHANGE)
				SendMessage(hwndDlg, DM_REBUILDICONSPREVIEW, 0, 0);
			break;
		}
		break;

	case WM_MOUSEMOVE:
		if (dragging) {
			LVHITTESTINFO lvhti;
			int onItem = 0;
			HWND hwndOver;
			RECT rc;
			POINT ptDrag;
			HWND hPPreview = GetDlgItem(hwndParent, IDC_PREVIEW);

			lvhti.pt.x = (short)LOWORD(lParam); lvhti.pt.y = (short)HIWORD(lParam);
			ClientToScreen(hwndDlg, &lvhti.pt);
			hwndOver = WindowFromPoint(lvhti.pt);
			GetWindowRect(hwndOver, &rc);
			ptDrag.x = lvhti.pt.x - rc.left; ptDrag.y = lvhti.pt.y - rc.top;
			if (hwndOver != hwndDragOver) {
				ImageList_DragLeave(hwndDragOver);
				hwndDragOver = hwndOver;
				ImageList_DragEnter(hwndDragOver, ptDrag.x, ptDrag.y);
			}

			ImageList_DragMove(ptDrag.x, ptDrag.y);
			if (hwndOver == hPPreview) {
				ScreenToClient(hPPreview, &lvhti.pt);

				if (ListView_HitTest(hPPreview, &lvhti) != -1) {
					if (lvhti.iItem != dropHiLite) {
						ImageList_DragLeave(hwndDragOver);
						if (dropHiLite != -1)
							ListView_SetItemState(hPPreview, dropHiLite, 0, LVIS_DROPHILITED);
						dropHiLite = lvhti.iItem;
						ListView_SetItemState(hPPreview, dropHiLite, LVIS_DROPHILITED, LVIS_DROPHILITED);
						UpdateWindow(hPPreview);
						ImageList_DragEnter(hwndDragOver, ptDrag.x, ptDrag.y);
					}
					onItem = 1;
				}
			}

			if (!onItem && dropHiLite != -1) {
				ImageList_DragLeave(hwndDragOver);
				ListView_SetItemState(hPPreview, dropHiLite, 0, LVIS_DROPHILITED);
				UpdateWindow(hPPreview);
				ImageList_DragEnter(hwndDragOver, ptDrag.x, ptDrag.y);
				dropHiLite = -1;
			}
			MySetCursor(onItem ? IDC_ARROW : IDC_NO);
		}
		break;

	case WM_LBUTTONUP:
		if (dragging) {
			ReleaseCapture();
			ImageList_EndDrag();
			dragging = 0;
			if (dropHiLite != -1) {
				TCHAR path[MAX_PATH], fullPath[MAX_PATH], filename[MAX_PATH];
				LVITEM lvi;

				GetDlgItemText(hwndDlg, IDC_ICONSET, fullPath, SIZEOF(fullPath));
				PathToRelativeT(fullPath, filename);
				lvi.mask = LVIF_PARAM;
				lvi.iItem = dragItem; lvi.iSubItem = 0;
				ListView_GetItem(hPreview, &lvi);
				mir_sntprintf(path, SIZEOF(path), _T("%s,%d"), filename, (int)lvi.lParam);
				SendMessage(hwndParent, DM_CHANGEICON, dropHiLite, (LPARAM)path);
				ListView_SetItemState( GetDlgItem(hwndParent, IDC_PREVIEW), dropHiLite, 0, LVIS_DROPHILITED);
			}
		}
		break;

	case WM_NOTIFY:
		switch (((LPNMHDR)lParam)->idFrom) {
		case IDC_PREVIEW:
			switch (((LPNMHDR)lParam)->code) {
			case LVN_BEGINDRAG:
				SetCapture(hwndDlg);
				dragging = 1;
				dragItem = ((LPNMLISTVIEW)lParam)->iItem;
				dropHiLite = -1;
				ImageList_BeginDrag(ListView_GetImageList(hPreview, LVSIL_NORMAL), dragItem, GetSystemMetrics(SM_CXICON)/2, GetSystemMetrics(SM_CYICON)/2);
				{
					POINT pt;
					RECT rc;

					GetCursorPos(&pt);
					GetWindowRect(hwndDlg, &rc);
					ImageList_DragEnter(hwndDlg, pt.x - rc.left, pt.y - rc.top);
					hwndDragOver = hwndDlg;
				}
				break;
			}
			break;
		}
		break;

	case WM_SIZE: // make the dlg resizeable
		if (!IsIconic(hwndDlg)) {
			UTILRESIZEDIALOG urd = {0};
			urd.cbSize = sizeof(urd);
			urd.hInstance = hInst;
			urd.hwndDlg = hwndDlg;
			urd.lParam = 0; // user-defined
			urd.lpTemplate = MAKEINTRESOURCEA(IDD_ICOLIB_IMPORT);
			urd.pfnResizer = IconDlg_Resize;
			CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);
		}
		break;

	case WM_CLOSE:
		DestroyWindow(hwndDlg);
		EnableWindow( GetDlgItem(hwndParent, IDC_IMPORT), TRUE);
		break;

	}

	return FALSE;
}
Beispiel #12
0
/**************************************************************************************************
	This function handles mouse events.
**************************************************************************************************/
void CGroup::HandleMouseEvent(UINT uEvent, UINT msg, WPARAM wParam, LPARAM lParam)
{
	if (m_bExplorerDesktop)
	{
		CallWindowProc(m_wpOrigListViewProc, m_hwndListView, msg, wParam, lParam);
		return;
	}

	if (msg == WM_LBUTTONDOWN || msg == WM_RBUTTONDOWN || msg == WM_LBUTTONDBLCLK)
	{
		LVHITTESTINFO lvhi = {0};
		lvhi.flags = LVHT_ONITEM;
		lvhi.pt.x = GET_X_LPARAM(lParam);
		lvhi.pt.y = GET_Y_LPARAM(lParam);

		if ( ListView_HitTest(m_hwndListView, &lvhi) != -1 )
		{
			CallWindowProc(m_wpOrigListViewProc, m_hwndListView, msg, wParam, lParam);
			if (msg == WM_LBUTTONDOWN && m_bSingleClick)
				SendMessage(m_hwndListView, WM_LBUTTONDBLCLK, wParam, lParam);
			return; // An icon was clicked.
		}
	}

	if (m_bStealFocus)
		SetFocus(m_hwndListView);

	if (_stricmp(m_szEventCommand[uEvent], EVENT_ACTION_CHANGEDIR) == 0)
	{
		// We can override HandleEvent actions like this ;)
		LVHITTESTINFO lvhi = {0};
		lvhi.flags = LVHT_ONITEM;
		lvhi.pt.x = GET_X_LPARAM(lParam);
		lvhi.pt.y = GET_Y_LPARAM(lParam);

		if (msg == WM_MOUSEWHEEL || msg == WM_MOUSEHWHEEL)
		{
			MapWindowPoints(HWND_DESKTOP, m_hwndListView, &lvhi.pt, 1);
		}

		int nFileid = ListView_HitTest(m_hwndListView, &lvhi);
		if ( nFileid != -1 )
		{
			char szFileName[MAX_PATH];
			if (GetNameFromId(nFileid, szFileName, sizeof(szFileName)))
			{
				if (utils::Is_Directory(szFileName))
				{
					if (!m_bNoVirtualSwitch && (_stricmp(szFileName, m_szDesktopPath) == 0))
					{
						ChangeDir(".desktop");
					}
					else
					{
						ChangeDir(szFileName);
					}
					return;
				}
			}
		}
	}

	// We just need to handle the mouse specific events and then forward the event to HandleEvent
	if (_stricmp(m_szEventCommand[uEvent], EVENT_ACTION_RECTANGLE) == 0)
	{
		if (CheckModkeys(m_wSelectionRectangleMod))
		{
			CallWindowProc(m_wpOrigListViewProc, m_hwndListView, WM_LBUTTONDOWN, wParam, lParam);
		}
		else
		{
			relayMouseMessage(msg, wParam, lParam);
		}
	}
	else if (_stricmp(m_szEventCommand[uEvent], EVENT_ACTION_SYSTEMMENU) == 0)
	{
		if (CheckModkeys(m_wSystemMenuMod))
		{
			CallWindowProc(m_wpOrigListViewProc, m_hwndListView, WM_RBUTTONDOWN, wParam, lParam);
		}
		else
		{
			relayMouseMessage(msg, wParam, lParam);
		}
	}
	else if (_stricmp(m_szEventCommand[uEvent], EVENT_ACTION_FORWARD) == 0)
	{
		relayMouseMessage(msg, wParam, lParam);
	}
	else
	{
		HandleEvent(uEvent);
	}
}
void NListView::ListView_HandleInsertionMark(HWND hListView,int iItemFocus,POINT *ppt)
{
	/* Remove the insertion mark. */
	if(ppt == NULL)
	{
		LVINSERTMARK lvim;
		lvim.cbSize		= sizeof(LVINSERTMARK);
		lvim.dwFlags	= 0;
		lvim.iItem		= -1;
		ListView_SetInsertMark(hListView,&lvim);

		return;
	}

	RECT ItemRect;
	DWORD dwFlags = 0;
	int iNext;

	LV_HITTESTINFO item;
	item.pt = *ppt;

	int iItem = ListView_HitTest(hListView,&item);

	if(iItem != -1 && item.flags & LVHT_ONITEM)
	{
		ListView_GetItemRect(hListView,item.iItem,&ItemRect,LVIR_BOUNDS);

		/* If the cursor is on the left side
		of this item, set the insertion before
		this item; if it is on the right side
		of this item, set the insertion mark
		after this item. */
		if((ppt->x - ItemRect.left) >
			((ItemRect.right - ItemRect.left)/2))
		{
			iNext = iItem;
			dwFlags = LVIM_AFTER;
		}
		else
		{
			iNext = iItem;
			dwFlags = 0;
		}
	}
	else
	{
		dwFlags = 0;

		/* VK_UP finds whichever item is "above" the cursor.
		This item may be in the same row as the cursor is in
		(e.g. an item in the next row won't be found until the
		cursor passes into that row). Appears to find the item
		on the right side. */
		LVFINDINFO lvfi;
		lvfi.flags			= LVFI_NEARESTXY;
		lvfi.pt				= *ppt;
		lvfi.vkDirection	= VK_UP;
		iNext = ListView_FindItem(hListView,-1,&lvfi);

		if(iNext == -1)
		{
			lvfi.flags			= LVFI_NEARESTXY;
			lvfi.pt				= *ppt;
			lvfi.vkDirection	= VK_LEFT;
			iNext = ListView_FindItem(hListView,-1,&lvfi);
		}

		ListView_GetItemRect(hListView,iNext,&ItemRect,LVIR_BOUNDS);

		/* This situation only occurs at the
		end of the row. Prior to this, it is
		always the item on the right side that
		is found, with the insertion mark been
		inserted before that item.
		Once the end of the row is reached, the
		item found will be on the left side of
		the cursor. */
		if(ppt->x > ItemRect.left +
			((ItemRect.right - ItemRect.left)/2))
		{
			/* At the end of a row, VK_UP appears to
			find the next item up. Therefore, if we're
			at the end of a row, and the cursor is
			completely below the "next" item, find the
			one under it instead (if there is an item
			under it), and anchor the insertion mark
			there. */
			if(ppt->y > ItemRect.bottom)
			{
				int iBelow;

				iBelow = ListView_GetNextItem(hListView,iNext,LVNI_BELOW);

				if(iBelow != -1)
					iNext = iBelow;
			}

			dwFlags = LVIM_AFTER;
		}

		int nItems = ListView_GetItemCount(hListView);

		/* Last item is at position nItems - 1. */
		ListView_GetItemRect(hListView,nItems - 1,&ItemRect,LVIR_BOUNDS);

		/* Special case needed for very last item. If cursor is within 0.5 to 1.5 width
		of last item, and is greater than it's y coordinate, snap the insertion mark to
		this item. */
		if((ppt->x > ItemRect.left + ((ItemRect.right - ItemRect.left)/2)) &&
			ppt->x < ItemRect.right + ((ItemRect.right - ItemRect.left)/2) + 2 &&
			ppt->y > ItemRect.top)
		{
			iNext = nItems - 1;
			dwFlags = LVIM_AFTER;
		}
	}

	LVINSERTMARK lvim;
	lvim.cbSize			= sizeof(LVINSERTMARK);
	lvim.dwFlags		= dwFlags;
	lvim.iItem			= iNext;
	ListView_SetInsertMark(hListView,&lvim);
}
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	LPNMHDR lpnmhdr;
	LPNMITEMACTIVATE lpnmitem;
	LVITEM lvItem;
	LVHITTESTINFO lvHti;
	HMENU hMenu;
	POINT pt;
	OPENFILENAME ofn;
	char szFile[MAX_PATH], szSize[15], *szDir = "", szBound[_MAX_FNAME] = "bound";
	HANDLE hFile;
	DWORD dwSize;

	switch(uMsg) {
	case WM_INITDIALOG:
		SendMessage(hwndDlg, WM_SETICON, (WPARAM)1, (LPARAM)LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON)));

		hwndList = GetDlgItem(hwndDlg, IDC_LIST);

		ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | LVS_EX_GRIDLINES);
		InitList();

		return TRUE;
	case WM_NOTIFY:
		lpnmhdr = (LPNMHDR)lParam;
		if(lpnmhdr->hwndFrom == hwndList) {
			if(lpnmhdr->code == NM_RCLICK) {
				lpnmitem = (LPNMITEMACTIVATE)lParam;
				hMenu = CreatePopupMenu();

				ZeroMemory(&lvHti, sizeof(LVHITTESTINFO));

				lvHti.pt = lpnmitem->ptAction;
				iSelect = ListView_HitTest(hwndList, &lvHti);

				if(lvHti.flags & LVHT_ONITEM) {
					AppendMenu(hMenu, MF_GRAYED | MF_STRING, IDM_ADD, "Add");
					AppendMenu(hMenu, MF_STRING, IDM_REMOVE, "Remove");
				}
				else {
					AppendMenu(hMenu, MF_STRING, IDM_ADD, "Add");
					AppendMenu(hMenu, MF_GRAYED | MF_STRING, IDM_REMOVE, "Remove");
				}

				AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);

				if(iIndex < 2)
					AppendMenu(hMenu, MF_GRAYED | MF_STRING, IDM_BIND, "Bind");
				else
					AppendMenu(hMenu, MF_STRING, IDM_BIND, "Bind");

				GetCursorPos(&pt);
				TrackPopupMenu(hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hwndDlg, 0);
			}
		}
		DestroyMenu(hMenu);

		return TRUE;
	case WM_COMMAND:
		switch(LOWORD(wParam)) {
		case IDM_ADD:
			ZeroMemory(&ofn, sizeof(OPENFILENAME));
			ZeroMemory(szFile, sizeof szFile);
			ZeroMemory(szDir, sizeof szDir);

			ofn.lStructSize = sizeof(OPENFILENAME);
			ofn.hwndOwner = hwndDlg;
			ofn.lpstrFilter = "All Files (*.*)\0*.*\0";
			ofn.lpstrFile = szFile;
			ofn.nMaxFile = MAX_PATH;
			ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;

			if(GetOpenFileName(&ofn)) {
				cancel = FALSE;

				DialogBox(hInst, MAKEINTRESOURCE(IDD_DIALOG_ADD), hwndDlg, AddDialogProc);

				if(!cancel) {
					lvItem.mask = LVIF_TEXT;
					lvItem.cchTextMax = MAX_PATH;

					lvItem.iItem = iIndex;
					lvItem.iSubItem = 0;
					lvItem.pszText = szFile;

					ListView_InsertItem(hwndList, &lvItem);

					hFile = CreateFile(szFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

					if(hFile == INVALID_HANDLE_VALUE)
						return FALSE;
					
					dwSize = GetFileSize(hFile, NULL);

					CloseHandle(hFile);
					wsprintf(szSize, "%d KB", dwSize / 1024);

					lvItem.iItem = iIndex;
					lvItem.iSubItem = 1;
					lvItem.pszText = szSize;

					ListView_SetItem(hwndList, &lvItem);

					lvItem.iItem = iIndex;
					lvItem.iSubItem = 2;

					if(windir == BST_CHECKED)
						szDir = "Windows";
					else if(sysdir == BST_CHECKED)
						szDir = "System";
					else
						szDir = "Temporary";

					lvItem.pszText = szDir;

					ListView_SetItem(hwndList, &lvItem);

					lvItem.iItem = iIndex;
					lvItem.iSubItem = 3;
				
					if(run == BST_CHECKED)
						lvItem.pszText = "Yes";
					else
						lvItem.pszText = "No";

					ListView_SetItem(hwndList, &lvItem);

					iIndex++;
				}
			}

			return TRUE;
		case IDM_REMOVE:
			ListView_DeleteItem(hwndList, iSelect);

			iIndex--;

			return TRUE;
		case IDM_BIND:
			ZeroMemory(&ofn, sizeof(OPENFILENAME));

			ofn.lStructSize = sizeof(OPENFILENAME);
			ofn.hwndOwner = hwndDlg;
			ofn.lpstrFilter = "Application (*.exe)\0*.exe\0";
			ofn.lpstrFile = szBound;
			ofn.lpstrDefExt = "exe";
			ofn.nMaxFile = MAX_PATH;
			ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;

			if(GetSaveFileName(&ofn)) {
				if(!ExtractLoader(szBound))
					return FALSE;

				if(!WriteFiles(iIndex)) {
					MessageBox(hwndDlg, "Error writing files.", NULL, MB_OK);

					CloseHandle(hLoader);

					return FALSE;
				}
			}

			return TRUE;
		}
	case WM_CLOSE:
		EndDialog(hwndDlg, 0);

		return TRUE;
	}

	return FALSE;
}