游戏游戏:CB代码转DELPHI代码喽(100分)

  • 主题发起人 主题发起人 kaithink
  • 开始时间 开始时间
K

kaithink

Unregistered / Unconfirmed
GUEST, unregistred user!
//---------------------------------------------------------------------------

#include <vcl.h>
#include <dir.h>

#include "xxxstruct.h"
#include "xxxctrl.h"
#include "xxxtags.h"
#include "xxxerr.h"
#pragma hdrstop

#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CSPIN"
#pragma resource "*.dfm"
TMainForm *MainForm;
xxxLoadProc xxxLoad;
xxxFreeProc xxxFree;
xxxSelectSourceProc xxxSelectSource;
xxxAcquireProc xxxAcquire;
xxxSetValueProc xxxSetValue;
xxxGetValueProc xxxGetValue;
xxxSetPropProc xxxSetProp;
xxxGetTagFlagProc xxxGetTagFlag;
xxxGetTagChoiceProc xxxGetTagChoice;
float fMaxWidth,fMaxHeight;

/***************************************************************************
*
* FUNCTION: GetImage(void *ptr, long *size, long status)
*
* ptr: 1.) pointer, handle, file name or LA_IMAGEINFOLV1 structure
* 2.) ptr can in and out
* size: 1.) if status=RC_IMAGEINFO, size is ignore
* 2.) if status!=RC_IMAGEINFO then the size only use on memory scan(pointer)
* and it's return size back to app
* 3.) size can in and out
* status: tell app current status, if status is RC_IMAGEINFO, ptr is LA_IMAGEINFOLV1 struct
*
****************************************************************************/
long WINAPI GetImage(void *ptr, unsigned long *size, long status)
{
HGLOBAL hDIB;
pxxxIMAGEINFO pInfo;

if (status==RC_IMAGEINFO) //Get Scanning setting
pInfo=(pxxxIMAGEINFO)ptr;

if (status == RC_XFERDONE)
hDIB = *(HANDLE *)ptr;

if (status == RC_XFERDONE){
// Get rid of old image first, because this App only deals with one
GlobalUnlock(hDIB);
GlobalFree(hDIB);
}

return RC_SUCCESS;
}

//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormShow(TObject *Sender)
{
curdir=GetCurrentDir();
ImgTypeComboBox->ItemIndex=0;

ResComboBox->Items->Clear();
ResComboBox->Items->Add("100");
ResComboBox->Items->Add("150");
ResComboBox->Items->Add("200");
ResComboBox->Items->Add("250");
ResComboBox->Items->Add("300");
ResComboBox->Items->Add("350");
ResComboBox->Items->Add("400");
ResComboBox->Items->Add("450");
ResComboBox->Items->Add("500");
ResComboBox->Items->Add("600");
ResComboBox->Items->Add("1200");
ResComboBox->ItemIndex=2;

SizeComboBox->Items->Clear();
SizeComboBox->Items->Add("A4");
SizeComboBox->Items->Add("Letter");
SizeComboBox->Items->Add("B5");
SizeComboBox->Items->Add("A5");
SizeComboBox->Items->Add("Bussiness Card");
SizeComboBox->Items->Add("3x5");
SizeComboBox->Items->Add("4x6");
SizeComboBox->Items->Add("Legal");
SizeComboBox->Items->Add("A3");
SizeComboBox->ItemIndex=1;

bAction=false;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::BrightTrackBarChange(TObject *Sender)
{
BrightLabel->Caption=IntToStr(BrightTrackBar->Position);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ContrastTrackBarChange(TObject *Sender)
{
ContrastLabel->Caption=IntToStr(ContrastTrackBar->Position);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::HighlightScrollBarChange(TObject *Sender)
{
HighlightLabel->Caption=IntToStr(HighlightScrollBar->Position);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ShadowScrollBarChange(TObject *Sender)
{
ShadowLabel->Caption=IntToStr(ShadowScrollBar->Position);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ScanMethodRadioGroupClick(TObject *Sender)
{
if (ScanMethodRadioGroup->ItemIndex==0)
DuplexCheckBox->Enabled=true;
else DuplexCheckBox->Enabled=false;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SelectButtonClick(TObject *Sender)
{
HINSTANCE hTwain;
LONG Err;

chdir(curdir.c_str());
hTwain = LoadLibrary("emgscan.dll");
if (hTwain>0){
xxxSelectSource = (xxxSelectSourceProc)GetProcAddress(hTwain, "xxxSelectSource");
xxxLoad = (xxxLoadProc)GetProcAddress(hTwain, "xxxLoad");
xxxFree = (xxxFreeProc)GetProcAddress(hTwain, "xxxFree");
if (xxxLoad)
Err=xxxLoad(Handle);

if (Err==RC_SUCCESS)
xxxSelectSource();

xxxFree;
}
FreeLibrary(hTwain);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::CloseButtonClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ScanButtonClick(TObject *Sender)
{
xxx_PROP twProp;
HINSTANCE hTwain;
LONG Err,flags,nSetVal,nGetVal;
void *pValue;
unsigned short CapId;
unsigned short CapMsg;
char szLString[256];
xxx_FLOAT fGamma;
xxx_SHORT shortvalue;
int nOpticalRes;

chdir(curdir.c_str());
hTwain = LoadLibrary("emgscan.dll");
if (hTwain>0){
xxxLoad = (xxxLoadProc)GetProcAddress(hTwain, "xxxLoad");
xxxFree = (xxxFreeProc)GetProcAddress(hTwain, "xxxFree");
xxxAcquire = (xxxAcquireProc)GetProcAddress(hTwain, "xxxAcquire");
xxxSetValue = (xxxSetValueProc)GetProcAddress(hTwain, "xxxSetValue");
xxxGetValue = (xxxGetValueProc)GetProcAddress(hTwain, "xxxGetValue");
xxxSetProp = (xxxSetPropProc)GetProcAddress(hTwain, "xxxSetProp");
xxxGetTagFlag = (xxxGetTagFlagProc)GetProcAddress(hTwain, "xxxGetTagFlag");
xxxGetTagChoice = (xxxGetTagChoiceProc)GetProcAddress(hTwain, "xxxGetTagChoice");
if (xxxLoad)
Err=xxxLoad(Handle);

if (Err==RC_SUCCESS){
xxxGetTagFlag(xxx_XRESOLUTION, &amp;flags);
xxxGetTagChoice(xxx_XRESOLUTION, xxx_RANGE_MAX, &amp;nOpticalRes);
/*Get the maximun scanning width*/
CapId = xxx_PHYSICALWIDTH;
pValue=&amp;fMaxWidth;
xxxGetValue(CapId, pValue);
/*Get the maximun scanning length*/
CapId = xxx_PHYSICALHEIGHT;
pValue=&amp;fMaxHeight;
Err=xxxGetValue(CapId, pValue);
if (UICheckBox->Checked)
twProp.ShowUI = 1;
else twProp.ShowUI = 0;

twProp.Brightness=1000-((20-BrightTrackBar->Position)*100); //-1000 to 1000
twProp.Contrast=1000-((20-ContrastTrackBar->Position)*100); //-1000 to 1000
twProp.TransMode =xxx_TRANSFERMODE_HANDLE;

CapId = xxx_FILTER;
pValue=&amp;shortvalue;
Err=xxxGetValue(CapId,pValue); //Get the default value for Color filter
twProp.Filter=shortvalue;
switch (ImgTypeComboBox->ItemIndex){
case 0://Lineart
twProp.PixelType =xxx_PIXELTYPE_BW;
twProp.BitsPerPixel=1;
CapId = xxx_DITHER;
strcpy(szLString,"None");
Err=xxxSetValue(CapId, szLString);
break;

case 1://Halftone
twProp.PixelType =xxx_PIXELTYPE_BW;
twProp.BitsPerPixel=1;
CapId = xxx_DITHER;
strcpy(szLString,"Halftone 1");
xxxSetValue(CapId, szLString);
break;

case 2://Gray
twProp.PixelType =xxx_PIXELTYPE_GRAY;
twProp.BitsPerPixel = 8;
break;

case 3://True color
twProp.PixelType =xxx_PIXELTYPE_RGB;
twProp.BitsPerPixel = 24;
break;
}
switch (ResComboBox->ItemIndex){
case 0:
twProp.XRes =100;
twProp.YRes =100;
break;

case 1:
twProp.XRes =150;
twProp.YRes =150;
break;

case 2:
twProp.XRes =200;
twProp.YRes =200;
break;

case 3:
twProp.XRes =250;
twProp.YRes =250;
break;

case 4:
twProp.XRes =300;
twProp.YRes =300;
break;

case 5:
twProp.XRes =350;
twProp.YRes =350;
break;

case 6:
twProp.XRes =400;
twProp.YRes =400;
break;

case 7:
twProp.XRes =450;
twProp.YRes =450;
break;

case 8:
twProp.XRes =500;
twProp.YRes =500;
break;

case 9:
twProp.XRes =600;
twProp.YRes =600;
break;

case 10:
twProp.XRes =1200;
twProp.YRes =1200;
break;
}
if (twProp.XRes>nOpticalRes){
twProp.XRes=nOpticalRes;
twProp.YRes =twProp.XRes;
}

twProp.Size.Unit=xxx_UNITS_INCH;
twProp.Size.DefPaper = 0;
twProp.Size.left=0;
twProp.Size.top=0;
switch (SizeComboBox->ItemIndex){
case 0://A4
twProp.Size.DefPaper=0;
twProp.Size.width=8.27;
twProp.Size.length=11;
break;

case 1://Letter
twProp.Size.DefPaper=0;
twProp.Size.width=8.27;
twProp.Size.length=11.69;
break;

case 2://B5
twProp.Size.DefPaper=0;
twProp.Size.width=8.27;
twProp.Size.length=11.69;
break;

case 3://A5
twProp.Size.DefPaper=0;
twProp.Size.width=5.83;
twProp.Size.length=8.27;
break;

case 4://Bussiness card
twProp.Size.DefPaper=0;
twProp.Size.width=4;
twProp.Size.length=2.5;
break;

case 5://3x5
twProp.Size.DefPaper=0;
twProp.Size.width=5.0;
twProp.Size.length=3.0;
break;

case 6://4x6
twProp.Size.DefPaper=0;
twProp.Size.width=6;
twProp.Size.length=4.0;
break;

case 7://Legal
twProp.Size.DefPaper=0;
twProp.Size.width=8.5;
twProp.Size.length=14;
break;

case 8://A3
twProp.Size.DefPaper=0;
twProp.Size.width=11.68;
twProp.Size.length=16.54;
break;
}
if (twProp.Size.width>fMaxWidth)
twProp.Size.width=fMaxWidth;
if (twProp.Size.length>fMaxHeight)
twProp.Size.length=fMaxHeight;
if (ColormatchCheckBox->Checked)
CapId = 1;
else CapId = 0;
pValue=&amp;CapId;
xxxSetValue(xxx_COLORMATCH, pValue);
switch (ScanMethodRadioGroup->ItemIndex){
case 0://ADF
pValue=&amp;CapMsg;
xxxGetValue(xxx_FEEDERSTATUS, pValue);
if (CapMsg==xxx_FEEDERSTATUS_LOAD){
twProp.ScanMethod=xxx_SCANTYPE_FEEDER;
if (DuplexCheckBox->Checked)
CapMsg=xxx_FEEDER_DUPLEX;
else CapMsg=xxx_FEEDER_SIMPLEX;
pValue=&amp;CapMsg;
xxxSetValue(xxx_FEEDERTYPE, pValue);
twProp.Size.left=(fMaxWidth/2.0)-((twProp.Size.width)/2.0);
CapId=1;
xxxSetValue(xxx_XFERCOUNT, &amp;CapId); //Set sheet feeder to scan one page
}else twProp.ScanMethod= xxx_SCANTYPE_FLATBED;
break;

case 1:twProp.ScanMethod= xxx_SCANTYPE_FLATBED;
}
CapId=1;
xxxSetValue(xxx_INDICATORS, &amp;CapId);
if (DescreenCheckBox->Checked)
CapId=1;
else CapId=0;
xxxSetValue(xxx_DESCREEN, &amp;CapId);

Err = xxxSetProp(twProp);
if (Err == RC_SUCCESS){
if (InvertCheckBox->Checked)
CapMsg = 1;
else CapMsg = 0;
pValue=&amp;CapMsg;
xxxSetValue(xxx_INVERT, &amp;CapMsg);
CapMsg=HighlightScrollBar->Position;
pValue=&amp;CapMsg;
xxxSetValue(xxx_HIGHLIGHT, pValue);
CapMsg=ShadowScrollBar->Position;
pValue=&amp;CapMsg;
xxxSetValue(xxx_SHADOW, pValue);
fGamma=GammaSpinEdit->Value/100;
pValue=&amp;fGamma;
xxxSetValue(xxx_GAMMA, pValue);
xxxAcquire(GetImage);
}
}
xxxFree;
}
FreeLibrary(hTwain);

}
//---------------------------------------------------------------------------
 
太多了,[:)]
 
玩嘛
xxxAcquire(GetImage);
这句什么意思?
 
xxxAcquire(GetImage);
xxxAcquire:是动态库emgscan.dll提供的一个方法,函数类型为xxxAcquireProc,可能在其它头文件中定义,你给的东东里看不出来。
根据上下文的意思理解,它应该是把GetImage这个函数的指针传进去,供emgscan.dll回调,emgscan.dll在需要的时候调用xxxAcquire传入的GetImage函数,实现一些功能使用户可以自己进行一些特别处理。
根据程序中的描述,GetImage应该进行了一些内存块的标记和释放(它为什么会用局部变量?),又做得不规范,看不明白。
 
扫描仪代码。
 
头文件来了,再就没有头文件 了
感觉这个头文件里没有什么
大家看看吧
是扫描仪的代码
不知怎么转
//---------------------------------------------------------------------------

#ifndef mainH
#define mainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
#include <ExtCtrls.hpp>
#include "CSPIN.h"
//---------------------------------------------------------------------------
class TMainForm : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TLabel *Label2;
TLabel *Label3;
TLabel *Label4;
TLabel *Label5;
TLabel *BrightLabel;
TLabel *ContrastLabel;
TButton *ScanButton;
TButton *CloseButton;
TComboBox *ImgTypeComboBox;
TComboBox *SizeComboBox;
TComboBox *ResComboBox;
TRadioGroup *ScanMethodRadioGroup;
TCheckBox *DuplexCheckBox;
TButton *SelectButton;
TCheckBox *UICheckBox;
TTrackBar *BrightTrackBar;
TTrackBar *ContrastTrackBar;
TCheckBox *InvertCheckBox;
TCheckBox *ColormatchCheckBox;
TCheckBox *DescreenCheckBox;
TLabel *Label6;
TLabel *Label7;
TLabel *HighlightLabel;
TLabel *ShadowLabel;
TScrollBar *HighlightScrollBar;
TScrollBar *ShadowScrollBar;
TCSpinEdit *GammaSpinEdit;
TLabel *Label8;
void __fastcall FormShow(TObject *Sender);
void __fastcall BrightTrackBarChange(TObject *Sender);
void __fastcall ContrastTrackBarChange(TObject *Sender);
void __fastcall HighlightScrollBarChange(TObject *Sender);
void __fastcall ShadowScrollBarChange(TObject *Sender);
void __fastcall ScanMethodRadioGroupClick(TObject *Sender);
void __fastcall SelectButtonClick(TObject *Sender);
void __fastcall CloseButtonClick(TObject *Sender);
void __fastcall ScanButtonClick(TObject *Sender);
private: // User declarations
public: // User declarations
AnsiString curdir;
BOOL bAction;
__fastcall TMainForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif
 
后退
顶部