| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> delphi >> Delphi中实现可以更改大小的对话框 Delphi zhong shi xian ke yi geng gai da xiao de dui hua kuang
 

Delphi中实现可以更改大小的对话框

2007-02-01 20:10:49 编辑來源:互联网 繁體版 评论
 
 
本文为【Delphi中实现可以更改大小的对话框】的汉字拼音对照版显示拼音
  guanjianziDialogduihuakuangresizable

  1wentidetichu

  wentilaiziStanley_Xuxiwangdedaozhiyouguanbianniuhuankeyiyoubangzhuzuoshangyemeiyouchengxudetubiaobingqienenggougenggaichuangkoudaxiaodeduihuakuang

  VCLzhongweiTFormshezhileBorderStyleheBorderIconsshuxingyongyijianhuachuangkouyangshideshezhifouzejiuyaotiaoyongSetWindowLongheGetWindowLongdengAPIhanshuTFormBorderStyleheTBorderIcondedingyiheshuomingruxia

  Value Meaning

  bsDialog Not resizable; standard dialog box border//bunenggaidaxiao

  bsSingle Not resizable; single-line border

  bsNone Not resizable; no visible border line

  bsSizeable Standard resizable border

  bsToolWindow like bsSingle but with a smaller caption

  bsSizeToolWin like bsSizeable with a smaller caption

  type TBorderIcon = (biSystemMenu, biMinimize, biMaximize, biHelp);

  TBorderIcons = set of TBorderIcon;

  Value Meaning

  biSystemMenu The form has a Control menu (also known as a System menu).

  biMinimize The form has a Minimize button

  biMaximize The form has a Maximize button

  biHelp If BorderStyle is bsDialog or biMinimize and biMaximize are excluded, a question mark appears in the form's title bar and when clicked, the cursor changes to crHelp; otherwise,no question mark appears.

  xianrantongguoBorderStyleheBorderIconszhinenggoumanzuyibandexuyaoyaoshixiannenggouxiugaidaxiaodeduihuakuangjiuyousuolibunengjile

  yibanqingkuangxiawoyaodedaobunengzuidazuixiaohuadanyoukeyigenggaidaxiaodechuangkoujiubaBorderStyleshezhiweibsSizeablebaBorderIconsdebiMinimizehebiMaximizequdiaojieguoxiangzheyangchuangkoukeyixiugaidaxiaodanzuoshangjiaoyoutubiao

Delphi中实现可以更改大小的对话框


  tu 1 daitubiaodeduihuakuang

  zhuyizuoshangjiaoyoutubiao

  erwomendemubiaozeshixiamiandeliangzhongxiaoguozuoshangjiaodoumeiyoutubiaodanchuangkoudoukeyixiugaidaxiao

Delphi中实现可以更改大小的对话框


  tu 2 dakaiwenjianduihuakuang

Delphi中实现可以更改大小的对话框


  tu 3liulanwenjianjiaduihuakuang

  2wentijiejueyiban

  sousuoleyixiaMSDNzhaodaoyipianjiaoniruheshejikeyikegenggaidaxiaodeshuxingyedewenzhangzaiMFCzhongCPRopertySheetshizuoweiCPropertyPageziyechuxiandehouzhecongCDialogjichengerlaitongchangbunengxiugaidaxiaoHow To Design a Resizable MFC Property SheetwenzhongjieshaodefangfashizaishuxingyechuangjianzhiqianxiugaichuangkouyangshiranhoushoudongchuliWM_SIZExiaoxi

  int CALLBACK CMyPropertySheet::XmnPropSheetCallback(HWND hWnd, UINT message, LPARAM lParam)

  {

   extern int CALLBACK AfxPropSheetCallback(HWND, UINT message, LPARAM lParam);

   // XMN: Call MFC's callback

   int nRes = AfxPropSheetCallback(hWnd, message, lParam);

   switch (message)

   {

   case PSCB_PRECREATE:

   // Set our own window styles

   ((LPDLGTEMPLATE)lParam)->style |= (DS_3DLOOK | DS_SETFONT

   | WS_THICKFRAME | WS_SYSMENU | WS_POPUP | WS_VISIBLE | WS_CAPTION);

   break;

   }

   return nRes;

  }

  woshizhejiangtongyangdefangfayongdaoVCLdeyigeFormzhongzaishejishibaBorderStyleshezhiweibsDialogranhouchongzaiCreateParamsfangfadanjieguoshiduihuakuangqueshibianchenglehoubiankuangyinweiyouWS_THICKFRAMEyangshishubiaoyidongdaogegebiankuanghounenggouzidongbianhuazuoshangjiaoyemeiyoutubiaodanchuangkoujiushibunenggaibiandaxiaotianjiadeWM_SIZExiaoxichuliguochengmeiyouchufawentichuzainaline

Delphi中实现可以更改大小的对话框


  tu 4 huanbunengwanquanlingrenmanyideduihuakuang

  3wentidejiejue

  chaleyifanForms.pasdeyuandaimafaxianlewentisuozaiTCustomFormdeWM_NCCREATExiaoxichuliguochengzhongyouyigeModifySystemMenuqianruguochengyonglaixiugaiFormdexitongcaidanzhuyixiamianhongsewenzishuodeshi使shixitongcaidankanqilaixiangduihuakuangyiyangjiexialaidejijudaimajiubaxitongcaidanxiangshandezhishengxialeyidongheguanbi

  procedure TCustomForm.WMNCCreate(var Message: TWMNCCreate);

  procedure ModifySystemMenu;

  var

   SysMenu: HMENU;

  begin

  

   { Modify the system menu to look more like it's s'pose to }

   SysMenu := GetSystemMenu(Handle, False);

   if FBorderStyle = bsDialog then

   begin

   { Make the system menu look like a dialog which has only

   Move and Close }

   DeleteMenu(SysMenu, SC_TASKLIST, MF_BYCOMMAND);

   DeleteMenu(SysMenu, 7, MF_BYPOSITION);

   DeleteMenu(SysMenu, 5, MF_BYPOSITION);

   DeleteMenu(SysMenu, SC_MAXIMIZE, MF_BYCOMMAND);

   DeleteMenu(SysMenu, SC_MINIMIZE, MF_BYCOMMAND);

   DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND);

   DeleteMenu(SysMenu, SC_RESTORE, MF_BYCOMMAND);

   end else

  

  end;

  begin

   inherited;

   SetMenu(FMenu);

   if not (csDesigning in ComponentState) then ModifySystemMenu;

  end;

  suoyiwentichuzaiyouyuSC_SIZEbeishandiaochuangkoudeyangshichuxianlejixingyouWS_THICKFRAMEkeyixiugaichuangkoudaxiaodanbuxiangyingWM_SIZExiaoxiSC_SIZEbeishandiao

  jiejuedebanfahenjiandanshixianzijideWM_NCCREATExiaoxichuliguochengshoudongxiugaixitongcaidan

  procedure TZoCDlgResizable.WMNCCreate(var Message: TWMNCCreate);

  //The following codes are copied from Form.pas line 4047, Delphi 7 sp1.

  procedure ModifySystemMenu;

  var

   SysMenu : HMENU;

  begin

   SysMenu := GetSystemMenu(Handle, False);

   { Make the system menu look like a dialog which has only

   Move, Size and Close commands}

   DeleteMenu(SysMenu, SC_TASKLIST, MF_BYCOMMAND);

   DeleteMenu(SysMenu, 7, MF_BYPOSITION);

   //Don't remove the separater before CLOSE command.

  // DeleteMenu(SysMenu, 5, MF_BYPOSITION);

   DeleteMenu(SysMenu, SC_MAXIMIZE, MF_BYCOMMAND);

   DeleteMenu(SysMenu, SC_MINIMIZE, MF_BYCOMMAND);

   { Don't remove the SIZE command, otherwise we'll lose the

   capability of resizing the Dialog. }

  // DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND);

   DeleteMenu(SysMenu, SC_RESTORE, MF_BYCOMMAND);

  end;

  begin

   { Skip TCustomForm's WM_NCCREATE handler, which remove

   the SIZE command from the System Menu.}

   inherited DefaultHandler(Message);

   //Dealing with the System Menu in our own way.

   ModifySystemMenu;

  end;

  4TZoCDlgResizablelei

  zuizhongdejiejuefanganwofengzhuangweiyigejichengziTFormdeleixiaoguoruxiayutu1xiangtongruguoxiangyaotu2nayangdexitongcaidanzebatiaoyongModifySystemMenudexingshandiao使shiyongdeshihoucongTZoCDlgResizablejichengyigejike

  BTWwohuanshunshougeiTZoCDlgResizablejialegeSizeGripshuxingjutiqingkuangkeyikandaima

Delphi中实现可以更改大小的对话框


  tu 5 meiyoutubiaokeyixiugaidaxiaodaiyouSizeGripdeduihuakuang

  xiazaiexeheyuandaima

  http://www.zocsoft.com/temp/Resizable_Dialog.rar

  5shenkaoziliao

  MSDN: How To Design a Resizable MFC Property Sheet

  yinyongdizhiDelphizhongshixiankeyigenggaidaxiaodeduihuakuang原文】【拼音
 
 
 
上一篇《Delphi中正常窗口的实现》
下一篇《在Delphi中实现类型安全的容器,Delphi泛型库DGL引介(提供源码下载)》
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
关键字:Dialog、对话框、resizable 1、问题的提出 问题来自Stanley_Xu,希望得到只有关闭按钮(还可以有帮助),左上也没有程序的图标并且能够更改窗口大小的对话框。 VCL中为TForm设置了BorderStyle和BorderIcons属性,用以简化窗口样式的设置(否则就要调用SetWindowLong和GetWindowLong等API函数)。TFormBorderStyle和TBorderIcon的定义和说明如下: Value Meaning bsDialog Not resizable; standard dialog box border//不能改大小 bsSingle Not resizable; single-line border bsNone Not resizable; no visible border line bsSizeable Standard resizable border bsToolWindow like bsSingle but with a smaller caption bsSizeToolWin like bsSizeable with a smaller caption type TBorderIcon = (biSystemMenu, biMinimize, biMaximize, biHelp); TBorderIcons = set of TBorderIcon; Value Meaning biSystemMenu The form has a Control menu (also known as a System menu). biMinimize The form has a Minimize button biMaximize The form has a Maximize button biHelp If BorderStyle is bsDialog or biMinimize and biMaximize are excluded, a question mark appears in the form's title bar and when clicked, the cursor changes to crHelp; otherwise,no question mark appears. 显然,通过BorderStyle和BorderIcons只能够满足一般的需要,要实现能够修改大小的对话框就有所力不能及了。 一般情况下,我要得到不能最大最小化但又可以更改大小的窗口,就把BorderStyle设置为bsSizeable,把BorderIcons的biMinimize和biMaximize去掉,结果象这样:窗口可以修改大小,但左上角有图标,: [url=http://www.wangchao.net.cn/bbs/hydetail_837874.html][img]http://image.wangchao.net.cn/it/1323636578530.gif[/img][/url] 图 1 带图标的对话框 注意左上角有图标。 而我们的目标则是下面的两种效果,左上角都没有图标,但窗口都可以修改大小。 [url=http://www.wangchao.net.cn/bbs/hydetail_837874.html][img]http://image.wangchao.net.cn/it/1323636593645.gif[/img][/url] 图 2 打开文件对话框 [url=http://www.wangchao.net.cn/bbs/hydetail_837874.html][img]http://image.wangchao.net.cn/it/1323636593756.gif[/img][/url] 图 3浏览文件夹对话框 2、问题解决一半 搜索了一下MSDN,找到一篇教你如何设计可以可更改大小的属性页的文章(在MFC中CPRopertySheet是作为CPropertyPage子页出现的,后者从CDialog继承而来,通常不能修改大小)《How To Design a Resizable MFC Property Sheet》,文中介绍的方法是在属性页创建之前修改窗口样式,然后手动处理WM_SIZE消息。 int CALLBACK CMyPropertySheet::XmnPropSheetCallback(HWND hWnd, UINT message, LPARAM lParam) { extern int CALLBACK AfxPropSheetCallback(HWND, UINT message, LPARAM lParam); // XMN: Call MFC's callback int nRes = AfxPropSheetCallback(hWnd, message, lParam); switch (message) { case PSCB_PRECREATE: // Set our own window styles ((LPDLGTEMPLATE)lParam)->style |= (DS_3DLOOK | DS_SETFONT | WS_THICKFRAME | WS_SYSMENU | WS_POPUP | WS_VISIBLE | WS_CAPTION); break; } return nRes; } 我试着将同样的方法用到VCL的一个Form中。在设计时把BorderStyle设置为bsDialog,然后重载CreateParams方法。但结果是对话框确实变成了厚边框(因为有WS_THICKFRAME样式),鼠标移动到各个边框后能够自动变化,左上角也没有图标,但窗口就是不能改变大小(添加的WM_SIZE消息处理过程没有触发)。问题出在哪里呢? [url=http://www.wangchao.net.cn/bbs/hydetail_837874.html][img]http://image.wangchao.net.cn/it/1323636593849.gif[/img][/url] 图 4 还不能完全令人满意的对话框 3、问题的解决 查了一翻Forms.pas的源代码,发现了问题所在。TCustomForm的WM_NCCREATE消息处理过程中有一个ModifySystemMenu嵌入过程,用来修改Form的系统菜单。注意下面红色文字说的是“使系统菜单看起来像对话框一样”。接下来的几句代码就把系统菜单项删得只剩下了“移动”和“关闭”。 procedure TCustomForm.WMNCCreate(var Message: TWMNCCreate); procedure ModifySystemMenu; var SysMenu: HMENU; begin …… { Modify the system menu to look more like it's s'pose to } SysMenu := GetSystemMenu(Handle, False); if FBorderStyle = bsDialog then begin { Make the system menu look like a dialog which has only Move and Close } DeleteMenu(SysMenu, SC_TASKLIST, MF_BYCOMMAND); DeleteMenu(SysMenu, 7, MF_BYPOSITION); DeleteMenu(SysMenu, 5, MF_BYPOSITION); DeleteMenu(SysMenu, SC_MAXIMIZE, MF_BYCOMMAND); DeleteMenu(SysMenu, SC_MINIMIZE, MF_BYCOMMAND); DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); DeleteMenu(SysMenu, SC_RESTORE, MF_BYCOMMAND); end else …… end; begin inherited; SetMenu(FMenu); if not (csDesigning in ComponentState) then ModifySystemMenu; end; 所以,问题出在由于“SC_SIZE”被删掉,窗口的样式出现了畸形:有WS_THICKFRAME(可以修改窗口大小),但不响应WM_SIZE消息(SC_SIZE被删掉)。 解决的办法很简单:实现自己的WM_NCCREATE消息处理过程,手动修改系统菜单。 procedure TZoCDlgResizable.WMNCCreate(var Message: TWMNCCreate); //The following codes are copied from Form.pas line 4047, Delphi 7 sp1. procedure ModifySystemMenu; var SysMenu : HMENU; begin SysMenu := GetSystemMenu(Handle, False); { Make the system menu look like a dialog which has only Move, Size and Close commands} DeleteMenu(SysMenu, SC_TASKLIST, MF_BYCOMMAND); DeleteMenu(SysMenu, 7, MF_BYPOSITION); //Don't remove the separater before CLOSE command. // DeleteMenu(SysMenu, 5, MF_BYPOSITION); DeleteMenu(SysMenu, SC_MAXIMIZE, MF_BYCOMMAND); DeleteMenu(SysMenu, SC_MINIMIZE, MF_BYCOMMAND); { Don't remove the SIZE command, otherwise we'll lose the capability of resizing the Dialog. } // DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND); DeleteMenu(SysMenu, SC_RESTORE, MF_BYCOMMAND); end; begin { Skip TCustomForm's WM_NCCREATE handler, which remove the SIZE command from the System Menu.} inherited DefaultHandler(Message); //Dealing with the System Menu in our own way. ModifySystemMenu; end; 4、TZoCDlgResizable类 最终的解决方案我封装为一个继承自TForm的类,效果如下,与图1相同(如果想要图2那样的系统菜单则把调用ModifySystemMenu的行删掉),使用的时候从TZoCDlgResizable继承一个即可。 BTW:我还顺手给TZoCDlgResizable加了个SizeGrip属性,具体情况可以看代码。 [url=http://www.wangchao.net.cn/bbs/hydetail_837874.html][img]http://image.wangchao.net.cn/it/1323636593970.gif[/img][/url] 图 5 没有图标、可以修改大小、带有SizeGrip的对话框 下载(exe和源代码) http://www.zocsoft.com/temp/Resizable_Dialog.rar 5、参考资料: MSDN: How To Design a Resizable MFC Property Sheet 引用地址:《Delphi中实现可以更改大小的对话框》
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
情人节的清纯女生(9)
情人节的清纯女生(8)
情人节的清纯女生(7)
情人节的清纯女生(6)
山东蓬莱海边组照
一探哲蚌 II
一探哲蚌 III
古长城的一角
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
©2005- 王朝网络 版权所有