SftTree/DLL 7.5 - Tree Control
SftBox/OCX 5.0 - Combo Box Control
SftButton/OCX 3.0 - Button Control
SftMask/OCX 7.0 - Masked Edit Control
SftTabs/OCX 6.5 - Tab Control (VB6 only)
SftTree/OCX 7.5 - Tree Control
SftPrintPreview/DLL 2.0 - Print Preview Control (discontinued)
SftTree/DLL 7.5 - Tree Control
SftBox/OCX 5.0 - Combo Box Control
SftButton/OCX 3.0 - Button Control
SftDirectory 3.5 - File/Folder Control (discontinued)
SftMask/OCX 7.0 - Masked Edit Control
SftOptions 1.0 - Registry/INI Control (discontinued)
SftPrintPreview/OCX 1.0 - Print Preview Control (discontinued)
SftTabs/OCX 6.5 - Tab Control (VB6 only)
SftTree/OCX 7.5 - Tree Control
SftTabs/NET 6.0 - Tab Control (discontinued)
SftTree/NET 2.0 - Tree Control
This sample illustrates SftTree/DLL control output.
The source code is located at C:\Program Files (x86)\Softelvdm\SftPrintPreview DLL 2.0\Samples\C\PreviewSftTree\PreviewSftTree.c or C:\Program Files\Softelvdm\SftPrintPreview DLL 2.0\Samples\C\PreviewSftTree\PreviewSftTree.c (on 32-bit Windows versions).
#include <windows.h> #include <stdlib.h> #include <time.h> #include <crtdbg.h> #include "SftPrintPreview.h" /* SftPrintPreview/DLL Header File */ // In order to rebuild this sample, the product SftTree/DLL 7.0 is required // otherwise the following #include directive will fail #include "SftTree.h" /* SftTree/DLL Header File */ #include "resource.h" #define IDC_PREVIEW 100 // ID for preview control #define IDC_TREE 101 // ID for tree control #define LINETEXT TEXT("Softel vdm, Inc. - www.softelvdm.com") #define COLUMNS 3 // # of columns in tree control /**********************************************************************/ /* Globals */ /**********************************************************************/ #define MAINWINDOWCLASS "SampleMainFrame" HINSTANCE m_hInstance; // App Instance Handle HWND m_hwndPreview; // Preview window HWND m_hwndTree; // SftTree/DLL window HMENU m_hMenuMain; // main menu HMENU m_hMenuPreview; // main menu HFONT m_hTreeFont; // printer font /**********************************************************************/ /* Initialize Tree Control Window */ /**********************************************************************/ #define MAX_BITMAPS 57 HBITMAP m_Bitmaps[MAX_BITMAPS]; // bitmaps static _inline int GetABitmapNumber() { return rand() % MAX_BITMAPS; } static _inline HBITMAP GetABitmap() { return m_Bitmaps[GetABitmapNumber()]; } static void AddItem(HWND hwndCtl, int level, BOOL fChild, LPCTSTR lpszText, BOOL fLabel, BOOL fCell, BOOL fRow) { SFT_PICTURE Pic; int i, index; index = SftTree_AddString(m_hwndTree, lpszText);/* Add an item */ SftTree_SetItemLevel(m_hwndTree, index, level);/* change level */ Sft_InitPicture(&Pic); Sft_SetPictureBitmap(&Pic, GetABitmap()); SftTree_SetItemPicture(m_hwndTree, index, &Pic); if (fLabel) { Sft_InitPicture(&Pic); Sft_SetPictureBitmap(&Pic, GetABitmap()); SftTree_SetItemLabel(m_hwndTree, index, GetABitmap()); SftTree_SetRowText(m_hwndTree, index, TEXT("Text")); } if (fCell) { for (i = 0 ; i < COLUMNS ; ++i) { SFTTREE_CELLINFOPARM CellInfo; CellInfo.version = 5; CellInfo.index = index; CellInfo.iCol = i; SftTree_GetCellInfo(m_hwndTree, &CellInfo); CellInfo.Cell.flag = SFTTREE_BMP_LEFT|SFTTREE_TEXT_LEFT; Sft_SetPictureBitmap(&CellInfo.Cell.CellPicture1, GetABitmap()); SftTree_SetCellInfo(m_hwndTree, &CellInfo); } } if (fRow) { SFTTREE_ROWINFOPARM RowInfo; RowInfo.version = 5; RowInfo.index = index; SftTree_GetRowInfo(m_hwndTree, &RowInfo); Sft_SetPictureBitmap(&RowInfo.Row.RowPicture1, GetABitmap()); RowInfo.Row.flag = SFTTREE_BMP_LEFT|SFTTREE_TEXT_LEFT; SftTree_SetRowInfo(m_hwndTree, &RowInfo); } for (i = 1 ; i < COLUMNS ; ++i) { TCHAR szBuffer[80]; if (((index + 3*i) % (COLUMNS+5)) == 0) { wsprintf(szBuffer, TEXT("This is a very long text line in column %d."), i); SftTree_SetTextCol(m_hwndTree, index, i, szBuffer); if (i < COLUMNS -1) { // leave next cell blank ++i; if (fCell) { // clear cell bitmap in each cell SFTTREE_CELLINFOPARM CellInfo; CellInfo.version = 5; CellInfo.index = index; CellInfo.iCol = i; SftTree_GetCellInfo(m_hwndTree, &CellInfo); CellInfo.Cell.flag = SFTTREE_BMP_LEFT|SFTTREE_TEXT_LEFT; Sft_ClearPicture(&CellInfo.Cell.CellPicture1); SftTree_SetCellInfo(m_hwndTree, &CellInfo); } } } else { wsprintf(szBuffer, TEXT("Column %d(%ld)"), i, index); SftTree_SetTextCol(m_hwndTree, index, i, szBuffer); } } } void InitTreeWindow(HWND hwndCtl) { SFT_PICTURE Pic; SFT_PICTURE aThreeItemPictures[3]; int i; srand( (unsigned)time( NULL ) ); // Init random number generator // load all bitmaps for (i = 0 ; i < MAX_BITMAPS ; ++i) m_Bitmaps[i] = LoadBitmap(m_hInstance, MAKEINTRESOURCE(IDB_BITMAP0+i)); SftTree_SetShowHeader(m_hwndTree, TRUE);/* Show column headers */ /* Register the label picture size. All label pictures */ /* used must be the same size. Only one picture needs to */ /* be registered, even if several are used. */ Sft_InitPicture(&Pic); Sft_SetPictureBitmap(&Pic, m_Bitmaps[0]);/* Load a label bitmap */ SftTree_SetItemLabelPicture(m_hwndTree, -1, &Pic);/* Register the label picture size */ /* Register the plus/minus bitmaps. These bitmaps are */ /* used for all items in the tree control. All three */ /* bitmaps must be the same size. You cannot override */ /* the plus/minus bitmap for individual items. */ SftTree_SetPlusMinus(m_hwndTree, m_Bitmaps+54);/* Use +/- bitmaps */ /* Register the item pictures. These pictures are used */ /* for all items in the tree control. All three pictures */ /* must be the same size. */ Sft_InitPicture(&aThreeItemPictures[0]); Sft_InitPicture(&aThreeItemPictures[1]); Sft_InitPicture(&aThreeItemPictures[2]); Sft_SetPictureBitmap(&aThreeItemPictures[0], m_Bitmaps[0]);/* Expandable picture */ Sft_SetPictureBitmap(&aThreeItemPictures[1], m_Bitmaps[1]);/* Expanded picture */ Sft_SetPictureBitmap(&aThreeItemPictures[2], m_Bitmaps[2]);/* Leaf picture */ SftTree_SetPictures(m_hwndTree, aThreeItemPictures);/* Use item picture */ SftTree_SetItemPictureAlign(m_hwndTree, TRUE);/* Align item bitmaps */ /* Register the cell picture size. All cell pictures used */ /* must be the same size. Only one picture needs to be */ /* registered, even if several are used. */ { SFTTREE_CELLINFOPARM CellInfo; CellInfo.version = 5; CellInfo.index = -1; /* Registering picture size */ Sft_InitPicture(&CellInfo.Cell.CellPicture1); Sft_SetPictureBitmap(&CellInfo.Cell.CellPicture1, m_Bitmaps[0]); SftTree_SetCellInfo(m_hwndTree, &CellInfo);/* Register use of cell pictures */ } SftTree_SetTreeLineStyle(m_hwndTree, SFTTREE_TREELINE_DOT0);/* Dotted tree lines (incl. level 0) */ SftTree_SetShowButtons(m_hwndTree, TRUE);/* Expand/collapse buttons (level 1..n) */ SftTree_SetShowButton0(m_hwndTree, TRUE);/* Show expand/collapse buttons (level 0) */ SftTree_SetButtons(m_hwndTree, SFTTREE_BUTTON_AUTOMATIC);/* Automatic button style */ SftTree_SetShowGrid(m_hwndTree, TRUE);/* Show grid */ SftTree_SetGridStyle(m_hwndTree, SFTTREE_GRID_BOTH_DOT);/* Dotted grid lines */ SftTree_SetShowTruncated(m_hwndTree, TRUE);/* Show ... if truncated */ SftTree_SetSelectionStyle(m_hwndTree, SFTTREE_SELECTION_CELL1);/* Select first cell only */ SftTree_SetSelectionArea(m_hwndTree, SFTTREE_SELECTIONAREA_ALLCELLS);/* Selection changes by clicking on an item's cells */ SftTree_SetFlyby(m_hwndTree, TRUE); /* Flyby highlighting */ SftTree_SetScrollTips(m_hwndTree, TRUE);/* Show Scrolltips */ SftTree_SetReorderColumns(m_hwndTree, TRUE);/* Column reordering */ SftTree_SetOpenEnded(m_hwndTree, TRUE);/* Last column width */ SftTree_SetShowHeaderButtons(m_hwndTree, TRUE);/* Show column header as buttons */ /* Define columns */ { SFTTREE_COLUMN_EX aCol[3] = { { 0, 0, /* Reserved */ 100, /* Width (in pixels) */ ES_LEFT | SFTTREE_TOOLTIP, /* Cell alignment */ ES_LEFT, /* Title style */ TEXT("Title0"), /* Column header title */ NULL, NULL, /* Reserved field and bitmap handle */ SFTTREE_BMP_RIGHT, /* Picture alignment */ 0, 0, 0, /* Reserved fields */ SFTTREE_NOCOLOR, /* Cell background color */ SFTTREE_NOCOLOR, /* Cell foreground color */ SFTTREE_NOCOLOR, /* Selected cell background color */ SFTTREE_NOCOLOR, /* Selected cell foreground color */ 0, /* Real column position (set by SetColumns call) */ 0, /* Display column number (display position) */ SFTTREE_COL_MERGE | /* Column can merge with next */ SFTTREE_COL_MERGEINTO | /* Previous column can merge into this column */ 0, /* Column flag */ 0, /* Minimum column width */ }, { 0, 0, /* Reserved */ 100, /* Width (in pixels) */ ES_LEFT | SFTTREE_TOOLTIP, /* Cell alignment */ ES_LEFT, /* Title style */ TEXT("Title1"), /* Column header title */ NULL, NULL, /* Reserved field and bitmap handle */ SFTTREE_BMP_RIGHT, /* Picture alignment */ 0, 0, 0, /* Reserved fields */ SFTTREE_NOCOLOR, /* Cell background color */ SFTTREE_NOCOLOR, /* Cell foreground color */ SFTTREE_NOCOLOR, /* Selected cell background color */ SFTTREE_NOCOLOR, /* Selected cell foreground color */ 0, /* Real column position (set by SetColumns call) */ 1, /* Display column number (display position) */ SFTTREE_COL_MERGE | /* Column can merge with next */ SFTTREE_COL_MERGEINTO | /* Previous column can merge into this column */ 0, /* Column flag */ 0, /* Minimum column width */ }, { 0, 0, /* Reserved */ 100, /* Width (in pixels) */ ES_LEFT | SFTTREE_TOOLTIP, /* Cell alignment */ ES_LEFT, /* Title style */ TEXT("Title2"), /* Column header title */ NULL, NULL, /* Reserved field and bitmap handle */ SFTTREE_BMP_RIGHT, /* Picture alignment */ 0, 0, 0, /* Reserved fields */ SFTTREE_NOCOLOR, /* Cell background color */ SFTTREE_NOCOLOR, /* Cell foreground color */ SFTTREE_NOCOLOR, /* Selected cell background color */ SFTTREE_NOCOLOR, /* Selected cell foreground color */ 0, /* Real column position (set by SetColumns call) */ 2, /* Display column number (display position) */ SFTTREE_COL_MERGE | /* Column can merge with next */ SFTTREE_COL_MERGEINTO | /* Previous column can merge into this column */ 0, /* Column flag */ 0, /* Minimum column width */ } }; SftTree_SetColumnsEx(m_hwndTree, 3, aCol);/* Set column attributes */ } /* Use column header pictures. All pictures used must be */ /* the same size. */ { LPSFTTREE_COLUMN_EX lpCol; int nCols; nCols = SftTree_GetColumnsEx(m_hwndTree, &lpCol);/* Get column attributes */ Sft_SetPictureBitmap(&lpCol[0].Picture1, GetABitmap());/* Set column header picture */ Sft_ClearPicture(&lpCol[1].Picture1);/* Clear column header picture */ Sft_SetPictureBitmap(&lpCol[2].Picture1, GetABitmap());/* Set column header picture */ SftTree_SetColumnsEx(m_hwndTree, nCols, lpCol);/* Set new column attributes */ } SftTree_SetShowRowHeader(m_hwndTree, SFTTREE_ROWSTYLE_BUTTONCOUNT0);/* Row style */ /* Register the row header picture size. All row header */ /* pictures used must be the same size. Only one picture */ /* needs to be registered, even if several are used. */ { SFTTREE_ROWINFOPARM RowInfo; RowInfo.version = 5; RowInfo.index = -1; Sft_InitPicture(&RowInfo.Row.RowPicture1); Sft_SetPictureBitmap(&RowInfo.Row.RowPicture1, GetABitmap()); SftTree_SetRowInfo(m_hwndTree, &RowInfo); } SftTree_SetRowColText(m_hwndTree, TEXT("?"));/* Row/column header text */ Sft_InitPicture(&Pic); Sft_SetPictureBitmap(&Pic, GetABitmap());/* Row/column header picture */ SftTree_SetRowColPicture(m_hwndTree, &Pic);/* Row/column picture */ SftTree_SetRowColPictureStyle(m_hwndTree, SFTTREE_BMP_RIGHT);/* Row/column picture alignment */ SftTree_SetCharSearchMode(m_hwndTree, SFTTREE_CHARSEARCH_ALLCHARS, -1);/* Consider all characters typed */ /* Change the default colors */ { SFTTREE_COLORS Colors; SftTree_GetCtlColors(m_hwndTree, &Colors);/* Get current color settings */ Colors.colorTreeLines = COLOR_BTNSHADOW | 0x80000000L;/* Tree line color */ Colors.colorTreeLinesGrayed = COLOR_BTNSHADOW | 0x80000000L;/* Tree line color (disabled control) */ Colors.colorSelBgNoFocus = COLOR_BTNFACE | 0x80000000L;/* Selection background color (no input focus) */ Colors.colorSelFgNoFocus = COLOR_BTNTEXT | 0x80000000L;/* Selection foreground color (no input focus) */ SftTree_SetCtlColors(m_hwndTree, &Colors);/* Set new colors */ } { int count = 0; int i; for (i = 0 ; i < 200 ; ++i) { TCHAR szBuffer[80]; wsprintf(szBuffer, TEXT("Item %d"), count++); AddItem(m_hwndTree, 0, FALSE, szBuffer, FALSE, FALSE, FALSE); wsprintf(szBuffer, TEXT("Item %d"), count++); AddItem(m_hwndTree, 1, FALSE, szBuffer, TRUE, FALSE, FALSE); wsprintf(szBuffer, TEXT("Item %d"), count++); AddItem(m_hwndTree, 2, FALSE, szBuffer, FALSE, FALSE, FALSE); wsprintf(szBuffer, TEXT("Item %d"), count++); AddItem(m_hwndTree, 3, TRUE, szBuffer, FALSE, TRUE, FALSE); wsprintf(szBuffer, TEXT("Item %d"), count++); AddItem(m_hwndTree, 3, TRUE, szBuffer, TRUE, FALSE, TRUE); wsprintf(szBuffer, TEXT("Item %d"), count++); AddItem(m_hwndTree, 2, FALSE, szBuffer, FALSE, FALSE, FALSE); wsprintf(szBuffer, TEXT("Item %d"), count++); AddItem(m_hwndTree, 3, TRUE, szBuffer, FALSE, FALSE, FALSE); wsprintf(szBuffer, TEXT("Item %d"), count++); AddItem(m_hwndTree, 2, TRUE, szBuffer, FALSE, TRUE, TRUE); wsprintf(szBuffer, TEXT("Item %d"), count++); AddItem(m_hwndTree, 1, FALSE, szBuffer, FALSE, FALSE, FALSE); wsprintf(szBuffer, TEXT("Item %d"), count++); AddItem(m_hwndTree, 2, TRUE, szBuffer, TRUE, FALSE, TRUE); wsprintf(szBuffer, TEXT("Item %d"), count++); AddItem(m_hwndTree, 2, TRUE, szBuffer, FALSE, TRUE, FALSE); } } /* Make all column widths optimal, so text and pictures */ /* are not clipped horizontally. */ SftTree_MakeColumnOptimal(m_hwndTree, -1);/* Make column widths optimal */ /* Make row header width optimal, so text and pictures are */ /* not clipped horizontally. */ SftTree_MakeRowHeaderOptimal(m_hwndTree);/* Make row header width optimal */ SftTree_RecalcHorizontalExtent(m_hwndTree);/* Update horizontal scroll bar */ } void TermTreeWindow(HWND hwndCtl) { int i; // delete all bitmaps for (i = 0 ; i < MAX_BITMAPS ; ++i) { if (m_Bitmaps[i]) DeleteObject(m_Bitmaps[i]); m_Bitmaps[i] = NULL; } } /**********************************************************************/ /* Initialize Preview Window */ /**********************************************************************/ void InitPreviewWindow(HWND hwndCtl) { // retrieve current control settings SFTPRINTPREVIEW_CONTROL Ctl; Ctl.cbSize = sizeof(SFTPRINTPREVIEW_CONTROL); if (!SftPrintPreview_GetControlInfo(hwndCtl, &Ctl)) { _ASSERT(0); // the SFTPRINTPREVIEW_CONTROL structure's cbSize member wasn't initialized properly return; } // set all desired options Ctl.fCenterOnClick = FALSE; Ctl.fDragPage = TRUE; Ctl.iZoomStyle = SFTPRINTPREVIEW_ZOOMSTYLE_BOTHBUTTONS_EXACT; Ctl.numPageRows = 1; // default to 1x2 pages Ctl.numPageGroups = 2; Ctl.zoom = 0; // start out with multiple pages lstrcpy(Ctl.szOutputName, TEXT("SftPrintPreview PreviewSftTree Sample Output")); // job name when printing lstrcpy(Ctl.szHeaderRight, TEXT("SftPrintPreview/DLL PreviewSftTree Sample")); lstrcpy(Ctl.szFooterLeft, TEXT("www.softelvdm.com")); if (!SftPrintPreview_SetControlInfo(hwndCtl, &Ctl)) { int errorValue = Ctl.errorValue; _ASSERT(0); // an error occurred, check errorValue for error code return; } } void DefineContents(HWND hwndCtl) { SFTPRINTPREVIEW_CONTROL Ctl; Ctl.cbSize = sizeof(SFTPRINTPREVIEW_CONTROL); if (!SftPrintPreview_GetControlInfo(hwndCtl, &Ctl)) { _ASSERT(0); // the SFTPRINTPREVIEW_CONTROL structure's cbSize member wasn't initialized properly return; } // define desired contents to preview/print Ctl.lpDrawPageWorkArea = (SFTPRINTPREVIEW_DWORD_PTR) NULL;// no workarea needed Ctl.lpDrawInfoProc = NULL; // no callback Ctl.hwndContent = m_hwndTree; // SftTree/DLL window Ctl.hwndData = NULL; // no data window (content window is data window) if (!SftPrintPreview_SetControlInfo(hwndCtl, &Ctl)) { int errorValue = Ctl.errorValue; _ASSERT(0); // an error occurred, check errorValue for error codes return; } } static void ViewPages(int rows, int cols) { SFTPRINTPREVIEW_CONTROL Ctl; memset(&Ctl, 0, sizeof(Ctl)); Ctl.cbSize = sizeof(Ctl); SftPrintPreview_GetControlInfo(m_hwndPreview, &Ctl); Ctl.zoom = 0; Ctl.numPageRows = rows; Ctl.numPageGroups = cols; SftPrintPreview_SetControlInfo(m_hwndPreview, &Ctl); SftPrintPreview_ZoomReset(m_hwndPreview); } /**********************************************************************/ /* Main Window Proc */ /**********************************************************************/ LRESULT CALLBACK MainWindowProc(HWND hwndMain, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CREATE: // create a preview window m_hwndPreview = CreateWindow(TEXT(SFTPRINTPREVIEW_CLASS), NULL, WS_CHILD, 0, 0, 0, 0, hwndMain, (HMENU) IDC_PREVIEW, m_hInstance, NULL); _ASSERT(m_hwndPreview); if (!m_hwndPreview) return -1; m_hwndTree = CreateWindow(TEXT(SFTTREE_CLASS), NULL, SFTTREESTYLE_NOTIFY | /* Notify parent window */ SFTTREESTYLE_LEFTBUTTONONLY | /* Only respond to left mouse button */ SFTTREESTYLE_SCROLL | /* Honor WS_H/VSCROLL */ WS_HSCROLL | WS_VSCROLL | /* Vertical and horizontal scrollbars */ WS_VISIBLE | WS_CHILD, /* Visible, child window */ 0, 0, 0, 0, hwndMain, (HMENU) IDC_TREE, m_hInstance, NULL); _ASSERT(m_hwndPreview); if (!m_hwndPreview) return -1; // initialize preview window InitPreviewWindow(m_hwndPreview); // initialize tree with data SendMessage(m_hwndTree, WM_SETREDRAW, FALSE, 0L); SendMessage(m_hwndTree, WM_SETFONT, (WPARAM) m_hTreeFont, TRUE); InitTreeWindow(m_hwndTree); SendMessage(m_hwndTree, WM_SETREDRAW, TRUE, 0L); InvalidateRect(m_hwndTree, NULL, TRUE); // connect preview window to tree DefineContents(m_hwndPreview); SetFocus(m_hwndTree); ShowWindow(hwndMain, SW_SHOW); break; case WM_DESTROY: if (m_hwndPreview) DestroyWindow(m_hwndPreview); m_hwndPreview = NULL; if (m_hwndTree) DestroyWindow(m_hwndTree); m_hwndTree = NULL; break; case WM_SIZE: { RECT rect; GetClientRect(hwndMain, &rect); MoveWindow(m_hwndPreview, 0, 0, rect.right-rect.left, rect.bottom-rect.top, TRUE); MoveWindow(m_hwndTree, 0, 0, rect.right-rect.left, rect.bottom-rect.top, TRUE); break; } case WM_SETFOCUS: if (IsWindowVisible(m_hwndPreview)) SetFocus(m_hwndPreview); else SetFocus(m_hwndTree); break; case WM_COMMAND: { HWND hwndCtl = (HWND) lParam; int id = LOWORD(wParam); int code = HIWORD(wParam); if (hwndCtl) { switch (id) { case IDC_PREVIEW: switch (code) { case SFTPRINTPREVIEWN_STARTPRINTING: SftPrintPreview_Print(hwndCtl, hwndMain); break; } break; case IDC_TREE: switch (code) { case SFTTREEN_LBUTTONDBLCLK_TEXT: case SFTTREEN_LBUTTONDOWN_BUTTON: case SFTTREEN_LBUTTONDBLCLK_BUTTON: case SFTTREEN_LBUTTONDOWN_PLUSMIN: case SFTTREEN_LBUTTONDBLCLK_PLUSMIN: { int index; BOOL fExpand, fControl; /* Get current position */ index = SftTree_GetExpandCollapseIndex(m_hwndTree);/* Get item to expand/collapse */ /* Check if item is expanded */ fExpand = SftTree_GetItemExpand(m_hwndTree, index); /* If the CONTROL key is pressed, expand all dependent levels */ fControl = (BOOL)(GetKeyState(VK_CONTROL)&0x8000); if (fExpand) SftTree_Collapse(m_hwndTree, index, TRUE); else SftTree_Expand(m_hwndTree, index, TRUE, fControl); break; } case SFTTREEN_LBUTTONDBLCLK_COLUMNRES: { /* Resize column optimally */ int realCol = SftTree_GetResizeColumn(m_hwndTree); if (realCol >= 0) { SftTree_MakeColumnOptimal(m_hwndTree, realCol);/* Make column width optimal */ SftTree_RecalcHorizontalExtent(m_hwndTree);/* Update horizontal scroll bar */ } break; } } break; } } else { switch (id) { case IDM_FILE_PRINTPREV: ShowWindow(m_hwndTree, SW_HIDE); InitPreviewWindow(m_hwndPreview); ShowWindow(m_hwndPreview, SW_SHOW); SetFocus(m_hwndPreview); SetMenu(hwndMain, m_hMenuPreview); break; case IDM_FILE_PRINTSETUP: SftPrintPreview_PrintSetup(m_hwndPreview, hwndMain); break; case IDM_FILE_PRINT: SftPrintPreview_PrintDialog(m_hwndPreview, hwndMain, FALSE); break; case ID_APP_EXIT: SendMessage(hwndMain, WM_CLOSE, 0, 0); break; case IDM_EDIT_PAGESETUP: SftPrintPreview_PageSetup(m_hwndPreview, hwndMain); break; case IDM_ZOOM_IN: { SFTPRINTPREVIEW_ZOOMIN zi; zi.centerPosX = zi.centerPosY = -1.0; zi.zoomFactor = +100; SftPrintPreview_ZoomIn(m_hwndPreview, &zi); break; } case IDM_ZOOM_OUT: { SFTPRINTPREVIEW_ZOOMIN zi; zi.centerPosX = zi.centerPosY = -1.0; zi.zoomFactor = -100; SftPrintPreview_ZoomIn(m_hwndPreview, &zi); break; } case IDM_ZOOM_EDIT: SftPrintPreview_ToolBarEdit(m_hwndPreview, SFTPRINTPREVIEW_TOOLBAR_ZOOM); break; case IDM_VIEW_NEXTPAGE: { SFTPRINTPREVIEW_CONTROL Ctl; memset(&Ctl, 0, sizeof(Ctl)); Ctl.cbSize = sizeof(Ctl); SftPrintPreview_GetControlInfo(m_hwndPreview, &Ctl); if (Ctl.zoom == 0) Ctl.currPage += Ctl.numPageRows * Ctl.numPageGroups; else ++Ctl.currPage; SftPrintPreview_SetControlInfo(m_hwndPreview, &Ctl); break; } case IDM_VIEW_PREVPAGE: { SFTPRINTPREVIEW_CONTROL Ctl; memset(&Ctl, 0, sizeof(Ctl)); Ctl.cbSize = sizeof(Ctl); SftPrintPreview_GetControlInfo(m_hwndPreview, &Ctl); if (Ctl.zoom == 0) Ctl.currPage -= Ctl.numPageRows * Ctl.numPageGroups; else --Ctl.currPage; SftPrintPreview_SetControlInfo(m_hwndPreview, &Ctl); break; } case IDM_VIEW_SINGLEPAGE: { SFTPRINTPREVIEW_ZOOM zoom; memset(&zoom, 0, sizeof(zoom)); zoom.zoomFactor = SFTPRINTPREVIEW_ZOOM_FULLPAGE; zoom.centerPosX = zoom.centerPosY = 0.0; SftPrintPreview_Zoom(m_hwndPreview, &zoom); break; } case IDM_VIEW_1x2: ViewPages(1, 2); break; case IDM_VIEW_2x4: ViewPages(2, 4); break; case IDM_VIEW_3x6: ViewPages(3, 6); break; case IDM_VIEW_4x8: ViewPages(4, 8); break; case IDM_VIEW_5x10: ViewPages(5, 10); break; case IDM_VIEW_6x12: ViewPages(6, 12); break; case IDM_VIEW_PAGE: SftPrintPreview_ToolBarEdit(m_hwndPreview, SFTPRINTPREVIEW_TOOLBAR_PAGE); break; } } break; } case WM_NOTIFY: { int id = (int) wParam; LPNMHDR pnmh = (LPNMHDR) lParam; switch (id) { case IDC_PREVIEW: switch (pnmh->code) { case NM_SFTPRINTPREVIEW_CLOSE_CODE: { // user wants to close NM_SFTPRINTPREVIEW_CLOSE* pNtfy = (NM_SFTPRINTPREVIEW_CLOSE*) lParam; ShowWindow(m_hwndPreview, SW_HIDE); ShowWindow(m_hwndTree, SW_SHOW); SetFocus(m_hwndTree); SetMenu(hwndMain, m_hMenuMain); break; } case NM_SFTPRINTPREVIEW_HELP_CODE: { // Help requested NM_SFTPRINTPREVIEW_HELP* pNtfy = (NM_SFTPRINTPREVIEW_HELP*) lParam; MessageBox(hwndMain, TEXT("Sorry, this sample application doesn't include online help."), TEXT("SftPrintPreview/DLL"), MB_OK); break; } case NM_SFTPRINTPREVIEW_PAGESETUP_CODE: { // Page setup requested SftPrintPreview_PageSetup(m_hwndPreview, hwndMain); break; } } break; } break; } case WM_INITMENUPOPUP: { HMENU hMenu = (HMENU) wParam; int pos = LOWORD(lParam); BOOL fMain = HIWORD(lParam); int i, count; count = GetMenuItemCount(hMenu); for (i = 0 ; i < count ; ++i) { UINT ID = GetMenuItemID(hMenu, i); switch(ID) { default: case 0: case -1: break; case IDM_VIEW_SINGLEPAGE: case IDM_VIEW_1x2: case IDM_VIEW_2x4: case IDM_VIEW_3x6: case IDM_VIEW_4x8: case IDM_VIEW_5x10: case IDM_VIEW_6x12: case IDM_VIEW_PAGE: case IDM_EDIT_PAGESETUP: { SFTPRINTPREVIEW_CONTROL Ctl; memset(&Ctl, 0, sizeof(Ctl)); Ctl.cbSize = sizeof(Ctl); SftPrintPreview_GetControlInfo(m_hwndPreview, &Ctl); EnableMenuItem(hMenu, i, MF_BYPOSITION | ((Ctl.hOwnDevMode && Ctl.hOwnDevNames) ? MF_ENABLED : MF_GRAYED)); break; } case IDM_ZOOM_IN: { SFTPRINTPREVIEW_CONTROL Ctl; memset(&Ctl, 0, sizeof(Ctl)); Ctl.cbSize = sizeof(Ctl); SftPrintPreview_GetControlInfo(m_hwndPreview, &Ctl); EnableMenuItem(hMenu, i, MF_BYPOSITION | ((Ctl.hOwnDevMode && Ctl.hOwnDevNames && Ctl.zoom < Ctl.maxZoom) ? MF_ENABLED : MF_GRAYED)); break; } case IDM_ZOOM_OUT: { SFTPRINTPREVIEW_CONTROL Ctl; memset(&Ctl, 0, sizeof(Ctl)); Ctl.cbSize = sizeof(Ctl); SftPrintPreview_GetControlInfo(m_hwndPreview, &Ctl); EnableMenuItem(hMenu, i, MF_BYPOSITION | ((Ctl.hOwnDevMode && Ctl.hOwnDevNames && Ctl.zoom > 0) ? MF_ENABLED : MF_GRAYED)); break; } case IDM_VIEW_NEXTPAGE: { SFTPRINTPREVIEW_CONTROL Ctl; BOOL fEnable = TRUE; memset(&Ctl, 0, sizeof(Ctl)); Ctl.cbSize = sizeof(Ctl); SftPrintPreview_GetControlInfo(m_hwndPreview, &Ctl); if (Ctl.zoom == 0) { int pages = Ctl.numPageRows * Ctl.numPageGroups; fEnable = Ctl.firstPage + pages < Ctl.maxPages-1; } else { fEnable = (Ctl.currPage < Ctl.maxPages-1); } EnableMenuItem(hMenu, i, MF_BYPOSITION | ((Ctl.hOwnDevMode && Ctl.hOwnDevNames && fEnable) ? MF_ENABLED : MF_GRAYED)); break; } case IDM_VIEW_PREVPAGE: { SFTPRINTPREVIEW_CONTROL Ctl; BOOL fEnable = TRUE; memset(&Ctl, 0, sizeof(Ctl)); Ctl.cbSize = sizeof(Ctl); SftPrintPreview_GetControlInfo(m_hwndPreview, &Ctl); EnableMenuItem(hMenu, i, MF_BYPOSITION | ((Ctl.hOwnDevMode && Ctl.hOwnDevNames && Ctl.currPage > 0) ? MF_ENABLED : MF_GRAYED)); break; } } } break; } case WM_CLOSE: if (IsWindowVisible(m_hwndTree)) PostQuitMessage(1); else { ShowWindow(m_hwndPreview, SW_HIDE); ShowWindow(m_hwndTree, SW_SHOW); SetFocus(m_hwndTree); SetMenu(hwndMain, m_hMenuMain); return 0L; } break; } return DefWindowProc(hwndMain, uMsg, wParam, lParam); } /**********************************************************************/ /* WinMain */ /**********************************************************************/ int PASCAL WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpszCmdLine, int cmdShow) { WNDCLASS wndClass; HWND hwndMain; MSG msg; m_hInstance = hinst; msg.wParam = 0; // Register with SftPrintPreview/DLL SftPrintPreview_RegisterApp(m_hInstance); // Register with SftTree/DLL SftTree_RegisterApp(m_hInstance); // Register main frame window memset(&wndClass, 0, sizeof(wndClass)); wndClass.lpfnWndProc = MainWindowProc; wndClass.hInstance = m_hInstance; wndClass.hIcon = LoadIcon(m_hInstance, MAKEINTRESOURCE(IDI_ICON1)); wndClass.hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)); wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wndClass.lpszClassName = TEXT(MAINWINDOWCLASS); if (!RegisterClass(&wndClass)) { _ASSERT(0); return -1; } m_hMenuMain = LoadMenu(m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME)); _ASSERT(m_hMenuMain); m_hMenuPreview = LoadMenu(m_hInstance, MAKEINTRESOURCE(IDR_PREVIEW)); _ASSERT(m_hMenuPreview); // Create an 8pt Arial font for the tree control { HDC hDC = GetDC(NULL); int height = MulDiv(8, GetDeviceCaps(hDC, LOGPIXELSY), 72);// 8 point font m_hTreeFont = CreateFont(- height, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE|DEFAULT_PITCH, TEXT("Microsoft Sans Serif")); _ASSERT(m_hTreeFont); ReleaseDC(NULL, hDC); } // Create main frame window hwndMain = CreateWindowEx(0, TEXT(MAINWINDOWCLASS), TEXT("SftPrintPreview/DLL PreviewSftTree Sample"), WS_OVERLAPPEDWINDOW|WS_SIZEBOX|WS_VISIBLE, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, m_hMenuMain, m_hInstance, NULL); _ASSERT(hwndMain); if (hwndMain) { for ( ; ; ) { if (GetMessage(&msg, NULL, 0, 0) == 0) break; TranslateMessage(&msg); DispatchMessage(&msg); } } DeleteObject(m_hTreeFont); DestroyMenu(m_hMenuMain); DestroyMenu(m_hMenuPreview); if (!UnregisterClass(TEXT(MAINWINDOWCLASS), m_hInstance)) _ASSERT(0); SftTree_UnregisterApp(m_hInstance); /* Unregister from SftTree/DLL */ SftPrintPreview_UnregisterApp(m_hInstance); /* Unregister from SftPrintPreview/DLL */ return (int) msg.wParam; }