OpenCV函数cvCreateTrackbar的问题

图片说明
这个cvCreateTrackbar函数在使用的时候为什么一旦拖动“帧”就能改变函数变量“value”,即使是当我把cvCreateTrackbar写在程序开始,程序执行到后面的时候,拖动“帧”就能回到cvCreateTrackbar函数,然后value发生改变,程序再继续执行?我在后面的代码中又没有使用回调函数,怎么莫名奇妙就回到前面去单独只执行cvCreateTrackbar函数?这是一种什么机制?

我来贴上源码图片说明

 #include <iostream>
#include "highgui.h"
#include "cv.h"

using namespace std;

CvCapture* g_capture = NULL;//视频对象指针变量,全局变量

void onTrackbarSlide(int pos)//被回调的函数
{
    cvSetCaptureProperty//设置视频对象CvCapture的各种属性,此处设置帧数 = 进度条的位置
    (
     g_capture,
     CV_CAP_PROP_POS_FRAMES,
     pos
     );
    cvShowImage("Example", cvQueryFrame(g_capture));//更新画面
}

int main(int argc, const char * argv[]) {
    cvNamedWindow("Example",CV_WINDOW_AUTOSIZE);
    g_capture = cvCreateFileCapture("/Users/sean/Documents/untitled folder/2.avi");
    //查询视频对象CvCapture的属性,获取视频文件的总帧数
    int frames = (int)cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT);
    int position=0;
    if(frames!=0)
    {
        cvCreateTrackbar//在"Example"窗口中创建"Postion"滚动条栏
        (
         "Postion",
         "Example",
         &position,
         frames,
         onTrackbarSlide//回调函数
        );
    }
    IplImage* frame=cvQueryFrame(g_capture);//获取画面
    while(frame!=0)
    {
        frame = cvQueryFrame(g_capture);
        cvSetTrackbarPos//帧随画面移动而移动
        (
         "Postion",
         "Example",
         position++
        );
        cvShowImage("Example", frame);
        if(cvWaitKey(1)==27) break;
    }
    cvReleaseCapture( &g_capture );
    cvDestroyWindow( "Example" );
    return 0;
}