문제

I am creating an MFC application which will be launched on click on Explorer Context (Rightclick) menu.

But I need to launch only single instance of the application. For that I have to use FindWindow and AfxRegisterClass

I tried to register the class in my MFC app as below:

BOOL CNDSClientDlg::InitInstance()
{
    //Register Window Updated on 16th Nov 2010, @Subhen
    // Register our unique class name that we wish to use
    WNDCLASS wndcls;
    memset(&wndcls, 0, sizeof(WNDCLASS));
    //Class name for using FindWindow later
    wndcls.lpszClassName = _T("NDSApp");
    // Register new class and exit if it fails

    if(!AfxRegisterClass(&wndcls)) // [C]

    {
        return FALSE;
    }
}

and called the method in the constructor of the MFC class. I verified that the class is being registered while I am starting the application.

Now in my shell Extension I am trying to find the Class registered in my MFC as below:

CWnd *pWndPrev = NULL;
 pWndPrev = CWnd::FindWindow(_T("NDSApp"),NULL);
         if(pWndPrev != NULL)
            pWndPrev->BringWindowToTop();

But I am not able to get the CWnd to Window. Not able to figure it out. Please let me know if I am missing something or doing something wrong.

도움이 되었습니까?

해결책

FindWindow finds window instances not window classes. In your app which registers the class you need to actually create a window so that the extension can find that window.

(Finding the window by class name is fine; the problem is you haven't actually created anything to find.)

Also, I suspect if you try to create a window based on the window-class you've registered it will fail because you've left most of the WNDCLASS structure null. See the example you linked to for better default values. (e.g. You must provide a wndproc and hinstance.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top