Category : C++ Source Code
Archive   : PRIVDLG.ZIP
Filename : PRIVDLG.CPP

 
Output of file : PRIVDLG.CPP contained in archive : PRIVDLG.ZIP
//*************************************************************
// File name: privdlg.cpp
//
// Description:
//
// This sample demonstrates the following techniques:
//
// 1. Creating an application with a dialog as the main window.
// This technique is demonstrated in the "Class Libraries
// User's Guide", page 334
//
// 2. Registering a private "Windows dialog class" (as opposed
// to the C++ dialog class).
//
// History: Date Author Comment
// 5/11/92 Mark Bader Created
//
// Written by Microsoft Product Support Services, Windows Developer Support
// Copyright (c) 1992 Microsoft Corporation. All rights reserved.
//*************************************************************

#include "precomp.h" // Precompiled header - contains AFXWIN.H
#include "resource.h" // Contains #defines for dialog box
#include "privdlg.h" // Contains class definitions

//*************************************************************
//
// Class
// CMainWindow
//
// Member Function:
// CMainDlgWindow() : Creates the main window
//
// Comments:
// Constructor for CMainDlgWidow. This function also takes
// care of registering our private dialog class, if it isn't
// already registered. This is accomplished by using a
// static member variable bRegistered, and a static member
// function to do the registration.
//
// History: Date Author Comment
// 5/11/92 Mark Bader Created
//
//*************************************************************

// CMainDlgWindow::bRegistered is a static member variable, which means
// there will be only one copy for all instances of the C++ class. This
// variable is set to TRUE when the wndclass is successfully registered.
// Subsequent instances of this C++ class will see that this variable is
// already set to TRUE, and won't try to re-register the wndclass (which
// would fail).

BOOL CMainDlgWindow::bRegistered = FALSE;

CMainDlgWindow::CMainDlgWindow() {

// Check to see if someone already registered our class
if (!bRegistered) {
// If not, register it!
bRegistered=RegisterMyClass();
}

// Create ourselves a dialog box with dialog template "MAINDLG"
Create("MAINDLG");
}

//*************************************************************
//
// Class
// CMainWindow
//
// Member Function:
// RegisterMyClass() : Registers the WNDCLASS Window class
// for our dialog box
// Comments:
// This function does the work of registering our WNDCLASS.
// This function actually calls ::RegisterClass() instead of
// AfxRegisterWndClass(), because you can't specify a class
// name with the Afx version of this function.
//
// History: Date Author Comment
// 5/11/92 Mark Bader Created
//
//*************************************************************

BOOL CMainDlgWindow::RegisterMyClass() {
WNDCLASS wndclass;

wndclass.style = 0;

// Let's use DefDlgProc for our dialog's Window Procedure, we
// don't need to modify any of the behavior anyway.
wndclass.lpfnWndProc = DefDlgProc;
wndclass.cbClsExtra = 0 ;

// This field MUST be set to DLGWINDOWEXTRA, or this class we're
// registering won't work properly with our dialog boxes.
wndclass.cbWndExtra = DLGWINDOWEXTRA ;

// Use the app's instance. AfxGetInstanceHandle() gets this for
// us nicely.
wndclass.hInstance = AfxGetInstanceHandle();

// Load our custom icon. "MYICON" should be defined in the .RC
// file.
wndclass.hIcon = ::LoadIcon (AfxGetInstanceHandle(), "MYICON") ;

// Use an arrow cursor for kicks
wndclass.hCursor = ::LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = (HBRUSH) COLOR_WINDOW + 1 ;
wndclass.lpszMenuName = NULL ;

// Make up a unique name for our dialog class. This same name must
// be used in our dialog box template to force the dialog box to
// use this new class.
wndclass.lpszClassName = "MYDLGCLASS";

return ::RegisterClass(&wndclass);
}

//*************************************************************
//
// Class
// CMainWindow
//
// Member Function:
// OnOK() : Processes "OK" button.
// OnHelp() : Processes "Help" button.
//
// History: Date Author Comment
// 5/11/92 Mark Bader Created
//
//*************************************************************

void CMainDlgWindow::OnOK() {

// Because we didn't derive our dialog from CModalDialog,
// EndDialog() won't completely close our window and exit
// our app, so we must do some special processing. Since
// we already take care of the WM_CLOSE message (see the
// class definition in the .H file), let's just send one
// to ourselves. This will clean up our app.

PostMessage(WM_CLOSE);
}

void CMainDlgWindow::OnHelp() {
MessageBox("This application demonstrates "
"using private dialog classes to allow "
"a dialog box main window to have it's own "
"icon!", "Help");
}

BEGIN_MESSAGE_MAP(CMainDlgWindow, CDialog)
ON_WM_CLOSE()
ON_COMMAND(IDC_HELP, OnHelp)
ON_COMMAND(IDOK, OnOK)
END_MESSAGE_MAP()



//*************************************************************
// theApp:
// Just creating this application object runs the whole application.
//
CTheApp theApp;


//*************************************************************
//
// Class
// CTheApp
//
// Member Function:
// InitInstance
//
// Purpose:
// This function is called when the object is created.
//
// Parameters:
//
// Return: ( BOOL )
// TRUE if the initialization was successful
// FALSE otherwise
//
// Comments:
//
// History: Date Author Comment
// 5/11/92 Mark Bader Created
//
//*************************************************************

BOOL CTheApp::InitInstance()
{
TRACE( "PRIVDLG is initializing.\n" );
m_pMainWnd = new CMainDlgWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return TRUE;
}


  3 Responses to “Category : C++ Source Code
Archive   : PRIVDLG.ZIP
Filename : PRIVDLG.CPP

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/