Assigning class names for applications

When registering applications for use with ActiveSync you must supply a window class name. Assigning class names is carried out at development time and your application development tool documentation is the primary source of information on the topic.

Microsoft Foundation Classes (MFC) dialog boxes are given a generic class name of Dialog, which is shared by all dialogs in the system. This section describes how to assign a distinct class name for your application if you are using MFC.

 To assign a window class name for MFC applications
  1. Create and register a custom window class for dialog boxes, based on the default class.

    Add the following code to your application's startup code. The code must be executed before any dialogs get created:

    WNDCLASS wc;
    if( ! GetClassInfo( NULL, L"Dialog", &wc ) ) {
     AfxMessageBox( L"Error getting class info" );
    }
    wc.lpszClassName = L"MY_APP_CLASS";
    if( ! AfxRegisterClass( &wc ) ) {
     AfxMessageBox( L"Error registering class" );
    }

    where MY_APP_CLASS is the unique class name for your application.

  2. Determine which dialog is the main dialog for your application.

    If your project was created with the MFC Application Wizard, this is likely to be a dialog named MyAppDlg.

  3. Find and record the resource ID for the main dialog.

    The resource ID is a constant of the same general form as IDD_MYAPP_DIALOG.

  4. Ensure that the main dialog remains open any time your application is running.

    Add the following line to your application's InitInstance function. The line ensures that if the main dialog dlg is closed, the application also closes.

    m_pMainWnd = &dlg;

    For more information, see the Microsoft documentation for CWinThread::m_pMainWnd.

    If the dialog does not remain open for the duration of your application, you must change the window class of other dialogs as well.

  5. Save your changes.

  6. Modify the resource file for your project.

    • Open your resource file (which has an extension of .rc) in a text editor such as Notepad.

    Locate the resource ID of your main dialog.

    • Change the main dialog's definition to use the new window class as in the following example. The only change that you should make is the addition of the CLASS line:

      IDD_MYAPP_DIALOG DIALOG DISCARDABLE  0, 0, 139, 103
      STYLE WS_POPUP | WS_VISIBLE | WS_CAPTION
      EXSTYLE WS_EX_APPWINDOW | WS_EX_CAPTIONOKBTN
      CAPTION "MyApp"
      FONT 8, "System"
      CLASS "MY_APP_CLASS"
      BEGIN
             LTEXT   "TODO: Place dialog controls here.",IDC_STATIC,13,33,112,17
      END

      where MY_APP_CLASS is the name of the window class you used earlier.

    • Save the .rc file.

  7. Add code to catch the synchronization message.

    See Adding ActiveSync synchronization (MFC).