How do I query all records in a container - tree view?

The following code works for querying all records in a tree structure but

 USHORT usParentCmd = CMA_FIRST, usChildCmd;
 PUSERREC purParent = NULL, purChild;

 for( ; ; )
 {
    purParent = (PUSERREC) WinSendMsg( hwndCnr, CM_QUERYRECORD,
                                       MPFROMP( purParent ),
                                       MPFROM2SHORT( usParentCmd, CMA_ITEMORDER ) );
    if( !purParent )
       break;

    DoWhatever( purParent );

    usChildCmd = CMA_FIRSTCHILD;
    purChild = NULL;
    for( ; ; )
    {
       purChild = (PUSERREC) WinSendMsg( hwndCnr, CM_QUERYRECORD,
                                         MPFROMP( purChild ),
                                         MPFROM2SHORT( usChildCmd, CMA_ITEMORDER ));
       if( !purChild )
          break;

       DoWhatever( purChild );
       usChildCmd = CMA_NEXT;
    }

    usCmdParent = CMA_NEXT;
 }

Credit: Rick Fishman


[Back: How do I sort a container control?]
[Next: I can't get different colors in text control windows]