Ejemplo n.º 1
0
BOOL CALLBACK dialog_proc_1(HWND dialog, UINT message,
							WPARAM wParam, LPARAM lParam)
{
	static HDEVNOTIFY notification_handle_hub = NULL;
	static HDEVNOTIFY notification_handle_dev = NULL;
	DEV_BROADCAST_HDR *hdr = (DEV_BROADCAST_HDR *) lParam;
	DEV_BROADCAST_DEVICEINTERFACE dev_if;
	static device_context_t *device = NULL;
	HWND list = GetDlgItem(dialog, ID_LIST);
	LVITEM item;

	switch (message)
	{
	case WM_INITDIALOG:
		SendMessage(dialog,WM_SETICON,ICON_SMALL, (LPARAM)mIcon);
		SendMessage(dialog,WM_SETICON,ICON_BIG,   (LPARAM)mIcon);

		device = (device_context_t *)lParam;
		if (device->user_allocated_wdi)
		{
			if (device->wdi)
			{
				free(device->wdi);
				device->wdi = NULL;
			}
			device->user_allocated_wdi = FALSE;
		}
		g_hwndTrackingTT = CreateTrackingToolTip(list, TEXT(" "));

#if defined(_WIN64)
		device_list_wndproc_orig = (WNDPROC)SetWindowLongPtr(list, GWLP_WNDPROC, (UINT_PTR)device_list_wndproc);
#else
		device_list_wndproc_orig = (WNDPROC)SetWindowLongPtr(list, GWL_WNDPROC, (UINT_PTR)device_list_wndproc);
#endif

		memset(device, 0, sizeof(*device));

		SetWindowText(GetDlgItem(dialog, ID_LIST_HEADER_TEXT), list_header_text);
		device_list_init(list);
		device_list_refresh(list);

		dev_if.dbcc_size = sizeof(dev_if);
		dev_if.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;

		dev_if.dbcc_classguid = GUID_DEVINTERFACE_USB_HUB;
		notification_handle_hub = RegisterDeviceNotification(dialog, &dev_if, 0);

		dev_if.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
		notification_handle_dev = RegisterDeviceNotification(dialog, &dev_if, 0);

		return TRUE;

	case WM_DEVICECHANGE:
		switch (wParam)
		{
		case DBT_DEVICEREMOVECOMPLETE:
			if (hdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
				device_list_refresh(list);
			break;
		case DBT_DEVICEARRIVAL:
			if (hdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
				device_list_refresh(list);
			break;
		default:
			;
		}
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case ID_BUTTON_NEXT:
			if (notification_handle_hub)
				UnregisterDeviceNotification(notification_handle_hub);
			if (notification_handle_dev)
				UnregisterDeviceNotification(notification_handle_dev);

			memset(&item, 0, sizeof(item));
			item.mask = LVIF_TEXT | LVIF_PARAM;
			item.iItem = ListView_GetNextItem(list, -1, LVNI_SELECTED);

			memset(device, 0, sizeof(*device));

			if (item.iItem >= 0)
			{
				if (ListView_GetItem(list, &item))
				{
					if (item.lParam)
					{
						memcpy(device, (void *)item.lParam, sizeof(*device));
					}
				}
			}

			if (!device->wdi)
			{
				device->user_allocated_wdi = TRUE;
				device->wdi = malloc(sizeof(struct wdi_device_info));
				memset(device->wdi,0,sizeof(struct wdi_device_info));

				device->wdi->vid = 0x12AB;
				device->wdi->pid = 0x12AB;
			}

			if (!device->manufacturer[0])
				strcpy(device->manufacturer, "Insert manufacturer name");
			if (!device->description[0])
				strcpy(device->description,  "Insert device description");

			device_list_clean(list);

			EndDialog(dialog, ID_DIALOG_2);
			return TRUE;

		case ID_BUTTON_BACK:
			device_list_clean(list);
			if (notification_handle_hub)
				UnregisterDeviceNotification(notification_handle_hub);
			if (notification_handle_dev)
				UnregisterDeviceNotification(notification_handle_dev);
			EndDialog(dialog, ID_DIALOG_0);
			return TRUE ;

		case ID_BUTTON_CANCEL:
		case IDCANCEL:
			device_list_clean(list);
			if (notification_handle_hub)
				UnregisterDeviceNotification(notification_handle_hub);
			if (notification_handle_dev)
				UnregisterDeviceNotification(notification_handle_dev);
			EndDialog(dialog, 0);
			return TRUE ;
		}
	}

	return FALSE;
}
Ejemplo n.º 2
0
INT_PTR CALLBACK DlgPluginOpt(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		timerID = 0;
		{
			HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);
			mir_subclassWindow(hwndList, PluginListWndProc);

			HIMAGELIST hIml = ImageList_Create(16, 16, ILC_MASK | ILC_COLOR32, 4, 0);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_UNICODE);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_ANSI);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_LOADED);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_NOTLOADED);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_LOADEDGRAY);
			ImageList_AddIcon_IconLibLoaded(hIml, SKINICON_OTHER_NOTLOADEDGRAY);
			ListView_SetImageList(hwndList, hIml, LVSIL_SMALL);

			LVCOLUMN col;
			col.mask = LVCF_TEXT | LVCF_WIDTH;
			col.pszText = _T("");
			col.cx = 40;
			ListView_InsertColumn(hwndList, 0, &col);

			col.pszText = TranslateT("Plugin");
			col.cx = 180;
			ListView_InsertColumn(hwndList, 1, &col);

			col.pszText = TranslateT("Name");
			col.cx = 180;//max = 220;
			ListView_InsertColumn(hwndList, 2, &col);

			col.pszText = TranslateT("Version");
			col.cx = 75;
			ListView_InsertColumn(hwndList, 3, &col);

			ListView_SetExtendedListViewStyleEx(hwndList, 0, LVS_EX_SUBITEMIMAGES | LVS_EX_CHECKBOXES | LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT);
			// scan the plugin dir for plugins, cos
			arPluginList.destroy();
			szFilter.Empty();
			enumPlugins(dialogListPlugins, (WPARAM)hwndDlg, (LPARAM)hwndList);
			// sort out the headers

			ListView_SetColumnWidth(hwndList, 1, LVSCW_AUTOSIZE); // dll name
			int w = ListView_GetColumnWidth(hwndList, 1);
			if (w > 110) {
				ListView_SetColumnWidth(hwndList, 1, w = 110);
			}
			int max = w < 110 ? 189 + 110 - w : 189;
			ListView_SetColumnWidth(hwndList, 3, LVSCW_AUTOSIZE); // short name
			w = ListView_GetColumnWidth(hwndList, 2);
			if (w > max)
				ListView_SetColumnWidth(hwndList, 2, max);

			ListView_SortItems(hwndList, SortPlugins, (LPARAM)hwndDlg);
		}
		return TRUE;

	case WM_NOTIFY:
		if (lParam) {
			NMLISTVIEW *hdr = (NMLISTVIEW *)lParam;
			if (hdr->hdr.code == LVN_ITEMCHANGED && IsWindowVisible(hdr->hdr.hwndFrom)) {
				if (hdr->uOldState != 0 && (hdr->uNewState == 0x1000 || hdr->uNewState == 0x2000)) {
					HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);

					LVITEM it;
					it.mask = LVIF_PARAM | LVIF_STATE;
					it.iItem = hdr->iItem;
					if (!ListView_GetItem(hwndList, &it))
						break;

					PluginListItemData *dat = (PluginListItemData*)it.lParam;
					if (dat->flags & STATIC_PLUGIN) {
						ListView_SetItemState(hwndList, hdr->iItem, 0x3000, LVIS_STATEIMAGEMASK);
						return FALSE;
					}
					// find all another standard plugins by mask and disable them
					if ((hdr->uNewState == 0x2000) && dat->stdPlugin != 0) {
						for (int iRow = 0; iRow != -1; iRow = ListView_GetNextItem(hwndList, iRow, LVNI_ALL)) {
							if (iRow != hdr->iItem) { // skip the plugin we're standing on
								LVITEM dt;
								dt.mask = LVIF_PARAM;
								dt.iItem = iRow;
								if (ListView_GetItem(hwndList, &dt)) {
									PluginListItemData *dat2 = (PluginListItemData*)dt.lParam;
									if (dat2->stdPlugin & dat->stdPlugin) {// mask differs
										// the lParam is unset, so when the check is unset the clist block doesnt trigger
										int iSave = dat2->stdPlugin;
										dat2->stdPlugin = 0;
										ListView_SetItemState(hwndList, iRow, 0x1000, LVIS_STATEIMAGEMASK);
										dat2->stdPlugin = iSave;
									}
								}
							}
						}
					}

					if (bOldMode)
						ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), TRUE); // this here only in "ghazan mode"
					SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
					break;
				}

				if (hdr->iItem != -1) {
					int sel = hdr->uNewState & LVIS_SELECTED;
					HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);
					LVITEM lvi = { 0 };
					lvi.mask = LVIF_PARAM;
					lvi.iItem = hdr->iItem;
					if (ListView_GetItem(hwndList, &lvi)) {
						PluginListItemData *dat = (PluginListItemData*)lvi.lParam;

						TCHAR buf[1024];
						ListView_GetItemText(hwndList, hdr->iItem, 2, buf, _countof(buf));
						SetDlgItemText(hwndDlg, IDC_PLUGININFOFRAME, sel ? buf : _T(""));

						ptrT tszAuthor(latin2t(sel ? dat->author : NULL));
						SetDlgItemText(hwndDlg, IDC_PLUGINAUTHOR, tszAuthor);

						ptrT tszEmail(latin2t(sel ? dat->authorEmail : NULL));
						SetDlgItemText(hwndDlg, IDC_PLUGINEMAIL, tszEmail);

						ptrT p(Langpack_PcharToTchar(dat->description));
						SetDlgItemText(hwndDlg, IDC_PLUGINLONGINFO, sel ? p : _T(""));

						ptrT tszCopyright(latin2t(sel ? dat->copyright : NULL));
						SetDlgItemText(hwndDlg, IDC_PLUGINCPYR, tszCopyright);

						ptrT tszUrl(latin2t(sel ? dat->homepage : NULL));
						SetDlgItemText(hwndDlg, IDC_PLUGINURL, tszUrl);

						if (!equalUUID(miid_last, dat->uuid)) {
							char szUID[128];
							uuidToString(dat->uuid, szUID, sizeof(szUID));
							SetDlgItemTextA(hwndDlg, IDC_PLUGINPID, sel ? szUID : "");
						}
						else SetDlgItemText(hwndDlg, IDC_PLUGINPID, sel ? TranslateT("<none>") : _T(""));
					}
				}
			}

			if (hdr->hdr.code == PSN_APPLY) {
				bool needRestart = false;
				TCHAR bufRestart[1024];
				int bufLen = mir_sntprintf(bufRestart, _T("%s\n"), TranslateT("Miranda NG must be restarted to apply changes for these plugins:"));

				HWND hwndList = GetDlgItem(hwndDlg, IDC_PLUGLIST);
				for (int iRow = 0; iRow != -1;) {
					TCHAR buf[1024];
					ListView_GetItemText(hwndList, iRow, 1, buf, _countof(buf));
					int iState = ListView_GetItemState(hwndList, iRow, LVIS_STATEIMAGEMASK);
					SetPluginOnWhiteList(buf, (iState & 0x2000) ? 1 : 0);

					if (!bOldMode && iState != 0x3000) {
						LVITEM lvi = { 0 };
						lvi.mask = LVIF_IMAGE | LVIF_PARAM;
						lvi.stateMask = -1;
						lvi.iItem = iRow;
						lvi.iSubItem = 0;
						if (ListView_GetItem(hwndList, &lvi)) {
							lvi.mask = LVIF_IMAGE;

							PluginListItemData *dat = (PluginListItemData*)lvi.lParam;
							if (iState == 0x2000) {
								// enabling plugin
								if (lvi.iImage == 3 || lvi.iImage == 5) {
									if (lvi.iImage == 3 && LoadPluginDynamically(dat)) {
										lvi.iImage = 2;
										ListView_SetItem(hwndList, &lvi);
									}
									else {
										bufLen += mir_sntprintf(bufRestart + bufLen, _countof(bufRestart) - bufLen, _T(" - %s\n"), buf);
										needRestart = true;
									}
								}
							}
							else {
								// disabling plugin
								if (lvi.iImage == 2 || lvi.iImage == 4) {
									if (lvi.iImage == 2 && UnloadPluginDynamically(dat)) {
										lvi.iImage = 3;
										ListView_SetItem(hwndList, &lvi);
									}
									else {
										bufLen += mir_sntprintf(bufRestart + bufLen, _countof(bufRestart) - bufLen, _T(" - %s\n"), buf);
										needRestart = true;
									}
								}
							}
						}
					}

					iRow = ListView_GetNextItem(hwndList, iRow, LVNI_ALL);
				}
				LoadStdPlugins();

				ShowWindow(GetDlgItem(hwndDlg, IDC_RESTART), needRestart);
				if (needRestart) {
					mir_sntprintf(bufRestart + bufLen, _countof(bufRestart) - bufLen, _T("\n%s"), TranslateT("Do you want to restart it now?"));
					if (MessageBox(NULL, bufRestart, _T("Miranda NG"), MB_ICONWARNING | MB_YESNO) == IDYES)
						CallService(MS_SYSTEM_RESTART, 1, 0);
				}
			}
		}
		break;

	case WM_COMMAND:
		if (HIWORD(wParam) == STN_CLICKED) {
			switch (LOWORD(wParam)) {
			case IDC_GETMOREPLUGINS:
				Utils_OpenUrl("http://miranda-ng.org/downloads/");
				break;

			case IDC_PLUGINEMAIL:
			case IDC_PLUGINURL:
				char buf[512];
				char *p = &buf[7];
				mir_strcpy(buf, "mailto:");
				if (GetDlgItemTextA(hwndDlg, LOWORD(wParam), p, _countof(buf) - 7))
					Utils_OpenUrl(LOWORD(wParam) == IDC_PLUGINEMAIL ? buf : p);
				break;
			}
		}
		break;

	case WM_DESTROY:
		arPluginList.destroy();
		RemoveAllItems(GetDlgItem(hwndDlg, IDC_PLUGLIST));
		break;
	}
	return FALSE;
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------
// Name: SampleDlgProc()
// Desc: Handles dialog messages
//-----------------------------------------------------------------------------
INT_PTR CALLBACK SampleDlgProc( HWND hDlg, UINT msg, 
                                WPARAM wParam, LPARAM lParam )
{
    switch( msg ) 
    {
        case WM_INITDIALOG:
        {
            OnInitDialog( hDlg );
            break;
        }

        case WM_APP_DISPLAY_PLAYERS:
        {
            DisplayPlayersInChat( hDlg );
            break;
        }

        case WM_TIMER:
        {
            DWORD            dwNumPlayers;
            DWORD            iIndex;
            LVITEM           lvItem;
            APP_PLAYER_INFO* pPlayerInfo = NULL;
            HWND             hListView = GetDlgItem( hDlg, IDC_PEOPLE_LIST );

            dwNumPlayers = ListView_GetItemCount( hListView );

            // Now that they are added and the listview sorted them by name,
            // run through them all caching the listview index with its dpnid
            for( iIndex = 0; iIndex < dwNumPlayers; iIndex++ )
            {
                HRESULT hr;
                APP_PLAYER_INFO* pPlayerInfo = NULL;
                DPNID dpnidPlayer;

                lvItem.mask  = LVIF_PARAM;
                lvItem.iItem = iIndex;
                ListView_GetItem( hListView, &lvItem );

                dpnidPlayer = (DPNID) lvItem.lParam;

                PLAYER_LOCK(); // enter player context CS
                hr = GetPlayerStruct( dpnidPlayer, &pPlayerInfo );
                PLAYER_ADDREF( pPlayerInfo ); // addref player, since we are using it now
                PLAYER_UNLOCK(); // leave player context CS

                if( FAILED(hr) || pPlayerInfo == NULL )
                {
                    // The player who sent this may have gone away before this 
                    // message was handled, so just ignore it
                    continue;
                }

                TCHAR strStatus[255];

                if( pPlayerInfo->bHalfDuplex )
                {
                    _tcscpy( strStatus, TEXT("Can't talk") );
                }
                else
                {
                    if( g_bMixingSessionType )
                    {
                        // With mixing servers, you can't tell which
                        // client is talking.
                        _tcscpy( strStatus, TEXT("n/a") );
                    }
                    else
                    {
                        if( pPlayerInfo->bTalking )
                            _tcscpy( strStatus, TEXT("Talking") );
                        else
                            _tcscpy( strStatus, TEXT("Silent") );
                    }
                }

                lvItem.iItem      = iIndex;
                lvItem.iSubItem   = 1;
                lvItem.mask       = LVIF_TEXT;
                lvItem.pszText    = strStatus;

                PLAYER_LOCK();
                PLAYER_RELEASE( pPlayerInfo );  // Release player and cleanup if needed
                PLAYER_UNLOCK();

                SendMessage( hListView, LVM_SETITEM, 0, (LPARAM) &lvItem );
            }
            break;
        }

        case WM_COMMAND:
        {
            switch( LOWORD(wParam) )
            {
                case IDC_SETUP:
                    {
                        // Ask the user for DirectPlayVoice setup params
                        DWORD dwResult = (DWORD)DialogBox( g_hInst, 
                                                           MAKEINTRESOURCE(IDD_VOICE_SETUP), 
                                                           hDlg, (DLGPROC) VoiceConfigDlgProc );
                        if( dwResult != IDCANCEL )
                            g_pNetVoice->ChangeVoiceClientSettings( &g_dvClientConfig );
                    }
                    return TRUE;

                case IDCANCEL:
                    g_hrDialog = S_OK;
                    EndDialog( hDlg, 0 );
                    return TRUE;
            }
            break;
        }
    }

    return FALSE; // Didn't handle message
}
Ejemplo n.º 4
0
static INT_PTR CALLBACK JabberMucJidListDlgProc( HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam )
{
	JABBER_MUC_JIDLIST_INFO* dat = (JABBER_MUC_JIDLIST_INFO*)GetWindowLongPtr( hwndDlg, GWLP_USERDATA );

	switch( msg ) {
	case WM_INITDIALOG:
		{
			LVCOLUMN lvc;
			RECT rc;
			HWND hwndList;

			TranslateDialogDefault( hwndDlg );

			hwndList = GetDlgItem( hwndDlg, IDC_LIST );
			ListView_SetExtendedListViewStyle(hwndList, LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
			GetClientRect( hwndList, &rc );
			//rc.right -= GetSystemMetrics( SM_CXVSCROLL );
			lvc.mask = LVCF_WIDTH;
			lvc.cx = rc.right - 20;
			ListView_InsertColumn( hwndList, 0, &lvc );
			lvc.cx = 20;
			ListView_InsertColumn( hwndList, 1, &lvc );
			SendMessage( hwndDlg, WM_JABBER_REFRESH, 0, lParam );
			dat = (JABBER_MUC_JIDLIST_INFO*)lParam;

			static struct
			{
				int idc;
				char *title;
				char *icon;
				bool push;
			} buttons[] =
			{
				{IDC_BTN_FILTERAPPLY,	"Apply filter",		"sd_filter_apply",	false},
				{IDC_BTN_FILTERRESET,	"Reset filter",		"sd_filter_reset",	false},
			};
			for (int i = 0; i < SIZEOF(buttons); ++i)
			{
				SendDlgItemMessage(hwndDlg, buttons[i].idc, BM_SETIMAGE, IMAGE_ICON, (LPARAM)dat->ppro->LoadIconEx(buttons[i].icon));
				SendDlgItemMessage(hwndDlg, buttons[i].idc, BUTTONSETASFLATBTN, 0, 0);
				SendDlgItemMessage(hwndDlg, buttons[i].idc, BUTTONADDTOOLTIP, (WPARAM)buttons[i].title, 0);
				if (buttons[i].push)
					SendDlgItemMessage(hwndDlg, buttons[i].idc, BUTTONSETASPUSHBTN, 0, 0);
			}

			Utils_RestoreWindowPosition(hwndDlg, NULL, dat->ppro->m_szModuleName, "jidListWnd_");
		}
		return TRUE;
	case WM_SIZE:
		{
			UTILRESIZEDIALOG urd = {0};
			urd.cbSize = sizeof(urd);
			urd.hInstance = hInst;
			urd.hwndDlg = hwndDlg;
			urd.lpTemplate = MAKEINTRESOURCEA(IDD_JIDLIST);
			urd.pfnResizer = sttJidListResizer;
			CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd);

			RECT listrc;
			LVCOLUMN lvc;
			HWND hwndList = GetDlgItem( hwndDlg, IDC_LIST );
			GetClientRect( hwndList, &listrc );
			lvc.mask = LVCF_WIDTH;
			//listrc.right -= GetSystemMetrics( SM_CXVSCROLL );
			lvc.cx = listrc.right - 20;
			SendMessage(hwndList, LVM_SETCOLUMN, 0, (LPARAM)&lvc);
			break;
		}
		break;

	case WM_JABBER_REFRESH:
		{
			// lParam is ( JABBER_MUC_JIDLIST_INFO * )
			HXML iqNode, queryNode;
			const TCHAR* from;
			TCHAR title[256];

			// Clear current GWL_USERDATA, if any
			if ( dat != NULL )
				delete dat;

			// Set new GWL_USERDATA
			dat = ( JABBER_MUC_JIDLIST_INFO * ) lParam;
			SetWindowLongPtr( hwndDlg, GWLP_USERDATA, ( LONG_PTR ) dat );

			// Populate displayed list from iqNode
			lstrcpyn( title, TranslateT( "JID List" ), SIZEOF( title ));
			if (( dat=( JABBER_MUC_JIDLIST_INFO * ) lParam ) != NULL ) {
				if (( iqNode = dat->iqNode ) != NULL ) {
					if (( from = xmlGetAttrValue( iqNode, _T("from"))) != NULL ) {
						dat->roomJid = mir_tstrdup( from );

						if (( queryNode = xmlGetChild( iqNode , "query" )) != NULL ) {
							TCHAR* localFrom = mir_tstrdup( from );
							mir_sntprintf( title, SIZEOF( title ), TranslateT("%s, %d items (%s)"),
								( dat->type == MUC_VOICELIST ) ? TranslateT( "Voice List" ) :
								( dat->type == MUC_MEMBERLIST ) ? TranslateT( "Member List" ) :
								( dat->type == MUC_MODERATORLIST ) ? TranslateT( "Moderator List" ) :
								( dat->type == MUC_BANLIST ) ? TranslateT( "Ban List" ) :
								( dat->type == MUC_ADMINLIST ) ? TranslateT( "Admin List" ) :
								( dat->type == MUC_OWNERLIST ) ? TranslateT( "Owner List" ) :
								TranslateT( "JID List" ), xmlGetChildCount(queryNode), localFrom );
							mir_free( localFrom );
			}	}	}	}
			SetWindowText( hwndDlg, title );

			SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_FILTER), GWLP_USERDATA, 0);
			sttFillJidList(hwndDlg);
		}
		break;
	case WM_NOTIFY:
		if (( ( LPNMHDR )lParam )->idFrom == IDC_LIST ) {
			switch (( ( LPNMHDR )lParam )->code ) {
			case NM_CUSTOMDRAW:
				{
					NMLVCUSTOMDRAW *nm = ( NMLVCUSTOMDRAW * ) lParam;

					switch ( nm->nmcd.dwDrawStage ) {
					case CDDS_PREPAINT:
					case CDDS_ITEMPREPAINT:
						SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, CDRF_NOTIFYSUBITEMDRAW );
						return TRUE;
					case CDDS_SUBITEM|CDDS_ITEMPREPAINT:
						{
							RECT rc;
							HICON hIcon;

							ListView_GetSubItemRect( nm->nmcd.hdr.hwndFrom, nm->nmcd.dwItemSpec, nm->iSubItem, LVIR_LABEL, &rc );
							if ( nm->iSubItem == 1 ) {
								if( nm->nmcd.lItemlParam == ( LPARAM )( -1 ))
									hIcon = ( HICON )LoadImage( hInst, MAKEINTRESOURCE( IDI_ADDCONTACT ), IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ), 0 );
								else
									hIcon = ( HICON )LoadImage( hInst, MAKEINTRESOURCE( IDI_DELETE ), IMAGE_ICON, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ), 0 );
								DrawIconEx( nm->nmcd.hdc, ( rc.left+rc.right-GetSystemMetrics( SM_CXSMICON ))/2, ( rc.top+rc.bottom-GetSystemMetrics( SM_CYSMICON ))/2,hIcon, GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ), 0, GetSysColorBrush(COLOR_WINDOW), DI_NORMAL );
								DestroyIcon( hIcon );
								SetWindowLongPtr( hwndDlg, DWLP_MSGRESULT, CDRF_SKIPDEFAULT );
								return TRUE;
				}	}	}	}
				break;
			case NM_CLICK:
				{
					NMLISTVIEW *nm = ( NMLISTVIEW * ) lParam;
					LVITEM lvi;
					LVHITTESTINFO hti;
					TCHAR text[128];

					if ( nm->iSubItem < 1 )
						break;

					hti.pt.x = ( short ) LOWORD( GetMessagePos());
					hti.pt.y = ( short ) HIWORD( GetMessagePos());
					ScreenToClient( nm->hdr.hwndFrom, &hti.pt );
					if ( ListView_SubItemHitTest( nm->hdr.hwndFrom, &hti ) == -1 )
						break;

					if ( hti.iSubItem != 1 )
						break;

					lvi.mask = LVIF_PARAM | LVIF_TEXT;
					lvi.iItem = hti.iItem;
					lvi.iSubItem = 0;
					lvi.pszText = text;
					lvi.cchTextMax = sizeof( text );
					ListView_GetItem( nm->hdr.hwndFrom, &lvi );
					if ( lvi.lParam == ( LPARAM )( -1 )) {
						TCHAR szBuffer[ 1024 ];
						_tcscpy( szBuffer, dat->type2str());
						if ( !dat->ppro->EnterString(szBuffer, SIZEOF(szBuffer), NULL, JES_COMBO, "gcAddNick_"))
							break;

						// Trim leading and trailing whitespaces
						TCHAR *p = szBuffer, *q;
						for ( p = szBuffer; *p!='\0' && isspace( BYTE( *p )); p++);
						for ( q = p; *q!='\0' && !isspace( BYTE( *q )); q++);
						if (*q != '\0') *q = '\0';
						if (*p == '\0')
							break;
						TCHAR rsn[ 1024 ];
						_tcscpy( rsn, dat->type2str());
						if ( dat->type == MUC_BANLIST ) {
							dat->ppro->EnterString(rsn, SIZEOF(rsn), TranslateT("Reason to ban") , JES_COMBO, "gcAddReason_");
							if ( szBuffer )
								dat->ppro->AddMucListItem( dat, p , rsn);
							else
								dat->ppro->AddMucListItem( dat, p );
						}
						else dat->ppro->AddMucListItem( dat, p );
					}
					else {
						//delete
						TCHAR msgText[128];

						mir_sntprintf( msgText, SIZEOF( msgText ), _T("%s %s?"), TranslateT( "Removing" ), text );
						if ( MessageBox( hwndDlg, msgText, dat->type2str(), MB_YESNO|MB_SETFOREGROUND ) == IDYES ) {
							dat->ppro->DeleteMucListItem( dat, ( TCHAR* )lvi.lParam );
							mir_free(( void * )lvi.lParam );
							ListView_DeleteItem( nm->hdr.hwndFrom, hti.iItem );
				}	}	}
				break;
			}
			break;
		}
		break;
	case WM_COMMAND:
		if ((LOWORD(wParam) == IDC_BTN_FILTERAPPLY) ||
			((LOWORD(wParam) == IDOK) && (GetFocus() == GetDlgItem(hwndDlg, IDC_FILTER))))
		{
			SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_FILTER), GWLP_USERDATA, 1);
			sttFillJidList(hwndDlg);
		} else
		if ((LOWORD(wParam) == IDC_BTN_FILTERRESET) ||
			((LOWORD(wParam) == IDCANCEL) && (GetFocus() == GetDlgItem(hwndDlg, IDC_FILTER))))
		{
			SetWindowLongPtr(GetDlgItem(hwndDlg, IDC_FILTER), GWLP_USERDATA, 0);
			sttFillJidList(hwndDlg);
		}
		break;
/*	case WM_SETCURSOR:
		if ( LOWORD( LPARAM )!= HTCLIENT ) break;
		if ( GetForegroundWindow() == GetParent( hwndDlg )) {
			POINT pt;
			GetCursorPos( &pt );
			ScreenToClient( hwndDlg,&pt );
			SetFocus( ChildWindowFromPoint( hwndDlg,pt ));	  //ugly hack because listviews ignore their first click
		}
		break;
*/	case WM_CLOSE:
		{
			HWND hwndList;
			int count, i;
			LVITEM lvi;

			// Free lParam of the displayed list items
			hwndList = GetDlgItem( hwndDlg, IDC_LIST );
			count = ListView_GetItemCount( hwndList );
			lvi.mask = LVIF_PARAM;
			lvi.iSubItem = 0;
			for ( i=0; i<count; i++ ) {
				lvi.iItem = i;
				if ( ListView_GetItem( hwndList, &lvi ) == TRUE ) {
					if ( lvi.lParam!=( LPARAM )( -1 ) && lvi.lParam!=( LPARAM )( NULL )) {
						mir_free(( void * ) lvi.lParam );
					}
				}
			}
			ListView_DeleteAllItems( hwndList );

			CJabberProto* ppro = dat->ppro;
			switch ( dat->type ) {
			case MUC_VOICELIST:
				ppro->m_hwndMucVoiceList = NULL;
				break;
			case MUC_MEMBERLIST:
				ppro->m_hwndMucMemberList = NULL;
				break;
			case MUC_MODERATORLIST:
				ppro->m_hwndMucModeratorList = NULL;
				break;
			case MUC_BANLIST:
				ppro->m_hwndMucBanList = NULL;
				break;
			case MUC_ADMINLIST:
				ppro->m_hwndMucAdminList = NULL;
				break;
			case MUC_OWNERLIST:
				ppro->m_hwndMucOwnerList = NULL;
				break;
			}

			DestroyWindow( hwndDlg );
		}
		break;

	case WM_DESTROY:
		// Clear GWL_USERDATA
		if ( dat != NULL ) {
			Utils_SaveWindowPosition(hwndDlg, NULL, dat->ppro->m_szModuleName, "jidListWnd_");
			delete dat;
		}
		break;
	}
	return FALSE;
}
Ejemplo n.º 5
0
static INT_PTR CALLBACK
ProbeListPageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    INT Index;

    switch (uMsg)
    {
        case WM_INITDIALOG:
        {
            pDeviceStatusText = (PWSTR)HeapAlloc(hProcessHeap, 0, MAX_STR_SIZE);
            InitProbeListPage(hwndDlg);
        }
        break;

        case WM_NOTIFY:
        {
            LPNMHDR lpnm = (LPNMHDR)lParam;

            switch (lpnm->code)
            {
                case PSN_SETACTIVE:
                {
                    PropSheet_SetWizButtons(GetParent(hwndDlg), PSWIZB_BACK | PSWIZB_NEXT);
                }
                break;

                case PSN_WIZNEXT:
                {
                    Index = (INT) SendMessage(GetDlgItem(hwndDlg, IDC_PROBELIST), LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
                    if (Index == -1) Index = 0;

                    if (Index == 0)
                    {
                        SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_SELECTWAYPAGE);
                    }
                    else
                    {
                        LVITEM Item;
                        PWSTR pts;

                        ZeroMemory(&Item, sizeof(LV_ITEM));
                        Item.mask = LVIF_PARAM;
                        Item.iItem = Index;
                        (VOID) ListView_GetItem(GetDlgItem(hwndDlg, IDC_PROBELIST), &Item);
                        pts = (PWSTR) Item.lParam;
                        wcscpy(pDeviceStatusText, pts);

                        SetWindowLongPtr(hwndDlg, DWL_MSGRESULT, IDD_HWSTATUSPAGE);
                    }
                    return TRUE;
                }
            }
        }
        break;

        case WM_DESTROY:
        {
            INT Index;
            LVITEM Item;

            for (Index = ListView_GetItemCount(GetDlgItem(hwndDlg, IDC_PROBELIST)); --Index > 0;)
            {
                ZeroMemory(&Item, sizeof(LV_ITEM));
                Item.mask = LVIF_PARAM;
                Item.iItem = Index;
                (VOID) ListView_GetItem(GetDlgItem(hwndDlg, IDC_PROBELIST), &Item);
                HeapFree(hProcessHeap, 0, (LPVOID) Item.lParam);
            }
            HeapFree(hProcessHeap, 0, (LPVOID) pDeviceStatusText);
        }
        break;
    }

    return FALSE;
}
Ejemplo n.º 6
0
static UINT_PTR APIENTRY frompc_hook_proc(HWND hwnd, UINT uimsg, WPARAM wparam, LPARAM lparam){
  HWND preview;
  char filename[256];
  LVCOLUMNA column;

  preview = GetDlgItem(hwnd, IDC_PREVIEW);
  switch (uimsg) {
  case WM_INITDIALOG:
    column.mask = LVCF_TEXT | LVCF_WIDTH;
    column.pszText = "No.";
    column.cx = 40;
    ListView_InsertColumn(preview, 0, &column);
    column.pszText = "Name";
    column.cx = 160;
    ListView_InsertColumn(preview, 1, &column);
    column.pszText = "Start address";
    column.cx = 80;
    ListView_InsertColumn(preview, 2, &column);
    column.pszText = "End address";
    ListView_InsertColumn(preview, 3, &column);

    SendMessage(GetDlgItem(hwnd, IDC_C64_NAME), EM_LIMITTEXT, 16, 0);

    break;
  case WM_NOTIFY:
    {
      LPOFNOTIFY notify = (LPOFNOTIFY) lparam;
      if (notify->hdr.code == CDN_SELCHANGE) {
        ListView_DeleteAllItems(preview);
        SetDlgItemTextA(hwnd, IDC_C64_NAME, "");
        EnableWindow(GetDlgItem(hwnd, IDC_C64_NAME), FALSE);
        if (CommDlg_OpenSave_GetFilePath
            (notify->hdr.hwndFrom, filename, 256) >= 0)
          write_entries_to_window(hwnd, filename);
      }
      else if (notify->hdr.code == CDN_FILEOK) {
        int entry_num;
        struct simple_block_list_element **block = (struct simple_block_list_element **)notify->lpOFN->lCustData;
        FILE *fd = NULL;

        if (CommDlg_OpenSave_GetFilePath(notify->hdr.hwndFrom, filename, 256)
            < 0) {
          MessageBoxA(hwnd, "Cannot get selected file name", "WAV-PRG error",
                     MB_ICONERROR);
        }
        else
          fd = fopen(filename, "rb");
        if (fd == NULL) {
          MessageBoxA(hwnd, "Cannot open selected file", "WAV-PRG error",
                     MB_ICONERROR);
          SetWindowLong(hwnd, DWL_MSGRESULT, -1);
        }
        else
        {
          switch (detect_type(fd)) {
          case not_a_valid_file:
            MessageBoxA(hwnd, "Selected file is not a supported file",
                       "WAV-PRG error", MB_ICONERROR);
            break;
          case t64:
            {
              int index;
              struct simple_block_list_element **current_block = block;

              for (index = ListView_GetNextItem(preview, -1, LVNI_SELECTED); index != -1; index = ListView_GetNextItem(preview, index, LVNI_SELECTED)) {
                LVITEMA sel_item;
                char sel_num[6];

                sel_item.mask = LVIF_TEXT;
                sel_item.iItem = index;
                sel_item.iSubItem = 0;
                sel_item.pszText = sel_num;
                sel_item.cchTextMax = sizeof(sel_num);
                if (!ListView_GetItem(preview, &sel_item))
                  continue;
                entry_num = atoi(sel_num);
                add_simple_block_list_element(current_block);
                if (!get_entry(entry_num, fd, &(*current_block)->block)){
                  remove_simple_block_list_element(current_block);
                  continue;
                }
                current_block = &(*current_block)->next;
              }
            }
            if (*block == NULL)
              add_all_entries_from_file(block, fd);

            if (*block == NULL)
              MessageBoxA(hwnd, "You chose a T64 file with no entries",
                          "WAV-PRG error", MB_ICONERROR);
            break;
          case p00:
          case prg:
            add_simple_block_list_element(block);
            if (!get_first_entry(fd, &(*block)->block)) {
              MessageBoxA(hwnd, "Error in reading file", "WAV-PRG error",
                         MB_ICONERROR);
              remove_simple_block_list_element(block);;
            }
            else
            {
              int i;
              char pad_with_spaces = 0;

              GetDlgItemTextA(hwnd, IDC_C64_NAME, (*block)->block.info.name, 17);
              for (i = 0; i < 16; i++) {
                if ((*block)->block.info.name[i] == 0)
                  pad_with_spaces = 1;
                if (pad_with_spaces)
                  (*block)->block.info.name[i] = 32;
              }
            }
            break;
          default:
            break;
          }
        }
        if (fd != NULL)
          fclose(fd);
        if (*block == NULL){
          SetWindowLong(hwnd, DWL_MSGRESULT, -1);
          return 1;
        }
      }
      break;
    }
  default:
    break;
  }
  return 0;
}
Ejemplo n.º 7
0
LRESULT CALLBACK stream_WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    RECT		rect ;
    int cxClient, cyClient;
    static HMENU	hMenu ;
    POINT point ;
    int ret, idx;
    TCHAR  buf[64];
    char file_name[MAX_FILE_PATH_LEN];

    static int edit_iItem=-1 ;
    static int edit_iSubItem;

     LVITEM lv_item;
    switch (message)
    {
        case WM_CREATE:
            hwnd_stream= hwnd;
            hMenu = LoadMenu (g_hInstance, TEXT("my_popup_menu")) ;
            hMenu = GetSubMenu (hMenu, 0) ;

            hwnd_dynamic_edit=CreateWindow (TEXT("edit"), TEXT(""),
                WS_CHILD|ES_AUTOHSCROLL,
                CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
                hwnd, (HMENU)ID_DYNAMIC_EDIT, g_hInstance, NULL) ;

            SendMessage(hwnd_dynamic_edit, WM_SETFONT, (WPARAM)char_font_2, 0); 

            hwnd_lv = CreateListView(hwnd);
            //InitListViewImageLists(hwnd_lv);
            InitListViewColumns(hwnd_lv);
            lv_row_color_init();
            old_lv_proc = (WNDPROC) SetWindowLong (hwnd_lv, 
                                 	GWL_WNDPROC, (LONG)my_lv_proc) ;

            ShowWindow(hwnd_lv, 1) ;
            refresh_window(hwnd_lv) ;

           add_tip(hwndTip, hwnd_lv, TEXT("点击鼠标右键进行操作"));

            return 0 ;

        case WM_SIZE:
      		cxClient = LOWORD (lParam) ;
      		cyClient = HIWORD (lParam) ;

            MoveWindow(hwnd_lv, 	0, 0,
                cxClient, cyClient, TRUE) ;

            return 0 ;

case WM_NOTIFY:
{

   NMHDR *pt_nmhdr=(void *)lParam;
   switch(LOWORD(wParam))
   { 
     case ID_LV:

     // if code == NM_CLICK - Single click on an item
     if(pt_nmhdr->code == NM_CLICK || pt_nmhdr->code == NM_DBLCLK) 
     {
        int iItem = ((LPNMITEMACTIVATE)lParam)->iItem;
        int iSubItem=((LPNMITEMACTIVATE)lParam)->iSubItem;

        if (iItem>=0 && ((iSubItem>=3 && iSubItem<=5) || iSubItem==7)) 
        {

            ListView_GetSubItemRect(hwnd_lv,iItem,iSubItem,LVIR_LABEL,&rect);
            ListView_GetItemText(hwnd_lv, iItem, iSubItem, buf, sizeof(buf));
            MoveWindow	(hwnd_dynamic_edit
                ,rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE);
            SetWindowText(hwnd_dynamic_edit, buf);
            ShowWindow (hwnd_dynamic_edit, 1) ;
            SetFocus(hwnd_dynamic_edit);
            SendMessage(hwnd_dynamic_edit, EM_SETSEL, (WPARAM)0, (LPARAM)-1);

            edit_iItem = iItem;
            edit_iSubItem = iSubItem;

        }

            return 0;
     }
    else if (pt_nmhdr->code == NM_RCLICK)
    {
        point = ((LPNMITEMACTIVATE)lParam)->ptAction;
        ListView_GetItem(hwnd_lv, &lv_item);

        ClientToScreen (hwnd_lv, &point) ;
  		TrackPopupMenu (hMenu, TPM_LEFTBUTTON, point.x, point.y, 0, hwnd_stream, NULL) ;
        return 0;

    }
    else if (pt_nmhdr->code == LVN_ITEMCHANGED)
    {
        if (!init_over) break;
        if (lv_in_op)   break;
        //if((((LPNMLISTVIEW)lParam)->uOldState&LVIS_STATEIMAGEMASK) != 
        //    (((LPNMLISTVIEW)lParam)->uNewState&LVIS_STATEIMAGEMASK)) 
        {
            int iItem = ((LPNMITEMACTIVATE)lParam)->iItem;
            int selected = ListView_GetCheckState(hwnd_lv, iItem);

            if (g_apt_streams[iItem]->selected!=selected)
            {
                doc_modified=1;
                g_apt_streams[iItem]->selected=selected;
                update_statusbar();
            }
        }
        return 0;

    }
    
    break;

   }

   break;
}

        case 	WM_COMMAND:
            switch (LOWORD(wParam))
            {
                  
                case    IDM_STREAM_NEW:
                    init_stream(&gt_edit_stream);
                    gt_edit_stream.len=gat_sample_pkts[0].len;
                    memcpy(gt_edit_stream.data, gat_sample_pkts[0].pkt_data, gt_edit_stream.len);

                    ret=DialogBox(g_hInstance, TEXT("STREAM_EDIT_DLG"), hwnd, StreamEditDlgProc);
                    if (IDOK==ret)
                    {
                        add_stream(&gt_edit_stream);
                        re_populate_items();
                    }
               	return 0 ;

                case    IDM_STREAM_NEW_HEX:
                {
                    int len;
                    char buf[MAX_PACKET_LEN];
                    if (get_open_file_name(file_name, hwnd, ALL_FILE_FILTER))
                        return 0;

                    len = read_file_to_buf(buf, sizeof(buf)-1, file_name);
                    if (len>0)
                        add_stream_from_hex_text(buf, len);
                    else
                        err_msg_box("读取文件内容失败");
                   	return 0 ;
                }

                case    IDM_STREAM_NEW_BIN:
                {
                    int len;
                    char buf[MAX_PACKET_LEN];
                    if (get_open_file_name(file_name, hwnd, ALL_FILE_FILTER))
                        return 0;

                    len = read_file_to_buf(buf, sizeof(buf)-1, file_name);
                    if (len>0)
                        add_stream_from_raw_data(buf, len);
                    else
                        err_msg_box("读取文件内容失败");
                   	return 0 ;
                }

                case    IDM_STREAM_NEW_PCAP:
                {
                    if (get_open_file_name(file_name, hwnd, PCAP_FILE_FILTER))
                        return 0;
                    add_stream_from_pcap(file_name);
                   	return 0 ;
                }
                                
                case    IDM_STREAM_DEL:
                    idx=GetIndex(hwnd_lv);
       				//ListView_DeleteItem(hwnd_lv, idx);
                    delete_stream(idx);
                    re_populate_items();
                    update_statusbar();
       				return 0 ;
                case    IDM_STREAM_EDIT:
                    cur_strm_idx=GetIndex(hwnd_lv);
                    if (cur_strm_idx<0) return 0;
                    cpy_stream(&gt_edit_stream, g_apt_streams[cur_strm_idx]);
                    ret=DialogBox(g_hInstance, TEXT("STREAM_EDIT_DLG"), hwnd, StreamEditDlgProc);
                    if (IDOK==ret)
                    {
                        doc_modified=1;
                        cpy_stream(g_apt_streams[cur_strm_idx], &gt_edit_stream);
                        re_populate_items();
                    }
       				//ListView_DeleteAllItems(hwnd_lv);
       				return 0 ;
                case    IDM_STREAM_DEL_SEL:
       				//DelSel(hwnd_lv);
                    delete_sel_stream();
                    re_populate_items();
                    update_statusbar();
       				return 0 ;

                case    IDM_STREAM_SEL_ALL:
       				SelAll(hwnd_lv);
       				return 0 ;

                case    IDM_STREAM_SEL_RVS:
       				SelRvs(hwnd_lv);
       				return 0 ;
                    
                case    IDM_STREAM_COPY:
       				copy_idx = GetIndex(hwnd_lv);
       				return 0 ;

                case    IDM_STREAM_PASTE:
       				cpy_stream(&gt_edit_stream, g_apt_streams[copy_idx]);
                    add_stream(&gt_edit_stream);
                    re_populate_items();
       				return 0 ;

                case    IDM_STREAM_MAKE_FRAGS:
                {
       				ret=DialogBox(g_hInstance, TEXT("FRAG_DLG"), hwnd, FragDlgProc);
       				return 0 ;
                }

                case    IDM_STREAM_SEL2PCAP:
                {
                    ret=get_save_file_name(file_name, hwnd, PCAP_FILE_FILTER, PCAP_FILE_SUFFIX);
                    if (ret) return 0 ;

       				stream2dump(file_name);
                    update_pcap_file_history(file_name);
       				return 0 ;
                }

                case    IDM_STREAM_2_BIN:
                {
                    ret=get_save_file_name(file_name, hwnd, BIN_FILE_FILTER, BIN_FILE_SUFFIX);
                    if (ret) return 0 ;

       				stream_2_bin(file_name);
       				return 0 ;
                }

                case    IDM_STREAM_2_TEXT:
                {
                    ret=get_save_file_name(file_name, hwnd, TEXT_FILE_FILTER, TEXT_FILE_SUFFIX);
                    if (ret) return 0 ;

       				stream_2_text(file_name);
       				return 0 ;
                }
                
                case    ID_DYNAMIC_EDIT:
       				if (HIWORD(wParam)==EN_KILLFOCUS)
                    {

            update_grid_from_edit(edit_iItem, edit_iSubItem);
            edit_iItem=-1;

           				return 0 ;
                    }

            }
            break;

case   WM_KEYDOWN:
    if (VK_RETURN==wParam)
    {

        SetFocus(hwnd);

         return 0;

    }
    break;

        case 	WM_INITMENUPOPUP:
        {
            int idx=GetIndex(hwnd_lv);
            t_stream *pt_stream = g_apt_streams[idx];
            int sel_cnt=GetSelCnt(hwnd_lv);
            int item_cnt=ListView_GetItemCount(hwnd_lv);
            if (lParam == 0)
            {
                UINT add_stream_menu_state = nr_cur_stream<MAX_STREAM_NUM ? MF_ENABLED : MF_GRAYED;
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_NEW, add_stream_menu_state);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_NEW_HEX, add_stream_menu_state);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_NEW_BIN, add_stream_menu_state);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_NEW_PCAP, add_stream_menu_state);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_EDIT, idx>=0 ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_DEL, idx>=0 ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_COPY, idx>=0 ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_PASTE, copy_idx>=0 && item_cnt>copy_idx ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_DEL_SEL, sel_cnt ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_SEL_ALL, item_cnt ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_SEL_RVS, item_cnt ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_MAKE_FRAGS, idx>=0&&stream_fragable(pt_stream) ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_SEL2PCAP, sel_cnt ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_2_BIN, idx>=0 ? MF_ENABLED : MF_GRAYED);
                EnableMenuItem ((HMENU) wParam, IDM_STREAM_2_TEXT, idx>=0 ? MF_ENABLED : MF_GRAYED);

                return 0;

            }

            break;
        }

    }
    
    return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Ejemplo n.º 8
0
BOOL CALLBACK RevokerSelectDlgProc(HWND hwndDlg, 
								   UINT uMsg, 
								   WPARAM wParam, 
								   LPARAM lParam)
{
	BOOL			bReturnCode = FALSE;
	pgpConfigInfo *	pConfig		= NULL;
	HWND hList;

	g_hCurrentDlgWnd = hwndDlg;

	if (uMsg != WM_INITDIALOG)
		pConfig = (pgpConfigInfo *) GetWindowLong(hwndDlg, GWL_USERDATA);

	hList = GetDlgItem(hwndDlg, IDC_REVOKER_ID);

	switch(uMsg)
	{
	case WM_INITDIALOG:
		{
			RECT rc;
			PROPSHEETPAGE *ppspConfig = (PROPSHEETPAGE *) lParam;

			// center dialog on screen
			GetWindowRect(GetParent(hwndDlg), &rc);
			SetWindowPos(GetParent(hwndDlg), NULL,
				(GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left))/2,
				(GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top))/2,
				0, 0, SWP_NOSIZE | SWP_NOZORDER);

			pConfig = (pgpConfigInfo *) ppspConfig->lParam;
			SetWindowLong(hwndDlg, GWL_USERDATA, (LPARAM) pConfig);

			ShowKeyring(hwndDlg, IDC_REVOKER_ID, pConfig->pgpContext, 
				NULL, FALSE, TRUE, FALSE, TRUE);
			g_bGotReloadMsg = FALSE;
			break;
		}

	case WM_DESTROY:
		FreeKeyring(hwndDlg, IDC_REVOKER_ID);
		break;

	case WM_PAINT:
		if (pConfig->hPalette)
		{
			PAINTSTRUCT ps;
			HDC	hDC = BeginPaint (hwndDlg, &ps);
			SelectPalette (hDC, pConfig->hPalette, FALSE);
			RealizePalette (hDC);
			EndPaint (hwndDlg, &ps);
			bReturnCode = TRUE;
		}
		break;
		
	case WM_NOTIFY:
		{
			LPNMHDR pnmh;

			pnmh = (LPNMHDR) lParam;
			switch(pnmh->code)
			{
			case PSN_SETACTIVE:
				{
					int nIndex;

					// Initialize window
					nIndex = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
					if (nIndex > -1)
					{
						PostMessage(GetParent(hwndDlg),
							PSM_SETWIZBUTTONS, 0, PSWIZB_NEXT | PSWIZB_BACK);
						bNextEnabled = TRUE;
					}
					else
					{
						PostMessage(GetParent(hwndDlg),
							PSM_SETWIZBUTTONS, 0, PSWIZB_BACK);
						bNextEnabled = FALSE;
					}

					SendDlgItemMessage(hwndDlg, IDC_WIZBITMAP, STM_SETIMAGE, 
						IMAGE_BITMAP, (LPARAM) pConfig->hBitmap);

					SetTimer(hwndDlg, ID_TIMER, 500, NULL);
					bReturnCode = TRUE;
					break;
				}

			case PSN_KILLACTIVE:
				{
					KillTimer(hwndDlg, ID_TIMER);
					bReturnCode = TRUE;
					break;
				}

			case PSN_WIZNEXT:
				{
					int nIndex;
					LV_ITEM lviKey;
					char *szKeyID;
					char szUserID[kPGPMaxUserIDSize+1];

					if (pConfig->szRevokerKeyID != NULL)
					{
						pgpFree(pConfig->szRevokerKeyID);
						pConfig->szRevokerKeyID = NULL;
					}

					if (pConfig->szRevokerKey != NULL)
					{
						pgpFree(pConfig->szRevokerKey);
						pConfig->szRevokerKey = NULL;
					}

					// Save user data for this page
					nIndex = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
					if (nIndex > -1)
					{
						lviKey.mask = LVIF_PARAM | LVIF_IMAGE | LVIF_TEXT;
						lviKey.iItem = nIndex;
						lviKey.iSubItem = 0;
						lviKey.pszText = szUserID;
						lviKey.cchTextMax = kPGPMaxUserIDSize;
						ListView_GetItem(hList, &lviKey);
						szKeyID = (char *) lviKey.lParam;

						pConfig->szRevokerKeyID = 
							(char *) pgpAlloc(strlen(szKeyID)+1);
						strcpy(pConfig->szRevokerKeyID, szKeyID);

						pConfig->szRevokerKey = 
							(char *) pgpAlloc(strlen(szUserID)+1);
						strcpy(pConfig->szRevokerKey, szUserID);

						if (lviKey.iImage == IDX_RSAPUBKEY)
							pConfig->revokerKeyType = 
												kPGPPublicKeyAlgorithm_RSA;
						if (lviKey.iImage == IDX_DSAPUBKEY)
							pConfig->revokerKeyType = 
												kPGPPublicKeyAlgorithm_DSA;
					}

					bReturnCode = TRUE;
					break;
				}

			case PSN_HELP:
				{
					// Display help
					break;
				}

			case PSN_QUERYCANCEL:
				{
					// User wants to quit
					g_bGotReloadMsg = FALSE;
					break;
				}

			case NM_CLICK:
			case NM_RCLICK:
			case NM_DBLCLK:
			case NM_RDBLCLK:
				if (pnmh->idFrom == IDC_REVOKER_ID)
				{
					int nIndex;

					nIndex = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
					if (nIndex > -1)
					{
						SendMessage(GetParent(hwndDlg),
							PSM_SETWIZBUTTONS, 0, PSWIZB_NEXT | PSWIZB_BACK);
						bNextEnabled = TRUE;
					}
					bReturnCode = TRUE;
				}
				break;
			}
			
			break;
		}

	case WM_TIMER:
		{
			int nIndex;

			nIndex = ListView_GetNextItem(hList, -1, LVNI_SELECTED);
			if (nIndex > -1)
			{
				if (!bNextEnabled)
				{
					SendMessage(GetParent(hwndDlg),
						PSM_SETWIZBUTTONS, 0, PSWIZB_NEXT | PSWIZB_BACK);
					bNextEnabled = TRUE;
				}
			}
			else if (bNextEnabled)
			{
				SendMessage(GetParent(hwndDlg),
					PSM_SETWIZBUTTONS, 0, PSWIZB_BACK);
				bNextEnabled = FALSE;
			}

			bReturnCode = TRUE;
			SetTimer(hwndDlg, ID_TIMER, 500, NULL);
			break;
		}
	}

	return(bReturnCode);
}
Ejemplo n.º 9
0
BOOL CALLBACK ReadMailDialogProc(HWND hDlg, UINT message, UINT wParam, LONG lParam)
{
   static HWND hEdit, hList;
   static int mail_index;  /* Number of currently displayed message, -1 if none */
   MailHeader *header;
   int index, msg_num, count;
   char str[MAX_HEADERLINE], msg[MAXMAIL];
   MINMAXINFO *lpmmi;
   LV_COLUMN lvcol;
   LV_ITEM lvitem;
   LV_HITTESTINFO lvhit;
   NM_LISTVIEW *nm;

   switch (message)
   {
   case WM_INITDIALOG:
      CenterWindow(hDlg, cinfo->hMain);
      hReadMailDlg = hDlg;

      hEdit = GetDlgItem(hDlg, IDC_MAILEDIT);
      hList = GetDlgItem(hDlg, IDC_MAILLIST);
      SendMessage(hDlg, BK_SETDLGFONTS, 0, 0);

      ListView_SetExtendedListViewStyleEx(hList, LVS_EX_FULLROWSELECT,
                                          LVS_EX_FULLROWSELECT);

      /* Store dialog rectangle in case of resize */
      GetWindowRect(hDlg, &dlg_rect);

      // Add column headings
      lvcol.mask = LVCF_TEXT | LVCF_WIDTH;
      lvcol.pszText = GetString(hInst, IDS_MHEADER1);
      lvcol.cx      = 25;
      ListView_InsertColumn(hList, 0, &lvcol);
      lvcol.pszText = GetString(hInst, IDS_MHEADER2);
      lvcol.cx      = 80;
      ListView_InsertColumn(hList, 1, &lvcol);
      lvcol.pszText = GetString(hInst, IDS_MHEADER3);
      lvcol.cx      = 150;
      ListView_InsertColumn(hList, 2, &lvcol);
      lvcol.pszText = GetString(hInst, IDS_MHEADER4);
      lvcol.cx      = 135;
      ListView_InsertColumn(hList, 3, &lvcol);

      mail_index = -1;

      SetFocus(hReadMailDlg);

      MailGetMessageList();
      RequestReadMail();
      return TRUE;

   case WM_SIZE:
      ResizeDialog(hDlg, &dlg_rect, mailread_controls);
      return TRUE;      

   case WM_GETMINMAXINFO:
      lpmmi = (MINMAXINFO *) lParam;
      lpmmi->ptMinTrackSize.x = 200;
      lpmmi->ptMinTrackSize.y = 300;
      return 0;

   case WM_ACTIVATE:
      if (wParam == 0)
	 *cinfo->hCurrentDlg = NULL;
      else *cinfo->hCurrentDlg = hDlg;
      return TRUE;
      
   case BK_SETDLGFONTS:
      SetWindowFont(hEdit, GetFont(FONT_MAIL), TRUE);
      SetWindowFont(hList, GetFont(FONT_MAIL), TRUE);
      return TRUE;
      
   case BK_SETDLGCOLORS:
      ListView_SetTextColor(hList, GetColor(COLOR_LISTFGD));
      ListView_SetBkColor(hList, GetColor(COLOR_LISTBGD));
      InvalidateRect(hDlg, NULL, TRUE);
      return TRUE;

   case EN_SETFOCUS:
      /* By default, whole message becomes selected for some reason */
      Edit_SetSel(hEdit, -1, 0);
      break;
      
   case BK_NEWMAIL: /* wParam = message number, lParam = message header string */
      msg_num = wParam;
      header = (MailHeader *) lParam;

      // Add message to list view
      if (!IsNameInIgnoreList(header->sender))
      {
         sprintf(str, "%d", msg_num);
         lvitem.mask = LVIF_TEXT | LVIF_PARAM;
         lvitem.iItem = 0;
         lvitem.iSubItem = 0;
         lvitem.pszText = str;
         lvitem.lParam = msg_num;
         ListView_InsertItem(hList, &lvitem);

         // Add subitems
         lvitem.mask = LVIF_TEXT;
         lvitem.iSubItem = 1;
         lvitem.pszText = header->sender;
         ListView_SetItem(hList, &lvitem);
         lvitem.iSubItem = 2;
         lvitem.pszText = header->subject;
         ListView_SetItem(hList, &lvitem);
         lvitem.iSubItem = 3;
         lvitem.pszText = header->date;
         ListView_SetItem(hList, &lvitem);
      }

      // Erase message in status area
      SetDlgItemText(hDlg, IDC_MAILINFO, "");
      return TRUE;
   
   case BK_NONEWMAIL:
      SetDlgItemText(hDlg, IDC_MAILINFO, GetString(hInst, IDS_NONEWMAIL));
      return TRUE;

      HANDLE_MSG(hDlg, WM_CTLCOLOREDIT, MailCtlColor);
      HANDLE_MSG(hDlg, WM_CTLCOLORLISTBOX, MailCtlColor);
      HANDLE_MSG(hDlg, WM_CTLCOLORSTATIC, MailCtlColor);
      HANDLE_MSG(hDlg, WM_CTLCOLORDLG, MailCtlColor);

      HANDLE_MSG(hDlg, WM_INITMENUPOPUP, InitMenuPopupHandler);
      
   case WM_CLOSE:
      SendMessage(hDlg, WM_COMMAND, IDCANCEL, 0);
      return TRUE;

   case WM_DESTROY:
      hReadMailDlg = NULL;
      if (exiting)
	 PostMessage(cinfo->hMain, BK_MODULEUNLOAD, 0, MODULE_ID);
      return TRUE;

   case WM_NOTIFY:
      if (wParam != IDC_MAILLIST)
	 return TRUE;

      nm = (NM_LISTVIEW *) lParam;

      switch (nm->hdr.code)
      {
      case NM_CLICK:
	 // If you click on an item, select it--why doesn't control work this way by default?
	 GetCursorPos(&lvhit.pt);
	 ScreenToClient(hList, &lvhit.pt);
	 lvhit.pt.x = 10;
	 index = ListView_HitTest(hList, &lvhit);

	 if (index == -1)
	    break;

	 ListView_SetItemState(hList, index, 
			       LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
	 break;

      case LVN_ITEMCHANGED:
	 // New item selected; get its message number
	 lvitem.mask = LVIF_STATE | LVIF_PARAM;
	 lvitem.stateMask = LVIS_SELECTED;
	 lvitem.iItem = nm->iItem;
	 lvitem.iSubItem = 0;
	 ListView_GetItem(hList, &lvitem);

	 if (!(lvitem.state & LVIS_SELECTED))
	    break;

	 msg_num = lvitem.lParam;
	 if (msg_num == mail_index)
	    break;
	 
	 if (MailLoadMessage(msg_num, MAXMAIL, msg) == False)
	 {
	    ClientError(hInst, hReadMailDlg, IDS_CANTLOADMSG);
	    break;
	 }

	 mail_index = msg_num;
	 Edit_SetText(hEdit, msg);
	 break;
      }
      return TRUE;

   case WM_COMMAND:
      UserDidSomething();

      switch(GET_WM_COMMAND_ID(wParam, lParam))
      {
      case IDC_DELETEMSG:
	 if (!ListViewGetCurrentData(hList, &index, &msg_num))
	    return TRUE;
	 
	 if (MailDeleteMessage(msg_num) == True)
	 {
	    /* Display new current message, if any */
	    Edit_SetText(hEdit, "");
	    ListView_DeleteItem(hList, index);

	    count = ListView_GetItemCount(hList);
	    if (count == 0)
	       return TRUE;

	    index = min(index, count - 1);  // in case last message deleted
	    ListView_SetItemState(hList, index, LVIS_SELECTED, LVIS_SELECTED);
	 }
	 return TRUE;

      case IDC_RESCAN:
	 SetDlgItemText(hDlg, IDC_MAILINFO, GetString(hInst, IDS_GETTINGMSGS));
	 RequestReadMail();
	 return TRUE;

      case IDC_SEND:
	 UserSendMail();
	 return TRUE;

      case IDC_REPLY:
      case IDC_REPLYALL:
	 /* Find message number for currently selected message */
	 if (!ListViewGetCurrentData(hList, &index, &msg_num))
	    return TRUE;

	 UserMailReply(msg_num, (Bool) (GET_WM_COMMAND_ID(wParam, lParam) == IDC_REPLYALL));
	 return TRUE;

      case IDCANCEL:
	 /* Note:  This code is also used by the WM_CLOSE message */
	 MailDeleteMessageList();
	 DestroyWindow(hDlg);
	 return TRUE;
      }
      break;
   }
   return FALSE;
}
Ejemplo n.º 10
0
static BOOL CALLBACK processTokenListMessage(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	/* hwndDlg must be a child of the help dialog */
	switch(msg) {
	case WM_INITDIALOG:
		{
			TOKENREGISTEREX *tr;
			TCHAR *tszTokenDesc, *tszHelpDesc, *last, *cat, *text;

			// token list things
			HWND hList = GetDlgItem(hwndDlg, IDC_TOKENLIST);

			LVCOLUMN lvCol = { 0 };
			lvCol.mask = LVCF_TEXT;
			lvCol.pszText = TranslateT("Token");
			ListView_InsertColumn(hList, 0, &lvCol);

			lvCol.pszText = TranslateT("Description");
			ListView_InsertColumn(hList, 1, &lvCol);

			HELPDLGDATA *hdd = (HELPDLGDATA *)GetWindowLongPtr(GetParent(hwndDlg), GWLP_USERDATA);
			int i = -1;
			do {
				i += 1;
				tszHelpDesc = tszTokenDesc = NULL;
				tr = getTokenRegister(i);
				if ((tr == NULL) || (tr->tszTokenString == NULL))
					continue;

				else if (hdd != NULL) {
					if (!_tcscmp(tr->tszTokenString, SUBJECT)) {
						if (hdd->vhs->flags&VHF_HIDESUBJECTTOKEN)
							continue;

						if (hdd->vhs->szSubjectDesc != NULL)
							tszHelpDesc = mir_a2t(hdd->vhs->szSubjectDesc);
					}
					if (!_tcscmp(tr->tszTokenString, MIR_EXTRATEXT)) {
						if (hdd->vhs->flags & VHF_HIDEEXTRATEXTTOKEN)
							continue;

						if (hdd->vhs->szExtraTextDesc != NULL)
							tszHelpDesc = mir_a2t(hdd->vhs->szExtraTextDesc);
					}
				}

				LVITEM lvItem = { 0 };
				lvItem.mask = LVIF_TEXT | LVIF_PARAM;
				lvItem.iItem = ListView_GetItemCount(hList);
				lvItem.lParam = (LPARAM)tr;
				tszTokenDesc = getTokenDescription(tr);
				if (tszTokenDesc == NULL)
					continue;

				lvItem.pszText = tszTokenDesc;
				ListView_InsertItem(hList, &lvItem);
				mir_free(tszTokenDesc);

				lvItem.mask = LVIF_TEXT;
				if (tszHelpDesc == NULL)
					tszHelpDesc = getHelpDescription(tr);

				if (tszHelpDesc == NULL)
					tszHelpDesc = mir_tstrdup(_T("unknown"));

				lvItem.iSubItem = 1;
				lvItem.pszText = TranslateTS(tszHelpDesc);
				ListView_SetItem(hList, &lvItem);
				mir_free(tszHelpDesc);
			}
				while (tr != NULL);
	
			ListView_SetColumnWidth(hList, 0, LVSCW_AUTOSIZE);
			ListView_SetColumnWidth(hList, 1, LVSCW_AUTOSIZE);
			ListView_SortItems(hList, compareTokenHelp, 0);
			last = text = NULL;
			for (i = 0; i < ListView_GetItemCount(hList); i++) {
				LVITEM lvItem = { 0 };
				lvItem.mask = LVIF_PARAM;
				lvItem.iItem = i;
				if (ListView_GetItem(hList, &lvItem) == FALSE)
					continue;

				cat = getTokenCategory((TOKENREGISTEREX *)lvItem.lParam);
				if (cat != NULL) {
					text = mir_tstrdup(TranslateTS(cat));
					mir_free(cat);
				}
				else text = NULL;

				if (text != NULL && (last == NULL || _tcsicmp(last, text))) {
					lvItem.mask = LVIF_TEXT;
					lvItem.pszText = text;
					ListView_InsertItem(hList, &lvItem);
					if (last != NULL) {
						mir_free(last);
						lvItem.iSubItem = 0;
						lvItem.pszText = _T("");
						ListView_InsertItem(hList, &lvItem);
					}
					last = text;
				}
				else mir_free(text);
			}
			mir_free(last);
		}
		break;

	case WM_NOTIFY:
		if ((((NMHDR*)lParam)->idFrom == IDC_TOKENLIST) && (((NMHDR*)lParam)->code == NM_DBLCLK)) {
			HWND hwndInputDlg = (HWND)SendMessage(GetParent(hwndDlg), VARM_GETDIALOG, (WPARAM)VHF_INPUT, 0);
			if (hwndInputDlg == NULL)
				break;

			HWND hList = GetDlgItem(hwndDlg, IDC_TOKENLIST);
			int item = ListView_GetNextItem(hList, -1, LVNI_SELECTED|LVNI_FOCUSED);

			LVITEM lvItem = { 0 };
			lvItem.mask = LVIF_PARAM;
			lvItem.iItem = item;
			if (ListView_GetItem(hList, &lvItem) == FALSE)
				break;

			TOKENREGISTER *tr = (TOKENREGISTER *)lvItem.lParam;
			if (tr == NULL)
				break;

			size_t len = _tcslen(tr->tszTokenString) + 2;
			if (len < 0)
				break;

			TCHAR *tokenString = (TCHAR*)mir_alloc((len+1)*sizeof(TCHAR));
			if (tokenString == NULL)
				break;

			memset(tokenString, 0, ((len + 1) * sizeof(TCHAR)));
			mir_sntprintf(tokenString, len + 1, _T("%c%s%c"), (tr->flags & TRF_FIELD) ? FIELD_CHAR : FUNC_CHAR, tr->tszTokenString, (tr->flags & TRF_FIELD) ? FIELD_CHAR : '(');
			SendDlgItemMessage(hwndInputDlg, IDC_TESTSTRING, EM_REPLACESEL, TRUE, (LPARAM)tokenString);
			mir_free(tokenString);
			SetFocus(GetDlgItem(hwndInputDlg, IDC_TESTSTRING));
		}
		break;
	}

	return FALSE;
}
Ejemplo n.º 11
0
INT_PTR CALLBACK FindWindowDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		SendDlgItemMessage(hwnd, IDC_SBAR, SB_SETTEXT, 0, (LPARAM)TranslateT("Enter a string to search the database for"));
		CheckDlgButton(hwnd, IDC_MODNAME, BST_CHECKED);
		CheckDlgButton(hwnd, IDC_SETTINGNAME, BST_CHECKED);
		CheckDlgButton(hwnd, IDC_SETTINGVALUE, BST_CHECKED);
		CheckDlgButton(hwnd, IDC_FOUND, BST_CHECKED);
		SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIcon(g_plugin.getInst(), MAKEINTRESOURCE(ICO_REGEDIT)));
		SetWindowLongPtr(GetDlgItem(hwnd, IDC_REPLACE), GWLP_USERDATA, 0);
		SetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA, 0);
		SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_APPWINDOW); // taskbar icon
		TranslateDialogDefault(hwnd);
		ListView_SetExtendedListViewStyle(GetDlgItem(hwnd, IDC_LIST), 32 | LVS_EX_LABELTIP); // LVS_EX_GRIDLINES
		loadListSettings(GetDlgItem(hwnd, IDC_LIST), csResultList);
		Utils_RestoreWindowPositionNoMove(hwnd, NULL, MODULENAME, "Search_");
		return TRUE;

	case WM_COMMAND:
		switch (LOWORD(wParam)) {
		case IDOK:
		case IDC_SEARCH:
			if (GetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA)) // stop the search
				SetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA, 0);
			else {
				wchar_t text[FLD_SIZE];
				wchar_t replace[FLD_SIZE] = { 0 };

				if (!GetDlgItemText(hwnd, IDC_TEXT, text, _countof(text)) && !IsDlgButtonChecked(hwnd, IDC_EXACT)) break;

				// empty replace is done only for exact match or entire replace
				if (LOWORD(wParam) == IDOK &&
					!GetDlgItemText(hwnd, IDC_REPLACE, replace, _countof(replace)) &&
					(!IsDlgButtonChecked(hwnd, IDC_ENTIRELY) && !IsDlgButtonChecked(hwnd, IDC_EXACT)))
					break;

				if (BST_UNCHECKED == IsDlgButtonChecked(hwnd, IDC_MODNAME) &&
					BST_UNCHECKED == IsDlgButtonChecked(hwnd, IDC_SETTINGNAME) &&
					BST_UNCHECKED == IsDlgButtonChecked(hwnd, IDC_SETTINGVALUE))
					break;

				FindInfo *fi = (FindInfo*)mir_calloc(sizeof(FindInfo));
				if (!fi)
					break;

				fi->hwnd = GetDlgItem(hwnd, IDC_LIST);
				fi->options = (IsDlgButtonChecked(hwnd, IDC_CASESENSITIVE) ? F_CASE : 0) |
					(IsDlgButtonChecked(hwnd, IDC_EXACT) ? F_EXACT : 0) |
					(IsDlgButtonChecked(hwnd, IDC_MODNAME) ? F_MODNAME : 0) |
					(IsDlgButtonChecked(hwnd, IDC_SETTINGNAME) ? F_SETNAME : 0) |
					(IsDlgButtonChecked(hwnd, IDC_SETTINGVALUE) ? F_SETVAL : 0);

				if (LOWORD(wParam) == IDOK) {

					if (IsDlgButtonChecked(hwnd, IDC_ENTIRELY))
						fi->options |= F_ENTIRE;

					fi->replace = mir_wstrdup(replace);

					SetDlgItemText(hwnd, IDOK, TranslateT("Stop"));
					EnableWindow(GetDlgItem(hwnd, IDC_SEARCH), 0);

				}
				else {
					SetDlgItemText(hwnd, IDC_SEARCH, TranslateT("Stop"));
					EnableWindow(GetDlgItem(hwnd, IDOK), 0);
				}

				fi->search = mir_wstrdup(text);

				ListView_DeleteAllItems(fi->hwnd);
				SetWindowLongPtr(GetDlgItem(hwnd, IDC_SEARCH), GWLP_USERDATA, 1);

				EnableWindow(GetDlgItem(hwnd, IDCANCEL), 0);
				mir_forkthread(FindSettings, fi);
			}
			break;

		case IDCANCEL:
			DestroyWindow(hwnd);
			break;
		}
		break;
	case WM_GETMINMAXINFO:
	{
		MINMAXINFO *mmi = (MINMAXINFO*)lParam;
		mmi->ptMinTrackSize.x = 610;
		mmi->ptMinTrackSize.y = 300;
	}
	return 0;

	case WM_SIZE:
		Utils_ResizeDialog(hwnd, g_plugin.getInst(), MAKEINTRESOURCEA(IDD_FIND), FindDialogResize);
		break;

	case WM_NOTIFY:
		if (LOWORD(wParam) != IDC_LIST) break;
		switch (((NMHDR*)lParam)->code) {
		case NM_DBLCLK:
		{
			LVHITTESTINFO hti;
			LVITEM lvi;
			HWND hwndResults = GetDlgItem(hwnd, IDC_LIST);
			hti.pt = ((NMLISTVIEW*)lParam)->ptAction;
			if (ListView_SubItemHitTest(hwndResults, &hti) > -1) {
				if (hti.flags&LVHT_ONITEM)
				{
					lvi.mask = LVIF_PARAM;
					lvi.iItem = hti.iItem;
					lvi.iSubItem = 0;
					if (ListView_GetItem(hwndResults, &lvi))
					{
						ItemInfo ii = { 0 };
						ii.hContact = (MCONTACT)lvi.lParam;
						ListView_GetItemTextA(hwndResults, hti.iItem, 2, ii.module, _countof(ii.module));
						ListView_GetItemTextA(hwndResults, hti.iItem, 3, ii.setting, _countof(ii.setting));
						if (ii.setting[0])
							ii.type = FW_SETTINGNAME;
						else if (ii.module[0])
							ii.type = FW_MODULE;

						SendMessage(hwnd2mainWindow, WM_FINDITEM, (WPARAM)&ii, 0);
					}
				}
			}
			break;
		}

		case LVN_COLUMNCLICK:
		{
			LPNMLISTVIEW lv = (LPNMLISTVIEW)lParam;
			ColumnsSortParams params;
			params.hList = GetDlgItem(hwnd, IDC_LIST);
			params.column = lv->iSubItem;
			params.last = lastColumn;
			ListView_SortItemsEx(params.hList, ColumnsCompare, (LPARAM)&params);
			lastColumn = (params.column == lastColumn) ? -1 : params.column;
			break;
		}
		} // switch
		break;
	case WM_DESTROY:
		ListView_DeleteAllItems(GetDlgItem(hwnd, IDC_LIST));
		saveListSettings(GetDlgItem(hwnd, IDC_LIST), csResultList);
		Utils_SaveWindowPosition(hwnd, NULL, MODULENAME, "Search_");
		break;
	}
	return 0;
}
Ejemplo n.º 12
0
/**
 *\fn           void dragFile(int x, int y)
 *\brief        拖动文件
 *\param[in]    int x 鼠标位置
 *\param[in]    int y 鼠标位置
 *\return       void 无
 */
void CBrowseWnd::dragFile(int x, int y)
{
    POINT pt = {x, y};
    ::ClientToScreen(wnd_, &pt);

    HWND wnd = ::WindowFromPoint(pt); // 得到鼠标所在的窗体

    char path[1024] = "";
    ::GetWindowText(wnd, path, sizeof(path)-1);

    if (0 == strcmp("FolderView", path)) // 桌面
    {
        SHGetSpecialFolderPath(NULL, path, CSIDL_DESKTOPDIRECTORY, FALSE);
    }
    else // 资源管理器
    {
        wnd = ::GetParent(wnd); // SHELLDLL_DefView
        wnd = ::GetParent(wnd); // CtrlNotifySink
        wnd = ::GetParent(wnd); // DirectUIHWND
        wnd = ::GetParent(wnd); // DUIViewWndClassName
        wnd = ::GetParent(wnd); // ShellTabWindowClass
        wnd = ::GetParent(wnd); // CabinetWClass
        wnd = ::FindWindowEx(wnd, NULL, "WorkerW", NULL);
        wnd = ::FindWindowEx(wnd, NULL, "ReBarWindow32", NULL);
        wnd = ::FindWindowEx(wnd, NULL, "Address Band Root", NULL);
        wnd = ::FindWindowEx(wnd, NULL, "msctls_progress32", NULL);
        wnd = ::FindWindowEx(wnd, NULL, "Breadcrumb Parent", NULL);
        wnd = ::FindWindowEx(wnd, NULL, "ToolbarWindow32", NULL);

        ::GetWindowText(wnd, path, sizeof(path)-1); // 地址: D:\360Downloads
    }

    // 没有找到窗体
    if (path[0] == '\0') return;

    int i = 0;
    int itemId = -1;
    int count = ListView_GetSelectedCount(list_.m_hWnd);

    for (i = 0; i < count; i++)
    {
        itemId = ListView_GetNextItem(list_.m_hWnd, itemId, LVNI_SELECTED);

        LV_ITEM item = {0};
        char filename[256] = "";
        item.iItem = itemId;
        item.mask = LVIF_TEXT | LVIF_PARAM; // 文字
        item.pszText = filename;
        item.cchTextMax = sizeof(filename);

        ListView_GetItem(list_.m_hWnd, &item);

        char remotePath[1024] = "";
        getPath((HTREEITEM)item.lParam, remotePath);

        char localPath[1024] = "";
        strcpy_s(localPath, strstr(path, "\\") - 2);

        strcat_s(localPath, sizeof(path), "\\");
        strcat_s(localPath, sizeof(path), filename);
        strcat_s(remotePath, sizeof(path), filename);

        sftp_download_file(&ssh_param_, localPath, remotePath);
    }
}
Ejemplo n.º 13
0
static INT_PTR CALLBACK ConfirmDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_INITDIALOG:
		TranslateDialogDefault(hwndDlg);
		{
			HWND hList = GetDlgItem(hwndDlg, IDC_STARTUPLIST);
			SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);

			// create columns
			LVCOLUMN lvCol = { 0 };
			lvCol.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
			lvCol.pszText = TranslateT("Protocol");
			ListView_InsertColumn(hList, 0, &lvCol);

			lvCol.cx = 100;
			lvCol.pszText = TranslateT("Status");
			ListView_InsertColumn(hList, 1, &lvCol);

			lvCol.pszText = TranslateT("Message");
			ListView_InsertColumn(hList, 2, &lvCol);
		}

		// create items
		SetStatusList(hwndDlg);

		EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), FALSE);
		// fill profile combo box
		if (!ServiceExists(MS_SS_GETPROFILE))
			EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILE), FALSE);
		else {
			int defaultProfile;
			int profileCount = (int)CallService(MS_SS_GETPROFILECOUNT, (WPARAM)&defaultProfile, 0);
			for (int i = 0; i < profileCount; i++) {
				TCHAR profileName[128];
				CallService(MS_SS_GETPROFILENAME, i, (LPARAM)profileName);
				int item = SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_ADDSTRING, 0, (LPARAM)profileName);
				SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_SETITEMDATA, item, i);
			}
			if (profileCount == 0)
				EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILE), FALSE);
			else
				SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_SETCURSEL, defaultProfile, 0);
		}
		// start timer
		if (timeOut > 0) {
			TCHAR text[32];
			mir_sntprintf(text, TranslateT("Closing in %d"), timeOut);
			SetDlgItemText(hwndDlg, IDC_CLOSE, text);
			SetTimer(hwndDlg, TIMER_ID, 1000, NULL);
		}
		return TRUE;

	case WM_TIMER:
	{
		TCHAR text[32];
		mir_sntprintf(text, TranslateT("Closing in %d"), timeOut - 1);
		SetDlgItemText(hwndDlg, IDC_CLOSE, text);
		if (timeOut <= 0) {
			KillTimer(hwndDlg, TIMER_ID);
			SendMessage(hwndDlg, UM_CLOSECONFIRMDLG, 0, 0);
		}
		else timeOut--;
	}
	break;

	case WM_COMMAND:
		// stop timer
		KillTimer(hwndDlg, TIMER_ID);
		SetDlgItemText(hwndDlg, IDC_CLOSE, TranslateT("Close"));
		if ((HIWORD(wParam) == CBN_SELCHANGE) || (HIWORD(wParam) == BN_CLICKED) || (HIWORD(wParam) == NM_CLICK)) { // something clicked
			switch (LOWORD(wParam)) {
			case IDC_PROFILE:
			{
				int profile = (int)SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_PROFILE, CB_GETCURSEL, 0, 0), 0);
				for (int i = 0; i < confirmSettings->getCount(); i++)
					if ((*confirmSettings)[i].szMsg != NULL) {
						free((*confirmSettings)[i].szMsg);
						(*confirmSettings)[i].szMsg = NULL;
					}

				CallService(MS_SS_GETPROFILE, (WPARAM)profile, (LPARAM)confirmSettings);
				for (int i = 0; i < confirmSettings->getCount(); i++)
					if ((*confirmSettings)[i].szMsg != NULL) // we free this later, copy to our memory space
						(*confirmSettings)[i].szMsg = _tcsdup((*confirmSettings)[i].szMsg);

				SetStatusList(hwndDlg);
			}
			break;

			case IDC_STATUS:
			{
				LVITEM lvItem = { 0 };
				lvItem.mask = LVIF_TEXT | LVIF_PARAM;
				lvItem.iSubItem = 0;
				lvItem.iItem = ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_STARTUPLIST), -1, LVNI_SELECTED);
				if (lvItem.iItem == -1)
					break;

				ListView_GetItem(GetDlgItem(hwndDlg, IDC_STARTUPLIST), &lvItem);
				PROTOCOLSETTINGEX* proto = (PROTOCOLSETTINGEX*)lvItem.lParam;
				int actualStatus = proto->status = (int)SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_GETCURSEL, 0, 0), 0);

				// LAST STATUS
				if (proto->status == ID_STATUS_LAST) {
					TCHAR last[80];
					mir_sntprintf(last, _T("%s (%s)"), TranslateT("<last>"), pcli->pfnGetStatusModeDescription(proto->lastStatus, 0));
					ListView_SetItemText(GetDlgItem(hwndDlg, IDC_STARTUPLIST), lvItem.iItem, 1, last);
					actualStatus = proto->lastStatus;
				}

				// CURRENT STATUS
				else if (proto->status == ID_STATUS_CURRENT) {
					int currentStatus = CallProtoService(proto->szName, PS_GETSTATUS, 0, 0);
					TCHAR current[80];
					mir_sntprintf(current, _T("%s (%s)"), TranslateT("<current>"), pcli->pfnGetStatusModeDescription(currentStatus, 0));
					ListView_SetItemText(GetDlgItem(hwndDlg, IDC_STARTUPLIST), lvItem.iItem, 1, current);
					actualStatus = currentStatus;
				}
				else ListView_SetItemText(GetDlgItem(hwndDlg, IDC_STARTUPLIST), lvItem.iItem, 1, pcli->pfnGetStatusModeDescription(proto->status, 0));

				if ((!((CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_1, 0)&PF1_MODEMSGSEND)&~PF1_INDIVMODEMSG)) || (!(CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0)&Proto_Status2Flag(actualStatus))))
					EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), FALSE);
				else if ((proto->status == ID_STATUS_LAST) || (proto->status == ID_STATUS_CURRENT))
					EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), TRUE);
				else
					EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), (CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_3, 0)&Proto_Status2Flag(actualStatus)) ? TRUE : FALSE);
				SetStatusList(hwndDlg);
			}
			break;

			case IDC_SETSTSMSG:
			{
				LVITEM lvItem = { 0 };
				lvItem.mask = LVIF_TEXT | LVIF_PARAM;
				lvItem.iSubItem = 0;
				lvItem.iItem = ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_STARTUPLIST), -1, LVNI_SELECTED);
				if (lvItem.iItem == -1)
					break;

				ListView_GetItem(GetDlgItem(hwndDlg, IDC_STARTUPLIST), &lvItem);
				DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_SETSTSMSGDIALOG), hwndDlg, StatusMessageDlgProc, lvItem.lParam);
			}
			break;

			case IDC_CLOSE:
				SendMessage(hwndDlg, UM_CLOSECONFIRMDLG, 0, 0);
				break;

			case IDC_CANCEL:
				DestroyWindow(hwndDlg);
				break;
			}
		}
		break;

	case WM_NOTIFY:
		switch (((NMHDR*)lParam)->idFrom) {
		case IDC_STARTUPLIST:
			if (((NMHDR*)lParam)->code == NM_CLICK) {
				KillTimer(hwndDlg, TIMER_ID);
				SetDlgItemText(hwndDlg, IDC_CLOSE, TranslateT("Close"));

				LVITEM lvItem = { 0 };
				lvItem.mask = LVIF_TEXT | LVIF_PARAM;
				lvItem.iSubItem = 0;
				lvItem.iItem = ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_STARTUPLIST), -1, LVNI_SELECTED);

				if (ListView_GetItem(GetDlgItem(hwndDlg, IDC_STARTUPLIST), &lvItem) == FALSE) {
					SetStatusList(hwndDlg);
					break;
				}

				PROTOCOLSETTINGEX *proto = (PROTOCOLSETTINGEX*)lvItem.lParam;
				int flags = CallProtoService(proto->szName, PS_GETCAPS, PFLAGNUM_2, 0) & ~CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_5, 0);
				// clear box and add new status, loop status and check if compatible with proto
				SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_RESETCONTENT, 0, 0);
				int actualStatus = proto->status;

				// last
				TCHAR buf[100];
				mir_sntprintf(buf, _T("%s (%s)"), TranslateT("<last>"), pcli->pfnGetStatusModeDescription(proto->lastStatus, 0));
				int item = SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_ADDSTRING, 0, (LPARAM)buf);
				SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_SETITEMDATA, item, ID_STATUS_LAST);
				if (proto->status == ID_STATUS_LAST) {
					SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_SETCURSEL, item, 0);
					actualStatus = proto->lastStatus;
				}

				// current
				int currentStatus = CallProtoService(proto->szName, PS_GETSTATUS, 0, 0);
				mir_sntprintf(buf, _T("%s (%s)"), TranslateT("<current>"), pcli->pfnGetStatusModeDescription(currentStatus, 0));
				item = SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_ADDSTRING, 0, (LPARAM)buf);
				SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_SETITEMDATA, item, ID_STATUS_CURRENT);
				if (proto->status == ID_STATUS_CURRENT) {
					SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_SETCURSEL, item, 0);
					actualStatus = currentStatus;
				}

				for (int i = 0; i < _countof(statusModeList); i++) {
					if (((flags & statusModePf2List[i]) || (statusModePf2List[i] == PF2_OFFLINE)) && (!((!(flags)& Proto_Status2Flag(statusModePf2List[i]))) || ((CallProtoService(proto->szName, PS_GETCAPS, (WPARAM)PFLAGNUM_5, 0)&Proto_Status2Flag(statusModePf2List[i]))))) {
						TCHAR *statusMode = pcli->pfnGetStatusModeDescription(statusModeList[i], 0);
						item = SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_ADDSTRING, 0, (LPARAM)statusMode);
						SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_SETITEMDATA, item, statusModeList[i]);
						if (statusModeList[i] == proto->status)
							SendDlgItemMessage(hwndDlg, IDC_STATUS, CB_SETCURSEL, item, 0);
					}
				}

				// enable status box
				EnableWindow(GetDlgItem(hwndDlg, IDC_STATUS), (ListView_GetNextItem(GetDlgItem(hwndDlg, IDC_STARTUPLIST), -1, LVNI_SELECTED) >= 0));
				if ((!((CallProtoService(proto->szName, PS_GETCAPS, PFLAGNUM_1, 0)&PF1_MODEMSGSEND)&~PF1_INDIVMODEMSG)) || (!(CallProtoService(proto->szName, PS_GETCAPS, PFLAGNUM_3, 0)&Proto_Status2Flag(actualStatus))))
					EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), FALSE);
				else if (proto->status == ID_STATUS_LAST || proto->status == ID_STATUS_CURRENT)
					EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), TRUE);
				else
					EnableWindow(GetDlgItem(hwndDlg, IDC_SETSTSMSG), (CallProtoService(proto->szName, PS_GETCAPS, PFLAGNUM_3, 0) & Proto_Status2Flag(actualStatus)) ? TRUE : FALSE);
			}
		}
		break;

	case UM_STSMSGDLGCLOSED:
		SetStatusList(hwndDlg);
		break;

	case UM_CLOSECONFIRMDLG:
		CallService(MS_CS_SETSTATUSEX, (WPARAM)confirmSettings, 0);
		DestroyWindow(hwndDlg);
		break;

	case WM_DESTROY:
		delete confirmSettings; confirmSettings = 0;
		break;
	}

	return 0;
}
Ejemplo n.º 14
0
static VOID
SetAllVars(HWND hwndDlg,
           INT iDlgItem)
{
    HWND hwndListView;
    PVARIABLE_DATA VarData;
    LV_ITEM lvi;
    INT iItem;
    HKEY hKey;
    DWORD dwValueCount;
    DWORD dwMaxValueNameLength;
    LPTSTR *aValueArray;
    DWORD dwNameLength;
    DWORD i;
    TCHAR szBuffer[256];
    LPTSTR lpBuffer;

    memset(&lvi, 0x00, sizeof(lvi));

    /* Get the handle to the list box with all system vars in it */
    hwndListView = GetDlgItem(hwndDlg, iDlgItem);
    /* First item is 0 */
    iItem = 0;
    /* Set up struct to retreive item */
    lvi.mask = LVIF_PARAM;
    lvi.iItem = iItem;

    /* Open or create the key */
    if (RegCreateKeyEx((iDlgItem == IDC_SYSTEM_VARIABLE_LIST ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER),
                       (iDlgItem == IDC_SYSTEM_VARIABLE_LIST ? _T("SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment") : _T("Environment")),
                       0,
                       NULL,
                       REG_OPTION_NON_VOLATILE,
                       KEY_WRITE | KEY_READ,
                       NULL,
                       &hKey,
                       NULL))
    {
        return;
    }

    /* Get the number of values and the maximum value name length */
    if (RegQueryInfoKey(hKey,
                        NULL,
                        NULL,
                        NULL,
                        NULL,
                        NULL,
                        NULL,
                        &dwValueCount,
                        &dwMaxValueNameLength,
                        NULL,
                        NULL,
                        NULL))
    {
        RegCloseKey(hKey);
        return;
    }

    if (dwValueCount > 0)
    {
        /* Allocate the value array */
        aValueArray = GlobalAlloc(GPTR, dwValueCount * sizeof(LPTSTR));
        if (aValueArray != NULL)
        {
            /* Get all value names */
            for (i = 0; i < dwValueCount; i++)
            {
                dwNameLength = 256;
                if (!RegEnumValue(hKey,
                                  i,
                                  szBuffer,
                                  &dwNameLength,
                                  NULL,
                                  NULL,
                                  NULL,
                                  NULL))
                {
                    /* Allocate a value name buffer, fill it and attach it to the array */
                    lpBuffer = (LPTSTR)GlobalAlloc(GPTR, (dwNameLength + 1) * sizeof(TCHAR));
                    if (lpBuffer != NULL)
                    {
                        _tcscpy(lpBuffer, szBuffer);
                        aValueArray[i] = lpBuffer;
                    }
                }
            }

            /* Delete all values */
            for (i = 0; i < dwValueCount; i++)
            {
                if (aValueArray[i] != NULL)
                {
                    /* Delete the value */
                    RegDeleteValue(hKey,
                                   aValueArray[i]);

                    /* Free the value name */
                    GlobalFree(aValueArray[i]);
                }
            }

            /* Free the value array */
            GlobalFree(aValueArray);
        }
    }

    /* Loop through all variables */
    while (ListView_GetItem(hwndListView, &lvi))
    {
        /* Get the data in each item */
        VarData = (PVARIABLE_DATA)lvi.lParam;
        if (VarData != NULL)
        {
            /* Set the new value */
            if (RegSetValueEx(hKey,
                              VarData->lpName,
                              0,
                              VarData->dwType,
                              (LPBYTE)VarData->lpRawValue,
                              (DWORD)(_tcslen(VarData->lpRawValue) + 1) * sizeof(TCHAR)))
            {
                RegCloseKey(hKey);
                return;
            }
        }

        /* Fill struct for next item */
        lvi.mask = LVIF_PARAM;
        lvi.iItem = ++iItem;
    }

    RegCloseKey(hKey);
}
Ejemplo n.º 15
0
/*
================
rvOpenFileDialog::DlgProc

Dialog Procedure for the open file dialog
================
*/
INT_PTR rvOpenFileDialog::DlgProc(HWND wnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
	rvOpenFileDialog *dlg = (rvOpenFileDialog *) GetWindowLong(wnd, GWL_USERDATA);

	switch (msg) {
		case WM_INITDIALOG:
			dlg = (rvOpenFileDialog *) lparam;
			SetWindowLong(wnd, GWL_USERDATA, lparam);
			dlg->mWnd = wnd;
			dlg->HandleInitDialog();
			return TRUE;

		case WM_NOTIFY: {
			NMHDR *nm = (NMHDR *) lparam;

			switch (nm->idFrom) {
				case IDC_TOOLS_FILELIST:

					switch (nm->code) {
						case LVN_ITEMCHANGED: {
							NMLISTVIEW *nmlv = (NMLISTVIEW *)nm;

							if (nmlv->uNewState & LVIS_SELECTED) {
								// Get the currently selected item
								LVITEM item;
								char   temp[256];
								item.mask = LVIF_IMAGE|LVIF_TEXT;
								item.iSubItem = 0;
								item.pszText = temp;
								item.cchTextMax = sizeof(temp)-1;
								item.iItem = nmlv->iItem;
								ListView_GetItem(dlg->mWndFileList, &item);

								if (item.iImage == 2) {
									SetWindowText(GetDlgItem(wnd, IDC_TOOLS_FILENAME), temp);
								}
							}

							break;
						}

						case NM_DBLCLK:
							dlg->HandleCommandOK();
							break;
					}

					break;
			}

			break;
		}

		case WM_COMMAND:

			switch (LOWORD(wparam)) {
				case IDOK: {
					dlg->HandleCommandOK();
					break;
				}

				case IDCANCEL:
					EndDialog(wnd, 0);
					break;

				case IDC_TOOLS_BACK: {
					int sel = SendMessage(GetDlgItem(wnd, IDC_TOOLS_LOOKIN), CB_GETCURSEL, 0, 0);

					if (sel > 0) {
						sel--;
						SendMessage(GetDlgItem(wnd, IDC_TOOLS_LOOKIN), CB_SETCURSEL, sel, 0);
						dlg->HandleLookInChange();
					}

					break;
				}

				case IDC_TOOLS_LOOKIN:

					if (HIWORD(wparam) == CBN_SELCHANGE) {
						dlg->HandleLookInChange();
					}

					break;
			}

			break;
	}

	return FALSE;
}
Ejemplo n.º 16
0
void CDebugTlb::RefreshTLBWindow(void)
{
    if (m_hWnd == NULL)
    {
        return;
    }

    HWND hList = GetDlgItem(IDC_LIST);
    char Output[100], OldText[100];
    LV_ITEM item, OldItem;
    int count;

    CTLB::TLB_ENTRY * tlb = g_TLB->m_tlb;
    for (count = 0; count < 32; count++)
    {
        sprintf(Output, "0x%02X", count);
        item.mask = LVIF_TEXT;
        item.iItem = count;
        item.pszText = Output;
        item.iSubItem = 0;

        OldItem.mask = LVIF_TEXT;
        OldItem.iItem = count;
        OldItem.pszText = OldText;
        OldItem.cchTextMax = sizeof(OldText) - 1;
        OldItem.iSubItem = 0;

        if (ListView_GetItemCount(hList) <= count)
        {
            ListView_InsertItem(hList, &item);
        }
        else
        {
            ListView_GetItem(hList, &OldItem);
            if (strcmp(item.pszText, OldItem.pszText) != 0)
            {
                ListView_SetItem(hList, &item);
            }
        }
        if (tlb[count].EntryDefined)
        {
            sprintf(Output, "0x%08X", tlb[count].PageMask.Value);
        }
        else
        {
            strcpy(Output, "................");
        }
        item.iSubItem = 1;
        OldItem.iSubItem = 1;
        ListView_GetItem(hList, &OldItem);
        if (strcmp(item.pszText, OldItem.pszText) != 0)
        {
            ListView_SetItem(hList, &item);
        }

        if (tlb[count].EntryDefined)
        {
            sprintf(Output, "0x%08X", tlb[count].EntryHi.Value);
        }
        else
        {
            strcpy(Output, "................");
        }
        item.iSubItem = 2;
        OldItem.iSubItem = 2;
        ListView_GetItem(hList, &OldItem);
        if (strcmp(item.pszText, OldItem.pszText) != 0)
        {
            ListView_SetItem(hList, &item);
        }

        if (tlb[count].EntryDefined)
        {
            sprintf(Output, "0x%08X", tlb[count].EntryLo0.Value);
        }
        else
        {
            strcpy(Output, "................");
        }
        item.iSubItem = 3;
        OldItem.iSubItem = 3;
        ListView_GetItem(hList, &OldItem);
        if (strcmp(item.pszText, OldItem.pszText) != 0)
        {
            ListView_SetItem(hList, &item);
        }

        if (tlb[count].EntryDefined)
        {
            sprintf(Output, "0x%08X", tlb[count].EntryLo1.Value);
        }
        else
        {
            strcpy(Output, "................");
        }
        item.iSubItem = 4;
        OldItem.iSubItem = 4;
        ListView_GetItem(hList, &OldItem);
        if (strcmp(item.pszText, OldItem.pszText) != 0)
        {
            ListView_SetItem(hList, &item);
        }
    }

    CTLB::FASTTLB   * FastTlb = g_TLB->m_FastTlb;
    hList = GetDlgItem(IDC_LIST2);
    for (count = 0; count < 64; count++)
    {
        sprintf(Output, "0x%02X", count);
        item.mask = LVIF_TEXT;
        item.iItem = count;
        item.pszText = Output;
        item.iSubItem = 0;

        OldItem.mask = LVIF_TEXT;
        OldItem.iItem = count;
        OldItem.pszText = OldText;
        OldItem.cchTextMax = sizeof(OldText) - 1;
        OldItem.iSubItem = 0;

        if (ListView_GetItemCount(hList) <= count)
        {
            item.iItem = ListView_InsertItem(hList, &item);
        }
        else
        {
            ListView_GetItem(hList, &OldItem);
            if (strcmp(item.pszText, OldItem.pszText) != 0)
            {
                ListView_SetItem(hList, &item);
            }
        }

        if (FastTlb[count].ValidEntry)
        {
            sprintf(Output, "%s", FastTlb[count].VALID ? "Yes" : "No");
        }
        else
        {
            strcpy(Output, "................");
        }
        item.iSubItem = 1;
        OldItem.iSubItem = 1;
        ListView_GetItem(hList, &OldItem);
        if (strcmp(item.pszText, OldItem.pszText) != 0)
        {
            ListView_SetItem(hList, &item);
        }

        if (FastTlb[count].ValidEntry && FastTlb[count].VALID)
        {
            sprintf(Output, "%s", FastTlb[count].DIRTY ? "Yes" : "No");
        }
        else
        {
            strcpy(Output, "................");
        }
        item.iSubItem = 2;
        OldItem.iSubItem = 2;
        ListView_GetItem(hList, &OldItem);
        if (strcmp(item.pszText, OldItem.pszText) != 0)
        {
            ListView_SetItem(hList, &item);
        }

        if (FastTlb[count].ValidEntry && FastTlb[count].VALID)
        {
            sprintf(Output, "%08X:%08X -> %08X:%08X", FastTlb[count].VSTART, FastTlb[count].VEND,
                FastTlb[count].PHYSSTART, FastTlb[count].PHYSEND);
        }
        else
        {
            strcpy(Output, "................");
        }
        item.iSubItem = 3;
        OldItem.iSubItem = 3;
        ListView_GetItem(hList, &OldItem);
        if (strcmp(item.pszText, OldItem.pszText) != 0)
        {
            ListView_SetItem(hList, &item);
        }
    }
}
Ejemplo n.º 17
0
LRESULT CALLBACK wppnlPoleCentDane(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	switch (uMsg) {

	case WM_COMMAND: {
		if (!Okno->Zdarzenia) break;

		if ((HWND)lParam == Okno->btnPoleCentDodaj) {
			StanProgramu->Zapisany = false;
			int id = Okno->DodajCialo(0, 0, 0, Okno->OstPromien);
			Okno->ZaznaczCialo(id);
			SetFocus(Okno->wndMain);
			RysujCiala();
		}

		return 0;
	}

	case WM_NOTIFY: {
		if (!Okno->Zdarzenia) break;

		NMHDR* n = (NMHDR*)lParam;

		if (n->code == NM_CLICK){
			NMITEMACTIVATE* ia = (NMITEMACTIVATE*)lParam;
			if (ia->iItem == -1) {
				Okno->ZaznaczCialo(-1);
				RysujCiala();
				return 0;
			}

			char*t = new char[DLUGOSC_TEKSTU];

			LVITEM lvi = {};
			lvi.iItem = ia->iItem;
			lvi.iSubItem = 0;
			lvi.pszText = t;
			lvi.cchTextMax = DLUGOSC_TEKSTU;
			lvi.mask = LVIF_TEXT;
			ListView_GetItem(Okno->lvCiala, &lvi);
			int id = 0;
			idtoi(id, lvi.pszText);
			id--;
			Okno->ZaznaczCialo(id);

			delete[] t;

			RysujCiala();
			
			return 0;
		}

		break;

	}

	case WM_VSCROLL: {

		SCROLLINFO si;
		ZeroMemory(&si, sizeof(si));
		si.cbSize = sizeof(SCROLLINFO);
		si.fMask = SIF_POS | SIF_PAGE | SIF_TRACKPOS;
		GetScrollInfo(Okno->vscPoleCentPrzewin, SB_CTL, &si);

		int pozycja = si.nPos;

		switch (LOWORD(wParam)) {
		case SB_TOP:
			pozycja = 0;
			break;
		case SB_BOTTOM:
			pozycja = Okno->KARTA_POLECENTPRZEWIN_ORYG_WYS;
			break;
		case SB_LINEUP:
			if (pozycja > 0) {
				pozycja--;
			}
			break;
		case SB_LINEDOWN:
			if (pozycja < (Okno->KARTA_POLECENTPRZEWIN_ORYG_WYS - Okno->KARTA_POLECENTPRZEWIN_WYS)) {
				pozycja++;
			}
			break;
		case SB_PAGEUP:
			pozycja -= si.nPage;
			if (pozycja < 0) {
				pozycja = 0;
			}
			break;
		case SB_PAGEDOWN:
			pozycja += si.nPage;
			if (pozycja > Okno->KARTA_POLECENTPRZEWIN_ORYG_WYS) {
				pozycja = Okno->KARTA_POLECENTPRZEWIN_ORYG_WYS;
			}
			break;
		case SB_THUMBPOSITION:
			pozycja = si.nTrackPos;
			break;
		case SB_THUMBTRACK:
			pozycja = si.nTrackPos;
			break;
		}

		int dy = -(pozycja - si.nPos);
		ScrollWindowEx(Okno->pnlPoleCentPrzewin, 0, dy, (CONST RECT *) NULL, (CONST RECT *) NULL, (HRGN)NULL, (LPRECT)NULL, SW_SCROLLCHILDREN | SW_INVALIDATE | SW_ERASE);
		UpdateWindow(Okno->pnlPoleCentPrzewin);

		ZeroMemory(&si, sizeof(si));
		si.cbSize = sizeof(SCROLLINFO);
		si.fMask = SIF_POS;
		si.nPos = pozycja;

		SetScrollInfo(Okno->vscPoleCentPrzewin, SB_CTL, &si, TRUE);
		return 0;
	}
	}
	return CallWindowProc(Okno->wpopnlPoleCentDane, hwnd, uMsg, wParam, lParam);
}
Ejemplo n.º 18
0
/*
 *	callback function for tab 3 options page
 */
INT_PTR CALLBACK DlgProcOpts_Tab3(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) {

	switch ( msg ) {
	case WM_INITDIALOG:
	{
		//executed once during init of each tab, on each enter to miranda options

		mirfoxMiranda.getMirfoxData().setTab3OptionsState(MFENUM_OPTIONS_INIT);

		TranslateDialogDefault(hwndDlg);

		//protocol list initialization
		HWND hAccountsList = GetDlgItem(hwndDlg, IDC3_PROTOCOLS_LIST);

		ListView_SetExtendedListViewStyleEx(hAccountsList, LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES, LVS_EX_FULLROWSELECT|LVS_EX_CHECKBOXES);

		LVCOLUMN lvCol = {0};
		lvCol.mask = LVCF_WIDTH|LVCF_TEXT;
		lvCol.pszText=TranslateT("Protocol");
		lvCol.cx = 260;	//column width
		ListView_InsertColumn(hAccountsList, 0, &lvCol);

		LVITEM lvItem = {0};
		lvItem.mask=LVIF_TEXT|LVIF_PARAM;
		lvItem.iItem=0;
		lvItem.iSubItem=0;

		//get accounts data from mirfoxData
		boost::ptr_list<MirandaAccount> * mirandaAccountsPtr = mirfoxMiranda.getMirfoxData().getMirandaAccounts();
		boost::ptr_list<MirandaAccount>::iterator mirandaAccountsIter;
		for (mirandaAccountsIter = mirandaAccountsPtr->begin(); mirandaAccountsIter != mirandaAccountsPtr->end(); mirandaAccountsIter++){

			lvItem.pszText = mirandaAccountsIter->tszAccountName;
			//http://www.experts-exchange.com/Programming/Languages/CPP/Q_20175412.html - must duplicate string
			lvItem.lParam = (LPARAM)_strdup(mirandaAccountsIter->szModuleName);
			ListView_InsertItem(hAccountsList,&lvItem);//winapi function

			MFENUM_MIRANDAACCOUNT_STATE accountState = mirandaAccountsIter->accountState;
			if (accountState == MFENUM_MIRANDAACCOUNT_STATE_ON){
				ListView_SetCheckState(hAccountsList, lvItem.iItem, 1 );
			} else {
				ListView_SetCheckState(hAccountsList, lvItem.iItem, 0 );
			}

			lvItem.iItem++;
		}
	    //protocol list initialization - end

		mirfoxMiranda.getMirfoxData().setTab3OptionsState(MFENUM_OPTIONS_WORK);
		return FALSE;

	}
	case WM_COMMAND:
	{
		if (mirfoxMiranda.getMirfoxData().getTab3OptionsState() != MFENUM_OPTIONS_WORK){
			break; //options not inited yet
		}

		break;
	}
	case WM_NOTIFY:
	{

		//executed on each change tab at options or after [OK]

		if (mirfoxMiranda.getMirfoxData().getTab3OptionsState() != MFENUM_OPTIONS_WORK){
			break; //options not inited yet
		}


		if (((NMHDR*)lParam)->idFrom == IDC3_PROTOCOLS_LIST) {
			if (((NMHDR*)lParam)->code== LVN_ITEMCHANGED) {
				NMLISTVIEW *nmlv = (NMLISTVIEW *)lParam;
				if (/*IsWindowVisible(GetDlgItem(hwndDlg,IDC_PROTOCOLLIST)) && */ ((nmlv->uNewState ^ nmlv->uOldState) & LVIS_STATEIMAGEMASK)) {
					SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
				}
			}
		}

		if (((LPNMHDR)lParam)->idFrom == 0 &&
			((LPNMHDR)lParam)->code == PSN_APPLY
		){
			//SaveOptions from tab3 mirfoxData to miranda database
			HWND hList = GetDlgItem(hwndDlg, IDC3_PROTOCOLS_LIST);
			LVITEM lvItem = {0};
			lvItem.mask = LVIF_PARAM;
			for (int i=0; i<ListView_GetItemCount(hList); i++) {

				lvItem.iItem = i;
				lvItem.iSubItem = 0;
				ListView_GetItem(hList, &lvItem);

				char * accountId ((char *)lvItem.lParam);
				BYTE accountStateB = (BYTE)ListView_GetCheckState(hList, lvItem.iItem);

				MFENUM_MIRANDAACCOUNT_STATE accountState;
				if (accountStateB == 0){
					accountState = MFENUM_MIRANDAACCOUNT_STATE_OFF;
				} else if (accountStateB == 1){
					accountState = MFENUM_MIRANDAACCOUNT_STATE_ON;
				} else {
					//todo errors handling
					accountState = MFENUM_MIRANDAACCOUNT_STATE_ON;
				}

				//save to mirfoxData
				int result = mirfoxMiranda.getMirfoxData().updateMirandaAccountState(accountId, accountState);
				if (result != 0){
					//todo errors handling
				}

				//save to db	1 - on, 2 - off
				std::string mirandaAccountDBKey("ACCOUNTSTATE_");
				mirandaAccountDBKey += accountId;
				if (accountState == MFENUM_MIRANDAACCOUNT_STATE_OFF){
					db_set_b(0, PLUGIN_DB_ID, mirandaAccountDBKey.c_str(), 2);
				} else {
					db_set_b(0, PLUGIN_DB_ID, mirandaAccountDBKey.c_str(), 1);
				}


			} //end for

		}

		break;

	}
	case WM_DESTROY:
		break;
	}

	return 0;

}
BOOL CALLBACK VerticalFileSwitcher::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message)
    {
        case WM_INITDIALOG :
        {
			_fileListView.init(_hInst, _hSelf, _hImaLst);
			_fileListView.initList();
			_fileListView.display();

            return TRUE;
        }

		case WM_NOTIFY:
		{
			switch (((LPNMHDR)lParam)->code)
			{
				case NM_DBLCLK:
				{
					LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam;
					int i = lpnmitem->iItem;
					if (i == -1)
					{
						::SendMessage(_hParent, WM_COMMAND, IDM_FILE_NEW, 0);
					}
					return TRUE;
				}

				case NM_CLICK:
				{
					if ((0x80 & GetKeyState(VK_CONTROL)) || (0x80 & GetKeyState(VK_SHIFT)))
						return TRUE;

					LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam;
					int nbItem = ListView_GetItemCount(_fileListView.getHSelf());
					int i = lpnmitem->iItem;
					if (i == -1 || i >= nbItem)
						return TRUE;

					LVITEM item;
					item.mask = LVIF_PARAM;
					item.iItem = i;	
					ListView_GetItem(((LPNMHDR)lParam)->hwndFrom, &item);
					TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam;

					activateDoc(tlfs);
					return TRUE;
				}

				case NM_RCLICK :
				{
					// Switch to the right document
					LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam;
					int nbItem = ListView_GetItemCount(_fileListView.getHSelf());

					if (nbSelectedFiles() == 1)
					{
						int i = lpnmitem->iItem;
						if (i == -1 || i >= nbItem)
 							return TRUE;

						LVITEM item;
						item.mask = LVIF_PARAM;
						item.iItem = i;	
						ListView_GetItem(((LPNMHDR)lParam)->hwndFrom, &item);
						TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam;

						activateDoc(tlfs);
					}
					// Redirect NM_RCLICK message to Notepad_plus handle
					NMHDR	nmhdr;
					nmhdr.code = NM_RCLICK;
					nmhdr.hwndFrom = _hSelf;
					nmhdr.idFrom = ::GetDlgCtrlID(nmhdr.hwndFrom);
					::SendMessage(_hParent, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr);
					return TRUE;
				}

				case LVN_GETINFOTIP:
				{
					LPNMLVGETINFOTIP pGetInfoTip = (LPNMLVGETINFOTIP)lParam;
					int i = pGetInfoTip->iItem;
					if (i == -1)
						return TRUE;
					generic_string fn = getFullFilePath((size_t)i);
					lstrcpyn(pGetInfoTip->pszText, fn.c_str(), pGetInfoTip->cchTextMax);
					return TRUE;
				}

				case LVN_COLUMNCLICK:
				{
					LPNMLISTVIEW pnmLV = (LPNMLISTVIEW)lParam;
					setHeaderOrder(pnmLV);
					ListView_SortItemsEx(pnmLV->hdr.hwndFrom, ListViewCompareProc,(LPARAM)pnmLV);
					return TRUE;
				}
				case LVN_KEYDOWN:
				{
					switch (((LPNMLVKEYDOWN)lParam)->wVKey)
					{
						case VK_RETURN:
						{
							int i = ListView_GetSelectionMark(_fileListView.getHSelf());
							if (i == -1)
								return TRUE;

							LVITEM item;
							item.mask = LVIF_PARAM;
							item.iItem = i;	
							ListView_GetItem(((LPNMHDR)lParam)->hwndFrom, &item);
							TaskLstFnStatus *tlfs = (TaskLstFnStatus *)item.lParam;
							activateDoc(tlfs);
							return TRUE;
						}
						default:
							break;
					}
				}
				break;

				default:
					break;
			}
		}
		return TRUE;

        case WM_SIZE:
        {
            int width = LOWORD(lParam);
            int height = HIWORD(lParam);
			::MoveWindow(_fileListView.getHSelf(), 0, 0, width, height, TRUE);
			_fileListView.resizeColumns(width);
            break;
        }
        
		case WM_DESTROY:
        {
			_fileListView.destroy();
            break;
        }

        default :
            return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
    }
	return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
}
Ejemplo n.º 20
0
void FileDialog::FilterFiles(HWND hDlg)
{
   HWND parent = ::GetParent(hDlg);
   IShellFolder *ishell = NULL;
   LPMALLOC imalloc = NULL;
   HRESULT hr;
   
   // Get pointer to the ListView control
   HWND lv = ::GetDlgItem(::GetDlgItem(parent, lst2), 1);
   if (lv == NULL)
   {
      wxASSERT(lv != NULL);
      return;
   }
   
   // Get shell's memory allocation interface (must be Release()'d)
   hr = SHGetMalloc(&imalloc);
   if ((hr != NOERROR) || (imalloc == NULL))
   {
      wxASSERT((hr == NOERROR) && (imalloc != NULL));
      return;
   }
   
   // Init
   LVITEM lvi;
   wxZeroMemory(lvi);
   
   // Process all items
   int fltcnt = m_Filters.GetCount();
   int itmcnt = ::SendMessage(lv, LVM_GETITEMCOUNT, 0, 0);
   for (int itm = 0; itm < itmcnt; itm++)
   {
      // Retrieve the file IDL
      lvi.iItem = itm;
      lvi.mask = LVIF_PARAM;
      if (ListView_GetItem(lv, &lvi) != TRUE)
      {
         wxASSERT(FALSE);
         break;
      }
      LPCITEMIDLIST fidl = (LPCITEMIDLIST) lvi.lParam;
      
      // Retrieve the IShellFolder interface of the parent (must be Release()'d)
      if (ishell == NULL)
      {
         hr = SHBindToParent(fidl, IID_IShellFolder, (void **)&ishell, NULL);
         if (!SUCCEEDED(hr))
         {
            wxASSERT(SUCCEEDED(hr));
            break;
         }
      }
      
      // Get the attributes of the object
      DWORD attr = SFGAO_FOLDER | SFGAO_STREAM;
      hr = ishell->GetAttributesOf(1, &fidl, &attr);
      if (!SUCCEEDED(hr))
      {
         wxASSERT(SUCCEEDED(hr));
         break;
      }
      
      // Allow all folders (things like zip files get filtered below)
      if (attr == SFGAO_FOLDER)
      {
         continue;
      }
      
      // Retrieve the parsable name of the object (includes extension)
      STRRET str;
      hr = ishell->GetDisplayNameOf(fidl, SHGDN_INFOLDER | SHGDN_FORPARSING, &str);
      if (hr != NOERROR)
      {
         // For some objects, we get back an error of 80070057.  I'm assuming this
         // means there is no way to represent the name (like some sort of virtual name)
         // or I've not used the correct PIDL.  But, in either case, it "probably"
         // represents some sort of folder (at least in all cases I've seen), so we
         // simply allow it to display.
         continue;
      }
      
      // Convert result to wxString
      wxString filename;
      switch (str.uType)
      {
         case STRRET_WSTR:
            filename = str.pOleStr;
            imalloc->Free(str.pOleStr);
            break;
            
         case STRRET_OFFSET:
            filename = wxString(((char *)fidl) + str.uOffset, wxConvISO8859_1);
            break;
            
         case STRRET_CSTR:
            filename = wxString(str.cStr, wxConvISO8859_1);
            break;
      }
      
      // Attempt to match it to all of our filters
      bool match = false;
      for (int flt = 0; flt < fltcnt; flt++)
      {
         if (wxMatchWild(m_Filters[flt], filename, false))
         {
            match = true;
            break;
         }
      }
      
      // Remove it from the display if it didn't match any of the filters.
      if (!match)
      {
         ListView_DeleteItem(lv, itm);
         itm--;
         itmcnt--;
      }
   }
   
done:
   
   // Release the interface
   if (ishell)
   {
      ishell->Release();
   }
   
   // Release the interface
   if (imalloc)
   {
      imalloc->Release();
   }
}
/*
 * Modifies the attributes of an item currently in the listview.
 */
void CFolderView::ModifyItemInternal(TCHAR *FileName)
{
	HANDLE			hFirstFile;
	ULARGE_INTEGER	ulFileSize;
	LVITEM			lvItem;
	TCHAR			FullFileName[MAX_PATH];
	BOOL			bFolder;
	BOOL			res;
	int				iItem;
	int				iItemInternal = -1;

	iItem = LocateFileItemIndex(FileName);

	/* Although an item may not have been added to the listview
	yet, it is critical that its' size still be updated if
	neccesary.
	It is possible (and quite likely) that the file add and
	modified messages will be sent in the same group, meaning
	that when the modification message is processed, the item
	is not in the listview, but it still needs to be updated.
	Therefore, instead of searching for items soley in the
	listview, also look through the list of pending file
	additions. */

	if(iItem == -1)
	{
		/* The item doesn't exist in the listview. This can
		happen when a file has been created with a non-zero
		size, but an item has not yet been inserted into
		the listview.
		Search through the list of items waiting to be
		inserted, so that files the have just been created
		can be updated without them residing within the
		listview. */
		list<AwaitingAdd_t>::iterator itr;

		for(itr = m_AwaitingAddList.begin();itr!= m_AwaitingAddList.end();itr++)
		{
			if(lstrcmp(m_pwfdFiles[itr->iItemInternal].cFileName,FileName) == 0)
			{
				iItemInternal = itr->iItemInternal;
				break;
			}
		}
	}
	else
	{
		/* The item exists in the listview. Determine its
		internal index from its listview information. */
		lvItem.mask		= LVIF_PARAM;
		lvItem.iItem	= iItem;
		lvItem.iSubItem	= 0;
		res = ListView_GetItem(m_hListView,&lvItem);

		if(res != FALSE)
			iItemInternal = (int)lvItem.lParam;
	}

	if(iItemInternal != -1)
	{
		/* Is this item a folder? */
		bFolder = (m_pwfdFiles[iItemInternal].dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ==
			FILE_ATTRIBUTE_DIRECTORY;

		ulFileSize.LowPart = m_pwfdFiles[iItemInternal].nFileSizeLow;
		ulFileSize.HighPart = m_pwfdFiles[iItemInternal].nFileSizeHigh;

		m_ulTotalDirSize.QuadPart -= ulFileSize.QuadPart;

		if(ListView_GetItemState(m_hListView,iItem,LVIS_SELECTED)
		== LVIS_SELECTED)
		{
			ulFileSize.LowPart = m_pwfdFiles[iItemInternal].nFileSizeLow;
			ulFileSize.HighPart = m_pwfdFiles[iItemInternal].nFileSizeHigh;

			m_ulFileSelectionSize.QuadPart -= ulFileSize.QuadPart;
		}

		StringCchCopy(FullFileName,SIZEOF_ARRAY(FullFileName),m_CurDir);
		PathAppend(FullFileName,FileName);

		hFirstFile = FindFirstFile(FullFileName,&m_pwfdFiles[iItemInternal]);

		if(hFirstFile != INVALID_HANDLE_VALUE)
		{
			ulFileSize.LowPart = m_pwfdFiles[iItemInternal].nFileSizeLow;
			ulFileSize.HighPart = m_pwfdFiles[iItemInternal].nFileSizeHigh;

			m_ulTotalDirSize.QuadPart += ulFileSize.QuadPart;

			if(ListView_GetItemState(m_hListView,iItem,LVIS_SELECTED)
				== LVIS_SELECTED)
			{
				ulFileSize.LowPart = m_pwfdFiles[iItemInternal].nFileSizeLow;
				ulFileSize.HighPart = m_pwfdFiles[iItemInternal].nFileSizeHigh;

				m_ulFileSelectionSize.QuadPart += ulFileSize.QuadPart;
			}

			if((m_pwfdFiles[iItemInternal].dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) ==
				FILE_ATTRIBUTE_HIDDEN)
			{
				ListView_SetItemState(m_hListView,iItem,LVIS_CUT,LVIS_CUT);
			}
			else
				ListView_SetItemState(m_hListView,iItem,0,LVIS_CUT);

			if(m_ViewMode == VM_DETAILS)
			{
				list<Column_t>::iterator itrColumn;
				int iColumnIndex = 0;

				if(m_pActiveColumnList != NULL)
				{
					for(itrColumn = m_pActiveColumnList->begin();itrColumn != m_pActiveColumnList->end();itrColumn++)
					{
						if(itrColumn->bChecked)
						{
							SetColumnData(itrColumn->id,iItem,iColumnIndex++);
						}
					}
				}
			}

			FindClose(hFirstFile);
		}
		else
		{
			/* The file may not exist if, for example, it was
			renamed just after a file with the same name was
			deleted. If this does happen, a modification
			message will likely be sent out after the file
			has been renamed, indicating the new items properties.
			However, the files' size will be subtracted on
			modification. If the internal structures still hold
			the old size, the total directory size will become
			corrupted. */
			m_pwfdFiles[iItemInternal].nFileSizeLow		= 0;
			m_pwfdFiles[iItemInternal].nFileSizeHigh	= 0;
		}
	}
}
Ejemplo n.º 22
0
LRESULT CALLBACK PropsProc(HWND hwnd, UINT iMessage, WPARAM wParam,
    LPARAM lParam)
{
    NM_TREEVIEW *nm;
    RECT rs;
    LVHITTESTINFO_x hittest;
    switch (iMessage)
    {
        case WM_NOTIFY:
            nm = (NM_TREEVIEW*)lParam;
            switch (nm->hdr.code)
            {
                case LVN_GETDISPINFO:
                {
                    LV_DISPINFO *plvdi = (LV_DISPINFO*)lParam;
                    plvdi->item.mask |= LVIF_TEXT | LVIF_DI_SETITEM;
                    plvdi->item.mask &= ~LVIF_IMAGE;
                    switch (plvdi->item.iSubItem)
                    {
                    case 1:
                        if (currentPropertyFuncs)
                        {
                            char buf[256];
                            LV_ITEM item;
                            memset(&item, 0, sizeof(item));
                            item.iItem = plvdi->item.iItem;
                            item.mask = LVIF_PARAM;
                            ListView_GetItem(lvwindow, &item);
                            currentPropertyFuncs->getText(buf, lvwindow, currentPropertyData, item.lParam);
                            plvdi->item.pszText = buf;
                        }
                        else
                        {
                            plvdi->item.pszText = "";
                        }
                        break;
                    default:
                        break;
                    }
                }
                case NM_CUSTOMDRAW:
                    return CustomDraw(hwnd, (LPNMLVCUSTOMDRAW)lParam);
                case NM_CLICK:
                    GetCursorPos(&hittest.pt);
                    ScreenToClient(lvwindow, &hittest.pt);
                    if (currentPropertyWindow)
                    {
//                        PostMessage(hwnd, WM_KILLPROPSEDITOR, 0, 0);
                    }
                    else
                    {
                        ListView_SubItemHitTest(lvwindow, &hittest);
                        if (hittest.flags & LVHT_ONITEM)
                        {
                            if (hittest.iSubItem == 1)
                            {
                                RECT r;
                                LV_ITEM item;
                                memset(&item, 0, sizeof(item));
                                item.iItem = hittest.iItem;
                                item.mask = LVIF_PARAM;
                                ListView_GetItem(lvwindow, &item);
                                currentPropertyRow = item.lParam;
                                currentPropertyWindow = currentPropertyFuncs->startEdit(lvwindow, 
                                                                                        currentPropertyRow,
                                                                                        currentPropertyData);
                                if (currentPropertyWindow)
                                {
                                    SendMessage(currentPropertyWindow, WM_SETFONT, SendMessage(lvwindow, WM_GETFONT, 0, 0), 0);
                                    ListView_GetSubItemRect(lvwindow,hittest.iItem, 1, LVIR_BOUNDS, &r);
                                    SetWindowPos(currentPropertyWindow, NULL,
                                                 r.left, r.top, r.right- r.left, r.bottom - r.top,
                                                 SWP_NOZORDER | SWP_SHOWWINDOW);
                                    SetFocus(currentPropertyWindow);
                                    // well it might not be an edit window in which case this should be ignored
                                    SendMessage(currentPropertyWindow, EM_SETSEL, 0, -1);
                                    // well it might not be a combo box in which case this should be ignored
                                    SendMessage(currentPropertyWindow, CB_SHOWDROPDOWN, 1, 0);
                                }
                            }
                        }
                    }
                    break;
                case NM_DBLCLK:
                    GetCursorPos(&hittest.pt);
                    ScreenToClient(lvwindow, &hittest.pt);
                    return 0;
                case NM_RCLICK:
                    GetCursorPos(&hittest.pt);
                    ScreenToClient(lvwindow, &hittest.pt);
                    break;
            }
            break;
        case WM_KILLPROPSEDITOR:
            if (currentPropertyFuncs)
            {
                currentPropertyFuncs->finishEdit(lvwindow, currentPropertyRow, currentPropertyWindow, currentPropertyData);
                currentPropertyWindow = NULL;
            }
            break;
        case WM_CREATE:
            GetClientRect(hwnd, &rs);
            lvwindow = CreateWindowEx(0, WC_LISTVIEW, "", WS_VISIBLE |
                WS_CHILD | LVS_REPORT | LVS_SINGLESEL,
                0, 0, rs.right, rs.bottom, hwnd, (HMENU)ID_TREEVIEW,
                hInstance, NULL);
            font = CreateFontIndirect(&fontdata);
            SetListViewColumns();
            break;
        case WM_SIZE:
            MoveWindow(lvwindow, 0, 0, LOWORD(lParam), HIWORD(lParam), 0);
            ResizeListViewColumns();
            break;
        case WM_DESTROY:
//            ReleasePropInfo();
            DestroyWindow(lvwindow);
            break;
    }
    return DefWindowProc(hwnd, iMessage, wParam, lParam);
}
Ejemplo n.º 23
0
static void sttFillJidList(HWND hwndDlg)
{
	JABBER_MUC_JIDLIST_INFO *jidListInfo;
	HXML iqNode, queryNode;
	const TCHAR* from, *jid, *reason, *nick;
	LVITEM lvi;
	HWND hwndList;
	int count, i;

	TCHAR *filter = NULL;
	if (GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_FILTER), GWLP_USERDATA))
	{
		int filterLength = GetWindowTextLength(GetDlgItem(hwndDlg, IDC_FILTER)) + 1;
		filter = (TCHAR *)_alloca(filterLength * sizeof(TCHAR));
		GetDlgItemText(hwndDlg, IDC_FILTER, filter, filterLength);
	}

	jidListInfo = ( JABBER_MUC_JIDLIST_INFO * ) GetWindowLongPtr( hwndDlg, GWLP_USERDATA );
	if ( !jidListInfo )
		return;

	hwndList = GetDlgItem( hwndDlg, IDC_LIST );
	SendMessage(hwndList, WM_SETREDRAW, FALSE, 0);

	count = ListView_GetItemCount( hwndList );
	lvi.mask = LVIF_PARAM;
	lvi.iSubItem = 0;
	for ( i=0; i<count; i++ ) {
		lvi.iItem = i;
		if ( ListView_GetItem( hwndList, &lvi ) == TRUE ) {
			if ( lvi.lParam!=( LPARAM )( -1 ) && lvi.lParam!=( LPARAM )( NULL )) {
				mir_free(( void * ) lvi.lParam );
			}
		}
	}
	ListView_DeleteAllItems( hwndList );

	// Populate displayed list from iqNode
	if (( iqNode = jidListInfo->iqNode ) != NULL ) {
		if (( from = xmlGetAttrValue( iqNode, _T("from"))) != NULL ) {
			if (( queryNode = xmlGetChild( iqNode , "query" )) != NULL ) {
				lvi.mask = LVIF_TEXT | LVIF_PARAM;
				lvi.iSubItem = 0;
				lvi.iItem = 0;
				for ( i=0; ; i++ ) {
					HXML itemNode = xmlGetChild( queryNode ,i);
					if ( !itemNode )
						break;

					if (( jid = xmlGetAttrValue( itemNode, _T("jid"))) != NULL ) {
						lvi.pszText = ( TCHAR* )jid;
						if ( jidListInfo->type == MUC_BANLIST ) {
							if (( reason = xmlGetText(xmlGetChild( itemNode , "reason" ))) != NULL ) {
								TCHAR jidreason[ JABBER_MAX_JID_LEN + 256 ];
								mir_sntprintf( jidreason, SIZEOF( jidreason ), _T("%s (%s)") , jid, reason );
								lvi.pszText = jidreason;
						}	}

						if ( jidListInfo->type == MUC_VOICELIST || jidListInfo->type == MUC_MODERATORLIST ) {
							if (( nick = xmlGetAttrValue( itemNode, _T("nick"))) != NULL ) {
								TCHAR nickjid[ JABBER_MAX_JID_LEN + 256 ];
								mir_sntprintf( nickjid, SIZEOF( nickjid ), _T("%s (%s)") , nick, jid );
								lvi.pszText = nickjid;
						}	}

						if (filter && *filter && !JabberStrIStr(lvi.pszText, filter))
							continue;

						lvi.lParam = ( LPARAM )mir_tstrdup( jid );

						ListView_InsertItem( hwndList, &lvi );
						lvi.iItem++;
	}	}	}	}	}

	lvi.mask = LVIF_PARAM;
	lvi.lParam = ( LPARAM )( -1 );
	ListView_InsertItem( hwndList, &lvi );

	SendMessage(hwndList, WM_SETREDRAW, TRUE, 0);
	RedrawWindow(hwndList, NULL, NULL, RDW_INVALIDATE);
}
Ejemplo n.º 24
0
DWORD WINAPI ApplicationPageRefreshThread(void *lpParameter)
{
    MSG msg;
    INT i;
    BOOL                            bItemRemoved = FALSE;
    LV_ITEM                         item;
    LPAPPLICATION_PAGE_LIST_ITEM    pAPLI = NULL;
    HIMAGELIST                      hImageListLarge;
    HIMAGELIST                      hImageListSmall;

    /* If we couldn't create the event then exit the thread */
    while (1)
    {
        /*  Wait for an the event or application close */
        if (GetMessage(&msg, NULL, 0, 0) <= 0)
            return 0;

        if (msg.message == WM_TIMER)
        {
            /*
             * FIXME:
             *
             * Should this be EnumDesktopWindows() instead?
             */
            noApps = TRUE;
            EnumWindows(EnumWindowsProc, 0);
            if (noApps)
            {
                (void)ListView_DeleteAllItems(hApplicationPageListCtrl);
                bApplicationPageSelectionMade = FALSE;
            }

            /* Get the image lists */
            hImageListLarge = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_NORMAL);
            hImageListSmall = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_SMALL);

            /* Check to see if we need to remove any items from the list */
            for (i=ListView_GetItemCount(hApplicationPageListCtrl)-1; i>=0; i--)
            {
                memset(&item, 0, sizeof(LV_ITEM));
                item.mask = LVIF_IMAGE|LVIF_PARAM;
                item.iItem = i;
                (void)ListView_GetItem(hApplicationPageListCtrl, &item);

                pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
                if (!IsWindow(pAPLI->hWnd)||
                    (wcslen(pAPLI->szTitle) <= 0) ||
                    !IsWindowVisible(pAPLI->hWnd) ||
                    (GetParent(pAPLI->hWnd) != NULL) ||
                    (GetWindow(pAPLI->hWnd, GW_OWNER) != NULL) ||
                    (GetWindowLongPtr(pAPLI->hWnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW))
                {
                    ImageList_Remove(hImageListLarge, item.iItem);
                    ImageList_Remove(hImageListSmall, item.iItem);

                    (void)ListView_DeleteItem(hApplicationPageListCtrl, item.iItem);
                    HeapFree(GetProcessHeap(), 0, pAPLI);
                    bItemRemoved = TRUE;
                }
            }

            /*
             * If an item was removed from the list then
             * we need to resync all the items with the
             * image list
             */
            if (bItemRemoved)
            {
                for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++)
                {
                    memset(&item, 0, sizeof(LV_ITEM));
                    item.mask = LVIF_IMAGE;
                    item.iItem = i;
                    item.iImage = i;
                    (void)ListView_SetItem(hApplicationPageListCtrl, &item);
                }
                bItemRemoved = FALSE;
            }

            ApplicationPageUpdate();
        }
    }
}
Ejemplo n.º 25
0
static LRESULT CALLBACK PluginListWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg) {
	case WM_CHAR:
		if (wParam == '\b') {
			if (szFilter.GetLength() > 0)
				szFilter.Truncate(szFilter.GetLength() - 1);
		}
		else {
			szFilter.AppendChar(wParam);

			for (int i = 0; i < arPluginList.getCount(); i++) {
				PluginListItemData *p = arPluginList[i];
				if (!_tcsnicmp(szFilter, p->fileName, szFilter.GetLength())) {
					LVFINDINFO lvfi;
					lvfi.flags = LVFI_PARAM;
					lvfi.lParam = (LPARAM)p;
					int idx = ListView_FindItem(hwnd, 0, &lvfi);
					if (idx != -1) {
						ListView_SetItemState(hwnd, idx, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
						ListView_EnsureVisible(hwnd, idx, FALSE);
						if (timerID != 0)
							KillTimer(hwnd, timerID);
						timerID = SetTimer(hwnd, 1, 1500, 0);
						return TRUE;
					}
				}
			}

			szFilter.Truncate(szFilter.GetLength() - 1);
			MessageBeep((UINT)-1);
		}
		return TRUE;

	case WM_TIMER:
		if (wParam == 1) {
			KillTimer(hwnd, timerID);
			timerID = 0;
			szFilter.Empty();
		}
		break;

	case WM_LBUTTONDOWN:
		LVHITTESTINFO hi;
		hi.pt.x = LOWORD(lParam);
		hi.pt.y = HIWORD(lParam);
		ListView_SubItemHitTest(hwnd, &hi);
		// Dynamically load/unload a plugin
		if ((hi.iSubItem == 0) && (hi.flags & LVHT_ONITEMICON)) {
			LVITEM lvi = { 0 };
			lvi.mask = LVIF_IMAGE | LVIF_PARAM;
			lvi.stateMask = -1;
			lvi.iItem = hi.iItem;
			lvi.iSubItem = 0;
			if (ListView_GetItem(hwnd, &lvi)) {
				lvi.mask = LVIF_IMAGE;
				PluginListItemData *dat = (PluginListItemData*)lvi.lParam;
				if (lvi.iImage == 3) {
					// load plugin
					if (LoadPluginDynamically(dat)) {
						lvi.iImage = 2;
						ListView_SetItem(hwnd, &lvi);
					}
				}
				else if (lvi.iImage == 2) {
					// unload plugin
					if (UnloadPluginDynamically(dat)) {
						lvi.iImage = 3;
						ListView_SetItem(hwnd, &lvi);
					}
				}
				LoadStdPlugins();
			}
		}
	}

	return mir_callNextSubclass(hwnd, PluginListWndProc, msg, wParam, lParam);
}
Ejemplo n.º 26
0
void AddOrUpdateHwnd(HWND hWnd, WCHAR *szTitle, HICON hIcon, BOOL bHung)
{
    LPAPPLICATION_PAGE_LIST_ITEM    pAPLI = NULL;
    HIMAGELIST                      hImageListLarge;
    HIMAGELIST                      hImageListSmall;
    LV_ITEM                         item;
    int                             i;
    BOOL                            bAlreadyInList = FALSE;

    memset(&item, 0, sizeof(LV_ITEM));

    /* Get the image lists */
    hImageListLarge = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_NORMAL);
    hImageListSmall = ListView_GetImageList(hApplicationPageListCtrl, LVSIL_SMALL);

    /* Check to see if it's already in our list */
    for (i=0; i<ListView_GetItemCount(hApplicationPageListCtrl); i++)
    {
        memset(&item, 0, sizeof(LV_ITEM));
        item.mask = LVIF_IMAGE|LVIF_PARAM;
        item.iItem = i;
        (void)ListView_GetItem(hApplicationPageListCtrl, &item);

        pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)item.lParam;
        if (pAPLI->hWnd == hWnd)
        {
            bAlreadyInList = TRUE;
            break;
        }
    }

    /* If it is already in the list then update it if necessary */
    if (bAlreadyInList)
    {
        /* Check to see if anything needs updating */
        if ((pAPLI->hIcon != hIcon) ||
            (_wcsicmp(pAPLI->szTitle, szTitle) != 0) ||
            (pAPLI->bHung != bHung))
        {
            /* Update the structure */
            pAPLI->hIcon = hIcon;
            pAPLI->bHung = bHung;
            wcscpy(pAPLI->szTitle, szTitle);

            /* Update the image list */
            ImageList_ReplaceIcon(hImageListLarge, item.iItem, hIcon);
            ImageList_ReplaceIcon(hImageListSmall, item.iItem, hIcon);

            /* Update the list view */
            (void)ListView_RedrawItems(hApplicationPageListCtrl, 0, ListView_GetItemCount(hApplicationPageListCtrl));
            /* UpdateWindow(hApplicationPageListCtrl); */
            InvalidateRect(hApplicationPageListCtrl, NULL, 0);
        }
    }
    /* It is not already in the list so add it */
    else
    {
        pAPLI = (LPAPPLICATION_PAGE_LIST_ITEM)HeapAlloc(GetProcessHeap(), 0, sizeof(APPLICATION_PAGE_LIST_ITEM));

        pAPLI->hWnd = hWnd;
        pAPLI->hIcon = hIcon;
        pAPLI->bHung = bHung;
        wcscpy(pAPLI->szTitle, szTitle);

        /* Add the item to the list */
        memset(&item, 0, sizeof(LV_ITEM));
        item.mask = LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM;
        ImageList_AddIcon(hImageListLarge, hIcon);
        item.iImage = ImageList_AddIcon(hImageListSmall, hIcon);
        item.pszText = LPSTR_TEXTCALLBACK;
        item.iItem = ListView_GetItemCount(hApplicationPageListCtrl);
        item.lParam = (LPARAM)pAPLI;
        (void)ListView_InsertItem(hApplicationPageListCtrl, &item);
    }

    /* Select first item if any */
    if ((ListView_GetNextItem(hApplicationPageListCtrl, -1, LVNI_FOCUSED | LVNI_SELECTED) == -1) && 
        (ListView_GetItemCount(hApplicationPageListCtrl) > 0) && !bApplicationPageSelectionMade)
    {
        ListView_SetItemState(hApplicationPageListCtrl, 0, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
        bApplicationPageSelectionMade = TRUE;
    }
    /*
    else
    {
        bApplicationPageSelectionMade = FALSE;
    }
    */
}
Ejemplo n.º 27
0
static void save_debug_log(void) {
	char filename_timestamp[MAX_TIMESTAMP_LEN];
	char filename[_MAX_PATH];
	char *filters = "Log Files (*.log, *.txt)\0*.log;*.txt\0\0";
	OPENFILENAME ofn = {0};
	FILE *fp;
	int count;
	LVITEM lvi_timestamp;
	char timestamp[128];
	LVITEM lvi_level;
	char level[64];
	LVITEM lvi_category;
	char category[64];
	LVITEM lvi_file;
	char file[256];
	LVITEM lvi_line;
	char line[64];
	LVITEM lvi_message;
	char message[1024];
	int i;

	format_timestamp(time(NULL), -1, filename_timestamp, sizeof(filename_timestamp), "", "_", "");
	_snprintf(filename, sizeof(filename), "brickd_debug_%s.log", filename_timestamp);

	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = _hwnd;
	ofn.hInstance = _hinstance;
	ofn.lpstrFilter = filters;
	ofn.lpstrFile = filename;
	ofn.lpstrDefExt = "log";
	ofn.nMaxFile = sizeof(filename);
	ofn.lpstrTitle = "Save Live Debug Log";
	ofn.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT;

	if (!GetSaveFileName(&ofn)) {
		return;
	}

	fp = fopen(filename, "wb");

	if (fp == NULL) {
		report_error("Could not write to '%s'", filename);
	}

	count = ListView_GetItemCount(_debug_list_view);

	lvi_timestamp.iSubItem = 0;
	lvi_timestamp.mask = LVIF_TEXT;
	lvi_timestamp.pszText = timestamp;
	lvi_timestamp.cchTextMax = sizeof(timestamp) - 1;

	lvi_level.iSubItem = 1;
	lvi_level.mask = LVIF_TEXT;
	lvi_level.pszText = level;
	lvi_level.cchTextMax = sizeof(level) - 1;

	lvi_category.iSubItem = 2;
	lvi_category.mask = LVIF_TEXT;
	lvi_category.pszText = category;
	lvi_category.cchTextMax = sizeof(category) - 1;

	lvi_file.iSubItem = 3;
	lvi_file.mask = LVIF_TEXT;
	lvi_file.pszText = file;
	lvi_file.cchTextMax = sizeof(file) - 1;

	lvi_line.iSubItem = 4;
	lvi_line.mask = LVIF_TEXT;
	lvi_line.pszText = line;
	lvi_line.cchTextMax = sizeof(line) - 1;

	lvi_message.iSubItem = 5;
	lvi_message.mask = LVIF_TEXT;
	lvi_message.pszText = message;
	lvi_message.cchTextMax = sizeof(message) - 1;

	for (i = 0; i < count; ++i) {
		lvi_timestamp.iItem = i;
		lvi_level.iItem = i;
		lvi_category.iItem = i;
		lvi_file.iItem = i;
		lvi_line.iItem = i;
		lvi_message.iItem = i;

		if (!ListView_GetItem(_debug_list_view, &lvi_timestamp)) {
			strcpy(timestamp, "<unknown>");
		}

		if (!ListView_GetItem(_debug_list_view, &lvi_level)) {
			strcpy(level, "unknown");
		}

		if (!ListView_GetItem(_debug_list_view, &lvi_category)) {
			strcpy(category, "unknown");
		}

		if (!ListView_GetItem(_debug_list_view, &lvi_file)) {
			strcpy(file, "unknown");
		}

		if (!ListView_GetItem(_debug_list_view, &lvi_line)) {
			strcpy(line, "unknown");
		}

		if (!ListView_GetItem(_debug_list_view, &lvi_message)) {
			strcpy(message, "<unknown>");
		}

		fprintf(fp, "%s <%s> <%s|%s:%s> %s\r\n", timestamp, level, category, file, line, message);
	}

	fclose(fp);
}
Ejemplo n.º 28
0
/*
================
rvOpenFileDialog::HandleCommandOK

Handles the pressing of the OK button but either opening a selected folder
or closing the dialog with the resulting filename
================
*/
void rvOpenFileDialog::HandleCommandOK(void)
{
	char	temp[256];
	LVITEM	item;

	// If nothing is selected then there is nothing to open
	int sel = ListView_GetNextItem(mWndFileList, -1, LVNI_SELECTED);

	if (sel == -1) {
		GetWindowText(GetDlgItem(mWnd, IDC_TOOLS_FILENAME), temp, sizeof(temp)-1);

		if (!temp[0]) {
			return;
		}

		item.iImage = 2;
	} else {
		// Get the currently selected item
		item.mask = LVIF_IMAGE|LVIF_TEXT;
		item.iImage = sel;
		item.iSubItem = 0;
		item.pszText = temp;
		item.cchTextMax = 256;
		item.iItem = sel;
		ListView_GetItem(mWndFileList, &item);
	}

	// If the item is a folder then just open that folder
	if (item.iImage == 0) {
		if (strlen(mLookin)) {
			idStr::snPrintf(mLookin, sizeof(mLookin), "%s/%s", mLookin, temp);
		} else {
			idStr::Copynz(mLookin, temp, sizeof(mLookin));
		}

		UpdateLookIn();
		UpdateFileList();
	}
	// If the item is a file then build the filename and end the dialog
	else if (item.iImage == 2) {
		mFilename = mLookin;

		if (mFilename.Length()) {
			mFilename.Append("/");
		}

		mFilename.Append(temp);

		// Make sure the file exists
		if (mFlags & OFD_MUSTEXIST) {
			idFile	*file;
			file = fileSystem->OpenFileRead(mFilename);

			if (!file) {
				MessageBox(mWnd, va("%s\nFile not found.\nPlease verify the correct file name was given", mFilename.c_str()), "Open", MB_ICONERROR|MB_OK);
				return;
			}

			fileSystem->CloseFile(file);
		}

		EndDialog(mWnd, 1);
	}

	return;
}
/*
 * Modifies the attributes of an item currently in the listview.
 */
void CShellBrowser::ModifyItemInternal(const TCHAR *FileName)
{
	HANDLE			hFirstFile;
	ULARGE_INTEGER	ulFileSize;
	LVITEM			lvItem;
	TCHAR			FullFileName[MAX_PATH];
	BOOL			bFolder;
	BOOL			res;
	int				iItem;
	int				iItemInternal = -1;

	iItem = LocateFileItemIndex(FileName);

	/* Although an item may not have been added to the listview
	yet, it is critical that its' size still be updated if
	necessary.
	It is possible (and quite likely) that the file add and
	modified messages will be sent in the same group, meaning
	that when the modification message is processed, the item
	is not in the listview, but it still needs to be updated.
	Therefore, instead of searching for items solely in the
	listview, also look through the list of pending file
	additions. */

	if(iItem == -1)
	{
		/* The item doesn't exist in the listview. This can
		happen when a file has been created with a non-zero
		size, but an item has not yet been inserted into
		the listview.
		Search through the list of items waiting to be
		inserted, so that files the have just been created
		can be updated without them residing within the
		listview. */
		std::list<AwaitingAdd_t>::iterator itr;

		for(itr = m_AwaitingAddList.begin();itr!= m_AwaitingAddList.end();itr++)
		{
			if(lstrcmp(m_pwfdFiles[itr->iItemInternal].cFileName,FileName) == 0)
			{
				iItemInternal = itr->iItemInternal;
				break;
			}
		}
	}
	else
	{
		/* The item exists in the listview. Determine its
		internal index from its listview information. */
		lvItem.mask		= LVIF_PARAM;
		lvItem.iItem	= iItem;
		lvItem.iSubItem	= 0;
		res = ListView_GetItem(m_hListView,&lvItem);

		if(res != FALSE)
			iItemInternal = (int)lvItem.lParam;

		TCHAR szFullFileName[MAX_PATH];
		StringCchCopy(szFullFileName,SIZEOF_ARRAY(szFullFileName),m_CurDir);
		PathAppend(szFullFileName,FileName);

		/* When a file is modified, its icon overlay may change.
		This is the case when modifying a file managed by
		TortoiseSVN, for example. */
		SHFILEINFO shfi;
		DWORD_PTR dwRes = SHGetFileInfo(szFullFileName,0,&shfi,sizeof(SHFILEINFO),SHGFI_ICON|SHGFI_OVERLAYINDEX);

		if(dwRes != 0)
		{
			lvItem.mask			= LVIF_STATE;
			lvItem.iItem		= iItem;
			lvItem.iSubItem		= 0;
			lvItem.stateMask	= LVIS_OVERLAYMASK;
			lvItem.state		= INDEXTOOVERLAYMASK(shfi.iIcon >> 24);
			ListView_SetItem(m_hListView,&lvItem);

			DestroyIcon(shfi.hIcon);
		}
	}
Ejemplo n.º 30
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);
}