Listed below are uses with examples, and the structure of the past perfect continuous tense.
Something that had been happening before something else took place
I had been working for three hours when you arrived.
Susan had been thinking about the idea for a while when Bob made the suggestion.
Something that had been happening over a period of time in the past up until another point in the of past
I had been playing tennis for two hours when I sprained my ankle.
Jack had been studying for two years when he was drafted into the army.
Something that had been happening in preparation for something else
I had been practicing for three days and was ready for the concert.
Tom had been studying hard and felt good about the test he was about to take.
In the third conditional to express imagined conditions
If I had been working on that project, we would have been successful.
She would have been ready for the test if she had been preparing diligently.
Common time expressions used with the past perfect continuous:
before, when
Structure
Positive
Subject + had + been + verb + ing
I, You, He, She, We, They had been working for two hours when she telephoned.
Negative
Subject + had + not (hadn't) + been + verb + ing
I, You, He, She, We, They hadn't been paying attention for long when he asked the question.
Questions
Question word (often 'How long') + had + been + subject + verb + ing
How long - had he, she, you, we, they been working before he arrived?