📄 tlib.h
字号:
/* @(#)Copyright (C) H.Shirouzu 1996-2005 tlib.h Ver0.97 */
/* ========================================================================
Project Name : Win32 Lightweight Class Library Test
Module Name : Main Header
Create : 1996-06-01(Sat)
Update : 2005-11-28(Mon)
Copyright : H.Shirouzu
Reference :
======================================================================== */
#ifndef TLIB_H
#define TLIB_H
#ifndef STRICT
#define STRICT
#endif
/* for crypto api */
#define _WIN32_WINNT 0x0600
#include <windows.h>
#include <windowsx.h>
#include "commctrl.h"
#include <regstr.h>
#include <shlobj.h>
#include <tchar.h>
#include "tapi32v.h"
#define WINEXEC_ERR_MAX 31
#define TLIB_SLEEPTIMER 32000
#define IsNewShell() (LOBYTE(LOWORD(GetVersion())) >= 4)
#define IsWin95() (LOBYTE(LOWORD(GetVersion())) >= 4 && GetVersion() >= 0x80000000)
#define IsWinNT() (LOBYTE(LOWORD(GetVersion())) >= 4 && GetVersion() < 0x80000000)
#define IsWin2K() (LOBYTE(LOWORD(GetVersion())) >= 5 && GetVersion() < 0x80000000)
#define IsWinXP() (LOBYTE(LOWORD(GetVersion())) >= 6 && GetVersion() < 0x80000000)
#define IsWin31() (LOBYTE(LOWORD(GetVersion())) == 3 && HIBYTE(LOWORD(GetVersion())) < 20)
#define IsNT350() (LOBYTE(LOWORD(GetVersion())) == 3 && HIBYTE(LOWORD(GetVersion())) == 50)
#define IsLang(lang) (PRIMARYLANGID(LANGIDFROMLCID(GetThreadLocale())) == lang)
#define BUTTON_CLASS _T("BUTTON")
#define COMBOBOX_CLASS _T("COMBOBOX")
#define EDIT_CLASS _T("EDIT")
#define LISTBOX_CLASS _T("LISTBOX")
#define MDICLIENT_CLASS _T("MDICLIENT")
#define SCROLLBAR_CLASS _T("SCROLLBAR")
#define STATIC_CLASS _T("STATIC")
#define MAX_WPATH 32000
#define MAX_PATH_EX (MAX_PATH * 8)
#define BITS_OF_BYTE 8
#define BYTE_NUM 256
#ifndef EM_SETTARGETDEVICE
#define COLOR_BTNFACE 15
#define COLOR_3DFACE COLOR_BTNFACE
#define EM_SETBKGNDCOLOR (WM_USER + 67)
#define EM_SETTARGETDEVICE (WM_USER + 72)
#endif
struct WINPOS {
int x;
int y;
int cx;
int cy;
};
typedef DWORD HashID;
class THash;
class THashObj {
protected:
THashObj *priorHash;
THashObj *nextHash;
HashID id;
public:
THashObj() { priorHash = nextHash = NULL; id = 0; }
~THashObj() { if (priorHash && priorHash != this) UnlinkHash(); }
BOOL LinkHash(THashObj *top, HashID _id);
BOOL UnlinkHash();
friend THash;
};
class THash {
protected:
THashObj *hashTbl;
int hashNum;
int registerNum;
public:
THash(int _hashNum);
~THash();
void Register(THashObj *obj, HashID id);
void UnRegister(THashObj *obj);
THashObj *GetHashObj(HashID id);
DWORD MakeHash(HashID id) { return id * 0xF3F77D13; }
int GetRegisterNum() { return registerNum; }
};
class TWin : public THashObj {
protected:
RECT rect;
HACCEL hAccel;
TWin *parent;
BOOL sleepBusy; // for TWin::Sleep() only
public:
TWin(TWin *_parent = NULL);
virtual ~TWin();
HWND hWnd;
virtual void Show(int mode = SW_SHOWDEFAULT);
virtual BOOL Create(LPCTSTR className=NULL, LPCTSTR title=_T(""), DWORD style=(WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN), DWORD exStyle=0, HMENU hMenu=NULL);
virtual void Destroy(void);
virtual BOOL EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl);
virtual BOOL EvSysCommand(WPARAM uCmdType, POINTS pos);
virtual BOOL EvCreate(LPARAM lParam);
virtual BOOL EvClose(void);
virtual BOOL EvNcDestroy(void);
virtual BOOL EvQueryEndSession(BOOL nSession, BOOL nLogOut);
virtual BOOL EvEndSession(BOOL nSession, BOOL nLogOut);
virtual BOOL EvQueryOpen(void);
virtual BOOL EvPaint(void);
virtual BOOL EvNcPaint(HRGN hRgn);
virtual BOOL EvSize(UINT fwSizeType, WORD nWidth, WORD nHeight);
virtual BOOL EvShowWindow(BOOL fShow, int fnStatus);
virtual BOOL EvGetMinMaxInfo(MINMAXINFO *info);
virtual BOOL EvTimer(WPARAM timerID, TIMERPROC proc);
virtual BOOL EvSetCursor(HWND cursorWnd, WORD nHitTest, WORD wMouseMsg);
virtual BOOL EvMouseMove(UINT fwKeys, POINTS pos);
virtual BOOL EvNcHitTest(POINTS pos, LRESULT *result);
virtual BOOL EvMeasureItem(UINT ctlID, MEASUREITEMSTRUCT *lpMis);
virtual BOOL EvDrawItem(UINT ctlID, DRAWITEMSTRUCT *lpDis);
virtual BOOL EvMenuSelect(UINT uItem, UINT fuFlag, HMENU hMenu);
virtual BOOL EvDropFiles(HDROP hDrop);
virtual BOOL EvNotify(UINT ctlID, NMHDR *pNmHdr);
virtual BOOL EvContextMenu(HWND childWnd, POINTS pos);
virtual BOOL EvHotKey(int hotKey);
virtual BOOL EventScroll(UINT uMsg, int nCode, int nPos, HWND scrollBar);
virtual BOOL EventButton(UINT uMsg, int nHitTest, POINTS pos);
virtual BOOL EventKey(UINT uMsg, int nVirtKey, LONG lKeyData);
virtual BOOL EventInitMenu(UINT uMsg, HMENU hMenu, UINT uPos, BOOL fSystemMenu);
virtual BOOL EventCtlColor(UINT uMsg, HDC hDcCtl, HWND hWndCtl, HBRUSH *result);
virtual BOOL EventFocus(UINT uMsg, HWND focusWnd);
virtual BOOL EventSystem(UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual BOOL EventUser(UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual UINT GetDlgItemText(int ctlId, LPTSTR buf, int len);
virtual UINT GetDlgItemTextV(int ctlId, void *buf, int len);
virtual BOOL SetDlgItemText(int ctlId, LPCTSTR buf);
virtual BOOL SetDlgItemTextV(int ctlId, const void *buf);
virtual int GetDlgItemInt(int ctlId, BOOL *err=NULL, BOOL sign=TRUE);
virtual BOOL SetDlgItemInt(int ctlId, int val, BOOL sign=TRUE);
virtual HWND GetDlgItem(int ctlId);
virtual BOOL CheckDlgButton(int ctlId, UINT check);
virtual UINT IsDlgButtonChecked(int ctlId);
virtual int MessageBox(LPCTSTR msg, LPCTSTR title=_T("msg"), UINT style=MB_OK);
virtual int MessageBoxV(void *msg, void *title=EMPTY_STR_V, UINT style=MB_OK);
virtual BOOL BringWindowToTop(void);
virtual BOOL SetForegroundWindow(void);
virtual BOOL SetForceForegroundWindow(void);
virtual BOOL PostMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual BOOL PostMessageV(UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual LRESULT SendMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual LRESULT SendMessageV(UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual LONG SendDlgItemMessage(int ctlId, UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual LONG SendDlgItemMessageV(int ctlId, UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual BOOL GetWindowRect(RECT *_rect=NULL);
virtual BOOL SetWindowPos(HWND hInsAfter, int x, int y, int cx, int cy, UINT fuFlags);
virtual HWND SetActiveWindow(void);
virtual int GetWindowText(LPTSTR text, int size);
virtual BOOL SetWindowText(LPCTSTR text);
virtual BOOL GetWindowTextV(void *text, int size);
virtual BOOL SetWindowTextV(const void *text);
virtual int GetWindowTextLengthV(void);
virtual LONG SetWindowLong(int index, LONG val);
virtual WORD SetWindowWord(int index, WORD val);
virtual LONG GetWindowLong(int index);
virtual WORD GetWindowWord(int index);
virtual TWin *GetParent(void) { return parent; };
virtual void SetParent(TWin *_parent) { parent = _parent; };
virtual BOOL MoveWindow(int x, int y, int cx, int cy, int bRepaint);
virtual BOOL Sleep(UINT mSec);
virtual BOOL Idle(void);
virtual RECT *Rect() { return ▭ }
virtual BOOL PreProcMsg(MSG *msg);
virtual LRESULT WinProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
virtual LRESULT DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
};
class TDlg : public TWin {
protected:
UINT resId;
BOOL modalFlg;
public:
TDlg(UINT resid, TWin *_parent = NULL);
virtual ~TDlg();
virtual BOOL Create(HINSTANCE hI = NULL);
virtual void Destroy(void);
virtual int Exec(void);
virtual void EndDialog(int);
UINT ResId(void) { return resId; }
virtual BOOL EvCreate(LPARAM lParam);
virtual BOOL EvCommand(WORD wNotifyCode, WORD wID, LPARAM hwndCtl);
virtual BOOL EvSysCommand(WPARAM uCmdType, POINTS pos);
virtual BOOL EvQueryOpen(void);
virtual BOOL PreProcMsg(MSG *msg);
virtual LRESULT WinProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
};
class TSubClass : public TWin {
protected:
WNDPROC oldProc;
public:
TSubClass(TWin *_parent = NULL);
virtual BOOL CreateByWnd(HWND _hWnd);
virtual LRESULT DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
};
class TSubClassCtl : public TSubClass {
protected:
public:
TSubClassCtl(TWin *_parent);
virtual BOOL PreProcMsg(MSG *msg);
};
BOOL TRegisterClass(LPCTSTR class_name, UINT style=CS_DBLCLKS, HICON hIcon=0, HCURSOR hCursor=0, HBRUSH hbrBackground=0, int classExtra=0, int wndExtra=0, LPCTSTR menu_str=0);
class TApp {
protected:
static TApp *tapp;
THash *hash;
LPCSTR defaultClass;
LPSTR cmdLine;
int nCmdShow;
TWin *mainWnd;
TWin *preWnd;
HINSTANCE hI;
TWin *SearchWnd(HWND hWnd) { return (TWin *)hash->GetHashObj((HashID)hWnd); }
virtual BOOL InitApp(void);
public:
TApp(HINSTANCE _hI, LPSTR _cmdLine, int _nCmdShow);
virtual ~TApp();
virtual void InitWindow() = 0;
virtual int Run();
LPCTSTR GetDefaultClass() { return defaultClass; }
void AddWin(TWin *win) { preWnd = win; }
void AddWinByWnd(TWin *win, HWND hWnd) { win->hWnd = hWnd; hash->Register(win, (HashID)win->hWnd); }
void DelWin(TWin *win) { hash->UnRegister(win); }
BOOL PreProcMsg(MSG *msg);
static TApp *GetApp() { return tapp; }
static HINSTANCE GetInstance() { return tapp->hI; }
static LRESULT CALLBACK WinProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam);
};
struct TListObj {
TListObj *prior, *next;
};
class TList {
protected:
TListObj top;
public:
TList(void);
void Init(void);
void AddObj(TListObj *obj);
void DelObj(TListObj *obj);
TListObj *TopObj(void);
TListObj *NextObj(TListObj *obj);
BOOL IsEmpty() { return top.next == ⊤ }
void MoveList(TList *from_list);
};
#define FREE_LIST 0
#define USED_LIST 1
#define RLIST_MAX 2
class TRecycleList {
protected:
char *data;
TList list[RLIST_MAX];
public:
TRecycleList(int init_cnt, int size);
~TRecycleList();
TListObj *GetObj(int list_type);
void PutObj(int list_type, TListObj *obj);
};
#define MAX_KEYARRAY 30
class TRegistry {
protected:
HKEY topKey;
int openCnt;
HKEY hKey[MAX_KEYARRAY];
public:
TRegistry(LPCSTR company, LPSTR appName=NULL);
TRegistry(HKEY top_key);
~TRegistry();
void ChangeTopKey(HKEY topKey);
BOOL ChangeApp(LPCSTR company, LPSTR appName=NULL);
BOOL GetInt(LPCSTR key, int *val);
BOOL SetInt(LPCSTR key, int val);
BOOL GetLong(LPCSTR key, long *val);
BOOL SetLong(LPCSTR key, long val);
BOOL GetStr(LPCSTR key, LPSTR str, int size);
BOOL SetStr(LPCSTR key, LPCSTR str);
BOOL GetByte(LPCSTR key, BYTE *data, int *size);
BOOL SetByte(LPCSTR key, const BYTE *data, int size);
BOOL OpenKey(LPCSTR subKey, BOOL createFlg=FALSE);
BOOL CreateKey(LPCSTR subKey) { return OpenKey(subKey, TRUE); }
BOOL CloseKey(void);
BOOL DeleteKey(LPCSTR str);
BOOL DeleteValue(LPCSTR str);
BOOL EnumKey(DWORD cnt, LPSTR buf, int size);
BOOL EnumValue(DWORD cnt, LPSTR buf, int size, DWORD *type=NULL);
BOOL DeleteChildTree(LPSTR subkey=NULL);
};
class TInifile {
protected:
char *ini_file;
char *cur_section;
public:
TInifile(char *ini_name=NULL);
~TInifile();
void Init(char *ini_name=NULL);
void SetSection(char *section);
BOOL SetStr(const char *key, const char *val);
DWORD GetStr(const char *key, char *val, int max_size, const char *default_val="");
BOOL SetInt(const char *key, int val);
BOOL DelSection(const char *section);
BOOL DelKey(const char *key);
int GetInt(const char *key, int default_val=-1);
const char *GetIniFileName(void) { return ini_file; }
};
void InitInstanceForLoadStr(HINSTANCE hI);
LPSTR GetLoadStrA(UINT resId, HINSTANCE hI=NULL);
LPWSTR GetLoadStrW(UINT resId, HINSTANCE hI=NULL);
void TSetDefaultLCID(LCID id=0);
HMODULE TLoadLibrary(LPTSTR dllname);
int MakePath(char *dest, const char *dir, const char *file);
int MakePathW(WCHAR *dest, const WCHAR *dir, const WCHAR *file);
WCHAR lGetCharIncW(const WCHAR **str);
WCHAR lGetCharIncA(const char **str);
WCHAR lGetCharW(const WCHAR *str, int);
WCHAR lGetCharA(const char *str, int);
void lSetCharW(WCHAR *str, int offset, WCHAR ch);
void lSetCharA(char *str, int offset, WCHAR ch);
#define CP_UTF8 65001 // UTF-8 translation
inline int AtoW(const char *src, WCHAR *dst, int bufsize, int max_len=-1) {
return ::MultiByteToWideChar(CP_ACP, 0, src, max_len, dst, bufsize);
}
inline int WtoA(const WCHAR *src, char *dst, int bufsize, int max_len=-1) {
return ::WideCharToMultiByte(CP_ACP, 0, src, max_len, dst, bufsize, 0, 0);
}
inline int WtoU8(const WCHAR *src, char *dst, int bufsize, int max_len=-1) {
return ::WideCharToMultiByte(CP_UTF8, 0, src, max_len, dst, bufsize, 0, 0);
}
inline int U8toW(const char *src, WCHAR *dst, int bufsize, int max_len=-1) {
return ::MultiByteToWideChar(CP_UTF8, 0, src, max_len, dst, bufsize);
}
WCHAR *AtoW(const char *src, BOOL noStatic=FALSE);
WCHAR *U8toW(const char *src, BOOL noStatic=FALSE);
char *WtoU8(const WCHAR *src, BOOL noStatic=FALSE);
char *WtoA(const WCHAR *src, BOOL noStatic=FALSE);
char *AtoU8(const char *src, BOOL noStatic=FALSE);
char *U8toA(const char *src, BOOL noStatic=FALSE);
BOOL InstallExceptionFilter(char *title, char *info);
void Debug(char *fmt,...);
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -