Friday, December 28, 2012

GetChildElemetsByTagName VC++


///Get child elements by tag name
IHTMLElementCollection* CTest::GetChildElemetsByTagName(IHTMLElement* pElem,CString TagName)
{
IDispatch* pDisp = NULL;
IDispatch *pdispSpan;
IHTMLElement *peltSpan;

pElem->get_all(&pDisp);

IHTMLElementCollection* pFormColl = NULL;
HRESULT hr = pDisp->QueryInterface(IID_IHTMLElementCollection, (void**)&pFormColl);

pFormColl->tags(CComVariant(TagName.AllocSysString()),&pdispSpan);

CComQIPtr pEltColl2(pdispSpan);

return pEltColl2;
}


//Access this collection

void CTest::ChangeId(IHTMLElement* objElem, int Seq)
{

IHTMLElementCollection *pElemClc= GetChildElemetsByTagName(objElem,"p");

long lPCount;
BSTR tempBSTR;

pElemClc->get_length(&lPCount);
IHTMLElement *pElem;

for(int iIndex=0;iIndex {
//Get first header elem
CComPtr pdispSpan2;
pElemClc->item(CComVariant(iIndex), CComVariant(iIndex), &pdispSpan2);
pdispSpan2->QueryInterface(&pElem);

VARIANT objAttr;
pElem->getAttribute(_bstr_t("name"),1,&objAttr);
CString AttribVal(objAttr.bstrVal);

       }
}

Friday, December 21, 2012

Delete Html Tag


void CTest::DeleteTag(IHTMLElement* pElem,long &TotalElem)
{
pElem->put_outerHTML(L"");
//Since we are removing one elements
TotalElem=TotalElem-1;
}

Friday, August 31, 2012

How to read Unicode file?


string content = File.ReadAllText(FilePath, Encoding.GetEncoding("iso-8859-1"));

Tuesday, July 3, 2012

Interview

Interview


1) Real scenario where you have used oops concept (abstraction,inheritance,polymorphism...etc)
2) Can we use pointers in .net?
Ans : Yes
3) How can we use unmanage code in .net?
Ans : using unsafe keyword
4) What is Localization?
Ans : Customize an application for a given culture. It is called Localization.
5) What is Page Life Cycle?
Ans : Click Here
6) What is Process Life Cycle?
Ans : Click Here
7) What is manage code?
8) What is unmanage code?
9) How CLR works?
Ans : .Net Framework provides runtime environment called Common Language Runtime (CLR).It provides an environment to run all the .Net Programs. The code which runs under the CLR is called as Managed Code. Programmers need not to worry on managing the memory if the programs are running under the CLR as it provides memory management and thread management.

Programmatically, when our program needs memory, CLR allocates the memory for scope and de-allocates the memory if the scope is completed.

Language Compilers (e.g. C#, VB.Net, J#) will convert the Code/Program to Microsoft Intermediate Language (MSIL) intern this will be converted to Native Code by CLR. See the below Fig.
10) How it knows that particular object is ready to reclaimed?
Ans : Click Here
11) What are generation in CLR process?
Ans : Click Here
12) Can we assign memory from gen2 explicitly for an object?
Ans :

You can't allocate directly in Gen 2. All allocations happen in either Gen 0 or on the large object heap (if they are 85000 bytes or larger). However, pushing something to Gen 2 is easy: Just allocate everything you want to go to Gen 2 and force GCs at that point. You can call GC.GetGeneration to inspect the generation of a given object.

Another thing to do is keep a pool of objects. I.e. instead of releasing objects and thus making them eligible for GC, you return them to a pool. This reduces allocations and thus the number of GCs as well.

13) Difference between abstract class and interface.
Ans : Click Here
14) What are joins?
Ans : Click Here
15) How can we develop an application for multiple languages?
Ans : Using resource assembly.

Friday, April 20, 2012

Use of Select function in Dictionary

private String GetFileName(int iPageNumber)
{
try
{
var objEnm = m_objDict.Select((Pages, index) => new { index, str = Pages.Value.Contains("," + iPageNumber + ",") });

String sKey = null;
foreach (var obj in objEnm)
{

if (obj.str == true)
{
IEnumerator objKeyClc = m_objDict.Keys.GetEnumerator();
int iIndex = 0;
while (objKeyClc.MoveNext())
{
if (obj.index == iIndex++)
{
sKey = objKeyClc.Current;
break;
}
}
}

}
return sKey;
}
catch (Exception ex)
{
throw ex;
}
}

Friday, April 13, 2012

Convert MatchCollection into List

private void ConvertMatchCollectionIntoList()
{
string test = "1a2bc23AB4C15";
//string regex = "(?a)|(?b)|(?c)]";
string regex = "[\\d]+";
Regex regNoCase = new Regex(regex, RegexOptions.IgnoreCase);
Regex regCase = new Regex(regex);

MatchCollection matchNoCase = regNoCase.Matches(test);
MatchCollection matchCase = regCase.Matches(test);


List lstIndex = matchNoCase.OfType().Where(m => m.Success).ToList();
lstIndex.Sort(CompareLst);

}

public int CompareLst(Match x, Match y)
{

int iFirst =0;
int.TryParse(x.Value,out iFirst);

int iSecond;
int.TryParse(y.Value,out iSecond);
return iFirst.CompareTo(iSecond);
}

Monday, March 26, 2012

Pass and Get parameter in Html

You can pass parameters in html file as below

<a href='test.html?foldername=red&imagename=1">Click Here</a>

Here red is folder name and 1 is image name.

How to retrieve the parameters in html


<script type="text/javascript">

var query = location.href.substring((location.href.indexOf('?')+1), location.href.length);
if(location.href.indexOf('?') < 0) query = '';
querysplit = query.split('&');
query = new Array();

for(var i = 0; i < querysplit.length; i++){
var namevalue = querysplit[i].split('=');
namevalue[1] = namevalue[1].replace(/\+/g, ' ');
query[namevalue[0]] = unescape(namevalue[1]);
}


</script>

Or you can download the html file Click Here

Friday, March 9, 2012

Add Copy To and Move To in Context Menu

Sometimes you need to copy some files in a particular folder this is irritating when you need to do it too frequently. For copy and move you can add item in Context menu like..


To Add Copy To Download

To Remove Copy To Download


To Add Move To Download


To Remove Move To Download

Friday, March 2, 2012

Customize Context Menu

If you want to add some items in windows context menu. You need to edit registry.

Following step will guide you to add Notepad++( or other program) in your context menu. You can add another item as well.

1. Press Window Key + R
2. Type regedit and press enter.
3. Go to this path in registry and expand.

HKEY_CLASSES_ROOT\*\shell

4. Right Click on Shell and Add a Key here


5. Rename it with your convenient name


6. Add another key here and rename it as command.


7. It will look as below after adding the key.



7. Double click on Default on Right side pane. And you will see following dialogue.


8. Paste your exe path in the text box and %1 also. It indicates that open that file on which user has right clicked.

I have paste this path. Your exe path may be different.

D:\RND Data\Imp Soft\NotePad++\notepad++.exe %1


9. Now click on Ok and "Open with Notepad++" added in your context menu.


Or you can simply download this file. Open it in Notepad. Change your exe path and item name, in this file item name is "Open with Notepad++" and exe path is "D:\RND Data\Imp Soft\NotePad++\notepad++.exe".

Friday, February 24, 2012

Remove Child Node VC++

RemoveChildeNode()
{
::CoInitialize(NULL);

IXMLDOMDocumentPtr domDocument;

HRESULT hr = domDocument.CreateInstance(CLSID_DOMDocument);
if (FAILED(hr))
{
_com_error er(hr);
AfxMessageBox(er.ErrorMessage());
}

CString strFileName ="C:\test.xml";

CComBSTR bstrFileName(strFileName);
VARIANT_BOOL vStatus = VARIANT_FALSE;
CComVariant name(strFileName);
hr = domDocument->load(name, &vStatus);

if (FAILED(hr))
{
int errorCode = ::GetLastError();
AfxMessageBox("Load XML failed!");
return ;
}

CComPtr xnlPage;

long l_CountZone;
long l_CountPage;

_bstr_t TPage = "Page";
hr = domDocument->getElementsByTagName(TPage,&xnlPage);
if (FAILED(hr))
{
int errorCode = ::GetLastError();
AfxMessageBox("get_firstChild failed!");
return ;
}

hr = xnlPage->get_length(&l_CountPage);

for(int iCountPage= m_CurrPageNum-1;iCountPage<l_CountPage; iCountPage++)
{
CComPtr xnPage;
hr = xnlPage->get_item(iCountPage,&xnPage);


CComPtr xnlZone;
hr = xnPage->selectNodes(_bstr_t("Zone"),&xnlZone);
hr = xnlZone->get_length(&l_CountZone);

for(int iCountZone= 0;iCountZone<l_CountZone; iCountZone++)
{
CComPtr xnZone;
CComPtr xnZoneParent;
hr = xnlZone->get_item(iCountZone,&xnZone);

xnZone->get_parentNode(&xnZoneParent);
xnZoneParent->removeChild(xnZone,&pXMLNodeOld);



xnZone.Release();
xnZone=NULL;

xnZoneParent.Release();
xnZoneParent=NULL;

}
xnlZone.Release();
xnlZone=NULL;
}
xnlPage.Release();
xnlPage=NULL;

domDocument->save(name);
domDocument.Release();
domDocument=NULL;
::CoUninitialize();
}

Tuesday, February 14, 2012

Use boolean value in printf VC++

printf("You are married: %s",(married)?"true":"false");

Followers

Link