1得到mac
//需要加入netapi32.lib
include "stdafx.h"
#include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
// 因为是通过NetAPI来获取网卡信息,所以需要包含其题头文件nb30.h
#include <nb30.h>
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER
NameBuff [30];
} ASTAT, * PASTAT;
ASTAT Adapter;
// 定义一个存放返回网卡信息的变量
// 输入参数:lana_num为网卡编号,一般地,从0开始,但在Windows 2000中并不一定是连续分配的
void getmac_one (int lana_num)
{
NCB ncb;
UCHAR uRetCode;
memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBRESET;
ncb.ncb_lana_num = lana_num // 指定网卡号
// 首先对选定的网卡发送一个NCBRESET命令,以便进行初始化
uRetCode = Netbios( &ncb );
printf( "The NCBRESET return code is: 0x%x \n", uRetCode );
memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBASTAT;
ncb.ncb_lana_num = lana_num; // 指定网卡号
strcpy((char *)ncb.ncb_callname,"*" );
ncb.ncb_buffer = (unsigned char *) &Adapter; // 指定返回的信息存放的变量
ncb.ncb_length = sizeof(Adapter);
// 接着,可以发送NCBASTAT命令以获取网卡的信息
uRetCode = Netbios( &ncb );
printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );
if ( uRetCode == 0 )
{
// 把网卡MAC地址格式化成常用的16进制形式,如0010-A4E4-5802
printf( "The Ethernet Number[%d] is: %02X%02X-%02X%02X-%02X%02X\n",
lana_num,
Adapter.adapt.adapter_address[0],
Adapter.adapt.adapter_address[1],
Adapter.adapt.adapter_address[2],
Adapter.adapt.adapter_address[3],
Adapter.adapt.adapter_address[4],
Adapter.adapt.adapter_address[5] );
}
}
int main(int argc, char* argv[])
{
NCB ncb;
UCHAR uRetCode;
LANA_ENUM lana_enum;
memset( &ncb, 0, sizeof(ncb) );
ncb.ncb_command = NCBENUM;
ncb.ncb_buffer = (unsigned char *) &lana_enum;
ncb.ncb_length = sizeof(lana_enum);
// 向网卡发送NCBENUM命令,以获取当前机器的网卡信息,如有多少个网卡、每张网卡的编号等
uRetCode = Netbios( &ncb );
printf( "The NCBENUM return code is: 0x%x \n", uRetCode );
if ( uRetCode == 0 )
{
printf( "Ethernet Count is : %d\n\n", lana_enum.length);
// 对每一张网卡,以其网卡编号为输入编号,获取其MAC地址
for ( int i=0; i<lana_enum.length; ++i)
getmac_one( lana_enum.lana[i]);
}
return 0;
}
2总听到论坛有人问起如何打印一些简单的图形并输出文字,因此简化出如下一段打印程序代码,仅供参与: [所有相关帖子]
CDC MemDC;
CPrintDialog dlg(FALSE,PD_NOPAGENUMS|PD_NOSELECTION,this);
if(dlg.DoModal() == IDOK)
{
MemDC.Attach(dlg.GetPrinterDC());//把打印设备环境附加到DC对象
DOCINFO di;
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "图形报告";
di.lpszOutput = NULL;
di.lpszDatatype = NULL;
di.fwType = 0;
MemDC.StartDoc(&di); //通知打印机驱动程序执行一新的打印任务
MemDC.StartPage();//通知打印机驱动程序打印新页
MemDC.SetMapMode(MM_ANISOTROPIC);//(MM_HIENGLISH);//设置当前影射模式为:单位0.001英寸
CSize size = CSize(800, 560);
MemDC.SetWindowExt(size);
//确定窗口大小
//得到实际设备每逻辑英寸的象素数量
int xLogPixPerInch = MemDC.GetDeviceCaps(LOGPIXELSX);
int yLogPixPerInch = MemDC.GetDeviceCaps(LOGPIXELSY);
//得到设备坐标和逻辑坐标的比例
long xExt = (long)size.cx * xLogPixPerInch/96 ;
long yExt = (long)size.cy * yLogPixPerInch/96 ;
MemDC.SetViewportExt((int)xExt, (int)yExt);
MemDC.TextOut(350,20,"测试报告");
//在这里加入你想要进行的绘制及文字输出
//
//
//
//
//
//
//
//
//
//
//
//
MemDC.EndPage(); //通知打印机驱动程序页结束
MemDC.EndDoc();//通知打印机驱动程序打印完毕
DeleteDC(MemDC.Detach());
}
3得到文件的创建时间和最后修改时间等。
BOOL GetFileTime(
HANDLE hFile,
LPFILETIME lpCreationTime,
LPFILETIME lpLastAccessTime,
LPFILETIME lpLastWriteTime
);
4.Re:如何改变Edit中的字体颜色 [所有相关帖子]
如何改变对话框内控件的字体?
你有没有感到Edit,Static....控件的字体太单调,没什么新新样?下面的内容,给你一个解答.
[解决方法]
简单的步骤:在Windows中,每个窗体都有自己的字体.要改变其字体首先要CFont::CreateFont创建一个字体,然后用CWnd::SetFont选择此字体,赋给控件.但很多人可能会因为CreateFont的参数之多,望而却步.下面我介绍一下参数.
函数原型:
BOOL CreateFont( int nHeight, int nWidth, int nEscapement, int nOrientation, int nWeight, BYTE bItalic, BYTE bUnderline, BYTE cStrikeOut, BYTE nCharSet, BYTE nOutPrecision, BYTE nClipPrecision, BYTE nQuality, BYTE nPitchAndFamily, LPCTSTR lpszFacename );
参数说明:
nHeight :字体高度.>0:字体的高度值;=0:字体采用缺省直.<0:此值的绝对值为高度.
nWidth :字体宽度.
nEscapement :文本行的倾斜度.
nOrientation :字符基线的倾斜度.
nWeight :字体的粗细.如下:
.FW_DONTCARE
.FW_THIN
.FW_EXTRALIGHT
.....
bItalic :字体是否为斜体
bUnderline :字体是否带下划线
cStrikeOut :字体是否带删除线
nCharSet :字体的字符集
.ANSI_CHARSET
.DEFAULT_CHARSET
.SYMBOL_CHARSET.....
nOutPrecision :字符的输出精度
nClipPrecision :字符裁剪的精度
nQuality :字符的输出质量
nPitchAndFamily :字符间距和字体族(低位说明间距,高位说明字符族)
lpszFacename :字体名称
[程序实现]
假设你已有了名为My的对话框工程.并有一个ID=IDC_EDIT1的Edit控件.
class CMyDlg : public CDialog
{
public:
CFont m_Font;
........
};
BOOL CTMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//CFont m_Font;
m_Font.CreateFont(-11,0,0,0,100,FALSE,FALSE,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_SWISS,"Arial");
CEdit *m_Edit=(CEdit *)GetDlgItem(IDC_EDIT1);
m_Edit->SetFont(&m_Font,FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
小小说明:在OnInitDialog()中的//CFont m_Font;前的"//"号去掉,将类声明中的CFont m_Font;去掉会是什么结果?请自己试试.
改变Edit字体颜色! [所有相关帖子]
HBRUSH CButtonDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if(nCtlColor == CTLCOLOR_EDIT)
{
if(pWnd->GetDlgCtrlID()== IDC_EDIT1)
{
pDC->SetTextColor(RGB(255,255,0));
pDC->SetBkColor(RGB(251, 247, 200));
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH) m_brush.GetSafeHandle();
}
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
5 如何注册控件?
这是一个很常见的问题,最简单用winodws自带的regsvr32或其它工具等,其原理是利用控件的regsiterserver函数与unregsiterserver来实现注册与取消注册,以下是代码实现注册:
dword registerserver( char* szpath )
{
hinstance hinstance = ::loadlibrary( szpath );
if ( 0 == hinstance )
{
return ::getlasterror();
}
typedef void (far pascal *regserver)(void);
regserver regserver = (regserver) ::getprocaddress( hinstance, _t( "dllregisterserver" ));
if ( 0 == regserver )
{
::freelibrary( hinstance );
return ::getlasterror();
}
regserver();
::freelibrary( hinstance );
}
6模拟点击按钮
::SendMessage(GetParent()->GetSafeHwnd(), WM_COMMAND, (WPARAM)MAKELONG(IDOK, BN_CLICKED), (LPARAM)GetParent()->GetDlgItem(IDOK)->GetSafeHwnd());
7枚举进程
void GetProcessID(LPTSTR pszProcessName, DWORD& th32ProcessID)
{
HANDLE hSnapshot = NULL;
__try
{
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (INVALID_HANDLE_VALUE == hSnapshot)
{
__leave;
}
PROCESSENTRY32 pe;
ZeroMemory(&pe, sizeof(PROCESSENTRY32));
pe.dwSize = sizeof(PROCESSENTRY32);
BOOL bProcess = Process32First(hSnapshot, &pe);
while (bProcess)
{
if (pe.szExeFile == StrStrI(pe.szExeFile, pszProcessName))
{
th32ProcessID = pe.th32ProcessID;
break;
}
bProcess = Process32Next(hSnapshot, &pe);
}
if (!bProcess)
{
__leave;
}
}
__finally
{
if (INVALID_HANDLE_VALUE != hSnapshot)
{
CloseHandle(hSnapshot);
}
}
}
8: 如何打开一个应用程序? ShellExecute(this->m_hWnd,"open","calc.exe","","", SW_SHOW );
或 ShellExecute(this->m_hWnd,"open","notepad.exe",
"c:\\MyLog.log","",SW_SHOW );
正如您所看到的,我并没有传递程序的完整路径。
Q: 如何打开一个同系统程序相关连的文档? ShellExecute(this->m_hWnd,"open",
"c:\\abc.txt","","",SW_SHOW );
Q: 如何打开一个网页? ShellExecute(this->m_hWnd,"open",
"http://www.google.com","","", SW_SHOW );
Q: 如何激活相关程序,发送EMAIL? ShellExecute(this->m_hWnd,"open",
"mailto:nishinapp@yahoo.com","","", SW_SHOW );
Q: 如何用系统打印机打印文档? ShellExecute(this->m_hWnd,"print",
"c:\\abc.txt","","", SW_HIDE);
Q: 如何用系统查找功能来查找指定文件? ShellExecute(m_hWnd,"find","d:\\nish",
NULL,NULL,SW_SHOW);
如何禁止/启用系统热键
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,true,&bOld,SPIF_UPDATEINIFILE);
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,false,&bOld,SPIF_UPDATEINIFILE);
9如何隐藏/显示WINDOWS系统任务栏
::ShowWindow (::FindWindow("Shell_TrayWnd",NULL),SW_HIDE);
::ShowWindow (::FindWindow("Shell_TrayWnd",NULL),SW_SHOW);
10谁能告诉我怎样得到任务栏的高度吗 [所有相关帖子]
HWND hwnd=::FindWindow("Shell_TrayWnd",NULL);
if(hwnd)
{
CRect rect;
::GetWindowRect(hwnd,&rect);
CString s;
s.Format("%d",rect.Height());
AfxMessageBox(s);
}
11怎样将当前进程名在任务管理器中隐藏? [所有相关帖子]
void CHideProcessDlg::OnHide()
{
UpdateData(TRUE);
HINSTANCE hDLL;
LPREGISTERSERVICEPROCESS lpRegisterServiceProcess;
//加载RegisterServiceProcess函数所在的链接库
hDLL = LoadLibrary("KERNEL32");
//得到RegisterServiceProcess函数的地址
lpRegisterServiceProcess = (LPREGISTERSERVICEPROCESS)GetProcAddress(hDLL, "RegisterServiceProcess");
//执行RegisterServiceProcess函数,在任务列表中隐藏程序
lpRegisterServiceProcess(GetCurrentProcessId(),1);
//卸载链接库
FreeLibrary(hDLL);
//设定定时器
SetTimer(0,m_nSeconds*1000,NULL);
//隐藏程序的同时,隐藏窗口
ShowWindow(SW_HIDE);
}
12螺旋线
void CSingerDlg::OnBesselOk()
{
// TODO: Add your control notification handler code here
CDC *pDC;
pDC=GetDC();
////////////////////
CRect rect;
GetClientRect(&rect);
//////////////////
UpdateData(true);
v=m_edit_v1;
x1=m_edit_x1;
x2=m_edit_x2;
//////////////////
double x0=rect.left+162,y0=(rect.top-rect.bottom+75)/2+rect.bottom-60;
pDC->MoveTo(x0,BesselJ(v,x1)*(rect.top-rect.bottom+75)/2);
double delta=0.2,x=0,y=0;
do
{
y=BesselJ(v,x1+x)*(rect.top-rect.bottom+75)/2;
if((x1-x2)>=0)
{
MessageBox("请输入计算范围!");
break;
}else pDC->LineTo(x0+x/(x2-x1)*(rect.right-rect.left-170),y+y0);
x=x+delta;
}while(x<=x2);
}
13全屏显示
void CMainFrame::OnFullScreen()
{
GetWindowPlacement(&m_OldWndPlacement);
CRect WindowRect;
GetWindowRect(&WindowRect);
CRect ClientRect;
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery,&ClientRect);
ClientToScreen(&ClientRect);
//获取屏幕的分辨率
int nFullWidth=GetSystemMetrics(SM_CXSCREEN);
int nFullHeight=GetSystemMetrics(SM_CYSCREEN);
/*将除控制条外的客户区全屏显示到从(0,0)到
(nFullWidth, nFullHeight)区域,将(0,0)和(nFullWidth, nFullHeight)
两个点外扩充原窗口和除控制条之外的客户区位置间的差值,
就得到全屏显示的窗口位置*/
m_FullScreenRect.left=WindowRect.left-ClientRect.left;
m_FullScreenRect.top=WindowRect.top-ClientRect.top;
m_FullScreenRect.right=WindowRect.right - ClientRect.right+nFullWidth;
m_FullScreenRect.bottom=WindowRect.bottom - ClientRect.bottom+nFullHeight;
//设置全屏显示标志为 TRUE
m_bFullScreen=TRUE;
//进入全屏显示状态
WINDOWPLACEMENT wndpl;
wndpl.length=sizeof(WINDOWPLACEMENT);
wndpl.flags=0;
wndpl.showCmd=SW_SHOWNORMAL;
wndpl.rcNormalPosition=m_FullScreenRect;
SetWindowPlacement(&wndpl);
}