home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C Programming Starter Kit 2.0
/
SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso
/
tybc4
/
commdlg3.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-29
|
4KB
|
185 lines
/*
Program to test the Find and Replace common dialog boxes.
*/
#include <owl\applicat.h>
#include <owl\framewin.h>
#include <owl\findrepl.h>
#include "commdlg3.h"
#include <stdio.h>
#include <string.h>
const int MaxStrLen = 31;
const int MaxLongStrLen = 1024;
// declare the custom application class as
// a subclass of TApplication
class TWinApp : public TApplication
{
public:
TWinApp() : TApplication() {}
protected:
virtual void InitMainWindow();
};
// expand the functionality of TWindow by
// deriving class TMainWindow
class TMainWindow : public TWindow
{
public:
TMainWindow();
protected:
TFindReplaceDialog::TData FRdata;
TFindDialog* pFindDlg;
TReplaceDialog* pReplaceDlg;
// handle invoking the Find dialog box
void CMFind();
// handle clicking the Find Next button
LRESULT EvFindMsg(WPARAM, LPARAM);
// handle the Replace menu item
void CMReplace();
// handle exiting the program
void CMExit();
// handle closing the window
virtual BOOL CanClose();
// write "TRUE" or "FALSE" in string
void BoolToStr(DWORD Flag, char* s);
// declare the message map macro
DECLARE_RESPONSE_TABLE(TMainWindow);
};
DEFINE_RESPONSE_TABLE1(TMainWindow, TWindow)
EV_COMMAND(CM_FIND, CMFind),
EV_COMMAND(CM_REPLACE, CMReplace),
EV_COMMAND(CM_EXIT, CMExit),
EV_REGISTERED(FINDMSGSTRING, EvFindMsg),
END_RESPONSE_TABLE;
TMainWindow::TMainWindow()
: TWindow(0, 0, 0)
{
pFindDlg = NULL;
pReplaceDlg = NULL;
}
void TMainWindow::CMFind()
{
if (!pFindDlg && !pReplaceDlg) {
FRdata.Flags |= FR_DOWN;
pFindDlg = new TFindDialog(this, FRdata);
pFindDlg->Create();
}
}
LRESULT TMainWindow::EvFindMsg(WPARAM, LPARAM lParam)
{
char s[256];
char s2[11];
if (pFindDlg) {
pFindDlg->UpdateData(lParam);
// is the dialog box still opened
if (!(FRdata.Flags & FR_DIALOGTERM)) {
strcpy(s, "Find String: ");
strcat(s, FRdata.FindWhat);
strcat(s, "\nSearch Down: ");
BoolToStr(DWORD(FRdata.Flags & FR_DOWN), s2);
strcat(s, s2);
strcat(s, "Match Case: ");
BoolToStr(DWORD(FRdata.Flags & FR_MATCHCASE), s2);
strcat(s, s2);
strcat(s, "Whole Word: ");
BoolToStr(DWORD(FRdata.Flags & FR_WHOLEWORD), s2);
strcat(s, s2);
MessageBox(s, "Find Dialog Box Data",
MB_OK | MB_ICONINFORMATION);
}
else
pFindDlg = NULL;
}
if (pReplaceDlg) {
pReplaceDlg->UpdateData(lParam);
// is the dialog box still opened
if (!(FRdata.Flags & FR_DIALOGTERM)) {
strcpy(s, "Find String: ");
strcat(s, FRdata.FindWhat);
strcat(s, "\nReplace String: ");
strcat(s, FRdata.ReplaceWith);
strcat(s, "\nSearch Down: ");
BoolToStr(DWORD(FRdata.Flags & FR_DOWN), s2);
strcat(s, s2);
strcat(s, "Match Case: ");
BoolToStr(DWORD(FRdata.Flags & FR_MATCHCASE), s2);
strcat(s, s2);
strcat(s, "Whole Word: ");
BoolToStr(DWORD(FRdata.Flags & FR_WHOLEWORD), s2);
strcat(s, s2);
strcat(s, "Replace Button Clicked: ");
BoolToStr(DWORD(FRdata.Flags & FR_REPLACE), s2);
strcat(s, s2);
strcat(s, "Replace All Button Clicked: ");
BoolToStr(DWORD(FRdata.Flags & FR_REPLACEALL), s2);
strcat(s, s2);
MessageBox(s, "Replace Dialog Box Data",
MB_OK | MB_ICONINFORMATION);
}
else
pReplaceDlg = NULL;
}
return 0;
}
void TMainWindow::CMReplace()
{
if (!pFindDlg && !pReplaceDlg) {
FRdata.Flags = FR_DOWN | FR_MATCHCASE | FR_WHOLEWORD;
pReplaceDlg = new TReplaceDialog(this, FRdata);
pReplaceDlg->Create();
}
}
void TMainWindow::CMExit()
{
Parent->SendMessage(WM_CLOSE);
}
void TMainWindow::BoolToStr(DWORD Flag, char* s)
{
strcpy(s, (Flag != 0) ? "TRUE\n" : "FALSE\n");
}
BOOL TMainWindow::CanClose()
{
return MessageBox("Want to close this application?",
"Query", MB_YESNO | MB_ICONQUESTION) == IDYES;
}
void TWinApp::InitMainWindow()
{
MainWindow = new TFrameWindow(0, "Simple Find/Replace Dialog Box Tester",
new TMainWindow);
// load the menu resource
MainWindow->AssignMenu(TResId(IDM_MAINMENU));
// enable the keyboard handler
MainWindow->EnableKBHandler();
}
int OwlMain(int /* argc */, char** /*argv[] */)
{
TWinApp app;
return app.Run();
}