delphi2007 教程

delphi2007 教程

首页 新随笔 联系 聚合 管理
  1013 Posts :: 0 Stories :: 28 Comments :: 0 Trackbacks

#

FreeLibrary问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061127162652164.html
释放动态库时报C盘下的系统文件,比如Boot.Ini、hiberfil.sys等等,这是怎么回事啊?!!  
   
  请高手赐教

有人知道吗?高手请回答,小弟很急

posted @ 2008-11-27 21:12 delphi2007 阅读(301) | 评论 (0)编辑 收藏

findwindow和findwindowex用来查找mid窗口的问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061127161821165.html
有一个mdi子窗口mdi_1,然后在mid_1窗口中mdi_11:=   tmdi_11.Create(self),最后在mdi_11中找mdi_1窗口的句柄,不能找到.请介绍一下findwindowex使用方法.  
   
  我使用的findwindow可以找到非mdi窗口  
  hd:=findwindow('mdi_1',0)  
   
  使用findwindowex什么都找不到  
  hd:=findwindowex(mdi_1.ParentWindow,0,'mdi_1',nil);  
 

用findCompent

已经解决了,但是'MDIClient'还不清楚是什么意思  
   
  //参考如下代码        
      var        
              vHandle:       THandle;        
      begin        
              vHandle       :=       FindWindow('TForm1',       nil);       //寻找MDI主窗体        
              Memo1.Lines.Add(IntToStr(vHandle));        
              vHandle       :=       FindWindowEx(vHandle,       0,       'MDIClient',       nil);       //寻找MDI容器区域        
              Memo1.Lines.Add(IntToStr(vHandle));        
              vHandle       :=       FindWindowEx(vHandle,       0,       'TForm3',       nil);       //寻找MDI子窗体        
      end;

FindWindowEx(  
  Parent:   HWND;                                               {a   handle   to   a   parent   window}  
  Child:   HWND;                                               {a   handle   to   a   child   window}  
  ClassName:   PChar;                                   {a   pointer   to   a   null   terminated   class   name   string}  
  WindowName:   PChar                                 {a   pointer   to   a   null   terminated   window   name   string}  
  ):   HWND;                                                                 {returns   a   handle   to   a   window}

posted @ 2008-11-27 21:12 delphi2007 阅读(1520) | 评论 (0)编辑 收藏

如何传递应用程序的返回值 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061127133508166.html
A.exe要调用B.exe,B需要返回一些值给A使用,请问B的返回值,在应用程序B中应该怎么写呀?同时A调用了B后,如何读取他的返回值呀?请各位大侠帮帮,谢谢!

沙发

//方案1   消息机制  
  把A的窗体句柄传递给B  
  //...  
      public  
          procedure   WMUSER10(var   Msg:   TMessage);   message   WM_USER   +   10;  
      end;  
  //...  
  implementation  
  //...  
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
      WinExec(PChar(ParamStr(0)   +   '   '   +   IntToStr(Handle)),   SW_SHOW);  
  end;  
   
  procedure   TForm1.WMUSER10(var   Msg:   TMessage);  
  begin  
      Caption   :=   IntToStr(Msg.WParam);   //接收消息  
  end;  
   
  B中处理后发送给A的窗体  
  procedure   TForm2.Button1Click(Sender:   TObject);  
  begin  
      SendMessage(StrToIntDef(ParamStr(1),   0),   WM_USER   +   10,   12345,   0);  
  end;

ParamStr(0)是我做测试的,用的时候换成B的文件名(注意路径)

方案2   利用CreateProcess()Api函数,   推荐  
  function   ExecProcess(mCommandLine:   string):   Longword;  
  var  
      vStartupInfo:   TStartupInfo;  
      vProcessInformation:   TProcessInformation;  
  begin  
      FillChar(vStartupInfo,   SizeOf(TStartupInfo),   0);  
      FillChar(vProcessInformation,   SizeOf(TProcessInformation),   0);  
      vStartupInfo.cb   :=   SizeOf(TStartupInfo);  
      vStartupInfo.dwFlags   :=   STARTF_USESHOWWINDOW;  
      vStartupInfo.wShowWindow   :=   SW_NORMAL;  
   
      if   CreateProcess(nil,   PChar(mCommandLine),   nil,   nil,   False,  
          CREATE_NEW_PROCESS_GROUP   or   NORMAL_PRIORITY_CLASS,  
          nil,   nil,   vStartupInfo,   vProcessInformation)   then  
      begin  
          WaitForSingleObject(vProcessInformation.hProcess,   INFINITE);  
          GetExitCodeProcess(vProcessInformation.hProcess,   Result);  
          CloseHandle(vProcessInformation.hThread);  
          CloseHandle(vProcessInformation.hProcess);  
      end   else   Result   :=   0;  
  end;   {   ExecProcess   }  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
      Caption   :=   IntToStr(ExecProcess('C:\temp\B.exe'));   //   调用B  
  end;  
   
  B工程中最后一句加上你要返回的值即可:  
  begin  
      Application.Initialize;  
      Application.CreateForm(TForm1,   Form1);  
      Application.Run;  
      ExitCode   :=   1234;   //《〈〈〈〈〈〈〈〈〈〈  
  end.  
 

学习

posted @ 2008-11-27 21:12 delphi2007 阅读(286) | 评论 (0)编辑 收藏

射频卡读取问题? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061127101938167.html
毕业第一个工作就是射频卡编程?  
  不知道怎么对射频卡怎么进行读和取数据     还有保存.      
  您可以帮我下吗   高手!     小弟万分感激!  
  QQ:432186       E-mail:432186@qq.com

问厂商要资料  
   
   
  my   qq   :   406110146

估计会有现成的SDK给你,照着说明书写就是了

会提供二次开发包的

这个最简单的,向提供射频卡的供应商要驱动(一般是提供一个Dll),然后要一个读写操作的例子(一般会含VC、VB、Delphi)。以后你照着例子做就Ok了。

基本都是RS232串口编程

大多数都是串口,直接用控件读写......

给你一个例子,各种厂家的也是大同小异  
   
  var  
      FRFSector:   SmallInt;  
      FRFBlock:   SmallInt;  
      FRFComm:   Integer;  
      FRFSNR:   LongInt;  
      FRFNKeyType:   Integer;  
      FRFNKey:   string;  
      FRFRtn:   Integer;  
   
  ......初始化  
   
  function   TRJCControl.InitRFControl:   Boolean;  
  begin  
      FRFRtn   :=   PTS.System.RJCLibrary.Open_Comm(FRFComm+1);  
      if   (FRFRtn   <>   0)   then  
      begin  
          Result   :=   False;  
          Exit;  
      end;  
      PTS.System.RJCLibrary.SetRC500State(1);  
      FRFSector   :=   1;  
      FRFBlock   :=   4;  
      FRFNKeyType   :=   0;  
      SetLength(FRFNKey,12);  
      FRFNKey   :=   'ffffffffffff';  
      Result   :=   True;  
  end;  
   
  ......读卡  
   
  function   TRJCControl.ReadCard:   Boolean;  
  var  
      ReadMessage:   string;  
  begin  
      Result   :=   False;  
      SetLength(ReadMessage,32);  
      FRFRtn   :=   PTS.System.RJCLibrary.ReadCard(FRFNKeyType,   FRFNKey,    
                                                                                        FRFBlock,   ReadMessage);  
      FRFMessage.RFMsg   :=   HexToStr(ReadMessage);  
      FRFMessage.RFFlag   :=   '成功';  
      FRFMessage.RFTag   :=   '读';  
      PTS.System.RJCLibrary.SetBeep(3,5);  
      Result   :=   True;  
  end;  
   
  很简单的。只要把厂家的API多熟悉就可以了。

posted @ 2008-11-27 21:12 delphi2007 阅读(240) | 评论 (0)编辑 收藏

如何让hook拦截到的按键消息区分大小写? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061127022414168.html
请给出参考代码,  
   
  不要偏题啊。。。

no   such   thing  
  you   need   to   check   the   state   of   Caps   lock   key   and   shift   key

是这样子的吗?  
   
  下面语句也不行  
  GetKeyboardState(KeyState);  
  ToAscii(paramL,   ((paramH   shr   16)and$00ff),   KeyState,   @KeyChar[0],   0)  
   
  ~~~

mark

posted @ 2008-11-27 21:12 delphi2007 阅读(253) | 评论 (0)编辑 收藏

要如何禁止键盘钩子? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061126120722169.html
很多游戏都有这个功能,来防止盗号。  
   
   
  不知道   这是怎么做到的?  
  能不能说说原理?

帮你顶

屏蔽键盘鼠标事件  
   
  //请试一试该程序  
  var  
    YourHook:   HHOOK;  
   
  //定义用于HOOK的消息,也可以是windows的标准消息  
  const  
    WM_YourMessage   =   WM_USER   +   2000;  
   
  //发送你需要的消息  
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
    PostMessage(self.Handle,WM_YourMessage,0,0);  
  end;  
   
  //你的HOOK处理函数  
  function   YourHookProc(Code:   Integer;   WParam:   Longint;   var   Msg:   TMsg):   Longint;   stdcall;  
  begin  
  //     if   (Code   =   HC_ACTION)   then  
        if   Msg.Message   =   WM_YourMessage   then  
          //调用你自己的HOOK函数  
          begin  
              showMessage('截获该消息');  
      end;  
    Result   :=   CallNextHookEx(YourHook,   Code,   WParam,   Longint(@Msg));  
  end;  
   
  //安装HOOK  
  procedure   TForm1.FormCreate(Sender:   TObject);  
  begin  
    YourHook   :=     SetWindowsHookEx(WH_GETMESSAGE,   @YourHookProc,   0,   GetCurrentThreadID);  
  end;      
   
  ===========================  
   
  帮LZ找的资料```

日志钩子(JournalRecord   Hook)的使用    
  ----   钩子是WINDOWS中消息处理机制的一个要点,通过安装各种钩子,应用程序能够设置相应的子例程来监视系统里的消息传递以及在这些消息到达目标窗口程序之前处理它们。钩子的种类很多,每种钩子可以截获并处理相应的消息,如键盘钩子可以截获键盘消息,鼠标钩子可以截获鼠标消息,外壳钩子可以截获启动和关闭应用程序的消息,日志钩子可以监视和记录输入事件。钩子分为线程专用钩子和全局钩子,线程专用钩子只监视指定的线程,要监视系统中的所有线程,必须用到全局钩子。对于全局钩子,钩子函数必须包含在独立的动态链接库(DLL)中,这样才能被各种相关联的应用程序调用。在WINDOWS中,日志钩子是个很特别的钩子,它只有全局钩子一种,是键盘鼠标等输入设备的消息在系统消息队列被取出时发生的,而且系统中只能存在一个这样的日志钩子,更重要是,它不必用在动态链接库中,这样可以省却了为安装一个全局钩子而建立一个动态链接库的麻烦。利用日志钩子,我们可以监视各种输入事件,下面的示例可以用来记录键盘的输入,当有按键发生时,自动记录按键动作的日期和时间以及当前激活的窗口名称。本示例在中文WIN98,Borland   C++   Builder4中编译通过。    
   
  ----   1.新建一个工程,在窗体Form1中放置两个按钮Button1和Button2,   CAPTION分别为“安装日志钩子”和“卸载日志钩子”。    
   
  ----   2.   定义如下全局变量:    
   
  HHOOK   g_hLogHook=NULL;           //钩子变量  
  HWND   g_hLastFocus=NULL;            
  //记录上一次得到焦点的窗口句柄  
  const   int   KeyPressMask=0x80000000;     //键盘掩码常量  
  char   g_PrvChar;             //保存上一次按键值  
   
  3.在Button1的OnClick事件中输入:  
   
  void   __fastcall   TForm1::Button1Click(TObject   *Sender)  
    {  
      if     (g_hLogHook==NULL)  
        g_hLogHook   =   SetWindowsHookEx  
  (WH_JOURNALRECORD,  
                  (HOOKPROC)JournalLogProc,  
  HInstance,0);     //安装日志钩子  
    }  
   
  4.在Button2的OnClick事件中输入:  
   
  void   __fastcall   TForm1::Button2Click(TObject   *Sender)  
  {  
    if   (g_hLogHook!=NULL)  
      {UnhookWindowsHookEx(g_hLogHook);  
        g_hLogHook=NULL;  
      }     //卸载日志钩子  
  }  
   
  5.输入钩子回调函数:  
  HOOKPROC   JournalLogProc(int   iCode,    
  WPARAM   wParam,   LPARAM   lParam)  
  {  
    if   (iCode<   0)   return   (HOOKPROC)CallNextHookEx  
  (g_hLogHook,iCode,wParam,lParam);  
    if   (iCode==HC_ACTION)  
      {EVENTMSG   *pEvt=(EVENTMSG   *)lParam;  
        int   i;  
        HWND   hFocus;             //保存当前活动窗口句柄  
        char   szTitle[256];           //当前窗口名称  
        char   szTime[128];         //保存当前的日期和时间  
        FILE   *stream=fopen(“c:\\logfile.txt”,"a+t");  
        if   (pEvt->message==WM_KEYDOWN)            
          {int   vKey=LOBYTE(pEvt-   >paramL);         //   取得虚拟键值  
            char   ch;  
            char   str[10];  
            hFocus=GetActiveWindow();            
      //取得当前活动窗口句柄  
            if(g_hLastFocus!=hFocus)            
      //当前活动窗口是否改变  
              {GetWindowText(hFocus,szTitle,256);  
                g_hLastFocus=hFocus;  
                strcpy(szTime,DateTimeToStr(Now())  
  .c_str());     //得到当前的日期时间  
                fprintf(stream,"%c%s%c%c%s",  
  10,szTime,32,32,szTitle);     //写入文件  
                fprintf(stream,"%c%c",32,32);      
              }  
            int   iShift=GetKeyState(0x10);      
  //测试SHIFT,CAPTION,NUMLOCK等键是否按下  
            int   iCapital=GetKeyState(0x14);  
            int   iNumLock=GetKeyState(0x90);  
            bool   bShift=(iShift   &   KeyPressMask)==KeyPressMask;        
            bool   bCapital=(iCapital   &   1)==1;  
            bool   bNumLock=(iNumLock   &   1)==1;  
            if   (vKey   >=48   &&   vKey<   =57)    
    //   数字0-9  
                if   (!bShift)   fprintf(stream,"%c",vKey);  
            if   (vKey   >=65   &&   vKey<   =90)    
  //   A-Z               a-z  
              {if   (!bCapital)  
                    if   (bShift)   ch=vKey;   else   ch=vKey+32;  
                else  
                    if   (bShift)   ch=vKey+32;   else   ch=vKey;  
                fprintf(stream,"%c",ch);  
              }  
            if   (vKey   >=96   &&   vKey<   =105)                   //   小键盘0-9  
                if   (bNumLock)   fprintf(stream,"%c",vKey-96+48);  
            if   (vKey>=186   &&   vKey<=222)                   //   其他键  
              {switch   (vKey)  
                  {case   186:if   (!bShift)   ch=';';   else   ch=':';break;  
                    case   187:if   (!bShift)   ch='=';   else   ch='+';break;  
                    case   188:if   (!bShift)   ch=',';   else   ch='<'   ;break;  
                    case   189:if   (!bShift)   ch='-';   else   ch='_';break;  
                    case   190:if   (!bShift)   ch='.';   else   ch='   >';break;  
                    case   191:if   (!bShift)   ch='/';   else   ch='?';break;  
                    case   192:if   (!bShift)   ch='`';   else   ch='~';break;  
                    case   219:if   (!bShift)   ch='[';   else   ch='{';break;  
                    case   220:if   (!bShift)   ch='\\';   else   ch='|';break;  
                    case   221:if   (!bShift)   ch=']';   else   ch='}';break;  
                    case   222:if   (!bShift)   ch='\'';   else   ch='\"';break;  
                    default:ch='n';break;  
                  }  
                if   (ch!='n')   fprintf(stream,"%c",ch);  
              }  
  //           if   (wParam   >=112   &&   wParam<=123)          
    //   功能键       [F1]-[F12]  
            if   (vKey   >=8   &&   vKey<   =46)       //方向键  
              {switch   (vKey)  
                  {case   8:strcpy(str,"[BK]");break;  
                    case   9:strcpy(str,"[TAB]");break;  
                    case   13:strcpy(str,"[EN]");break;  
                    case   32:strcpy(str,"[SP]");break;  
                    case   33:strcpy(str,"[PU]");break;  
                    case   34:strcpy(str,"[PD]");break;  
                    case   35:strcpy(str,"[END]");break;  
                    case   36:strcpy(str,"[HOME]");break;  
                    case   37:strcpy(str,"[LF]");break;  
                    case   38:strcpy(str,"[UF]");break;  
                    case   39:strcpy(str,"[RF]");break;  
                    case   40:strcpy(str,"[DF]");break;  
                    case   45:strcpy(str,"[INS]");break;  
                    case   46:strcpy(str,"[DEL]");break;  
                    default:ch='n';break;  
                  }  
                if   (ch!='n')  
                  {if   (g_PrvChar!=vKey)  
                      {fprintf(stream,"%s",str);  
                        g_PrvChar=vKey;  
                      }  
                  }  
              }  
  }  
              if  
  (pEvt-   >message==WM_LBUTTONDOWN   ||   pEvt-   >message  
  ==WM_RBUTTONDOWN)  
              {hFocus=GetActiveWindow();  
                if   (g_hLastFocus!=hFocus)  
                  {g_hLastFocus=hFocus;  
                    GetWindowText(hFocus,szTitle,256);                
            strcpy(szTime,DateTimeToStr(Now()).c_str());      
  //得到当前的日期时间  
            fprintf(stream,"%c%s%c%c%s",  
  10,szTime,32,32,szTitle);     //写入文件  
            fprintf(stream,"%c%c",32,32);      
                  }  
              }  
    fclose(stream);  
    return   (HOOKPROC)CallNextHookEx  
  (g_hLogHook,iCode,wParam,lParam);  
  }  
 

http://dev.cbw.com/cbuilder/api/20055245505_2738869.shtml

转贴:  
  “证券大盗”实质上是利用键盘钩子技术进行做案的,他们最关心的是键盘消息“钩子”(WH_KEYBOARD   Hook)。对付此类病毒的有效措施是以毒攻毒,以键盘钩子对付键盘监视:即在应用程序中需要键盘输入的时候,应用程序自己创建并安装一个键盘监视钩子,并使其处于钩子链的顶端,这样键盘输入的消息将被自己的钩子处理程序截获。只要在钩子处理程序中不再调用CallNextHookEx函数,即不把消息传递给下面的钩子

不知道管不管用,测试先。  
      谢谢大家啦~

posted @ 2008-11-27 21:12 delphi2007 阅读(319) | 评论 (0)编辑 收藏

求人看看这个代码,有关DLL中使用回调函数的问题:回调不能返回正确值 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061125234815170.html
用回调函数总是不能正确返回,我发送消息SendMessage是可以的。  
   
   
  unit   Unit1;  
  .........  
   
  type  
      TCallback   =   procedure(s:   pchar);   stdcall;  
   
  var  
      Form1:   TForm1;  
  function   OpenPort(PORT:   shortstring;   BTL:   integer):   integer;   stdcall   External   'DRYPRT5.dll';  
  function   ClosePort:   integer;   stdcall   External   'DRYPRT5.dll';  
  function   OutDate(SD:   string):   integer;   stdcall   External   'DRYPRT5.dll';  
  procedure   SetCallback(ACallback:   TCallback);   stdcall   External   'DRYPRT5.dll';  
  procedure   CallbackExample(s:   pchar);   stdcall;  
   
  implementation  
   
  {$R   *.dfm}  
   
  procedure   CallbackExample(s:   pchar);   stdcall;  
  begin  
      Form1.Label1.Caption   :=   (s);  
  end;  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
      if   OpenPort('1',   9600)   =   1   then   Shape1.Brush.Color   :=   clred;  
  end;  
   
  procedure   TForm1.Button2Click(Sender:   TObject);  
  begin  
      if   ClosePort   =   1   then   Shape1.Brush.Color   :=   clblack;  
  end;  
   
  procedure   TForm1.Button4Click(Sender:   TObject);  
  begin  
      SetCallback(@CallbackExample);//此处传给DLL地址  
  end;  
   
  end.  
   
  /////////////////////////////////////////////////////////////////////////////////  
   
  library   DRYPRT5;  
   
  uses  
      SysUtils,  
      Classes,  
      PRTTING   in   'PRTTING.pas';  
   
  {$R   *.RES}  
  exports  
      SetCallback,  
      OpenPort,  
      ClosePort,  
      OutDate,  
      IniComm;  
  begin  
  end.  
   
  /////////////  
  unit   PRTTING;  
  .......  
  type  
      TMYOBJ   =   class  
          procedure   MYComReceiveData(Sender:   TObject;   Buffer:   Pointer;   BufferLength:   Word);  
      end;  
  type  
      TCallback   =   procedure(s:   pchar);  
   
  var  
      Read_busy,   Open_busy,   Port_active,   Receive_finish:   BOOLEAN;  
   
      S_DATA:   string;  
   
      MYCOM:   TCOMM;  
      MYOBJ:   TMYOBJ;  
      FCallback:   TCallback;  
   
      hd:   THandle;  
   
  function   OpenPort(Port:   shortstring;   BTL:   INTEGER):   INTEGER;   STDCALL;  
  function   ClosePort:   INTEGER;   STDCALL;  
  function   OutDate(SD:   string):   INTEGER;   STDCALL;  
  procedure   SetCallback(ACallback:   TCallback);   STDCALL;  
  procedure   SendData(SData:   string);   STDCALL;  
  procedure   IniComm(formhd:   THandle);   STDCALL;  
   
  implementation  
   
  procedure   TMYOBJ.MYComReceiveData(Sender:   TObject;   Buffer:   Pointer;   BufferLength:   Word);  
  var  
      S1:   string;  
      RD:   pchar;  
  begin  
      SetLength(S1,   BufferLength);  
      Move(Buffer^,   pchar(S1)^,   BufferLength);  
      S_DATA   :=   S1;  
      if   Assigned(FCallback)   then  
          FCallback(pchar(S_DATA   ));//回调  
  end;  
   
  procedure   SetCallback(ACallback:   TCallback);   stdcall;  
  begin  
      FCallback   :=   ACallback;//得到  
  end;  
   
   
  下面是另外的函数有这个问题没有关系  
   
  procedure   INI_OBJ;  
  begin  
      MYOBJ   :=   TMYOBJ.Create;  
      MYCOM   :=   TCOMM.Create(nil);  
      MYCOM.OnReceiveData   :=   MYOBJ.MYComReceiveData;  
  end;  
   
  procedure   FREE_OBJ;  
  begin  
      try  
          if   MYOBJ   <>   nil   then  
          begin  
              MYOBJ.FREE;  
              MYOBJ   :=   nil;  
          end;  
          if   MYCOM   <>   nil   then  
          begin  
              MYCOM.FREE;  
              MYCOM   :=   nil;  
          end;  
      except  
      end;  
  end;  
   
  function   OutDate(SD:   string):   INTEGER;   stdcall;  
  begin  
      if   Read_busy   then   //正在发送  
      begin  
          RESULT   :=   0;  
          Exit;  
      end;  
      if   not   Port_active   then   //没有打开串口  
      begin  
          RESULT   :=   -1;  
          Exit;  
      end;  
      Read_busy   :=   TRUE;   //发送开始  
      MYCOM.WriteCommData(pchar(SD),   Length(SD));  
      Read_busy   :=   FALSE;   //发送结束  
      RESULT   :=   1;  
  end;  
   
  function   OpenPort(Port:   shortstring;   BTL:   INTEGER):   INTEGER;   stdcall;  
  begin  
      if   Open_busy   or   Read_busy   then  
      begin  
          RESULT   :=   0;  
          Exit;  
      end;  
      if   Port_active   then  
      begin  
          RESULT   :=   -1;  
          Exit;  
      end;  
      Open_busy   :=   TRUE;  
      INI_OBJ;  
   
      MYCOM.BaudRate   :=   BTL;  
      MYCOM.CommName   :=   'com'   +   Port;  
      try  
          MYCOM.StartComm;  
          Port_active   :=   TRUE;  
          RESULT   :=   1;  
      except  
          Port_active   :=   FALSE;  
          RESULT   :=   -2;  
      end;  
      Open_busy   :=   FALSE;  
  end;  
   
  function   ClosePort:   INTEGER;   stdcall;  
  begin  
      try  
          if   MYCOM   <>   nil   then   MYCOM.StopComm;  
          Port_active   :=   FALSE;  
          RESULT   :=   1;  
      except  
          RESULT   :=   -1;  
      end;  
      FREE_OBJ;  
  end;  
   
   
   
  end.

type  
      TCallback   =   procedure(s:   pchar);   stdcall;  
                                                                        ~~~~~~~~加上,dll和app两边声明要一致  
   
 

谢谢.看得可真仔细了,哈哈

posted @ 2008-11-27 21:12 delphi2007 阅读(337) | 评论 (0)编辑 收藏

如何做到游戏双开??修改进程名可以吗? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061125213427171.html
有的游戏不允许运行多个.有没有办法可以实现多开?  
  修改进程名可以吗?  
  高手指点下,最好有代码,呵呵

不行

要看游戏是怎么实现不允许多个同时运行的了!  
          如果只是简单的FindWindow查找窗口句柄或查找进程,当然可以实现,不过一般很少会这样设计吧!如果用互斥量来实现,估计是没有办法!

这个你应该到破解的那些论坛上去问,可能回答率相对高些,试试到看雪学院的论坛去问问看

posted @ 2008-11-27 21:12 delphi2007 阅读(819) | 评论 (0)编辑 收藏

如何带参数打开其他程序? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061125212626172.html
有一个程序temp.exe,可以带3个参数运行,三个参数分别是   a   ;   b;   c  
  怎么编写点击按钮后带参数的打开temp.exe,并且得到该进程的句柄还有进程句柄等等?

参数直接写后面就好了呀,用空格隔开。  
  temp.exe   a   b   c  
   
  后面那个问题就不知道了。

CreateProcess

mark

ShellExecute(Handle,   nil,   PChar(FName),   PChar(Param),   nil,   SW_SHOWNORMAL);  
   
  然后查找窗体

WinExec('c:\temp\temp.exe   a   b   c',   SW_SHOW);

学习!

posted @ 2008-11-27 21:12 delphi2007 阅读(288) | 评论 (0)编辑 收藏

串口打印问题,各位大侠帮帮忙! Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061125105716173.html
我想实现串口打印这样的功能,如果串口打印机   不开,我就不发送打印命令,  
  谁帮忙给段代码例子  
  arrqi@163.com  
  谢谢

靠!不发指令你咋知道它开了没?  
  98或95下有汇编指令可以做到,2K以后就只能发指令然后等回复了,若没回复就认为它挂了!

或者你和打印机厂商的硬件工程师协调,增加个打开验证指令,打印支前要有此指令的验证,否则不发送打印指令。

posted @ 2008-11-27 21:12 delphi2007 阅读(169) | 评论 (0)编辑 收藏

[请教] 关于把mscomm控件封装进dll的 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061124231637174.html
不知道什么原因,封装好生成的dll用delphi调用总是报错。  
  还有mscomm接收的数据怎么给exe?  
   
  如果大家有现成的解决方案请发给我一份guangzhao@163.com  
  多谢大家  
   
  下面是找来的一点代码:  
   
  library       lib1;        
      .....        
      exports        
              OpenComm;        
              SendText;        
              CloseComm;        
      begin        
          ...        
      end.        
           
           
      unit       unit1;        
           
      interface        
          uses        
                  ActiveX,....        
           
      procedure       OpenComm(Port:Integer);stdcall;        
      procedure       SendText(Text:PChar);stdcall;        
      procedure       CloseComm;stdcall;        
           
      implementation        
           
      procedure       OpenComm(Port:Integer);        
      begin        
              MSComm1.CommPort:=1;        
              MSComm1.Open;        
      end;        
      procedure       SendText(Text:PChar);        
      begin        
              MSComm1.Output:=string(Text);        
      end;        
      procedure       CloseComm;        
      begin        
          MSComm1.Close;        
      end;        
      initialization        
              CoIntialize(nil);        
              MSComm1:=TMSComm.Create(nil);        
      finalization        
              MSComm1.Free;        
              CoUnitialize;        
      end.  
  ----------------------------------------------    
   
  上面代码中CoIntialize,CoUnitialize这俩个delphi识别不了啊,uses   ActiveX也没有用  
   
  oosmile@msn.com  
     
 

回调函数的资料,始终编译通不过  
   
  exports        
              SetCallback;        
           
           
           
      type        
                  TCallback=procedure(s:string);        
                  TABC=class(TComponent)        
                          procedure       MSCommOnComm(Sender:TObject);        
                  end;            
      var        
              FCallback:TCallback;        
              ABC:TABC;        
           
      procedure       SetCallback(ACallback:TCallback);        
      begin        
              FCallback:=@ACallback;        
      end;        
      procedure       TABC.MSCommComm(Sender:TObject);        
      var        
              s:string;        
      begin        
              while       MSComm1.InBufferCount>0       do        
              begin        
                      s:=MSComm1.Input;        
                      if       Assigned(FCallback)       then        
                                  FCallback(PChar(s));        
              end;        
      end;        
           
      initialization        
              ...        
              ABC:=TABC.Create(nil);            
              MSComm1.OnComm:=ABC.MSCommOnComm        
      finalization        
          ...        
              ABC.Free;        
      end.

大家帮帮忙,用CPort或者spcomm都好  
  如果有pcomm的delphi资料给咱一份

我没有这样做过,不过很感兴趣。在台湾大富翁查了一份封装SPCOMM的资料,不知道对你有没有帮助。  
   
  http://delphi.ktop.com.tw/board.php?cid=30&fid=70&tid=79147

感谢楼上的

不客气,因为我对工业控制一直很感兴趣,也做了好几个项目。但一直没有用串口通讯组件,都是用的自己写的WIN32底层封装。

楼上能否给一份自己封装好的api

源码都可以给。你可以根据你的需要来封装

10分感谢。先给你记分

睡觉了,明天给你揭帖

unit   Unit1;  
   
  interface  
   
  uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs,   StdCtrls;  
   
  type  
      TForm1   =   class(TForm)  
          Button1:   TButton;  
          Button2:   TButton;  
          procedure   Button1Click(Sender:   TObject);  
          procedure   Button2Click(Sender:   TObject);  
      private  
          {   Private   declarations   }  
      public  
          {   Public   declarations   }  
      end;  
   
  var  
      Form1:   TForm1;  
  function   OPEN_PORT(PORT:   SHORTSTRING;   BTL:   INTEGER):   INTEGER;   StdCall   External   'DRYPRT5.dll';  
  function   CLOSE_PORT:   INTEGER;   StdCall   External   'DRYPRT5.dll';  
  function   SEND_COMMAND(SD:   string;   var   RD:   PChar):   INTEGER;   StdCall   External   'DRYPRT5.dll';  
   
  implementation  
   
  {$R   *.dfm}  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
      if   OPEN_PORT('1',   9600)   =   1   then   ShowMessage('正常打开');  
  end;  
   
  procedure   TForm1.Button2Click(Sender:   TObject);  
  begin  
      if   CLOSE_PORT   =   1   then   ShowMessage('正常关闭');  
  end;  
   
  end.  
   
   
   
  -----------------------------------------------------------  
   
  library   DRYPRT5;  
   
  uses  
      SysUtils,  
      Classes,  
      PRTTING   in   'PRTTING.pas';  
   
  {$R   *.RES}  
  exports  
      OPEN_PORT,  
      CLOSE_PORT,  
      SEND_COMMAND;  
  begin  
  end.  
   
   
  unit   PRTTING;  
   
  interface  
   
  uses  
      Windows,   Forms,   ExtCtrls,   SysUtils,   SPComm;  
   
  type  
      TMYOBJ   =   class  
          procedure   MYComReceiveData(Sender:   TObject;   Buffer:   Pointer;   BufferLength:   Word);  
      end;  
   
  var  
      WAIT_TIMES,   N_NUMBER:   INTEGER;  
      START_TIMES:   REAL;  
      READ_BUSY,   OPEN_BUSY,   PORT_ACTIVE,   RECEIVE_FINISH:   BOOLEAN;  
      S_DATA:   string;  
   
      MYCOM:   TCOMM;  
      MYOBJ:   TMYOBJ;  
   
  function   OPEN_PORT(PORT:   SHORTSTRING;   BTL:   INTEGER):   INTEGER;   STDCALL;  
  function   CLOSE_PORT:   INTEGER;   STDCALL;  
  function   SEND_COMMAND(SD:   string;   var   RD:   PChar):   INTEGER;   STDCALL;  
   
   
  implementation  
   
  procedure   INI_OBJ;  
  begin  
      MYOBJ   :=   TMYOBJ.Create;  
      MYCOM   :=   TCOMM.Create(nil);  
      MYCOM.OnReceiveData   :=   MYOBJ.MYComReceiveData;  
  end;  
   
  procedure   FREE_OBJ;  
  begin  
      try  
          if   MYOBJ   <>   nil   then  
          begin  
              MYOBJ.FREE;  
              MYOBJ   :=   nil;  
          end;  
          if   MYCOM   <>   nil   then  
          begin  
              MYCOM.FREE;  
              MYCOM   :=   nil;  
          end;  
      except  
      end;  
  end;  
   
  procedure   TMYOBJ.MYComReceiveData(Sender:   TObject;   Buffer:   Pointer;   BufferLength:   Word);  
  var  
      S1:   string;  
  begin  
      START_TIMES   :=   Now;  
      SetLength(S1,   BufferLength);  
      Move(Buffer^,   PChar(S1)^,   BufferLength);  
      S_DATA   :=   S_DATA   +   S1;  
   
      if   Pos(#13,   S_DATA)   >   0   then   RECEIVE_FINISH   :=   TRUE;  
  end;  
   
  //function   SEND_COMMAND(var   SD,   RD:   PChar):   INTEGER;   stdcall;  
  function   SEND_COMMAND(SD:   string;   var   RD:   PChar):   INTEGER;   stdcall;  
  var  
      N2:   REAL;  
      B:   BOOLEAN;  
  begin  
      if   READ_BUSY   then  
      begin  
          RESULT   :=   0;  
          Exit;  
      end;  
      if   not   PORT_ACTIVE   then  
      begin  
          RESULT   :=   -1;  
          Exit;  
      end;  
      READ_BUSY   :=   TRUE;  
      RECEIVE_FINISH   :=   FALSE;  
      START_TIMES   :=   Now;  
      S_DATA   :=   '';  
      MYCOM.WriteCommData(PChar(SD),   Length(SD));  
   
      B   :=   FALSE;  
      while   not   RECEIVE_FINISH   do  
      begin  
          APPLICATION.ProcessMessages;  
          N2   :=   Now   -   START_TIMES;  
          N2   :=   N2   *   100000000;  
          B   :=   N2   >   2000;  
          if   B   then   Break;  
      end;  
      if   B   then   RESULT   :=   -2   //   超时没有返回值  
      else   RESULT   :=   1;  
   
      //RD   :=   PChar(S_DATA);  
      //Move(S_DATA[1],   RD^,   length(S_DATA));  
      RD   :=   StrNew(PChar(S_DATA));  
      S_DATA   :=   '';  
      READ_BUSY   :=   FALSE;  
  end;  
   
  function   OPEN_PORT(PORT:   SHORTSTRING;   BTL:   INTEGER):   INTEGER;   stdcall;  
  begin  
      if   OPEN_BUSY   or   READ_BUSY   then  
      begin  
          RESULT   :=   0;  
          Exit;  
      end;  
      if   PORT_ACTIVE   then  
      begin  
          RESULT   :=   -1;  
          Exit;  
      end;  
      OPEN_BUSY   :=   TRUE;  
      INI_OBJ;  
   
      MYCOM.BaudRate   :=   BTL;  
      MYCOM.CommName   :=   'com'   +   PORT;  
      try  
          MYCOM.StartComm;  
          PORT_ACTIVE   :=   TRUE;  
          RESULT   :=   1;  
      except  
          PORT_ACTIVE   :=   FALSE;  
          RESULT   :=   -2;  
      end;  
      OPEN_BUSY   :=   FALSE;  
  end;  
   
  function   CLOSE_PORT:   INTEGER;   stdcall;  
  begin  
      try  
          if   MYCOM   <>   nil   then   MYCOM.StopComm;  
          PORT_ACTIVE   :=   FALSE;  
          RESULT   :=   1;  
      except  
          RESULT   :=   -1;  
      end;  
   
      FREE_OBJ;  
  end;  
   
  end.  
   
   
   
  上面代码还有返回没有解决,这样返回不好。回调怎么实现?

while   not   RECEIVE_FINISH   do会占用100%   CPU时间的哦  
  SPCOMM是异步线程控制的,所以最好你也采用异步管理方法

同意楼上的,就是这个返回方式还没有解决

spcomm的ReceiveData触发后用什么方法把数据给exe合适呢

下面代码,exe如何调用SetCallback?  
   
  library   DRYPRT5;  
   
  uses  
      SysUtils,  
      Classes,  
      PRTTING   in   'PRTTING.pas';  
   
  {$R   *.RES}  
  exports  
      SetCallback,  
      OPEN_PORT,  
      CLOSE_PORT,  
      SEND_COMMAND;  
  begin  
  end.  
   
   
   
  unit   PRTTING;  
   
  interface  
   
  uses  
      Windows,   Forms,   ExtCtrls,   SysUtils,   SPComm;  
   
  type  
      TCallback   =   procedure(s:   string);  
      TMYOBJ   =   class  
          procedure   MYComReceiveData(Sender:   TObject;   Buffer:   Pointer;   BufferLength:   Word);  
      end;  
   
  var  
      WAIT_TIMES,   N_NUMBER:   INTEGER;  
      START_TIMES:   REAL;  
      READ_BUSY,   OPEN_BUSY,   PORT_ACTIVE,   RECEIVE_FINISH:   BOOLEAN;  
      S_DATA:   string;  
   
      MYCOM:   TCOMM;  
      MYOBJ:   TMYOBJ;  
      FCallback:   TCallback;  
   
  function   OPEN_PORT(PORT:   SHORTSTRING;   BTL:   INTEGER):   INTEGER;   STDCALL;  
  function   CLOSE_PORT:   INTEGER;   STDCALL;  
  function   SEND_COMMAND(SD:   string;   var   RD:   PChar):   INTEGER;   STDCALL;  
  procedure   SetCallback(ACallback:   TCallback);   STDCALL;  
   
   
  implementation  
   
   
   
  function   SEND_COMMAND(SD:   string;   var   RD:   PChar):   INTEGER;   stdcall;  
  var  
      N2:   REAL;  
      B:   BOOLEAN;  
  begin  
      if   READ_BUSY   then  
      begin  
          RESULT   :=   0;  
          Exit;  
      end;  
      if   not   PORT_ACTIVE   then  
      begin  
          RESULT   :=   -1;  
          Exit;  
      end;  
      READ_BUSY   :=   TRUE;  
      RECEIVE_FINISH   :=   FALSE;  
      START_TIMES   :=   Now;  
      S_DATA   :=   '';  
      MYCOM.WriteCommData(PChar(SD),   Length(SD));  
      {B   :=   FALSE;  
      while   not   RECEIVE_FINISH   do  
      begin  
          APPLICATION.ProcessMessages;  
          N2   :=   Now   -   START_TIMES;  
          N2   :=   N2   *   100000000;  
          B   :=   N2   >   2000;  
          if   B   then   Break;  
      end;  
      if   B   then   RESULT   :=   -2   //   超时没有返回值  
      else   RESULT   :=   1;  
   
      //RD   :=   PChar(S_DATA);  
      //Move(S_DATA[1],   RD^,   length(S_DATA));  
      RD   :=   StrNew(PChar(S_DATA));  
      S_DATA   :=   '';   }  
      READ_BUSY   :=   FALSE;  
  end;  
   
  function   OPEN_PORT(PORT:   SHORTSTRING;   BTL:   INTEGER):   INTEGER;   stdcall;  
  begin  
      if   OPEN_BUSY   or   READ_BUSY   then  
      begin  
          RESULT   :=   0;  
          Exit;  
      end;  
      if   PORT_ACTIVE   then  
      begin  
          RESULT   :=   -1;  
          Exit;  
      end;  
      OPEN_BUSY   :=   TRUE;  
   
      MYCOM.BaudRate   :=   BTL;  
      MYCOM.CommName   :=   'com'   +   PORT;  
      try  
          MYCOM.StartComm;  
          PORT_ACTIVE   :=   TRUE;  
          RESULT   :=   1;  
      except  
          PORT_ACTIVE   :=   FALSE;  
          RESULT   :=   -2;  
      end;  
      OPEN_BUSY   :=   FALSE;  
  end;  
   
  function   CLOSE_PORT:   INTEGER;   stdcall;  
  begin  
      try  
          if   MYCOM   <>   nil   then   MYCOM.StopComm;  
          PORT_ACTIVE   :=   FALSE;  
          RESULT   :=   1;  
      except  
          RESULT   :=   -1;  
      end;  
  end;  
   
   
  procedure   TMYOBJ.MYComReceiveData(Sender:   TObject;   Buffer:   Pointer;   BufferLength:   Word);  
  var  
      S1:   string;  
  begin  
      START_TIMES   :=   Now;  
      SetLength(S1,   BufferLength);  
      Move(Buffer^,   PChar(S1)^,   BufferLength);  
      S_DATA   :=   S_DATA   +   S1;  
      if   Assigned(FCallback)   then  
          FCallback(PChar(S_DATA));  
  end;  
   
  procedure   SetCallback(ACallback:   TCallback);  
  begin  
      FCallback   :=   @ACallback;  
  end;  
   
   
  initialization  
      MYOBJ   :=   TMYOBJ.Create;  
      MYCOM   :=   TCOMM.Create(nil);  
      MYCOM.OnReceiveData   :=   MYOBJ.MYComReceiveData;  
  finalization  
      try  
          if   MYOBJ   <>   nil   then  
          begin  
              MYOBJ.FREE;  
              MYOBJ   :=   nil;  
          end;  
          if   MYCOM   <>   nil   then  
          begin  
              MYCOM.FREE;  
              MYCOM   :=   nil;  
          end;  
      except  
      end;  
   
  end.

想通过DLL给EXE,自然是要通过函数的返回值了!返回ARRAY   OF   CHAR  
  偶还用过一种方法,那就是向EXE的MAINFORM发消息,把一个字符串的地址放在消息参数里面!

jf

posted @ 2008-11-27 21:12 delphi2007 阅读(442) | 评论 (0)编辑 收藏

Delphi 中的Edit输入框如何限定只能输入七位数,,第一位为1到4的数字,第二位到第七位为日期格式取后六位,如:20060123取:060123,任何一位都 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061124165258175.html
Delphi   中的Edit输入框如何限定只能输入七位数,,第一位为1到4的数字,第二位到第七位为日期格式取后六位,如:20060123取:060123,任何一位都可以换成"+,-,*"  
   
  如果用正则表达式,应该怎么用?  
   
  当输入格式不对时就提示,如,第一位应输入1到4的数,却按了字母A,则弹出提示

这个可在OnChange事件里面自己判断

还要用到正则表达式吗?

不需要。  
  多找几个字符串函数就行了。  
  你用什么?delphi?

if   length(edit1.text)<=6   then  
      begin  
          if   not   (copy(Edit1.text,0,1)   in   ['1'..'4'])   then  
                begin  
                      application.messageboxs(pchar('fuck   you'),pchar('123'),0);  
                      exit;  
                end;  
              edit1.text:=   edit1.text+copy(formatdatetime(yyyyMMdd,now()),3,length(formatdatetime(yyyyMMdd,now())));  
      end;

DELPHI

给分   给分

我也用到了,是在OnChange事件里判断的

给的这个例子只判断了第一位,后面判断日期的你可以自己参考着写,就是用一些字符串的操作函数。

XX

posted @ 2008-11-27 21:12 delphi2007 阅读(630) | 评论 (0)编辑 收藏

保存资源文件 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061124154849176.html
做了一个res文件。时面包含一个cry.dll  
   
  想在运行时,单按钮把这个dll保存到C:\下。  
   
  不知道用什么方法把它保存出去。

搜索TResourceStream

posted @ 2008-11-27 21:12 delphi2007 阅读(179) | 评论 (0)编辑 收藏

钩子报内存错误。。急。。。 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061124122024177.html
我在DLL里定义一个鼠标钩子,可是在鼠标点击某些窗口后,会报内存异常,通常是点了某个窗口之后的时候,就报错误,显示“指定内存引用0xxxxxx   ,该内存不能written”我的系统是xp,用的是delphi2006。大家指点一下,到底是什么原因,急死我了。。。。    
  先谢谢大家了。  
 

应该钩子代码那里有问题,把代码贴出来看看...

2006   LS的就用了一段时间~   异常看你参数正确不正确   还有你的异常执行到哪   光说错误别人无法解决你的问题啊

我的代码是这样的:  
  unit   unithook;  
   
  interface  
  uses   windows,Messages,Udllconst,SysUtils,Graphics,Classes,Dialogs;  
   
  var  
  h:   HHook;  
  hMappingFile:   THandle;  
  PShMem:   PShareMem;  
   
  function   StartHook(sender:   HWND;messageID:   LongInt):boolean;stdcall;  
  function   StopHook:boolean;stdcall;  
   
  implementation  
   
  function   hookproc(nCode:   Integer;wParam:   WPARAM;lParam:   LPARAM):LRESULT;stdcall;  
  var  
      aRect,R   :TRect;//reRect:   TRect;  
      dc:   hdc;  
      Mycan:   TCanvas;  
      Mybmp:   TBitmap;  
  begin  
      Result   :=   0;  
      if   nCode   <   0   then  
          Result   :=   CallNextHookEx(h,nCode,wparam,lparam);  
      case   wparam   of  
          WM_LBUTTONDOWN,WM_NCLBUTTONDOWN   :  
              begin  
                  if   pShMem^.data1[1]   =   pMOUSEHOOKSTRUCT(lparam)^.hwnd   then  
                              exit;  
                  if   not   pShMem^.SeCapBMP   then  
                      begin  
                           
                          if   (pMOUSEHOOKSTRUCT(lparam)^.pt.X   >   pShMem^.SeRect.Left)     and  
                                (pMOUSEHOOKSTRUCT(lparam)^.pt.X   <   pShMem^.SeRect.Right)   and  
                                (pMOUSEHOOKSTRUCT(lparam)^.pt.Y   >   pShMem^.SeRect.Top)       and  
                                (pMOUSEHOOKSTRUCT(lparam)^.pt.Y   <   pShMem^.SeRect.Bottom)   then  
                              begin  
                                  //Showmessage('222');  
                                  pShMem^.data2:=pMOUSEHOOKSTRUCT(lparam)^;  
                                  aRect   :=   Rect(pShMem^.SeRect.Left+3,pShMem^.SeRect.Top+3,pShMem^.SeRect.Right-2,pShMem^.SeRect.Bottom-2);  
                                  Mybmp   :=   Tbitmap.Create;  
                                  if   (pShMem^.MyHandle   =0)or(pShMem^.MyHandle   <>   pShMem^.data2.hwnd)   then  
                                      begin  
                                          //reRect   :=   Rect(aRect.Left-3,aRect.Top-3,aRect.Right+3,arect.Bottom+3);  
                                          //ShowMessage('111');  
                                          Mycan   :=   TCanvas.Create;  
                                          dc   :=   GetWindowDC(0);  
                                          try  
                                              Mycan.Handle   :=   dc;  
                                              Mybmp.Width   :=   aRect.Right   -   aRect.Left;  
                                              Mybmp.Height   :=   aRect.Bottom   -   aRect.Top;  
                                              R   :=   Rect(0,0,Mybmp.width,Mybmp.Height);  
                                              Mybmp.Canvas.CopyRect(R,   Mycan,aRect);  
                                          finally  
                                              releaseDC(0,   DC);  
                                          end;  
                                          Mycan.Handle   :=   0;  
                                          Mycan.Free;  
                                          Inc(pShMem^.BMPIndex);  
                                          pShMem^.MyHandle   :=   pShMem^.data2.hwnd;  
                                      end  
                                  else  
                                      Mybmp.LoadFromFile('D:\program\DemoCreator截屏预研\output\copy'+IntToStr(pShMem^.BMPIndex)+'.BMP');  
                                  Mybmp.Canvas.Pen.Color   :=   clBlue;  
                                  Mybmp.Canvas.Brush.Style   :=   BsClear;  
                                  Mybmp.Canvas.Rectangle(Rect(pShMem^.data2.pt.X-aRect.Left-3,pShMem^.data2.pt.Y-aRect.Top-3,pShMem^.data2.pt.X-aRect.Left+28,pShMem^.data2.pt.Y-aRect.Top+15));  
                                  Mybmp.Canvas.TextOut(pShMem^.data2.pt.X-aRect.Left,pShMem^.data2.pt.Y-aRect.Top,'Click');  
                                  Mybmp.SaveToFile('D:\program\DemoCreator截屏预研\output\copy'+IntToStr(pShMem^.BMPIndex)+'.BMP');  
                                  Mybmp.Free;  
                              end;  
                      end;  
      end;  
  end;  
   
  function   StartHook(sender:   HWND;messageID:   LongInt):boolean;stdcall;  
  begin  
  Result   :=   false;  
  if   h   =   0   then  
      begin  
          pShMem^.data1[1]:=sender;  
          pShMem^.data1[2]:=messageid;  
          h   :=   SetWindowsHookEx(WH_MOUSE,@hookProc,Hinstance,0);  
          Result   :=   true;  
      end;  
  end;  
   
  function   StopHook:boolean;stdcall;  
  begin  
  Result   :=   false;  
  if   h   <>   0   then  
      begin  
          UnHookWindowsHookEx(h);  
          h   :=   0;  
          Result   :=   true;  
      end;  
  end;  
   
  Initialization  
      hMappingFile   :=   OpenFileMapping(FILE_MAP_WRITE,False,MappingFileName);  
      if   hMappingFile=0   then  
          hMappingFile   :=   CreateFileMapping($FFFFFFFF,nil,PAGE_READWRITE,0,SizeOf(TShareMem),MappingFileName);  
      if   hMappingFile=0   then   Exception.Create('不能建立共享内存!');  
          pShMem   :=     MapViewOfFile(hMappingFile,FILE_MAP_WRITE   or   FILE_MAP_READ,0,0,0);  
      if   pShMem   =   nil   then  
          begin  
              CloseHandle(hMappingFile);  
              Exception.Create('不能映射共享内存!');  
          end;  
      h   :=   0;  
      pShMem^.MyHandle   :=   0;  
      pShMem^.BMPIndex   :=   0;  
   
  finalization  
      try  
          UnMapViewOfFile(pShMem);  
          //pShMem   :=   nil;  
          CloseHandle(hMappingFile);  
          //hMappingFile   :=   0;  
      except  
          ShowMessage('problem!');  
      end;  
  end.

请大家指点一下,为什么会报内存错误呢?  
  运行也能达到我要的效果,就是操作一下之后,再点击一些窗口就会出现内存错误。。。

已经解决。。

posted @ 2008-11-27 21:12 delphi2007 阅读(474) | 评论 (0)编辑 收藏

100分求解 用madCodeHook Hook Send和Recv的问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061124075201178.html
目前可以正常呼出HOOK窗口..但是记录不到封包....  
   
  全部代码如下....  
  还试过   HookAPI('wsock32.dll'   同样不行....  
   
  Unit   MainUnit;  
   
  Interface  
   
  Uses  
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,  
      Dialogs;  
   
  Type  
      TFrmMain=Class(TForm)  
          Procedure   FormCreate(Sender:TObject);  
      Private  
      Public  
      End;  
   
  Var  
      FrmMain:TFrmMain;  
   
  Function   HookIn(bHook:Boolean):Longint;   Stdcall;External'Hook.DLL';  
   
  Implementation  
   
  {$R   *.dfm}  
   
  Procedure   TFrmMain.FormCreate(Sender:TObject);  
  Begin  
      HookIn(True);  
  End;  
   
  End.  
   
  --------------------------------------------------------------------------  
  Library   Hook;  
   
  Uses  
      Windows,  
      WinSock2,  
      Messages,  
      SysUtils,  
      madCodeHook,  
      FrmUnit   In'FrmUnit.pas'{frm};  
   
  Type  
      TSock=Function(s:TSocket;Var   Buf;Len,   flags:Integer):Integer;Stdcall;  
   
  Var  
      OldSend,   OldRecv:TSock;  
      hMesHWnd:HWnd;  
   
  Function   pCharToHex(Buf:pChar;Len:Integer):String;  
  Var  
      I:Integer;  
  Begin  
      For   I   :=   0   To   Len-1   Do  
          Result   :=   Result+IntToHex(Ord(Buf[I]),   2)+'   ';  
  End;  
   
  Function   MySend(s:TSocket;Var   Buf;Len,   flags:Integer):Integer;   Stdcall;  
  Begin  
      frm.Logs.Lines.Add('Send:   '+pCharToHex(@Buf,   Len));  
      Result   :=   OldSend(s,   Buf,   Len,   flags);  
  End;  
  Function   MyRecv(s:TSocket;Var   Buf;Len,   flags:Integer):Integer;   Stdcall;  
  Begin  
      Result   :=   OldRecv(s,   Buf,   Len,   flags);  
      frm.Logs.Lines.Add('Reav:   '+pCharToHex(@Buf,   Len));  
  End;  
   
  Function   MesHook(nCode:Integer;WPARAM:WPARAM;lParam:lParam):LRESULT;   Stdcall;  
  Var  
      Msg:PMsg;  
      //tID:DWORD;  
  Begin  
      If   (nCode=HC_ACTION)   Then   Begin  
          If   (GetModuleHandleA('iexplore.exe')>0)   Then   Begin  
              Msg   :=   PMsg(lParam);  
              Case   Msg.Message   Of  
                  WM_KEYUP:Case   Msg.WPARAM   Of  
                          VK_F12:Begin  
                                  If   (frm=Nil)   Then   Begin  
                                      frm   :=   Tfrm.Create(Nil);  
                                      HookAPI('ws2_32.dll',   'send',   @MySend,   @OldSend);  
                                      HookAPI('ws2_32.dll',   'recv',   @MyRecv,   @OldRecv);  
                                      //HookCode(@send,   @MySend,   @OldSend);  
                                      //HookCode(@recv,   @MyRecv,   @OldRecv);  
                                  End;  
                                  frm.Show;  
                              End;  
                      End;//Case   Msg.WPARAM  
              End;//Case   Msg.message  
          End;//if   GetModuleHandleA  
      End;//If   nCode  
      Result   :=   CallNextHookEx(hMesHWnd,   nCode,   WPARAM,   lParam);  
  End;  
   
  Function   HookIn(bHook:Boolean):LongInt;   Stdcall;  
  Begin  
      If   bHook   Then   Begin  
          hMesHWnd   :=   SetWindowsHookEx(WH_GETMESSAGE,   @MesHook,   HInstance,   0);  
      End   Else   Begin  
          If   (hMesHWnd<>0)   Then   UnhookWindowsHookEx(hMesHWnd);  
          hMesHWnd   :=   0;  
      End;  
      Result   :=   hMesHWnd;  
  End;  
   
  {$R   *.res}  
  Exports  
      HookIn;  
  Begin  
   
  End.  
   
  --------------------------------------------------------------------------  
 

弄了1晚上..都不行...高手们帮帮忙了...  
  菜鸟我先去睡一觉先...55555

已经知道了问题所在...是因为没有madCHook.dll这个文件的问题...  
 

posted @ 2008-11-27 21:12 delphi2007 阅读(609) | 评论 (0)编辑 收藏

关于字符串转化问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061123175711179.html
var   num:integer;  
          varCode:string;  
  num:=copy(varCode,n*2,1);  
  报类型错误  
  如何将字符串取出的字符转换为字符类型

呵呵,字符类型是integer么?  
   
  var   num:char;  
          varCode:string;  
  num:=copy(varCode,n*2,1)[1];  
 

num:=StrToInt(copy(varCode,n*2,1));

posted @ 2008-11-27 21:12 delphi2007 阅读(139) | 评论 (0)编辑 收藏

为什么象网络蚂蚁这样的多线程程序可以加快下载速度? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061123172417180.html
现在的下载程序都是多线程的,可以加快下载速度。但是我们用的都是单cpu机子,不明白为什么多线程可以加快下载速度。  
  比如现在有一个任务是往表里加100w条记录,我感觉用1个线程去执行和用5个线程去执行时间是差不多的。  
 

http://community.csdn.net/Expert/topic/4867/4867262.xml?temp=.5583002

觉得这两个例子没有可比性。  
   
  1)我举个例子,可能不大正确。CPU的分成10份的时间去执行任务,现在这个程序轮到的执行时间是十分之一,现在我多开10个线程,那么这个程序轮到的执行时间就远远大于十分之一了。  
   
  2)数据库更改表的时候,可能会对表进行锁定。你可以比比看,用5个线程执行5张表各插入20W记录。

其实就是等于   你在一起下载5样东西    
  占服务器5个连接

我想搂住可能想错方向了。这个道理是很明显的

呵呵

无语,路过。

posted @ 2008-11-27 21:12 delphi2007 阅读(178) | 评论 (0)编辑 收藏

ATGrid报表控件/WEB插件[专业版] Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061123152617181.html
ATGrid报表控件/WEB插件[专业版],对EtCell进行了进行了全面的改革,  
  将会彻彻底底的解决你的报表问题,让你开发达到从未有过的轻松和喜悦......     ,详细见http://www.etcell.com/  
  支持的报表功能如下:    
     
  1、自定义各种报表格式,可以让用户设计报表,定义公式和脚本,及其报表间关系;    
  2、报表套打,各种报表即可以作为套打,也可以作为普通打印,    
  3、支持各种发票打印,各种单据打印,票据打印;    
  4、即可以支持WEB报表打印,同时也可以支持普通的C/S   MIS报表打印;    
  5、支持各种机关事业单位的报表打印,    
  例如:税务系统的报表打印,乡镇企业局的各种报表打印;    
  财务报表打印;各种海关报表打印;各种医院系统的报表打印;    
  学校用的各种报表,油田报表打印;    
  6、适用于报表的统计、汇总,例如:日报,月报,半年报,年报;    
  7、可以在线填写各种报表,提交报表数据到数据库;    
  8、对报表进行自定义别名和数据绑定,数据集的绑定,报表绑定数据库;  
  9、   自带报表设计器WinTable,可以设计各种报表模板,是报表工具中的佼佼者;  
  10、支持主从报表  
  11、交叉报表  
  12、支持分组报表:小计、汇总自由设置  
  13、支持的套打报表,让套打简单灵活  
  14、支持分组报表的每组打印控制  
  15、支持连续打印,解决了票据打印的难题  
  16、支持自定义报表  
  17、支持MIS开发的各种开发工具:如VC、VB、Delphi、C   Bulider、InterDev  
  18、支持WEB开发,FrontPage、InterDev、ASP.NEt、C#  
  19、EtCell内置支持VBScript脚本包括事件  
  20、在WEB上支持VBScript、JavaScript脚本  
  21、支持URL连接  
  22、支持的WEB服务器:NT的WEB服务器、Linux、Unix、WebLogic、TOMCAT、IIS;  
  23、在MIS开发中直接支持数据库,让程序开发更方便快捷    
  24、WEB插件和浏览器紧密融合,完全成为浏览器的一个分子!  
  25、一个页面安放多个ATGrid报表插件,再也不会出现其他控件的闪烁变动的效果!  
  26、完全支持XML,后台程序可以通过XML控制报表的每一部分!  
  27、让WEB开发变的更加简单,在WEB页[html]可以不用写一行代码.......  
  28、报表的单元格类型多大几十种,如:Text,Num,Button,Radio,CheckBox,Combox.....  
  29、不但实现报表展示功能,更重要突破了报表在线编辑功能........  
  30、和后端服务器程序的交互更加简单...............  
  31、可以把多个ATGrid控件的数据打印到一起,在也不用担心页眉和页脚问题......  
  功能多多,肯定会让你满意,不必再为选择报表控件发愁!!!  
     
  WinTable报表设计器   For   ATGrid报表控件/插件   V1.0.0.3   ,欢迎下载试用!  
  包括ATGrid控件/插件DLL,WinTable使用说明,ATGrid的SDK开发文档,和各种例子!    
   
     
   
  下面是ATGrid在线演示例子地址:   分组报表的在线演示例子:    
  http://www.etcell.com/ATGrid/Group.asp    
   
  直接引入HTML中的Table表格的在线演示例子:    
  http://www.etcell.com/ATGrid/ImportTable.asp    
   
  多列数据集的在线演示例子:    
  http://www.etcell.com/ATGrid/MultiCol.asp    
   
  一条记录多行显示的在线例子:    
  http://www.etcell.com/ATGrid/MultiRow.asp    
   
  单元格是密码Password的各种情况演示:    
  http://www.etcell.com/ATGrid/test_Password.asp    
   
  个人简历波报表得演示,包括CSS得演示:    
  http://www.etcell.com/ATGrid/test_TextArea.asp  
   
  数据缓存的演示例子:    
  http://www.etcell.com/ATGrid/DBBuffer.asp    
   
  一个页面含有多个ATGrid报表控件得演示:    
  http://www.etcell.com/AtGrid/TestATGrid2.asp    
  http://www.etcell.com/Sepco/    
   
  各种单元格类型演示:  
  http://www.etcell.com/ATGrid/test_Type.asp    
   
  ATGrid报表WEB插件在iframe框架中的演示例子    
  http://www.etcell.com/ATGrid/ATGrid_IFrame.htm    
   
  ATGrid控件作为ETChart图表控件展示,柱状图、饼图、折线图.....    
  http://www.etcell.com/EtChart/TestATGrid_ETChart.asp    
   
  ATGrid在进销存系统中的应用演示!    
  http://www.etcell.com/ATGrid/SalesOnline/    
   
  一个ATGrid控件打印另外一个ATGrid控件的报表例子!  
  http://www.etcell.com/ATGrid/test_Print_Footer.asp    
   
  新增加ATGrid网络报表Web版设计器!    
  http://www.etcell.com/WebATGrid/    
   
  多个ETSet数据集支持的例子:    
  http://www.etcell.com/ATGrid/MultiETSet.asp    
   
  本例子是实是数据,具有合计和统计功能!   报表和图表的数据随着时钟变化,时时变化的例子:    
  http://www.etcell.com/EtChart/TestATGrid_ETChart_DyData.asp    
   
  新增加多条曲线拟合到一个图表显示的功能请参看下面的电力系统实时监测的演示  
  http://www.etcell.com/EtChart/TestATGrid_ETChart_DyLine.asp    
   
   
  .NET   C#   利用ATGrid报表控件实现数据库报表套打例子  
   
  http://www.etcell.com/nprint/testImportHtmlXML.aspx  
   
  http://www.etcell.com/nprint/testImportHtmlXML2.aspx  
   
  http://www.etcell.com/nprint/testImportHtmlXML3.aspx  
   
     
   
  例子下载http://www.etcell.com/nprint/NPrint.rar  
   
     
   
   
  ASP   下使用ATGrid报表控件访问Access数据库的具体方法  
   
  http://soft.etcell.com/topicView.aspx?Id=87408  
   
     
   
   
  asp.net   C#   利用ATGrid报表打印控件   产生报表数据的方法  
   
  http://soft.etcell.com/topicView.aspx?Id=87406


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061123152617181.html
posted @ 2008-11-27 21:11 delphi2007 阅读(306) | 评论 (0)编辑 收藏

EXE文件如何读取它自身的内容. Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061123125818182.html
我在EXE文件尾部追加一些数据,在EXE运行时想把这些数据读出来,Delphi不能自己打开自己,请问一下怎么记取?  
 

你会不会程序调用别的程序   会的话打开自己也是一样的    
   
  shellexecute  
   
  use   shellapi

http://www.delphibox.com/article.asp?articleid=422  
   
  还是先看下windows     pe文件格式  
  修改   可以通过很多方式的\  
   
  最终都是   映射成硬盘的文件

学习了

用文件流喽

读取是容易,,master   delphi7   就有demo  
   
  procedure   TForm1.FormCreate(Sender:   TObject);  
  var  
      nSize:   Integer;  
      hFile:   THandle;  
      strSize:   String;  
   
  begin  
      hFile   :=   CreateFile   (PChar   (ParamStr   (0)),  
          0,   FILE_SHARE_READ,   nil,   OPEN_EXISTING,   0,   0);  
      nSize   :=   GetFileSize   (hFile,   nil);  
      CloseHandle   (hFile);  
   
      SetLength   (strSize,   20);  
      Str   (nSize,   strSize);  
   
      Caption   :=   'Size   =   '   +   strSize;  
  end;  
   
  createfile打开,再read   即可;但是写到入exe文件中,需要点技巧  
   
  顶~~~vividw(vividw)   ~~~  
 

故意路过,不发表意见和谬论。:)   :)

然也

procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
      fs:TFileStream;  
      strBuf:array[0..501]   of   char;  
  begin  
      fs:=TFileStream.Create(Application.ExeName,fmOpenRead);         //创建一个文件流对象  
      try  
          fs.Position:=1000;                                     //将文件流对象指针指到1000的位置  
          fs.ReadBuffer(strBuf,500);                     //读取长度为500的这一段内容  
          showmessage(strBuf);  
      finally  
          fs.Free;  
      end;  
  end;  
   
  主要思想应该都是这些了,其他的你可以自己再改造一下。

蹭分

刚好前几天写了这个..不过我不是这样的..写入就不说了,太简单了..读取是COPY自身到TEMP目录..再已文本读取..指向尾部..反向读取100个再CenterCat(string,'start:',':end')..

用   TFileStream   就可以打开。模式:   fmOpenRead   +   fmShareDenyNone


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061123125818182.html
posted @ 2008-11-27 21:11 delphi2007 阅读(311) | 评论 (0)编辑 收藏

关于WMI~~~,找sanmaotuo(老冯)...... Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061122164538183.html
sanmaotuo(老冯)   呵呵,刚才以为没有人顶帖子了,就结了,继续请教中

没有关系,老水好梗直!  
  我不过用了另外一种方法来获取运行的应用程序列表。这个方法里面包含了很多有用的东西

特别是如何实现FOR   EACH   这种在DELPHI中所不具有的语句以及如何操纵COM。

关于WMI它的全程是Windows   Management   Instrumentation,MS在里面定义了很多(应该是完全)的系统信息类,利用它你可以获得系统几乎所有的信息(硬的、软的),还可以利用它实行远程操纵和监控。他的语法与SQL语法很相近,所以操作起来很方便。我主要最近在做一个资产(计算机系统资产)管理系统,要全面获取一台机器的信息,所以有点对它狂热:):)

sanmaotuo(老冯)   最近是天天泡CSDN啊   LZ找他可找对人了   我可是看着他从2个角裤衩变成4个裤衩的   WMI我找了篇帖子给LZ     我也没用过   仅供LZ参考    
   
  http://www.programfan.com/article/showarticle.asp?id=1364

关于WMI的详尽资料请参考MSDN  
  http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/anch_wmi.asp  
   
  我把如何通过Word来获取应用程序列表的代码再帖一下。  
   
  procedure   TForm1.ButtonClick(Sender:   TObject);  
  var  
      _Tasks:   Tasks;  
      Enum:   IEnumVARIANT;  
      NumElements:   ULong;  
      _Task:   OleVariant;  
  begin  
      _Tasks   :=   WordApplication.Tasks;  
      Enum   :=   _Tasks._NewEnum   as   IEnumVARIANT;  
      Enum.Next(1,   _Task,   NumElements);  
      while   Succeeded(Enum.Next(1,   _Task,   NumElements))   and   (NumElements   >   0)   do  
      begin  
          if   (IUnknown(_Task)   as   Task).Visible   then  
              ListBox.Items.Add((IUnknown(_Task)   as   Task).Name);  
      end;  
  end;  
   
  共同学习,共同进步!  
   
  PS:WMI的WQL语法例子  
          Select   *   from   Win32_Process    
   
 

学习

问一下老冯,IEnumVARIANT是在哪个单元的呢?

在ACTIVEX单元

to   老冯:  
  呵呵,那个Tasks在什么地方定义的啊?编译器通不过。  
 

呵呵,找到了,以前没有用过WORD,但是还是有问题_Tasks   :=   WordApplication.Tasks;  
  通不过,想查看WordApplication的定义报错提示“Unable   to   locate   file   "word2000.pas"”怎么回事啊?

你在控件板上找到SERVER,拖拉一个WordApplication(NAME也改为WordApplication)就可以了;  
  另外要uses   ACTIVEX

1   import   type   library路径是C:\WINNT\system32\wbem\wbemdisp.tlb  
  2   use   WbemScripting_TLB  
  3   具体WQL语句怎么写,可以搜索msdn参考  
  我有部分源代码,如需要。y.walter@eyou.com

呵呵,这两天网速太慢,多谢各位了,明天结帖,大家还有什么感兴趣的再说说看吧:)

没什么感兴趣的啦   只盼望LZ早点揭贴   ~~   热盼ING!~~~~


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061122164538183.html
posted @ 2008-11-27 21:11 delphi2007 阅读(166) | 评论 (0)编辑 收藏

请教如何获得类似于“任务管理器”中“应用程序”面板下的程序标题?? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061122142354184.html
如题,请各位帮帮忙~~~~  
  请注意不是进程列表,是应用程序标题列表:)

用WMI轻松搞定

 
  procedure   TForm1.FormCreate(Sender:   TObject);  
  begin  
      WList   :=   TObjectList.Create;  
  end;  
   
  procedure   TForm1.FormDestroy(Sender:   TObject);  
  begin  
      WList.Free;  
  end;  
   
  function   EnumWindowProc(Handle:   HWND;   LParam:   Longint):   BOOL;   stdcall;  
  var  
      Info:   TWindowInfo;  
      s:   string;  
  begin  
      Info   :=   TWindowInfo.Create;  
      Info.Handle   :=   Handle;  
      SetLength(s,   256);  
      GetWindowText(Handle,   PChar(s),   256);  
      Info.Name   :=   s;  
      Info.DispStr   :=   'Handle:   '   +   IntToHex(Handle,   8)   +   ',   Text:   '   +   s;  
      TList(LParam).Add(Info);  
      Result   :=   True;  
  end;  
   
  procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
      i:   Integer;  
  begin  
      WList.Clear;  
      EnumWindows(@EnumWindowProc,   Integer(WList));  
      ListBox1.Clear;  
      for   I   :=   0   to   WList.Count   -   1   do  
          ListBox1.Items.Add(TWindowInfo(WList[I]).DispStr);  
  end;  
 

同意楼上  
 

呵呵,各位同志们,有那么简易全面好使的WMI你们怎么都不动容啊。

TO   maozefa(阿发伯):  
  程序无法运行,提示Undeclared   identifier:   'TObjectList'  
  而且TWindowInfo只是一个结构体而已阿,没有.create这个构造函数啊~~~  
  帮忙~~~  
  谢了先~~~

uses  
      Contnrs;  
   
      TWindowInfo   =   class  
      public  
          Handle:   HWND;  
          Name:   string;  
          DispStr:   string;  
      end;  
 

WList:   TList;

to   maozefa(阿发伯):  
  呵呵,现在程序可以执行了,但不是我要的效果,有一些没有用处的名称。我想要的就是在任务管理器中显示出来的那些,呵呵,帮帮忙~~~~~再看看~~~~~  
  //**********************//  
  Windows   任务管理器  
  自动下拉  
  CodeParamWindow  
  CodeParamWindow  
  金山词霸   2006(暂停取词)  
  SysFader  
  SysFader  
  SysFader  
  SysFader  
  Shabout  
  Delphi   7  
  请教如何获得类似于“任务管理器”中“应用程序”面板下的程序标题??   -   Windows   Internet   Explorer  
  Delphi   7  
  Delphi   7  
  SendMessage   -   Microsoft   Visual   C++   -   [sc.c]  
  Microsoft   Spy++   -   [Windows   4]  
  无标题   -   记事本  
  KibitzWindow  
  DBK  
  MCI   command   handling   window  
  杂项  
  ActiveMovie   Window  
  ddd  
  Acrobat   IEHelper  
  DDE   Server   Window  
  Acrobat   IEHelper  
  DBK  
  Acrobat   IEHelper  
  压缩包  
  MCI   command   handling   window  
  MCI   command   handling   window  
  DDE   Server   Window  
  GDI+   Window  
  Delphi  
  C:\WINDOWS\system32\cmd.exe  
  Acrobat   IEHelper  
  SysFader  
  CodeParamWindow  
  MCI   command   handling   window  
  Acrobat   IEHelper  
  迅雷5  
  MCI   command   handling   window  
  DBK  
  SysFader  
  DDE   Server   Window  
  电表  
  Acrobat   IEHelper  
  MCI   command   handling   window  
  MCI   command   handling   window  
  Connections   Tray  
  MS_WebcheckMonitor  
  MediaCenter  
  NVSVCPMMWindowClass  
  SysFader  
  Program   Manager  
  //**********************//

http://community.csdn.net/Expert/topic/4742/4742530.xml?temp=.8409998

大家帮忙看看~~~~

to   sanmaotuo(老冯):  
  呵呵,没听过WMI啊,是什么东东?详细说一下呗~~~~

to   liangqingzhi(老之):   谢谢了,解决,顺便问一下,Style:=   GetWindowLong(aHWnd,   GWL_STYLE);   中Style的值都包括什么啊(类似于WS_POPUP之类)?候教中~~~~

没有WMI没有关系,你这样处理。包你满意  
   
  var  
      _Tasks:   Tasks;  
      Enum:   IEnumVARIANT;  
      NumElements:   ULong;  
      _Task:   OleVariant;  
  begin  
  _Tasks   :=   WordApplication.Tasks;  
  Enum   :=   _Tasks._NewEnum   as   IEnumVARIANT;  
  while   Succeeded(Enum.Next(1,   _Task,   NumElements))   and   (NumElements   >   0)   do  
  begin  
      if   (IUnknown(_Task)   as   Task).Visible   then  
      ShowMessage((IUnknown(_Task)   as   Task).Name);  
  end;

最佳路径哈。

老水你试试我这个,好轻松哟。


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061122142354184.html
posted @ 2008-11-27 21:11 delphi2007 阅读(278) | 评论 (0)编辑 收藏

Delphi中如何杀进程呀? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061122100442185.html
Delphi中如何杀进程呀?  
  给个代码例子嘛。谢谢各位了。

TerminateProcess

有些进程是杀不死的......

这个怎么用嘛?  
  比如有个进程是“project1”如何编个程序杀掉它?

我杀的都是些应用程序,不是系统程序。

我会了,哈哈!!


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061122100442185.html
posted @ 2008-11-27 21:11 delphi2007 阅读(208) | 评论 (0)编辑 收藏

救命的问题-------在线急等!! Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061122092919186.html
请问delphi中如何根据计算机名称ping一台电脑是否成功。  
  有直接的api吗?  
   
 

不是一条命令就能搞定的哈。

ping   了以后,看返回的数据

偶也不知道有这样的命令    
   
  盒子论坛上有实现ping功能的源码   建议LZ去下载学习

ShellExecute   (Handle,nil,   'cmd.exe',PChar('/k   ping   '+edit1.Text),nil,SW_HIDE);  
  但是不管地址他都返回>32的值啊!  
  有甚么办法??


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061122092919186.html
posted @ 2008-11-27 21:11 delphi2007 阅读(146) | 评论 (0)编辑 收藏

关于键盘钩子的问题,请教大家 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061122084602187.html
function     StartHookMouse:boolean;  
  const  
      WH_MOUSE_LL   =   14;  
  begin  
    if   hhkLowLevelMouse   =   0   then   hhkLowLevelMouse   :=   SetWindowsHookEx(WH_MOUSE_LL,   LowlevelMouseProc,   HInstance,   0);  
    //if   hhkLowLevelMouse   =   0   then   hhkLowLevelMouse   :=   SetWindowsHook(WH_MOUSE_LL,   @LowlevelMouseProc);  
    result   :=   (hhkLowLevelMouse   <>   0)   ;  
  end;  
   
  这段放在自己的程序里面,没有放在dll里面,在xp里面可以做到全局钩子,但是在  
  98中钩子无效,何解????  
  请问高手

kernel32.dll?

function     StartHookMouse:boolean;  
  begin  
    if   hhkLowLevelMouse   =   0   then   hhkLowLevelMouse   :=   SetWindowsHookEx(WH_MOUSE_LL,   LowlevelMouseProc,   HInstance,   0);  
    result   :=   (hhkLowLevelMouse   <>   0)   ;  
  end;

const  
      WH_KEYBOARD_LL   =   13;    
      WH_MOUSE_LL   =   14;

98中钩子无效!


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061122084602187.html
posted @ 2008-11-27 21:11 delphi2007 阅读(232) | 评论 (0)编辑 收藏

有个很少的C++源码急着需要翻译成其它源码,版主、高手请进。 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061121222102188.html
下面的源码是用来判断数据流的编码的,由一个叫jiangsheng的朋友提供,在此先谢谢他。  
  但是我不会用C++,现在急着需要用这个源码,请大虾们帮个忙,帮个忙把下面的源码翻译成vb\delphi或net的,或者做个DLL给我,最好是翻译成VB.NET的,小弟不胜感激,在此先谢谢了。Mail:237019683@qq.com

static   HRESULT   DetectCodePage(  
                  IStreamPtr   spStream,  
                  std::vector<DWORD>&   dwCodePages,  
                  DWORD   dwFlag   =   MLDETECTCP_8BIT,  
                  DWORD   dwPrefWinCodePage   =   0)  
          {  
                  HRESULT   hr   =   S_OK;  
   
                  const   int   N   =   32;                                          
                  INT   nScores   =   N;  
                  DetectEncodingInfo   info[N];  
                  hr   =   DetectCodepageInIStream(  
                          dwFlag,  
                          dwPrefWinCodePage,  
                          spStream,  
                          info,  
                          &nScores);  
                  if   (FAILED(hr))  
                  {  
                          return   hr;  
                  }  
   
                  for   (int   i   =   0;   i   <   nScores;   i++)  
                  {  
                          dwCodePages.push_back(info[i].nCodePage);  
                  }  
   
                  return   S_OK;  
          }  
   
          //   IE5.0   or   lator  
          static   HRESULT   DetectCodepageInIStream(  
                  DWORD   dwFlag,  
                  DWORD   dwPrefWinCodePage,  
                  IStream   *pstmIn,  
                  DetectEncodingInfo   *lpEncoding,  
                  INT   *pnScores)  
          {  
                  HRESULT   hr   =   S_OK;  
   
                  try  
                  {  
                          IMultiLanguage2Ptr   spMultiLanguage2   =   GetMultiLanguage();  
                          if   (spMultiLanguage2   ==   NULL)  
                          {  
                                  return   E_FAIL;  
                          }  
          这个是调用浏览器的spMultiLanguage2接口的一个方法DetectCodepageInIStream  
                          hr   =   spMultiLanguage2->DetectCodepageInIStream(  
                                  dwFlag,  
                                  dwPrefWinCodePage,  
                                  pstmIn,  
                                  lpEncoding,  
                                  pnScores);  
                          if   (FAILED(hr))  
                          {  
                                  return   hr;  
                          }  
                  }  
                  catch   (...)  
                  {  
                          return   E_FAIL;  
                  }  
   
                  return   S_OK;  
          }  
   
          static   IMultiLanguagePtr   GetMultiLanguage()  
          {  
                  HRESULT   hr   =   S_OK;  
   
                  IMultiLanguagePtr   spMultiLanguage;  
                  hr   =   spMultiLanguage.CreateInstance(__uuidof(CMultiLanguage));  
                  if   (FAILED(hr))  
                  {  
                          return   NULL;  
                  }  
   
                  return   spMultiLanguage;  
          }


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061121222102188.html
posted @ 2008-11-27 21:11 delphi2007 阅读(218) | 评论 (0)编辑 收藏

请问 Wallpaper Calendar 是如何实现在桌面显示日历和输入数据的???? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061121094119189.html
Wallpaper   Calendar   是一个日程安排的小软件,它在桌面显示日历,可以点击具体的时间输入一些提示文字,哪位大侠有无指点啊,多谢!!

windows.SetParent(form1.Handle,findwindow('Progman',nil));

楼上有理

有全局的鼠标钩子

有全局的鼠标钩子  
   
  不知道能否直接写入到数据库中


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061121094119189.html
posted @ 2008-11-27 21:11 delphi2007 阅读(388) | 评论 (0)编辑 收藏

开仓放粮了: delphi在命令行执行命令时的2个问题? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061120203959190.html
1:   怎么等待命令执行完后再执行下面的语句  
  2:   怎么捕获命令产生的错误,并提示出来?

第2个问题值150分啊

1   用WaitForSingleObject  
   
  2   var   a:TStringList;  
  begin  
          a:=TStringList.Create;  
            try  
                  a.LoadFromFile('123.txt');   //不存在这个文件  
                except  
                        on     E:     Exception     do  
                              Showmessage('出错:'     +     E.message);  
                        a.Free  
                end;  
  end;

用WaitForSingleObject可行。。

try    
   
  except  
      on   e:   exception   do  
          showmessage(e.message)  
  end;      
   
  这种方法是可行的  
   
  还有一种办法在你程序的界面放一个ApplicationEvents   这个控件    
   
  在它的Exception事件里写代码  
   
  procedure   Tfrmo1.ApplicationEvents1Exception(Sender:   TObject;  
      E:   Exception);  
   
  Sender就是你的对象   而Exception就是异常

第一个问题用sleep(1000)   就可以解决了吧~~~    
   
 

可参考下<delphi源代码分析>  
 

1.用WaitForSingleObject  
  procedure   TForm1.Button1Click(Sender:   TObject);  
  var  
      MutexHandle:THandle;  
  begin  
      WaitForSingleObject(MutexHandle,INFINITE);  
      //do   your   code  
      CloseHandle(MutexHandle);  
  end;  
   
   
  2.var    
          List:TStringList;  
      begin  
          List:=TStringList.Create;  
            try  
                  //do   something   error  
                except  
                        on     E:     Exception     do  
                              Showmessage(E.message);  
                        a.Free  
                end;  
  end;  
   
 

JF。。.

第2个问题用debug  
  有错的话就debug

抢分!

JF。。。。

路过。

jf

1   用WaitForSingleObject  
   
  2   try  
                except  
                        on     E:     Exception

大家怎么不看楼主是几个星星的~~~  
    try    
     
    except  
   
  他会不知道〉?

如果楼主的命令是指DOS命令行的话,   则必须使用  
  CreateProcess   建议命令进程  
  然后使用Wait函数(如:   WaitForSingleObject)   等待进程的Handle  
 

接粮

接粮

再接粮

接分  
 

第1个问题:  
  function   WinExecAndWait32(  
      FileName:   string;   Visibility:   integer):   integer;  
  var  
      zAppName:   array[0..512]   of   char;  
      zCurDir:   array[0..255]   of   char;  
      WorkDir:   string;  
      StartupInfo:   TStartupInfo;  
      ProcessInfo:   TProcessInformation;  
      ExitCode:   DWORD;  
  begin  
      StrPCopy(zAppName,   FileName);  
      GetDir(0,   WorkDir);  
      StrPCopy(zCurDir,   WorkDir);  
      FillChar(StartupInfo,   Sizeof(StartupInfo),   #0);  
      StartupInfo.cb   :=   Sizeof(StartupInfo);  
      StartupInfo.dwFlags   :=   STARTF_USESHOWWINDOW;  
      StartupInfo.wShowWindow   :=   Visibility;  
      if   not   CreateProcess(nil,   zAppName,  
          {   pointer   to   command   line   string   }  
          nil,   {   pointer   to   process   security   attributes   }  
          nil,   {   pointer   to   thread   security   attributes   }  
          false,   {   handle   inheritance   flag   }  
          CREATE_NEW_CONSOLE   or   {   creation   flags   }  
          NORMAL_PRIORITY_CLASS,  
          nil,   {   pointer   to   new   environment   block   }  
          nil,   {   pointer   to   current   directory   name   }  
          StartupInfo,   {   pointer   to   STARTUPINFO   }  
          ProcessInfo)   then   Result   :=   -1  
          {   pointer   to   PROCESS_INF   }  
      else   begin  
          WaitforSingleObject(ProcessInfo.hProcess,   INFINITE);  
          GetExitCodeProcess(ProcessInfo.hProcess,   ExitCode);  
          Result:=ExitCode;  
      end;  
  end;  
   
  第2个没试过

procedure   CaptureConsoleOutput(DosApp   :   string;AMemo   :   TMemo);  
  const  
      ReadBuffer   =   1048576;     //   1   MB   Buffer  
  var  
      Security                         :   TSecurityAttributes;  
      ReadPipe,WritePipe     :   THandle;  
      start                               :   TStartUpInfo;  
      ProcessInfo                   :   TProcessInformation;  
      Buffer                             :   Pchar;  
      TotalBytesRead,  
      BytesRead                       :   DWORD;  
      Apprunning,n,  
      BytesLeftThisMessage,  
      TotalBytesAvail   :   integer;  
  begin  
      with   Security   do  
      begin  
          nlength                             :=   SizeOf(TSecurityAttributes);  
          binherithandle               :=   true;  
          lpsecuritydescriptor   :=   nil;  
      end;  
   
      if   CreatePipe   (ReadPipe,   WritePipe,   @Security,   0)   then  
      begin  
          //   Redirect   In-   and   Output   through   STARTUPINFO   structure  
   
          Buffer     :=   AllocMem(ReadBuffer   +   1);  
          FillChar(Start,Sizeof(Start),#0);  
          start.cb                     :=   SizeOf(start);  
          start.hStdOutput     :=   WritePipe;  
          start.hStdInput       :=   ReadPipe;  
          start.dwFlags           :=   STARTF_USESTDHANDLES   +   STARTF_USESHOWWINDOW;  
          start.wShowWindow   :=   SW_HIDE;  
   
          //   Create   a   Console   Child   Process   with   redirected   input   and   output  
   
          if   CreateProcess(nil             ,PChar(DosApp),  
                                            @Security,@Security,  
                                            true           ,CREATE_NO_WINDOW   or   NORMAL_PRIORITY_CLASS,  
                                            nil             ,nil,  
                                            start         ,ProcessInfo)   then  
          begin  
              n:=0;  
              TotalBytesRead:=0;  
              repeat  
                  //   Increase   counter   to   prevent   an   endless   loop   if   the   process   is   dead  
                  Inc(n,1);  
   
                  //   wait   for   end   of   child   process  
                  Apprunning   :=   WaitForSingleObject(ProcessInfo.hProcess,100);  
                  Application.ProcessMessages;  
   
                  //   it   is   important   to   read   from   time   to   time   the   output   information  
                  //   so   that   the   pipe   is   not   blocked   by   an   overflow.   New   information  
                  //   can   be   written   from   the   console   app   to   the   pipe   only   if   there   is  
                  //   enough   buffer   space.  
   
                  if   not   PeekNamedPipe(ReadPipe                 ,@Buffer[TotalBytesRead],  
                                                            ReadBuffer             ,@BytesRead,  
                                                            @TotalBytesAvail,@BytesLeftThisMessage)   then   break  
                  else   if   BytesRead   >   0   then  
                      ReadFile(ReadPipe,Buffer[TotalBytesRead],BytesRead,BytesRead,nil);  
                  TotalBytesRead:=TotalBytesRead+BytesRead;  
              until   (Apprunning   <>   WAIT_TIMEOUT)   or   (n   >   150);  
   
              Buffer[TotalBytesRead]:=   #0;  
              OemToChar(Buffer,Buffer);  
              AMemo.Text   :=   AMemo.text   +   StrPas(Buffer);  
          end;  
          FreeMem(Buffer);  
          CloseHandle(ProcessInfo.hProcess);  
          CloseHandle(ProcessInfo.hThread);  
          CloseHandle(ReadPipe);  
          CloseHandle(WritePipe);  
      end;  
  end;  
 

 
  我来回答第二个问题。 上边回答的都是自己的程序出异常,实际中,你在调用外部程序发生异常后出错时,一般的程序都会将错误输出到标准错误(STDERR),所以,你只要能读到他的STDERR或STDOUT(标准输出)就行了.    
   
  读取方法:  
  1.象楼上那样,用一个命名管道    
  2.有一个控件的,名字不记得了....  
  3.加上命令行参数,将标准输出和错误输出存到文件中....如下:  
   
  mCommand   :=   "test.exe   >a.txt   2>b.txt";  
  winexec(mCommand);  
   
  这样在执行过后,标准输出就写入了   a.txt,   错误输出就写入了b.txt    
   
  不一定能帮上你的忙,只是提供一个思路.


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061120203959190.html
posted @ 2008-11-27 21:11 delphi2007 阅读(191) | 评论 (0)编辑 收藏

Delphi写的ActiveX控件如何返回数组到Vbscript/javascript Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061120161640191.html
 
  各位,用VBScript调用ActiveX很容易送入一个Variant参数,内容是一个数组,但是反过来,就一直没有成功,哪位知道如何实现delphi   ActiveX控件送出数组内容给Vbscript么?多谢!  
   
  Javascript也可以……  
   
  也就是,如何实现在脚本和ActiveX之间的复杂数据交互  
   
  多谢  
 

Delphi的函数返回值好像不支持数组。

我也为这个问题困惑了很久,实际上,javascript中的数组并非safeArray,不是delphi数组转换成varArray的兼容类型,它是一个支持双接口的Com对象,我找了很久,没找到这个对象的类型库,我觉得可以写一个支持双接口的类,包含javascript数组的公共方法就可以了。但是,又有问题,我不知道在javascript中如何转换索引器(比如fg[2])的,这个找了很久也找不到说明。  
   
  郁闷的不行,最后,只好在调用函数中多包含一个参数,这个参数类型就是IDispatch接口,然后在javascript中传入new   Array()。再用IDispatch的invoke调用这个数组对象的方法来添加值。  
   
  我都快疯了。  
   
  我实在要疯了,真不知道javascript对象的类型库在哪里。找遍MSDN找不到。

再后来,我也不需要使用者传递数组。  
   
  我可以从ActiveX获取Browsor,进而获取Document,然后让Document执行一个脚本,他有一个方法InvokeScript,我就调用这个方法,用eval执行了new   Array()。得到返回的JS数组对象。  
   
  后来,只要是JS需要的对象,除了基本的值类型以外,我都用这个办法来创造兼容的JS对象。  
   
  我还给我的ActiveX对象添加了attachEvent和detachEvent方法,这样,javascript可以用习惯办法来响应ActiveX事件,而不是用event类型的script代码段来做。我在内部用了一个列表,支持多播。  
   
  后来我的ActiveX对象搞得和标准的内置的JS对象差不多了,呵呵,当然都没用标准的办法,实际上是得益于IDispatch的灵活。他的后期绑定和按照名称绑定的策略的确不错。  
   
  实际上IDispatch并没拒绝重载,只是delphi这种编译型的语言,运行期类型信息很不完整,不会包含函数参数列表的,所以,在后期绑定的时候无法实现重载。


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061120161640191.html
posted @ 2008-11-27 21:11 delphi2007 阅读(528) | 评论 (0)编辑 收藏

已知道 一个窗口的句柄, 如何扑捉该窗口的onresize 事件,并在onresize 事件中写入自己的代码? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061120145223192.html
已知道   一个窗口的句柄,   如何扑捉该窗口的onresize   事件,并在其中写入自己的代码?

 
  用   SetWindowLong   大概代码如下  
   
  Txxxform  
      function   NewWinProc(var   Message:   TMessage):   Integer;  
   
  下面代码设成你的处理过程  
  //     NewProc,   OldProc:   Pointer;  
      NewProc   :=   WinUtils.MakeObjectInstance(NewWinProc);  
      OldProc   :=   Pointer(GetWindowLong(你的句柄,   GWL_WNDPROC));  
      SetWindowLong(你的句柄,   GWL_WNDPROC,   Longint(NewProc));  
   
  function   xxx.NewWinProc(var   Message:   TMessage):   Integer;  
  begin  
      if   Message.Msg   =   WM_SIZE   then  
      begin  
          ...  
          result   :=   1;  
      end  
      else   OldProc(Message);  
  end;  
   
 

Hook


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061120145223192.html
posted @ 2008-11-27 21:11 delphi2007 阅读(291) | 评论 (0)编辑 收藏

如何实现窗体跟随另一个程序一起显示,一起隐藏!! Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiAPI/html/delphi_20061120120925193.html
编写一个窗口,启动计算器,计算器最小化,则该窗口也最小化,计算器显示,则窗口也显示(在计算器旁),...  
  就是说,计算器的窗口处于什么状态,该窗口也处于一样的状态.包括   在窗口Z轴上的顺序都保持一致!!  
   
  高手来啊

是不是想要Winamp那种效果

可以通过如下相关api得到窗体是否可见或更多信息  
  IsWindowVisible()  
  GetWindowPlacement()  
   
  可以通过如下相关api控制窗体显示和位置  
  ShowWindow()  
  MoveWindow()  
   
 


文章来源:http://www.delphi2007.net/DelphiAPI/html/delphi_20061120120925193.html
posted @ 2008-11-27 21:11 delphi2007 阅读(273) | 评论 (0)编辑 收藏

仅列出标题
共34页: First 18 19 20 21 22 23 24 25 26 Last