子级分类:
C++/MFC基础
Windows界面
网络与通信
图形图象处理
系统通信
数据库
文件系统
硬件/系统调用
组件技术
其它技术
 |
时间日期差的计算例子(大家拍砖啊)
|
|
| |
| 拍砖拍砖//dtmfnct.h
//char=8bt
//int=32bt
//pure c ++ code
#ifndef dtmfnctH
#define dtmfnctH
#include <math.h>
//------------------------------------------------------------------------
int __fastcall strTOdate(char *);
int __fastcall ymdTOdate(int, int, int);
int __fastcall dateTOymd(int &, int &, int &, int);
//--------//--------//--------//--------//--------//--------
int __fastcall strTOtime(char *);
int __fastcall hmsTOtime(int, int, int);
int __fastcall timeTOhms(int &,int &,int &, int);
//--------//--------//--------//--------//--------//--------
int __fastca ...
|
|
| 作者:不祥 Bccv张贴于2004-04-14 10:48:29.0,共阅读1838次,回复0次 |
|
|
 |
全程键盘钩子的一种简单实现
|
|
| |
| 随着中间件技术的发展, DLL越来越为程序员所关注,因为使用DLL具有一系列优点,所以程序设计人员可能更多的在自己的软件中采用这种技术。
下面我就把以前做过的一个简单的全程键盘钩子分析一下。
钩子[以下简称Hook]是应用程序在Microsoft Windows 消息处理过程中设置的用来监控消息流并且处理系统中尚未到达目的窗口的某一类型消息过程的机制。如果Hook过程在应用程序中实现,若应用程序不是当前窗口时,该Hook就不起作用;如果Hook在DLL中实现,程序在运行中动态调用它,它能实时对系统进行监控。根据需要,我们采用的是在DLL中实现Hook的方式[关于HOOK更详细的资料请查阅资料]。
在VC中新建一Win32 Dynamic-Link Library 工程,工程名为KBLock。AppWizard会生成相关文件,编译生成的KBLock.cpp:
#include "stdafx.h"
#include "KBLock.h"
HHOOK hhkHook=NULL; //钩子
HINSTANCE hInstance=NULL; //程序实例
//主入口
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
...
|
|
| 作者:不祥 Bccv张贴于2004-04-14 10:35:54.0,共阅读2382次,回复0次 |
|
|
 |
Serial Number 生成器
|
|
| |
| class CSerialNumber
{
public:
CString XOR(LPCTSTR sSource, LPCTSTR sXOR);
bool IsValid(LPCTSTR sSource, LPCTSTR sSN, int nMethod = 0);
CString Generate(LPCTSTR sSource, int nMethod = 0); //生成注册码
CSerialNumber();
virtual ~CSerialNumber();
};
CSerialNumber::CSerialNumber()
{
}
CSerialNumber::~CSerialNumber()
{
}
CString CSerialNumber::Generate(LPCTSTR sSource, int nMethod)
{
//将用户名换算成15位注册码
double Num1, Num2, Num3;
char sn[16] = {0};
Num1 = 0;
Num2 = 0;
Num3 = 0;
int len = strlen(sSource);
if(len)
{
for(int i = ...
|
|
| 作者:不祥 bluejoe张贴于2004-04-10 11:15:51.0,共阅读1664次,回复0次 |
|
|
 |
FTP 服务器返回信息类型归纳
|
|
| |
| 兼容ftp服务器的话,必须对上面进行枚举,目前还没有别的好办法,希望大家添加! "-rw-r--r-- 1 root other 531 Jan 29 03:26 README",
"dr-xr-xr-x 2 root other 512 Apr 8 1994 etc",
"dr-xr-xr-x 2 root 512 Apr 8 1994 etc2",
"lrwxrwxrwx 1 root other 7 Jan 25 00:17 bin -> usr/bin",
/* Some listings with uncommon date/time format: */
"-rw-r--r-- 1 root other 531 09-26 2000 README2",
"-rw-r--r-- 1 root other 531 09-26 13:45 README3",
...
|
|
| 作者:不祥 xler张贴于2004-03-30 11:46:43.0,共阅读1654次,回复0次 |
|
|
 |
键盘VK值列表
|
|
| |
| /*
* Virtual Keys, Standard Set
*/
#define VK_LBUTTON 0x01
#define VK_RBUTTON 0x02
#define VK_CANCEL 0x03
#define VK_MBUTTON 0x04 /* NOT contiguous with L & RBUTTON */
#define VK_BACK 0x08
#define VK_TAB 0x09
#define VK_CLEAR 0x0C
#define VK_RETURN 0x0D
#define VK_SHIFT 0x10
#define VK_CONTROL 0x11
#define VK_MENU 0x12
#define VK_PAUSE 0x13
#define VK_CAPITAL 0x14
#define VK_KANA 0x15
#define VK_HANGEUL 0x15 /* old name - should be here fo ...
|
|
| 作者:不祥 bluejoe张贴于2004-03-11 09:09:55.0,共阅读1380次,回复0次 |
|
|
 |
关机代码
|
|
| |
| //判断操作系统版本
OSVERSIONINFO osVer;
osVer.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
::GetVersionEx(&osVer);
//操作系统为win2000
if(osVer.dwPlatformId==VER_PLATFORM_WIN32_NT)
{
// Get a token for this process.
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
MessageBox("OpenProcessToken Error");
// Get the LUID for the shutdown privilege.
LookupP ...
|
|
| 作者:不祥 jerry张贴于2004-03-10 21:15:52.0,共阅读1496次,回复0次 |
|
|
 |
自定义消息
|
|
| |
| #define MY_MSG WM_USER+1
再在message map中
ON_MESSAGE(MY_MSG,OnGoodbye)
加在CPP文件的头上
BEGIN_MESSAGE_MAP(CTest, CView)
ON_MESSAGE(MY_MSG , OnGoodbye)
//{{AFX_MSG_MAP(CTest)
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
在类申明中加
afx_msg void myFunction();
加在头文件这个位置:
eg:// Generated message map functions
protected:
//{{AFX_MSG(CEx07aView)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
afx_msg LRESULT OnGoodbye(WPARAM wParam ...
|
|
| 作者:不祥 jerry张贴于2004-03-10 21:10:41.0,共阅读1389次,回复0次 |
|
|
 |
发送一个关于某个按钮单击的消息
|
|
| |
| GetDlgItem(IDOK)->PostMessage(BM_CLICK,0,0);
或
PostMessage(WM_COMMAND,IDOK|BN_CLICKED<<16,GetDlgItem(IDOK)->m_hWnd);
|
|
| 作者:不祥 jerry张贴于2004-03-10 21:08:28.0,共阅读1406次,回复0次 |
|
|
 |
DAO选数据源为ACCESS2000的MDB文件,防止格式错误
|
|
| |
| AfxGetModuleState()->m_dwVersion = 0x0601;
AfxDaoInit();
|
|
| 作者:不祥 jerry张贴于2004-03-10 21:06:56.0,共阅读1227次,回复0次 |
|
|
 |
保存桌面到位图
|
|
| |
| Copy_Screen_To_Bitmap(CRect rcArea, int nBits)
{
HDC hScrDC, hMemDC; // 屏幕和内存设备描述表
HBITMAP hBitmap, hOldBitmap; // 位图句柄
int xScrn, yScrn; // 屏幕分辨率
HDC hDC; //设备描述表
int iBits; //当前显示分辨率下每个像
WORD wBitCount; //位图中每个像素所占字节
//定义调色板大小, 位图中像素字节大小 ,位图文件大小 , 写入文件字节数
DWORD dwPaletteSize=0, dwBmBitsSize;
BITMAP Bit ...
|
|
| 作者:不祥 jerry张贴于2004-03-10 21:03:48.0,共阅读1762次,回复0次 |
|
|
 |
域名到IP的转换
|
|
| |
| #define WIN32_LEAN_AND_MEAN
#include <winsock2.h>
#include <stdlib.h>
#include <stdio.h>
const VERSION_MAJOR = 1;
const VERSION_MINOR = 1;
void ShowUsage(void)
{
printf("usage: FINDADDR some.address.com\n");
exit(0);
}
int main(int argc,char *argv[])
{
WSADATA WSData;
LPHOSTENT lpHostEntry;
DWORD dwIPAddress;
LPSTR szIPAddress;
if(WSAStartup(MAKEWORD(VERSION_MAJOR,VERSION_MINOR),&WSData))
{
printf("Cannot find Winsock(v%d.%d or late)!\n",
...
|
|
| 作者:不祥 jerry张贴于2004-03-10 18:07:13.0,共阅读2678次,回复0次 |
|
|
 |
创建文件的快捷方式
|
|
| |
| BOOL CShell::CreateLink(CString sPathSource, CString sPathLink, CString sDescription)
{
return CreateLink((LPCITEMIDLIST)(LPSTR)(LPCTSTR)sPathSource, sPathLink, sDescription, TRUE);
}
BOOL CShell::CreateLink(LPCITEMIDLIST lpi, CString sPathLink, CString sDescription, BOOL bByName)
{
HRESULT hres;
IShellLink * psl;
//Get a pointer to the IShellLink interface.
hres =
CoCreateInstance(
CLSID_ShellLink,
NULL,
CLSCTX_INPROC_SERVER,
IID_IShellLink,
(void * *) & psl);
if (SUCCEEDED(hres))
{
IPersistFile * ppf;
// Set the path to the shortcut targ ...
|
|
| 作者:不祥 bluejoe张贴于2004-03-10 15:02:26.0,共阅读1479次,回复0次 |
|
|
 |
获取系统可用串口列表
|
|
| |
| int CUtil::GetSystemPorts(CString *pNameList, CString *pPortList)
{
CRegKey RegKey;
int nCount = 0;
if(RegKey.Open(HKEY_LOCAL_MACHINE, "Hardware\\DeviceMap\\SerialComm") == ERROR_SUCCESS)
{
while(true)
{
char ValueName[_MAX_PATH];
unsigned char ValueData[_MAX_PATH];
DWORD nValueSize = _MAX_PATH;
DWORD nDataSize = _MAX_PATH;
DWORD nType;
if(::RegEnumValue(HKEY(RegKey), nCount, ValueName, &nValueSize, NULL, &nType, ValueData, &nDataSize) == ERROR_NO_MORE_ITEMS)
{
break;
}
if(pNameList)
pNameList[nCount] = ValueName;
...
|
|
| 作者:不祥 bluejoe张贴于2004-03-10 14:59:41.0,共阅读2108次,回复0次 |
|
|
 |
不堵塞的等待函数
|
|
| |
| void CUtil::Wait(int nDelay, UINT nMsgFilter)
{
DWORD nStartTime = GetTickCount();
while (true)
{
DWORD nEndTime = GetTickCount();
if (nEndTime - nStartTime > (DWORD) nDelay)
break;
continue;
PumpMessages(NULL, nMsgFilter);
}
}
void CUtil::PumpMessages(HWND hWnd, UINT nMsgFilter)
{
MSG msg;
// Handle dialog messages
while(::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
//需要过滤的消息
if(nMsgFilter && nMsgFilter == msg.message)
{
continue;
}
if(!::IsDialogMessage(hWnd, &msg))
{
::TranslateMessage(&msg);
::DispatchMessage(&msg); ...
|
|
| 作者:不祥 bluejoe张贴于2004-03-10 14:55:04.0,共阅读1500次,回复0次 |
|
|
 |
多行文本输出
|
|
| |
| int CUtil::MultiLineTextOut(
CDC * pDC,
int x,
int y,
CString Text,
int LineSpace)
{
TEXTMETRIC Metric;
if (pDC->GetOutputTextMetrics(& Metric))
{
LineSpace += Metric.tmHeight;
}
int Lines = 0;
int Length = Text.GetLength();
int Start = 0;
for (int i = 0; i < Length; i++)
{
if (Text.GetAt(i) == '\n')
{
Lines++;
pDC->TextOut(x, y, Text.Mid(Start, i - Start));
y += LineSpace;
Start = i + 1;
}
}
pDC->TextOut(x, y, Text.Mid(Start, i - Start));
return Lines;
}
|
|
| 作者:不祥 bluejoe张贴于2004-03-10 14:51:56.0,共阅读1582次,回复0次 |
|
|
 |
显示目录选择对话框
|
|
| |
| //显示选择文件夹窗口
//参数 sFolderPath:用于返回用户选择的文件夹的路径
//参数 sTitle:用于指定选择文件夹窗口的标题
//返回值 :操作结果,用户取消选择或操作失败返回FALSE,否则TRUE
BOOL CShell::BrowseForFolder(CString & sFolderPath, CString sTitle)
{
BROWSEINFO bi;
char Buffer[_MAX_PATH];
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = Buffer;
bi.lpszTitle = sTitle;
bi.ulFlags = 0;
bi.lpfn = NULL;
LPITEMIDLIST pIDList = SHBrowseForFolder(& bi);
if (!pIDList)
return FALSE;
SHGetPathFromIDList(pIDList, Buffer);
sFolderPath = Buffer;
LPMALLOC lpMalloc;
if (FAILED(SHGetMalloc(& lpMalloc)))
return FALSE;
//释放内 ...
|
|
| 作者:不祥 bluejoe张贴于2004-03-10 14:50:18.0,共阅读1726次,回复0次 |
|
|
 |
PE格式效验
|
|
| |
| //打开文件
OPENFILENAME ofn;
ZeroMemory(&ofn, sizeof(OPENFILENAME));
ofn.hwndOwner = hWnd;
ofn.lStructSize = sizeof(ofn);
ofn.lpstrFilter = "Executable Files (*.exe, *.dll)\0*.exe;*.dll\0All Files\0*.*\0\0";
ofn.lpstrFile = buffer;
ofn.nMaxFile = MAX_FILE_LENGTH;
ofn.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_LONGNAMES | OFN_EXPLORER | OFN_HIDEREADONLY ;
GetOpenFileName(&ofn);
HANDLE hFile = CreateFile(buffer,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
//获得文件的内存映射句柄
HANDLE hMapping = Cr ...
|
|
| 作者:不祥 jerry张贴于2004-03-09 22:08:03.0,共阅读1488次,回复0次 |
|
|
 |
CWin32Exception源码
|
|
| |
| class CWin32Exception : public CException
{
public:
int ReportError(UINT nType = MB_OK, UINT nMessageID = 0);
BOOL GetErrorMessage( LPTSTR lpszError, UINT nMaxError, PUINT pnHelpContext = NULL);
void ParseError();
DWORD m_nErrorCode;
CString m_sErrorName;
CString m_sErrorDescription;
CString m_sErrorLabel;
CWin32Exception(DWORD nErrorCode);
virtual ~CWin32Exception();
private:
};
CWin32Exception::CWin32Exception(DWORD nErrorCode)
{
ASSERT(nErrorCode);
m_nErrorCode = nErrorCode;
ParseError();
::Logger.Log("发生系统错误:%s", m_sErrorLabel);
}
CWin32Excep ...
|
|
| 作者:不祥 bluejoe张贴于2004-03-06 17:12:52.0,共阅读1996次,回复0次 |
|
|
 |
颜色分布
|
|
| |
| 大家颜色处理的时候,可以对照对照!
常用颜色代码:
|
|
| 作者:不祥 xler张贴于2004-03-05 23:15:53.0,共阅读1586次,回复0次 |
|
|
 |
洗牌程序
|
|
| |
| int No[54];
int Which = 0, Total = 54;
//初始化牌
for(int i = 0; i < 54; i++)
No[i] = -1;
srand((unsigned)time(NULL));
for(Which = 0; Which < 54; Which ++)
{
i = rand()*Total / RAND_MAX;
int k = 0;
int m = 0;
while(true)
{
//该牌没有设置
if(No[m] < 0)
k ++;
if(k > i)
break;
m ++;
}
No[m] = Which;
Total --;
}
|
|
| 作者:不祥 bluejoe张贴于2004-02-25 11:50:41.0,共阅读1653次,回复0次 |
|
|
|