CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Delphi >  VCL组件开发及应用

编制几十k的程序,还要有窗体,不用Tform类怎么遍?

楼主coolbaby(coolbaby)2001-08-06 12:29:52 在 Delphi / VCL组件开发及应用 提问

      我知道好多高手都是这么编的,程序特别小,谁能不能给个通用的api原代码模板。谢谢! 问题点数:40、回复次数:7Top

1 楼trainbox(rain)回复于 2001-08-06 12:39:08 得分 16

program   hook2001;  
   
  uses  
      Windows,  
      Messages,  
      SysUtils;  
  type  
   
  var  
        hMain,hInst,hlist:integer;  
        Msg:TMsg;  
        wClass:TWndClass;  
  {$r   *.res}  
   
  function   WindowProc(hWnd,Msg,wParam,lParam:longint):Longint;   stdcall;  
  begin  
      Result:=DefWindowProc(hWnd,Msg,wParam,lParam);  
      case   Msg   of  
          WM_CREATE:  
          WM_HOTKEY:  
          WM_DESTROY:  
      end;  
  end;  
   
  procedure   Init;  
  begin  
      hInst:=GetModuleHandle(nil);  
      with   wClass   do  
      begin  
          Style:=                   CS_PARENTDC;  
          hIcon:=                   LoadIcon(hInst,'MAINICON');  
          lpfnWndProc:=       @WindowProc;  
          hInstance:=           hInst;  
          hbrBackground:=   COLOR_BTNFACE+1;  
          lpszClassName:=   'HackSoft-Hook2001';  
          hCursor:=               LoadCursor(0,IDC_ARROW);  
      end;  
      RegisterClass(wClass);  
      hmain:=CreateWindowEx(0,wClass.lpszClassName,'Super   Hook   2001',WS_OVERLAPPEDWINDOW   or   WS_VISIBLE,10,10,410,400,0,0,hInst,nil);  
      hlist:=CreateWindowEx(WS_EX_CLIENTEDGE,'LISTBOX','hello',WS_VISIBLE   or   WS_CHILD   or   WS_VSCROLL,10,10,380,330,hmain,0,hinst,nil);  
  //     sendmessage(hlist,LB_ADDSTRING,0,integer(@sbuf));  
  //     hlist:=CreateWindowEx(WS_EX_CLIENTEDGE,'EDIT','hello',WS_VISIBLE   or   WS_CHILD   or   ES_MULTILINE   or   ES_AUTOVSCROLL   or   ES_READONLY   or   WS_VSCROLL,10,10,380,330,hmain,0,hinst,nil);  
   
  end;  
   
  procedure   Run;  
  begin  
      while(GetMessage(Msg,hmain,0,0))do  
      begin  
          TranslateMessage(Msg);  
          DispatchMessage(Msg);  
      end;  
  end;  
   
  begin  
      if   GetLastError<>ERROR_ALREADY_EXISTS   then  
      begin  
          Init;  
          Run;  
      end   else  
      begin  
      end;  
  end.  
  Top

2 楼Xb_xj(2页3皮)回复于 2001-08-06 12:51:15 得分 0

太对拉Top

3 楼小星星(小星星)回复于 2001-08-06 13:28:01 得分 0

编译通不过。。。。。。Top

4 楼coolbaby(coolbaby)回复于 2001-08-06 13:51:44 得分 0

ok,我已经调试成功,谢谢,41k.  
  能不能在改的更小点?  
   
  在程序里加控件的部分,能不能给我解释一下,谢谢!Top

5 楼prometheusphinx(白日梦)回复于 2001-08-06 14:10:42 得分 0

用汇编更小,不超过10K.Top

6 楼zhujunfeng(ericss)回复于 2001-08-06 14:12:51 得分 8

可以调试成功,稍做修改  
  program   project1;  
   
  uses  
      Windows,  
      Messages,  
      SysUtils;  
   
  var  
      hMain,hInst,hlist:integer;  
      Msg:TMsg;  
      wClass:TWndClass;  
  {$r   *.res}  
   
  function   WindowProc(hWnd,Msg,wParam,lParam:longint):Longint;   stdcall;  
  begin  
      Result:=DefWindowProc(hWnd,Msg,wParam,lParam);  
      case   Msg   of  
          WM_CREATE:begin  
                              end;  
          WM_HOTKEY:begin  
                              end;  
          WM_DESTROY:begin  
                                    UnRegisterClass(wClass.lpszClassName,hInst);  
                                    ExitProcess(hInst);  
                                end;  
      end;  
  end;  
   
  procedure   Init;  
  begin  
      hInst:=GetModuleHandle(nil);  
      with   wClass   do  
      begin  
          Style:=                 CS_PARENTDC;  
          hIcon:=                 LoadIcon(hInst,'MAINICON');  
          lpfnWndProc:=     @WindowProc;  
          hInstance:=         hInst;  
          hbrBackground:=   COLOR_BTNFACE+1;  
          lpszClassName:=   'HackSoft-Hook2001';  
          hCursor:=             LoadCursor(0,IDC_ARROW);  
      end;  
      RegisterClass(wClass);  
      hmain:=CreateWindowEx(0,wClass.lpszClassName,'Super   Hook   2001',WS_OVERLAPPEDWINDOW   or   WS_VISIBLE,10,10,410,400,0,0,hInst,nil);  
      hlist:=CreateWindowEx(WS_EX_CLIENTEDGE,'LISTBOX','hello',WS_VISIBLE   or   WS_CHILD   or   WS_VSCROLL,10,10,380,330,hmain,0,hinst,nil);  
  //     sendmessage(hlist,LB_ADDSTRING,0,integer(@sbuf));  
  //     hlist:=CreateWindowEx(WS_EX_CLIENTEDGE,'EDIT','hello',WS_VISIBLE   or   WS_CHILD   or   ES_MULTILINE   or   ES_AUTOVSCROLL   or   ES_READONLY   or   WS_VSCROLL,10,10,380,330,hmain,0,hinst,nil);  
   
  end;  
   
  procedure   Run;  
  begin  
      while(GetMessage(Msg,hmain,0,0))do  
      begin  
          TranslateMessage(Msg);  
          DispatchMessage(Msg);  
      end;  
  end;  
   
  begin  
      if   GetLastError<>ERROR_ALREADY_EXISTS   then  
      begin  
          Init;  
          Run;  
      end   else  
      begin  
      end;  
  end.  
  Top

7 楼WanderBoy(TObject)回复于 2001-08-06 14:14:11 得分 16

//作  者:hack2003  
  program   Project2;  
   
  uses  
      windows,  
      messages,  
      sysutils;  
   
  {$R   *.RES}  
   
  const  
      CRLF=#13#10;  
      exename:pchar='刷屏机器人   2001';  
  var  
  //----------------------  
      wClass:     TWndClass;     //窗口类变量  
      Msg:             TMSG;                 //消息变量  
      hInst,                                 //程序实例  
      Handle,                                 //主窗口句柄  
      hFont,                                 //字体句柄  
  //----------------  
      hButtonStart,     //开始按钮  
      hButtonStop,         //停止按钮  
      hButtonHelp,         //帮助按钮  
      hButtonExit,         //退出按钮  
      hEditEmail,         //e-mail编辑  
      hLabelEmail,         //e-mail提示  
      mcount,tempwnd,qqmainw,richedit:integer;  
      lp:longint;  
      newtime:integer;  
   
  //--------------------  
  //往一个窗口写标题  
  procedure   WriteCaption(hwnd:hwnd;text:pchar);  
  begin  
      sendmessage(hwnd,WM_SETTEXT,0,integer(text));  
  end;  
  //从一个窗口读标题  
  procedure   ReadCaption(hwnd:hwnd;text:pchar);  
  begin  
      sendmessage(hwnd,WM_GETTEXT,400,integer(text));  
  end;  
   
  procedure   ButtonHelp;  
  var   s1:string;  
  begin  
      s1:='本软件只用学习用,不可害人'+CRLF+  
              '程序向QQ2000B的输入框中输入文字并发送!'+CRLF+  
              '详细资料,及源码在作者主页上'+CRLF+  
              '主页:hotsky.363.net'+CRLF;  
      messagebox(handle,pchar(s1),'帮助',0);  
  end;  
  //主程序结束  
  procedure   ShutDown;  
  begin  
      //删除字体对象  
      DeleteObject(hFont);  
      //取消窗口类的注册  
      UnRegisterClass(wClass.lpszClassName,hInst);  
      //结束主进程  
      ExitProcess(hInst);  
  end;  
   
  procedure   ontimer;  
  var  
  len:integer;  
  str:array[0..500]   of   char;  
  begin  
      inc(mcount);  
      //strcopy(str,pchar(format('我是   %d   号刷屏机器人......',[mcount])));  
      readCaption(heditemail,str);  
      strcopy(str,pchar(format('我是   %d   号刷屏机器人......',[mcount])));  
   
      if   (mcount   mod   2)<>0   then  
      begin  
          len:=strlen(str);  
          str[len]:='   ';                                  
          str[len+1]:=#0;  
      end;  
      qqmainw:=FindWindow('AfxFrameOrView42s',nil);  
      qqmainw:=FindWindowEx(qqmainw,0,'AfxMDIFrame42s',nil);  
   
      qqmainw:=FindWindowEx(qqmainw,0,'AfxFrameOrView42s',nil);  
      qqmainw:=GetNextWindow(qqmainw,GW_HWNDNEXT);  
      qqmainw:=FindWindowEx(qqmainw,0,'#32770',nil);  
      richedit:=FindWindowEx(qqmainw,0,'RICHEDIT',nil);  
   
  //     SetFocus(richedit);  
      SendMessage(richedit,EM_SETSEL,0,-1);  
      SendMessage(richedit,EM_REPLACESEL,1,integer(@str));  
      PostMessage(richedit,WM_KEYDOWN   ,VK_RETURN,$001c0001);  
      PostMessage(richedit,WM_KEYUP,VK_RETURN,$c01c0001);  
      strcopy(str,pchar(format('我是   %d   号刷屏机器人......',[mcount])));  
      writeCaption(hlabelemail,str);  
  end;  
   
  //这是主窗口的消息处理函数  
  function   WindowProc(hWnd,Msg,wParam,lParam:integer):Longint;   stdcall;  
  begin  
      Result:=DefWindowProc(hWnd,Msg,wParam,lParam);  
      case   Msg   of  
      WM_COMMAND:  
      begin  
          if   lParam=hButtonStart   then   begin   mcount:=0;newtime:=SetTimer(handle,100,2950,nil);   end;  
          if   lParam=hButtonStop   then   begin   mcount:=0;killtimer(handle,newtime);   end;  
          if   lParam=hButtonHelp   then   ButtonHelp;  
          if   lParam=hButtonExit   then   ShutDown;  
      end;  
      WM_TIMER:ontimer;  
      WM_DESTROY:   ShutDown;  
      end;  
  end;  
  //定义几个窗口创建函数  
  function   CreateButton(name:pchar;x1,y1,x2,y2:integer):hwnd;  
  begin  
      Result:=CreateWindow('Button',name,WS_VISIBLE   or   WS_CHILD   or   BS_PUSHLIKE   or   BS_TEXT,x1,y1,x2,y2,Handle,0,hInst,nil);  
  end;  
  function   CreateEdit(name:pchar;x1,y1,x2,y2:integer):hwnd;  
  begin  
      Result:=CreateWindowEx(WS_EX_CLIENTEDGE,'Edit',name,WS_VISIBLE   or   WS_CHILD   or   ES_LEFT   or   ES_AUTOHSCROLL,x1,y1,x2,y2,Handle,0,hInst,nil);  
  end;  
  function   CreateLabel(name:pchar;x1,y1,x2,y2:integer):hwnd;  
  begin  
      Result:=CreateWindow('Static',name,WS_VISIBLE   or   WS_CHILD   or   SS_LEFT,x1,y1,x2,y2,Handle,0,hInst,nil);  
  end;  
  function   CreateMain(name:pchar;x1,y1,x2,y2:integer):hwnd;  
  begin  
      //取得应用程序实例句柄  
      hInst:=GetModuleHandle(nil);  
      //初使化窗口类的信息  
      with   wClass   do  
      begin  
          Style:=                 CS_PARENTDC;  
          hIcon:=                 LoadIcon(hInst,'MAINICON');  
          lpfnWndProc:=     @WindowProc;  
          hInstance:=         hInst;  
          hbrBackground:=   COLOR_BTNFACE+1;  
          lpszClassName:=   'MainClass';  
          hCursor:=             LoadCursor(0,IDC_ARROW);  
      end;  
      //   注册窗口类  
      RegisterClass(wClass);  
      //   建立主窗口  
      Result:=CreateWindow(wClass.lpszClassName,name,WS_OVERLAPPEDWINDOW   or   WS_VISIBLE,x1,y1,x2,y2,0,0,hInst,nil);  
  end;  
   
  function   EnumChildProc(hwnd:integer;uint:integer):bool;  
  var   classname,c2:array[0..100]   of   char;  
  hp:integer;  
  begin  
      if   hwnd<>0   then  
      begin  
      hp:=hwnd;  
      //hp:=getparent(hwnd);  
  //     hp:=getparent(hp);  
  //     hp:=getparent(hp);  
  //     hp:=getparent(hp);  
      writeCaption(hlabelemail,pchar(format('%x',[hp])));  
      end;  
      //     GetClassName(hwnd,classname,100);  
  //     GetClassName(hp,c2,100);  
  //     if   (strcomp(classname,pchar('RICHEDIT'))=0)   and   (strcomp(c2,pchar('AfxFrameOrView42s'))=0)   then   richedit:=hwnd;  
      result:=true;  
  end;  
   
  //---------主过程,类似于   C语言   中的   WinMain()  
  begin  
      //建立主窗口  
      handle:=CreateMain(exename,0,0,384,140);  
      //建立四个控制按钮  
      hButtonStart:=CreateButton('开始刷屏',300,4+26*0,70,24);  
      hButtonStop:=CreateButton('停止刷屏'     ,300,4+26*1,70,24);  
      hButtonHelp:=CreateButton('帮     助'     ,300,4+26*2,70,24);  
      hButtonExit:=CreateButton('退     出'     ,300,4+26*3,70,24);  
      //建立两个编辑框  
      hEditEmail:=CreateEdit('我是刷屏机器人1.0',4,26,286,80);  
      //建立三个标签  
      hLabelEmail:=CreateLabel('刷屏信息:',4,8,286,16);  
      //创建字体对象  
      hFont:=CreateFont(-12,0,0,0,0,0,0,0,GB2312_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH   or   FF_DONTCARE,'宋体');  
      //改变字体  
      SendMessage(hButtonStart,WM_SETFONT,hFont,0);  
      SendMessage(hButtonStop,WM_SETFONT,hFont,0);  
      SendMessage(hButtonHelp,WM_SETFONT,hFont,0);  
      SendMessage(hButtonExit,WM_SETFONT,hFont,0);  
      SendMessage(hEditEmail,WM_SETFONT,hFont,0);  
      SendMessage(hLabelEmail,WM_SETFONT,hFont,0);  
      //  
  //     qqmainw:=FindWindow('AfxFrameOrView42s',nil);  
  //     if   qqmainw<>0   then   messagebox(0,'','',0);  
      //     tempwnd:=FindWindowEx(qqmainw,0,'AfxMDIFrame42s',nil);  
      lp:=0;  
  //     EnumChildWindows(GetDesktopWindow,@EnumChildProc,lp);  
  //     EnumChildWindows(qqmainw,@EnumChildProc,lp);  
   
   
      //进入消息循环  
      while(GetMessage(Msg,Handle,0,0))do  
      begin  
          TranslateMessage(Msg);  
          DispatchMessage(Msg);  
      end;  
  end.Top

相关问题

  • 编制几十k的程序,还要有窗体,不用TForm类怎么遍??
  • 如何编制没有窗体的程序
  • 如何创建基于 HWND 的子 TForm窗体
  • 窗体
  • 窗体
  • 窗体
  • 窗体
  • 用VFP编制的菜单可以加载到用VFP编制的表单文件(屏幕文件)或窗体中吗?
  • 从TForm类中继承一个窗体,此窗体有windows消息处理函数。当从此窗体派生出的子窗体也需要处理windows消息时,应该如何做?
  • 随便编译一个窗体文件EXE有300多K正常吗?

关键词

  • ws
  • qqmainw
  • wclass
  • hinst
  • hmain
  • richedit
  • hlist
  • nil
  • createwindowex
  • twndclass

得分解答快速导航

  • 帖主:coolbaby
  • trainbox
  • zhujunfeng
  • WanderBoy

相关链接

  • Delphi类图书
  • Delphi类源码下载
  • Delphi控件下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo