// Flat Scroll Bar.c : Implementation File
// Control Spy: Flat Scroll Bar
// Mark J. Finocchio (markfi), Microsoft Corporation
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) 1998 Microsoft Corporation. All Rights Reserved.
// Defines
#define CSMAIN
// Included files
#include <windows.h>
#include <windowsx.h>
#include <commctrl.h>
#include <richedit.h>
#include <stdio.h>
#include "Parser\Cci.h"
#include "Flat Scroll Bar.h"
#include "Resource\Resource.h"
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// ** User definable Control Implementation Code
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// User global variables
HPALETTE g_hPalette = NULL; // Value returned by 'palette' in parser
// Name: InitialControlStyles
// Description: Control styles used upon initial creation
// Parameters: Pointer to styles and extended styles
// Returns: none
void InitialControlStyles(LPDWORD p_pStyles,LPDWORD p_pExStyles)
{
*p_pStyles = 0;
*p_pExStyles = 0;
}
// Name: ControlStateCallback
// Description: Control state callback for user code
// Parameters: State, can be CSPY_STARTUP, CSPY_SHUTDOWN, or user numeric state value provided
// through interface
// Returns: none
void ControlStateCallback(INT p_dState)
{
// Customizable code placed here
// Parent handle is g_hContainer
// Main Dialog handle is g_hDialog
// Instance handle is g_hInstance
switch(p_dState)
{
case 0: // Numeric state generated via interface
break;
case CSPY_STARTUP: // Control just created
{
SCROLLINFO siBar;
// Initialize scroll bars
InitializeFlatSB(g_hContainer);
FlatSB_ShowScrollBar(g_hContainer,SB_BOTH,TRUE);
siBar.cbSize = sizeof(SCROLLINFO);
siBar.fMask = SIF_PAGE;
siBar.nPage = 32;
FlatSB_SetScrollInfo(g_hContainer,SB_HORZ,&siBar,TRUE);
FlatSB_SetScrollInfo(g_hContainer,SB_VERT,&siBar,TRUE);
}
break;
case CSPY_SHUTDOWN: // Control spy closing
break;
}
}
// Name: ProcessControlNotification
// Description: Handles all notification messages from the contol, callbacks handled here
// Parameters: Notification message structure
// Returns: Result
LRESULT ProcessControlNotification(LPNMHDR p_pNotifyStruct)
{
// Custom control notification messages handled here
// Parent handle is g_hContainer
// Main Dialog handle is g_hDialog
// Instance handle is g_hInstance
// Return
return 0;
}
// Name: ProcessControlCommand
// Description: Handles all command messages from the contol, callbacks handled here
// Parameters: Command notification code
// Returns: Result
LRESULT ProcessControlCommand(WORD p_wCode)
{
// Parent handle is g_hContainer
// Main Dialog handle is g_hDialog
// Instance handle is g_hInstance
// Return
return 0;
}
// Name: ProcessWindowMessage
// Description: Handles all window messages sent to container as a direct result of the
// contol, callbacks handled here
// Parameters: Message, wParam, lParam
// Returns: Result
LRESULT ProcessWindowMessage(UINT p_iMsg,WPARAM p_wParam,LPARAM p_lParam)
{
// Parent handle is g_hContainer
// Main Dialog handle is g_hDialog
// Instance handle is g_hInstance
switch(p_iMsg)
{
case WM_HSCROLL: // Horizontal scroll event
case WM_VSCROLL: // Vertical scroll event
{
int dBar;
// Determine which scroll bar
dBar = (p_iMsg==WM_HSCROLL)?SB_HORZ:SB_VERT;
// Set position
switch(LOWORD(p_wParam))
{
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
FlatSB_SetScrollPos(g_hContainer,dBar,HIWORD(p_wParam),TRUE);
break;
case SB_LINEUP:
FlatSB_SetScrollPos(g_hContainer,dBar,FlatSB_GetScrollPos(g_hContainer,dBar)-2,TRUE);
break;
case SB_LINEDOWN:
FlatSB_SetScrollPos(g_hContainer,dBar,FlatSB_GetScrollPos(g_hContainer,dBar)+2,TRUE);
break;
case SB_PAGEUP:
FlatSB_SetScrollPos(g_hContainer,dBar,FlatSB_GetScrollPos(g_hContainer,dBar)-32,TRUE);
break;
case SB_PAGEDOWN:
FlatSB_SetScrollPos(g_hContainer,dBar,FlatSB_GetScrollPos(g_hContainer,dBar)+32,TRUE);
break;
}
break;
}
}
// Return
return 0;
}
// Name: RegisterControl
// Description: Used to register the control so it may be created
// Parameters: none
// Returns: none
void RegisterControl()
{
INITCOMMONCONTROLSEX icc;
// Initialize common controls structure
icc.dwSize = sizeof(INITCOMMONCONTROLSEX);
icc.dwICC = ICC_BAR_CLASSES;
// Initialize common control
InitCommonControlsEx(&icc);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// ** Background Logic Code
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Name: WinMain
// Description: Main entry point
// Parameters: Application instance, previous instance, command line, show command
// Returns: Return code
int WINAPI WinMain(HINSTANCE p_hInstance,HINSTANCE p_hPrevInstance,PSTR p_szCmdLine,int p_iCmdShow)
{
RegisterControl();
// Make instance handle available to all functions
g_hInstance = p_hInstance;
// Initialize global variables
g_dLastNotifyIndex = -1;
g_dLastMessageIndex = -1;
g_dLastSendMessageIndex = -1;
g_dLastStylesIndex = -1;
g_dLastExStylesIndex = -1;
g_hStyles = NULL;
g_hInformation = NULL;
g_hControl = NULL;
g_cFilter = '\0';
g_dSLCurrent = -1;
g_dSLCount = 0;
g_pSL = NULL;
g_pSLIndex = NULL;
g_bSendAll = FALSE;
g_bLogging = FALSE;
g_hLogOn = NULL;
g_hLogOff = NULL;
// Main application dialog
return DialogBox(p_hInstance,MAKEINTRESOURCE(IDD_MAINDIALOG),NULL,DlgProc);
}
// Name: CreateControl
// Description: Creates and initializes the control on the specified window.
// Parameters: Creation styles, extended styles
// Returns: none
void CreateControl(UINT p_dStyles,UINT p_dExStyles)
{
// >> Start control specific
// Set control as container so can still track events
g_hControl = g_hContainer;
// End control specific <<
// Initialize control
ControlStateCallback(CSPY_STARTUP);
}
// Name: DialogProc
// Description: Dialog message callback
// Parameters: Handle to dialog, message, message parameters
// Returns: TRUE if handled message, FALSE otherwise
BOOL CALLBACK DlgProc(HWND p_hDlg,UINT p_iMsg,WPARAM p_wParam,LPARAM p_lParam)
{
switch(p_iMsg)
{
// Initialize Dialog
case WM_INITDIALOG:
{
DWORD dControlStyles;
DWORD dControlExStyles;
// Make dialog handle available to all functions
g_hDialog = p_hDlg;
// Create support controls (tooltips, images lists, etc.)
CreateSupportControls();
// Create control
InitialControlStyles(&dControlStyles,&dControlExStyles);
CreateControl(dControlStyles,dControlExStyles);
}
break;
// Process command messages from interface
case WM_COMMAND:
return CommandHandler(HIWORD(p_wParam),LOWORD(p_wParam));
// Close
case WM_CLOSE:
// Clean up
ControlStateCallback(CSPY_SHUTDOWN);
if(g_pSL)
free(g_pSL);
if(g_pSLIndex)
free(g_pSLIndex);
// Uninstall hook and end dialog
UnhookWindowsHookEx(g_hGMHook);
UnhookWindowsHookEx(g_hCWHook);
EndDialog(p_hDlg,0);
return TRUE;
}
// Did not process message
return FALSE;
}
// Name: CreateSupportControls
// Description: Create all controls that make up the background support
// Parameters: none
// Returns: none
void CreateSup