( Index )
Month

Brief Information about the September 2000 CSIG Meeting

BANNER--- Large Text Letters for a Banner Page.

Tuesday - Sept. 19th 7:30PM - C/C++ Group, SPRS

Command Box Banner Sample Windows Banner Sample

Welcome to start of a new season for the C++ users group. This group is a "Special Interest Group" of the ACGNJ devoted to discussing programming languages in general and C, C++, and C++ for Windows programming in particular. Each month a small but hopefully useful program (complete with source code) is presented for discussion.

This month I will present two versions of a banner program. Those of you familiar with Unix will recognize the name of a program which creates large letters and may be used to form a header on program code title pages.

The first version might be called a "DOS" version however this is a misnomer because operating systems such as Windows NT do not run on DOS. A more correct term would be called a command box. Commands such says DIR or COPY may be typed in a command box and the output redirected to a file if desired. This is the simplest type of programming since it does not involve handling Windows and Graphics.

The second version of the banner program is compiled using Microsoft Visual C++ version 5. The application generator is used to create a dialog type window using MFC (Microsoft Foundation Classes) and the program is built inside that window. The banner text is presented in that window and a menu allows copying the text to the Clipboard.


SAMPLE CODE
===========
void CBannerWDlg::OnOptionsCopytoclipboard() 
    {
    CString buff;
    HANDLE hMem;
    LPSTR  lpStr;
    int i, bytes, count = m_Banner.GetCount();

    if (!count) { MessageBox("There is nothing to copy."); return; }

    for(i=0,bytes=0; i < count; i++)
	    {
	    bytes += m_Banner.GetTextLen(i);  bytes += 3;  // string + cr, lf, 0
	    }

/* **************************** Sequence of events *********************
    1    GlobalAlloc some memory.
    2    GlobalLock it.
    3    Fill it with "Some data".
    4    GlobalUnlock it.
    5    OpenClipboard.
    6    EmptyClipboard.
    7    SetClipboardData from Global Memory.
    8    CloseClipboard.
   ********************************************************************* */

    hMem = GlobalAlloc(GHND, bytes);
    if (NULL==hMem) { MessageBox("Out of Memory."); return; }

    lpStr = (LPSTR) GlobalLock(hMem);
    if (NULL==lpStr) { MessageBox("Memory Lock Failed."); return; }

    for(i=0,lpStr[0]=0; i<count; i++)    // copy data to memory
	    {
        m_Banner.GetText(i, buff);
        lstrcat(lpStr, LPCTSTR(buff) );lstrcat(lpStr, "\r\n");
	    }

    GlobalUnlock(hMem);
    if (OpenClipboard())
	    {
	EmptyClipboard();
	SetClipboardData(CF_OEMTEXT, hMem);
	CloseClipboard();
	    }
    else MessageBox("Clipboard could not be opened.");
    }

"Random Access" questions start at 7:30 Tuesday night.

SOURCE CODE

Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page