大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> 比较VC和Delphi的WinTest工程

比较VC和Delphi的WinTest工程

时间: 2021-07-31 作者:daque

#include <windows.h>hwnd hwndbutton;int cx, cy;

lresult callback mainwndproc (hwnd hwindow, uint nmsg, wparam wprm, lparam lprm){

 hdc dc; paintstruct ps; rect rc; switch (nmsg) {  case wm_create:  {   textmetric tm;

   dc = getdc (hwindow);   selectobject (dc, getstockobject (system_fixed_font));   gettextmetrics (dc, &tm);   cx = tm.tmavecharwidth * 30;   cy = (tm.tmheight + tm.tmexternalleading) * 2;   releasedc (hwindow, dc);

   hwndbutton = createwindow (     "button",     "click here",     ws_child | ws_visible | bs_pushbutton,     0, 0, cx, cy,     hwindow,     (hmenu) 1,     ((lpcreatestruct) lprm)->hinstance,     null     );

   return 0;   break;  }

  case wm_destroy:  {   postquitmessage (0);   return 0;   break;  }

  case wm_paint:  {   dc = beginpaint (hwindow, &ps);   getclientrect (hwindow, &rc);

   rc.bottom = rc.bottom / 2;   drawtext (dc, "hello, world!", -1, &rc,   dt_singleline | dt_center | dt_vcenter);

   endpaint (hwindow, &ps);   return 0;   break;  }

  case wm_size:  {   if (hwndbutton && (wprm == sizefullscreen ||wprm == sizenormal))   {    rc.left = (loword(lprm) - cx) / 2;    rc.top = hiword(lprm) * 3 / 4 - cy / 2;    movewindow (hwndbutton,rc.left, rc.top, cx, cy, true);   }   return 0;   break;  }

  case wm_command:  {   if (loword(wprm) == 1 && hiword(wprm) == bn_clicked &&     (hwnd) lprm == hwndbutton)   {    destroywindow (hwindow);   }   return 0;   break;  } }

 return defwindowproc (hwindow, nmsg, wprm, lprm);}

//winmain int __stdcall winmain (hinstance hinst, hinstance hprev, lpstr lpcmd, int nshow){ hwnd hwindowmain; msg mymsg;

 wndclassex wcex;

 wcex.cbsize = sizeof(wndclassex);  wcex.style   = cs_hredraw | cs_vredraw; wcex.lpfnwndproc = (wndproc)mainwndproc; wcex.cbclsextra  = 0; wcex.cbwndextra  = 0; wcex.hinstance  = hinst; wcex.hicon   = loadicon (null, idi_application); wcex.hcursor  = loadcursor (null, idc_arrow); wcex.hbrbackground = (hbrush)(color_window+1); wcex.lpszclassname = "wintestwin"; wcex.hiconsm  = loadicon (null, idi_application);

 registerclassex (&wcex);

 hwindowmain = createwindow (  "wintestwin",  "hello",  ws_overlappedwindow,  cw_usedefault,  cw_usedefault,  cw_usedefault,  cw_usedefault,  0,  0,  hinst,  null );

 showwindow (hwindowmain, nshow); updatewindow (hwindowmain);

 while (getmessage (&mymsg, 0, 0, 0)) {  translatemessage (&mymsg);  dispatchmessage (&mymsg); } return mymsg.wparam;}

个中采用release办法编写翻译,翻开vc6的最小代码优化,编写翻译天生的实行码为36.0kb, 而后将其翻译成delphi代码,如次:program wintest;

uses  windows,messages;

var  hwndbutton:hwnd;  cx,cy:integer;

function mainwndproc (hwindow:hwnd;nmsg:uint;wprm:wparam;lprm:lparam):lresult;stdcall;var  dc:hdc; ps:paintstruct; rc:trect;  tm:textmetric;  pctst:pcreatestruct;begin  case nmsg of    wm_create:    begin      dc := getdc (hwindow);   selectobject (dc, getstockobject (system_fixed_font));   gettextmetrics (dc, tm);   cx := tm.tmavecharwidth * 30;   cy := (tm.tmheight + tm.tmexternalleading) * 2;   releasedc (hwindow, dc);      pctst:= pcreatestruct(lprm);      hwndbutton := createwindow(     'button',     'click here',     ws_child or ws_visible or bs_pushbutton,     0, 0, cx, cy,     hwindow,     hmenu(1),     pctst^.hinstance,     nil     );       result:=0;      exit;     end;

    wm_destroy:    begin      postquitmessage(0);      result:=0;      exit;    end;

    wm_paint:    begin   dc := beginpaint (hwindow, ps);   getclientrect (hwindow, rc);

   rc.bottom := round(rc.bottom / 2);   drawtext (dc, 'hello, world!', -1, rc,   dt_singleline or dt_center or dt_vcenter);

   endpaint (hwindow, ps);   result:= 0;   exit;    end;

    wm_size:    begin   if (hwndbutton<>0) and (wprm = sizefullscreen)  or (wprm = sizenormal) then   begin    rc.left := round((loword(lprm) - cx) / 2);    rc.top := round(hiword(lprm) * 3 / 4 - cy / 2);    movewindow (hwndbutton,rc.left, rc.top, cx, cy, true);   end;   result:= 0;   exit;    end;

    wm_command:    begin   if (loword(wprm) = 1) and (hiword(wprm) = bn_clicked) and    (hwnd(lprm) = hwndbutton) then   begin    destroywindow (hwindow);   end;   result:= 0;   exit;    end;

  end;

  result:=defwindowproc (hwindow, nmsg, wprm, lprm);

end;

//winmain var hwindowmain:hwnd; mymsg:msg; wcex:wndclassex;begin wcex.cbsize := sizeof(wndclassex); wcex.style := cs_hredraw or cs_vredraw; wcex.lpfnwndproc := @mainwndproc; wcex.cbclsextra := 0; wcex.cbwndextra := 0; wcex.hinstance := maininstance; wcex.hicon := loadicon (0, idi_application); wcex.hcursor := loadcursor (0, idc_arrow); wcex.hbrbackground := hbrush(color_window+1); wcex.lpszclassname := 'wintestwin'; wcex.hiconsm := loadicon (0, idi_application);

 registerclassex (wcex);

 hwindowmain := createwindow (  'wintestwin',  'hello',  ws_overlappedwindow,  cw_usedefault,  cw_usedefault,  cw_usedefault,  cw_usedefault,  0,  0,  maininstance,  nil );

 showwindow (hwindowmain, cmdshow); updatewindow (hwindowmain);

 while getmessage (mymsg, 0, 0, 0)=true do begin  translatemessage (mymsg);  dispatchmessage (mymsg); end;  end.

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.