1得到mac
//需要加入netapi32.lib
include "stdafx.h"
#include <windows.h>
#include <wincon.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
// 因為是通過NetAPI來獲取網(wǎng)卡信息,所以需要包含其題頭文件nb30.h
#include <nb30.h>
typedef struct _ASTAT_
{
ADAPTER_STATUS adapt;
NAME_BUFFER
NameBuff [30];
} ASTAT, * PASTAT;
ASTAT Adapter;
// 定義一個存放返回網(wǎng)卡信息的變量
// 輸入?yún)?shù):lana_num為網(wǎng)卡編號,一般地,從0開始,但在Windows 2000中并不一定是連續(xù)分配的
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 // 指定網(wǎng)卡號
// 首先對選定的網(wǎng)卡發(fā)送一個NCBRESET命令,以便進(jìn)行初始化
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; // 指定網(wǎng)卡號
strcpy((char *)ncb.ncb_callname,"*" );
ncb.ncb_buffer = (unsigned char *) &Adapter; // 指定返回的信息存放的變量
ncb.ncb_length = sizeof(Adapter);
// 接著,可以發(fā)送NCBASTAT命令以獲取網(wǎng)卡的信息
uRetCode = Netbios( &ncb );
printf( "The NCBASTAT return code is: 0x%x \n", uRetCode );
if ( uRetCode == 0 )
{
// 把網(wǎng)卡MAC地址格式化成常用的16進(jìn)制形式,如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);
// 向網(wǎng)卡發(fā)送NCBENUM命令,以獲取當(dāng)前機器的網(wǎng)卡信息,如有多少個網(wǎng)卡、每張網(wǎng)卡的編號等
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);
// 對每一張網(wǎng)卡,以其網(wǎng)卡編號為輸入編號,獲取其MAC地址
for ( int i=0; i<lana_enum.length; ++i)
getmac_one( lana_enum.lana[i]);
}
return 0;
}
2總聽到論壇有人問起如何打印一些簡單的圖形并輸出文字,因此簡化出如下一段打印程序代碼,僅供參與: [所有相關(guān)帖子]
CDC MemDC;
CPrintDialog dlg(FALSE,PD_NOPAGENUMS|PD_NOSELECTION,this);
if(dlg.DoModal() == IDOK)
{
MemDC.Attach(dlg.GetPrinterDC());//把打印設(shè)備環(huán)境附加到DC對象
DOCINFO di;
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = "圖形報告";
di.lpszOutput = NULL;
di.lpszDatatype = NULL;
di.fwType = 0;
MemDC.StartDoc(&di); //通知打印機驅(qū)動程序執(zhí)行一新的打印任務(wù)
MemDC.StartPage();//通知打印機驅(qū)動程序打印新頁
MemDC.SetMapMode(MM_ANISOTROPIC);//(MM_HIENGLISH);//設(shè)置當(dāng)前影射模式為:單位0.001英寸
CSize size = CSize(800, 560);
MemDC.SetWindowExt(size);
//確定窗口大小
//得到實際設(shè)備每邏輯英寸的象素數(shù)量
int xLogPixPerInch = MemDC.GetDeviceCaps(LOGPIXELSX);
int yLogPixPerInch = MemDC.GetDeviceCaps(LOGPIXELSY);
//得到設(shè)備坐標(biāo)和邏輯坐標(biāo)的比例
long xExt = (long)size.cx * xLogPixPerInch/96 ;
long yExt = (long)size.cy * yLogPixPerInch/96 ;
MemDC.SetViewportExt((int)xExt, (int)yExt);
MemDC.TextOut(350,20,"測試報告");
//在這里加入你想要進(jìn)行的繪制及文字輸出
//
//
//
//
//
//
//
//
//
//
//
//
MemDC.EndPage(); //通知打印機驅(qū)動程序頁結(jié)束
MemDC.EndDoc();//通知打印機驅(qū)動程序打印完畢
DeleteDC(MemDC.Detach());
}
3得到文件的創(chuàng)建時間和最后修改時間等。
BOOL GetFileTime(
HANDLE hFile,
LPFILETIME lpCreationTime,
LPFILETIME lpLastAccessTime,
LPFILETIME lpLastWriteTime
);
4.Re:如何改變Edit中的字體顏色 [所有相關(guān)帖子]
如何改變對話框內(nèi)控件的字體?
你有沒有感到Edit,Static....控件的字體太單調(diào),沒什么新新樣?下面的內(nèi)容,給你一個解答.
[解決方法]
簡單的步驟:在Windows中,每個窗體都有自己的字體.要改變其字體首先要CFont::CreateFont創(chuàng)建一個字體,然后用CWnd::SetFont選擇此字體,賦給控件.但很多人可能會因為CreateFont的參數(shù)之多,望而卻步.下面我介紹一下參數(shù).
函數(shù)原型:
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 );
參數(shù)說明:
nHeight :字體高度.>0:字體的高度值;=0:字體采用缺省直.<0:此值的絕對值為高度.
nWidth :字體寬度.
nEscapement :文本行的傾斜度.
nOrientation :字符基線的傾斜度.
nWeight :字體的粗細(xì).如下:
.FW_DONTCARE
.FW_THIN
.FW_EXTRALIGHT
.....
bItalic :字體是否為斜體
bUnderline :字體是否帶下劃線
cStrikeOut :字體是否帶刪除線
nCharSet :字體的字符集
.ANSI_CHARSET
.DEFAULT_CHARSET
.SYMBOL_CHARSET.....
nOutPrecision :字符的輸出精度
nClipPrecision :字符裁剪的精度
nQuality :字符的輸出質(zhì)量
nPitchAndFamily :字符間距和字體族(低位說明間距,高位說明字符族)
lpszFacename :字體名稱
[程序?qū)崿F(xiàn)]
假設(shè)你已有了名為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;前的"http://"號去掉,將類聲明中的CFont m_Font;去掉會是什么結(jié)果?請自己試試.
改變Edit字體顏色! [所有相關(guān)帖子]
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函數(shù)與unregsiterserver來實現(xiàn)注冊與取消注冊,以下是代碼實現(xiàn)注冊:
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枚舉進(jìn)程
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: 如何打開一個應(yīng)用程序? ShellExecute(this->m_hWnd,"open","calc.exe","","", SW_SHOW );
或 ShellExecute(this->m_hWnd,"open","notepad.exe",
"c:\\MyLog.log","",SW_SHOW );
正如您所看到的,我并沒有傳遞程序的完整路徑。
Q: 如何打開一個同系統(tǒng)程序相關(guān)連的文檔? ShellExecute(this->m_hWnd,"open",
"c:\\abc.txt","","",SW_SHOW );
Q: 如何打開一個網(wǎng)頁? ShellExecute(this->m_hWnd,"open",
"Q: 如何激活相關(guān)程序,發(fā)送EMAIL? ShellExecute(this->m_hWnd,"open",
"mailto:nishinapp@yahoo.com","","", SW_SHOW );
Q: 如何用系統(tǒng)打印機打印文檔? ShellExecute(this->m_hWnd,"print",
"c:\\abc.txt","","", SW_HIDE);
Q: 如何用系統(tǒng)查找功能來查找指定文件? ShellExecute(m_hWnd,"find","d:\\nish",
NULL,NULL,SW_SHOW);
如何禁止/啟用系統(tǒng)熱鍵
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,true,&bOld,SPIF_UPDATEINIFILE);
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING,false,&bOld,SPIF_UPDATEINIFILE);
9如何隱藏/顯示W(wǎng)INDOWS系統(tǒng)任務(wù)欄
::ShowWindow (::FindWindow("Shell_TrayWnd",NULL),SW_HIDE);
::ShowWindow (::FindWindow("Shell_TrayWnd",NULL),SW_SHOW);
10誰能告訴我怎樣得到任務(wù)欄的高度嗎 [所有相關(guān)帖子]
HWND hwnd=::FindWindow("Shell_TrayWnd",NULL);
if(hwnd)
{
CRect rect;
::GetWindowRect(hwnd,&rect);
CString s;
s.Format("%d",rect.Height());
AfxMessageBox(s);
}
11怎樣將當(dāng)前進(jìn)程名在任務(wù)管理器中隱藏? [所有相關(guān)帖子]
void CHideProcessDlg::OnHide()
{
UpdateData(TRUE);
HINSTANCE hDLL;
LPREGISTERSERVICEPROCESS lpRegisterServiceProcess;
//加載RegisterServiceProcess函數(shù)所在的鏈接庫
hDLL = LoadLibrary("KERNEL32");
//得到RegisterServiceProcess函數(shù)的地址
lpRegisterServiceProcess = (LPREGISTERSERVICEPROCESS)GetProcAddress(hDLL, "RegisterServiceProcess");
//執(zhí)行RegisterServiceProcess函數(shù),在任務(wù)列表中隱藏程序
lpRegisterServiceProcess(GetCurrentProcessId(),1);
//卸載鏈接庫
FreeLibrary(hDLL);
//設(shè)定定時器
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);
/*將除控制條外的客戶區(qū)全屏顯示到從(0,0)到
(nFullWidth, nFullHeight)區(qū)域,將(0,0)和(nFullWidth, nFullHeight)
兩個點外擴充原窗口和除控制條之外的客戶區(qū)位置間的差值,
就得到全屏顯示的窗口位置*/
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;
//設(shè)置全屏顯示標(biāo)志為 TRUE
m_bFullScreen=TRUE;
//進(jìn)入全屏顯示狀態(tài)
WINDOWPLACEMENT wndpl;
wndpl.length=sizeof(WINDOWPLACEMENT);
wndpl.flags=0;
wndpl.showCmd=SW_SHOWNORMAL;
wndpl.rcNormalPosition=m_FullScreenRect;
SetWindowPlacement(&wndpl);
}