
470 N.W.2d 253 (1991)
Tamera COOPER, Plaintiff and Appellee,
v.
Donald Jacob MERKEL, Defendant and Appellant.
No. 17205.
Supreme Court of South Dakota.
Considered on Briefs February 15, 1991.
Decided May 15, 1991.
*254 Randy S. Bingner, Clark, for plaintiff and appellee.
Michael B. Thompson of Bartron, Wiles & Rylance, Watertown, for defendant and appellant.
PER CURIAM.
Donald Jacob Merkel (Donald) appeals an order dismissing his motion for visitation rights with the minor child of Tamera Cooper (Tamera). We affirm.

FACTS
Donald and Tamera lived together for seven years, however, Donald is not the legal or biological father of Tamera's son. On September 5, 1989, Tamera filed a pro se petition for protection from domestic abuse against Donald. A hearing was held and, on October 6, 1989, the trial court entered an order restraining Donald from committing any acts of domestic abuse against Tamera and further restraining him from going to Tamera's residence. The order also provided that Donald, "may be allowed to contact the son of [Tamera]... at a reasonable time and in a reasonable manner for the purpose of visitation."
On March 29, 1990, Donald filed a motion for a trial court order granting him a schedule of visitation with Tamera's son. The motion asserted that Donald had assumed part of the responsibility for raising the boy, that Donald was a de facto parent to him and, therefore, that Donald should be granted the opportunity to visit him. On May 16, 1990, the trial court informed Donald's counsel that it wanted the parties to brief the question of whether Donald, not being the boy's biological father, had standing to request visitation. The parties stipulated to a briefing schedule approved by the trial court and subsequently submitted their briefs.
The trial court issued its decision on June 6, 1990, holding at common law a nonparent had no right to visitation with a minor child and in the absence of any statute it lacked authority to order nonparent visitation. The trial court entered its order of dismissal and Donald appeals.

ISSUE

WHETHER THE TRIAL COURT ERRED IN DISMISSING DONALD'S MOTION FOR VISITATION?
A court may, on its own initiative, dismiss a complaint under SDCL 15-6-12(b)(5) for failure to state a claim on which relief can be granted. See, K/O Ranch, Inc. v. Norwest Bank of Black Hills, 748 F.2d 1246 (8th Cir.1984); Martin-Trigona *255 v. Stewart, 691 F.2d 856 (8th Cir.1982). If, on a motion to dismiss for failure to state a claim, matters outside the pleadings are presented to, and not excluded by, the trial court, the motion should be treated as one for summary judgment. Glanzer v. St. Joseph Indian School, 438 N.W.2d 204 (S.D.1989) (citing SDCL 15-6-12(b)). Thus, in Glanzer, supra, where the record indicated that matters outside the pleadings were presented to, and considered by the trial court in dismissing the case, this court reviewed the dismissal under the rules applicable to summary judgment.
Donald contends that factual matters outside the pleadings were submitted to the trial court in Tamera's brief. As a consequence, Donald argues that the trial court erred in not converting the dismissal proceeding to a summary judgment proceeding. He argues this denied him an opportunity to present the trial court with additional matters pertinent to his claim. We disagree.
While extraneous matters were submitted to the trial court in Tamera's brief, the only matters pertinent to the ultimate decision were contained in the pleadings, i.e., that Donald is a nonparent seeking visitation rights with a minor child. This fact is clear from Tamera's original petition for a protection order and is not disputed on appeal. Thus, although extraneous matters may have been submitted, the record is clear that, in contrast with Glanzer, the extraneous matters were not relevant to the trial court's ultimate legal determination that nonparents have no visitation rights with minor children. Thus, the trial court did not err in failing to convert the dismissal proceeding to one for summary judgment. Such a conversion would have served no useful purpose as the key facts relevant to the trial court's decision were contained in the pleadings and were not disputed.
Donald contends that he should have been afforded the opportunity to present facts establishing that he was a de facto parent to Tamera's son or that he stood in loco parentis[1] to the boy. He argues that proof of these facts would have established his claim for visitation rights with the child.[2]
This court has not spoken directly to the issue of the visitation rights of a nonparent. However, "[t]he right of visitation derives from the right of custody and is controlled by the same legal principles." 59 Am.Jur.2d Parent and Child § 36 (1987). This court has spoken to the custodial rights of nonparents.
Before a parent's right to custody over his or her own children will be disturbed in favor of a nonparent a clear showing against the parent of "gross misconduct or unfitness, or of other extraordinary circumstances affecting the welfare of the child" is required, and an award cannot be made to [nonparents] simply because they may be better custodians.
Langerman v. Langerman, 336 N.W.2d 669, 670 (S.D.1983). Accord, Langerman v. Langerman, 321 N.W.2d 532 (S.D.1982). It follows that in order to grant a nonparent visitation rights with a minor child over *256 the wishes of a parent, a clear showing against the parent of gross misconduct, unfitness or other extraordinary circumstances affecting the welfare of the child is required.[3]
A similar test was employed by the District of Columbia Court of Appeals in Jackson v. Fitzgerald, 185 A.2d 724 (D.C.1962). In Jackson, a grandparent sought custody or visitation rights with a four-year-old grandchild against the wishes of the child's father. As in this case, the lower court dismissed the grandparent's complaint for failure to state a claim. The substance of the complaint was that the child and its mother had lived with the grandparent for a period of time, that during that time the grandparent expended considerable money for the support of the child and devoted much care and attention to it and that the child would benefit by the grandparent's companionship. There was, however, no charge in the complaint of parental unfitness or misconduct. In upholding the dismissal, the D.C. Court stated:
In the absence of any charge of unfitness or misconduct, there was plainly no basis for disturbing the father's right to custody. And, logically, the same must be said as to the claim for visitation rights. The right of visitation derives from the right to custody. The court could not award the plaintiff visitation rights without impinging on the father's vested right of custody. And that could not be done on the basis of the barren complaint we have described.
Jackson, 185 A.2d at 725-26. See also, Chodzko v. Chodzko, 66 Ill.2d 28, 4 Ill.Dec. 313, 360 N.E.2d 60 (1976) (right to determine third parties who have visitation privileges with children should vest with parent who has responsibility of rearing children and normally should not be a judicial concern).
Like the complaint in Jackson, Donald's motion for visitation contained no charge that Tamera was unfit or guilty of misconduct nor was there any allegation of unusual circumstances. The motion merely alleged that Donald helped raise Tamera's son and that having assumed part of that responsibility he should be granted the opportunity to visit the boy. Thus, as in Jackson and under the settled law of Langerman, the trial court appropriately dismissed Donald's motion for failure to state a claim.
Affirmed.
MILLER, C.J., and WUEST, HENDERSON and SABERS, JJ., and HERTZ, Circuit Judge, acting as a Supreme Court Justice, participating.
AMUNDSON, J., not having been a member of the Court at the time this action was submitted did not participate.
NOTES
[1]  "A person standing in loco parentis to a child is one who has put himself in the situation of a lawful parent by assuming the obligations incident to the parental relation, without going through the formalities necessary to a legal adoption, and the rights, duties, and liabilities of such person are the same as those of the lawful parent...." Cornhusker Christian Child. Home v. DSS, 227 Neb. 94, 416 N.W.2d 551, 561 (1987) (quoting Austin v. Austin, 147 Neb. 109, 112-13, 22 N.W.2d 560, 563 (1946)).
[2]  Of the numerous in loco parentis cases cited in Donald's brief, the only one specifically addressing the issue of nonparent visitation rights is Gribble v. Gribble, 583 P.2d 64 (Utah 1978). In Gribble, a man married a woman who had a minor child from a previous marriage. When this couple also divorced, the man sought visitation rights with the minor child. Observing that Utah statutes allowing visitation rights to parents, grandparents and other relatives could allow visitation where custodial rights would not exist, the Utah Court found greater flexibility in determining visitation rights than in determining custody. Accordingly, the Utah Court held that if the man could establish in loco parentis status with the child he should have a hearing to determine his visitation rights. South Dakota has not expanded such visitation rights by statute other than to extend such rights to grandparents if in the best interests of the child. SDCL 25-4-52.
[3]  We do not reach the issue of whether a similar test would be applicable to a grandparent's claim for visitation rights under SDCL 25-4-52.
