ADLink ACL-8112系列例程,代码比较老。全部资源在http://download.csdn.net/source/440228
#include "windows.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "resource.h"
#include "dll2.h"
#define IDM_EXIT 110 //定义菜单、对话框控件等
#define IDC_ADDR 200
#define IDC_AD1 201
#define IDC_AD2 202
#define IDC_AD3 203
#define IDC_AD4 204
#define IDC_AD5 205
#define IDC_AD6 206
#define IDC_SCROLL 207
#define IDC_SPIN 301
#define IDC_START 208
#define IDC_STOP 209
#define IDC_PAUSE 210
#define IDC_EDIT 211
#define IDC_GAIN 212
#define IDC_DA 400
#define IDC_HG 500
#define IDC_DG 501
#define TIMER1 1
#define NONE 0
#define DEMO 1
#define SINE 1
#define SQUARE 2
int PASCAL WinMain(HANDLE, HANDLE, LPSTR, int); //两个主要函数声明
long PASCAL MainWndProc(HWND, UINT, WPARAM, LPARAM);
HANDLE hInst; //自定义句柄,全局
HWND hAddrComboBox;
HWND hADComboBox1; //窗口句柄
HWND hADComboBox2;
HWND hADComboBox3;
HWND hADComboBox4;
HWND hADComboBox5;
HWND hADComboBox6;
HWND hADScroll;
HWND hEdit;
HWND MainhWnd;
unsigned int input=0, output=0; //定义输入输出变量
unsigned int oldinput=0,analog_input[16],adinput[16],old_adinput1[16],old_adinput2[16];
unsigned char input_lo=0, input_hi=0;
unsigned int demo_input=0, demo_output;
LPSTR AD_Range[2][12]={ //电压范围
{"+/-5V","+/-0.5V","+/-0.05V","+/-0.005V","0~10V","0~1V","0~0.1V","0~0.01V","+/-10V","+/-1V","+/-0.1V","+/-0.01V"}
,{"+/-10V","+/-5V","+/-2.5V","+/-1.25V","0-10V","0-5V","0-2.5V","0-1.25V"," "," "," "," "}
};
//声明彩色刷子和笔
HBRUSH hLTGreenBrush,hGreenBrush,hBlueBrush,hYellowBrush,hRedBrush,hBlackBrush,hWhiteBrush
,hLTRedBrush,hLTBlueBrush;
HPEN hRedPen,hYellowPen,hGreenPen,hBluePen,hLTBluePen,hLTRedPen,hLTGreenPen,hWhitePen;
#define A8112B_HG 0
int base_addr=NONE,sample_rate=10,time_interval,gain=1;
int Card_Type=A8112B_HG;
int Input_Mode=SINGLE_ENDED;
int DA_wave[6] = {NONE, NONE, NONE, NONE, NONE, NONE};
double angle[6] = {0, 0, 0, 0, 0, 0};
int sq[6] = {0, 0, 0, 0, 0, 0};
//定义输入输出坐标点
POINT input_pos[16]= {
{470, 280}, {440, 280},
{410, 280}, {380, 280},
{350, 280}, {320, 280},
{ 290, 280}, {260, 280},
{230, 280}, {200, 280},
{170, 280}, {140, 280},
{110, 280}, {80, 280},
{ 50, 280}, { 20, 280},
};
POINT output_pos[16] ={
{470, 340}, {440, 340},
{410, 340}, {380, 340},
{350, 340}, {320, 340},
{ 290, 340}, {260, 340},
{230, 340}, {200, 340},
{170, 340}, {140, 340},
{110, 340}, {80, 340},
{ 50, 340}, { 20, 340},
};
POINT io_pos[16] ={
{395, 40}, {370, 40},
{345, 40}, {320, 40},
{295, 40}, {270, 40},
{ 245, 40}, {220, 40},
{195, 40}, {170, 40},
{145, 40}, {120, 40},
{95, 40}, {70, 40},
{ 45, 40}, { 20, 40},
};
//布尔变量选择框、按钮
BOOL bCheck1[8],bCheck2[8],bStart=FALSE,bStop=FALSE,bPause=FALSE;
BOOL InitApplication(HANDLE);//函数声明
BOOL InitInstance(HANDLE, int);
int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HANDLE hInstance, hPrevInstance;
LPSTR lpCmdLine;
int nCmdShow;
{
MSG msg;
if (!hPrevInstance)
if (!InitApplication(hInstance)) return(FALSE);//初始化应用程序
if (!InitInstance(hInstance, nCmdShow)) return(FALSE);//初始化实例
while (GetMessage(&msg, NULL, NULL, NULL)) { //进入消息循环
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(msg.wParam);
}
BOOL InitApplication(hInstance)
HANDLE hInstance;
{
WNDCLASS wc;
/* Main Window Class */
wc.style = NULL;
wc.lpfnWndProc = (WNDPROC)MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, "MyIcon");
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "GenericWClass";
if (!RegisterClass(&wc)) return(FALSE);
}
BOOL InitInstance(hInstance, nCmdShow)
HANDLE hInstance;
int nCmdShow;
{
HWND hWnd;
HMENU hSampleMenu;
hInst = hInstance;//赋值给全局变量,实例句柄
hSampleMenu = LoadMenu(hInstance, "U7120Menu");
hWnd = CreateWindow("GenericWClass",
(LPCSTR)"8112",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
530,
480,
NULL,
hSampleMenu,
hInstance,
NULL);
MainhWnd=hWnd; //赋值给全局变量,窗口句柄
if (!hWnd) return(FALSE);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return(TRUE);
}
//Setup菜单对话框
BOOL PASCAL setup(HWND hWnd, unsigned message, WPARAM wParam, LPARAM lParam)
{
int i,k;
char n[16];
switch (message) { //处理消息
case WM_INITDIALOG: //初始化对话框时
SendMessage(GetDlgItem(hWnd,IDC_COMBO1), CB_ADDSTRING,//下拉框添字符串
NULL,(LONG)(LPSTR)"(NONE)");
for (i=0x200; i<=0x3f8; i+=0x10) {
sprintf(n, "%xH", i);
_strupr(n); //字符串大写
SendMessage(GetDlgItem(hWnd,IDC_COMBO1), CB_ADDSTRING, NULL, (LONG)(LPSTR)n);
}
SendMessage(GetDlgItem(hWnd,IDC_COMBO2), CB_ADDSTRING, NULL, (LONG)(LPSTR)"8112 HG");
SendMessage(GetDlgItem(hWnd,IDC_COMBO2), CB_ADDSTRING, NULL, (LONG)(LPSTR)"8112 DG");
SendMessage(GetDlgItem(hWnd,IDC_COMBO3), CB_ADDSTRING, NULL, (LONG)(LPSTR)"Single Ended");
SendMessage(GetDlgItem(hWnd,IDC_COMBO3), CB_ADDSTRING, NULL, (LONG)(LPSTR)"Differential");