Exemple #1
0
// Function to create a favorite file or folder in the given path //
wyBool 
FavoriteBase::InsertFavoriteItem(wyString &path, wyBool isfolder , wyString &favquery)
{	
	DWORD				byteswritten;
	HANDLE				hfile;
	//const unsigned char utf8bom[10] = {unsigned char(0xEF), unsigned char(0xBB), unsigned char(0xBF)};
			
	// if the favorite is file type then add the extension//
	if(!isfolder)
	{
		path.Add(".sql");

        hfile = ::CreateFile(path.GetAsWideChar(), GENERIC_WRITE, 0, NULL, CREATE_NEW,
								   NULL, NULL);

		if(hfile  == INVALID_HANDLE_VALUE)
		{
            if(::GetLastError() == ERROR_FILE_EXISTS)
			{
                if(::MessageBox(NULL, _(L"The name you have entered for the shortcut already exists in Favorites menu.\nWould you like to overwrite it?"), _(L"Add Favorite"), MB_YESNO | MB_TASKMODAL | MB_ICONINFORMATION | MB_DEFBUTTON2) == IDYES)
				{
                    hfile = ::CreateFile(path.GetAsWideChar(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, NULL, NULL);
					
					if(hfile  == INVALID_HANDLE_VALUE)
                         OnError(_("Cannot write into Favorite File"));
				}
				else
					return wyFalse;			
			}
			else
			    return OnError(_("Cannot write into Favorite File"));
		}
		
		//if (!::WriteFile(hfile,  utf8bom, 3, &byteswritten , NULL))
		//	return OnError("Cannot write into Favorite File");

        if (!::WriteFile(hfile,  favquery.GetString(), favquery.GetLength(), &byteswritten , NULL))
			return OnError(_("Cannot write into Favorite File"));

        ::CloseHandle(hfile);
	}
    else if(!::CreateDirectory(path.GetAsWideChar(), NULL))
	  return OnError(_("Cannot create Favorite Folder"));
	
    return wyTrue;
}
Exemple #2
0
// Function to add the given item to the treeview control //
HTREEITEM	
FavoriteBase::AddItem(HWND htree, HTREEITEM parent, wyString name, wyInt32 pos) 
{	
	TV_INSERTSTRUCT			str ;
	str.hParent				= parent ;
	str.item.mask			= TVIF_TEXT |  TVIF_IMAGE | TVIF_SELECTEDIMAGE ; 
	str.hInsertAfter		= TVI_SORT;
	str.item.pszText		= (LPWSTR)name.GetAsWideChar();
	str.item.iImage			= pos ;
	str.item.iSelectedImage = pos;

    HTREEITEM htreeitem;
    VERIFY(htreeitem = (HTREEITEM)SendMessage(htree, TVM_INSERTITEM, NULL, (wyInt32)&str));
	return(htreeitem);
 }
Exemple #3
0
// function to process file type Favorite//
wyBool
FavoriteBase::AddFile(HMENU hmenu, wyString &parentpath,  wyWChar *filename)
{
	wyInt32				i , j=0;
	wyUInt32			lengthwchar = 1;
	wyWChar				ext[_MAX_EXT] = {0} , *data = {0};
	wyChar				*path = {0};
	MENUITEMINFO		lpmii={0};
	
	parentpath.GetAsWideChar(&lengthwchar);
	
	path = AllocateBuff(parentpath.GetLength() + 2);
	data = AllocateBuffWChar(wcslen(filename) + 2);

	wcscpy(data, (wyWChar*)filename);
	strcpy(path, (wyChar*)parentpath.GetString());

	for(i = wcslen(data) - 1; i && data[i]!='.'; i--, j++)
		ext[j] = data[i];
	
	if(wcsnicmp(ext, L"lqs", 3) != 0)
		return wyFalse;

	ext[j] = 0;
	data[i] = 0;
	
	lpmii.cbSize		= sizeof(MENUITEMINFO);
	lpmii.fMask			= MIIM_STRING|MIIM_ID|MIIM_DATA;
	lpmii.wID			= m_menuid++;
	lpmii.dwItemData	= (ULONG_PTR)path;
	lpmii.cch			= wcslen(data);
	lpmii.dwTypeData	= data;
	
    VERIFY(::InsertMenuItem(hmenu, -1, TRUE, &lpmii));

	free(data);

    return wyTrue;
}