線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1757
推到 Plurk!
推到 Facebook!

測試電腦的I/O是否正常

答題得分者是:yeeddt
hank73317
一般會員


發表:20
回覆:47
積分:13
註冊:2008-12-12

發送簡訊給我
#1 引用回覆 回覆 發表時間:2008-12-12 20:57:49 IP:118.169.xxx.xxx 訂閱
請問各位大大~~~~~~~~~~

如果我要測試電腦的周邊~~~~~


例如~~~~USB~~~滑鼠~~~鍵盤~~~或音效卡之類的~~~~

我要用API嗎?

~~~~還有有沒有書籍有教這些阿~~~~我找不到~~~~


請各位大大給我解答~~~~

感恩~~~
yeeddt
初階會員


發表:18
回覆:28
積分:29
註冊:2008-11-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2008-12-30 11:08:09 IP:211.21.xxx.xxx 訂閱
不知道你所謂的測試是什麼?
如果是要偵測硬體新增移除之類的動作可以試試看這個方法。
當中的訊息涵義請自己查一下吧

.h
[code cpp]
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include <Forms.hpp><br />//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TMemo *Memo1;
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);


void __fastcall OnDeviceChange(TMessage& Msg);

BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DEVICECHANGE, TMessage, OnDeviceChange)
END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

[/code]

.cpp
[code cpp]
#include
#include
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;

int a=0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::OnDeviceChange(TMessage& Msg)
{
a ;
Memo1->Lines->Add((AnsiString)a ") " "Msg.WParam = " Msg.WParam "; Msg.LParam = " Msg.LParam
"; Msg.Result = " Msg.Result
);



WPARAM wParam = Msg.WParam;
LPARAM lParam = Msg.LParam;

switch(wParam)
{
case DBT_DEVICEARRIVAL:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_DEVICEARRIVAL");
Memo1->Lines->Add("===================");
//pDeviceInfo = (DEV_BROADCAST_HDR *)lParam;

break;

case DBT_DEVICEREMOVECOMPLETE:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_DEVICEREMOVECOMPLETE");
Memo1->Lines->Add("===================");
//pDeviceInfo = (DEV_BROADCAST_HDR *)lParam;
break;

case DBT_DEVNODES_CHANGED:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_DEVNODES_CHANGED");
Memo1->Lines->Add("===================");
break;

case DBT_CONFIGCHANGECANCELED:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_CONFIGCHANGECANCELED");
Memo1->Lines->Add("===================");
break;

case DBT_DEVICEQUERYREMOVEFAILED:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_DEVICEQUERYREMOVEFAILED");
Memo1->Lines->Add("===================");
break;

case DBT_CUSTOMEVENT:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_CUSTOMEVENT");
Memo1->Lines->Add("===================");
break;

case DBT_DEVICEREMOVEPENDING:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_DEVICEREMOVEPENDING");
Memo1->Lines->Add("===================");
break;

case DBT_DEVICETYPESPECIFIC:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_DEVICETYPESPECIFIC");
Memo1->Lines->Add("===================");
break;

case DBT_QUERYCHANGECONFIG:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_QUERYCHANGECONFIG");
Memo1->Lines->Add("===================");
break;

case DBT_USERDEFINED:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_USERDEFINED");
Memo1->Lines->Add("===================");
break;

case DBT_CONFIGCHANGED:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_CONFIGCHANGED");
Memo1->Lines->Add("===================");
break;

case DBT_DEVICEQUERYREMOVE:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("DBT_DEVICEQUERYREMOVE");
Memo1->Lines->Add("===================");
break;

default:
Memo1->Lines->Add("WParam");
Memo1->Lines->Add(Msg.WParam);
Memo1->Lines->Add("LParam");
Memo1->Lines->Add(Msg.LParam);
Memo1->Lines->Add("default");
Memo1->Lines->Add("===================");
break;
}

}

[/code]
編輯記錄
yeeddt 重新編輯於 2008-12-30 11:09:07, 註解 無‧
系統時間:2017-12-17 6:23:30
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!