重载FormMain::WndProc时ShowWindow有时失效

天籁晓国 2014-11-18 10:47:19
c++ builder中 ShowWindow有时会失效 Application->onmessage 已被重载

void __fastcall TFormMain::WndProc(TMessage & Message)
{
if (Message.WParam == SC_MINIMIZE)
{
ShowWindow(Application->Handle, SW_MINIMIZE);//这句代码有时失效
}
TFormMain::Dispatch(&Message);
}
...全文
399 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccrun.com 2014-11-19
  • 打赏
  • 举报
回复
TFormMain::Dispatch(&Message); 这一句,建议用: TFormMain的父类::WndProc(Message); // 比如 TForm::WndProc(Message); 来代替
天籁晓国 2014-11-19
  • 打赏
  • 举报
回复
改为TForm::WndProc(Message)后最小化窗口依然有问题 这是相关代码请大家看看到底哪的逻辑有问题 int Count = 0; //--------------------------------------------------------------------------- __fastcall TForm5::TForm5(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm5::WndProc(TMessage & Message) { if (Form6) return; if (Message.WParam == SC_MINIMIZE) { ShowWindow(Application->Handle, SW_MINIMIZE); Message.WParam = 0; } TForm::WndProc(Message); } // --------------------------------------------------------------------------- void __fastcall TForm5::MyMessage(tagMSG &Msg, bool &Handled) { if (Form6) return; switch(Msg.message) { case WM_SYSCOMMAND: if (Msg.wParam == SC_MINIMIZE) { ShowWindow(Application->Handle, SW_MINIMIZE); } Msg.wParam = 0; break; case WM_USER_A: Handled = true; if (Form6) return; Hide(); Application->CreateForm(__classid(TForm6), &Form6); Form6->ShowModal(); Form6 = NULL; Show(); Count = 0; break; } } void __fastcall TForm5::FormActivate(TObject *Sender) { Application->OnMessage = MyMessage; } //--------------------------------------------------------------------------- void __fastcall TForm5::FormDeactivate(TObject *Sender) { Application->OnMessage = OldEvent; } //--------------------------------------------------------------------------- void __fastcall TForm5::FormCreate(TObject *Sender) { OldEvent = Application->OnMessage; } //--------------------------------------------------------------------------- void __fastcall TForm5::Timer1Timer(TObject *Sender) { if (Form6) return; Count++; if (Count >= 20) { PostMessage(Handle, WM_USER_A, 0, 0); } else Edit1->Text = IntToStr(20 - Count); } //--------------------------------------------------------------------------- void __fastcall TForm5::WMA(TMessage & Message) { PostMessage(Handle, WM_USER_A, 0, 0); } void __fastcall TForm5::Button1Click(TObject *Sender) { PostMessage(Handle, WM_USER_A, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TForm5::FormShow(TObject *Sender) { Application->OnMessage = MyMessage; } //--------------------------------------------------------------------------- 头文件中消息定义 MESSAGE void __fastcall WMA(TMessage & Message); TMessageEvent OldEvent; BEGIN_MESSAGE_MAP VCL_MESSAGE_HANDLER(WM_USER_A, TMessage, WMA) END_MESSAGE_MAP(TForm)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; namespace 图片查看器 { public partial class Formmain : Form { bool isLoad = false; FileInfo[] images=null ; //FormRename renameForm = null; int index = -1; public Formmain() { InitializeComponent(); } public void GetFileInder() { DirectoryInfo dir = new DirectoryInfo(folderBrowserDialg1.SelectedPath); images = dir.GetFiles("*.jpg"); } private void btnload_Click(object sender, EventArgs e) { if (folderBrowserDialg1.ShowDialog() == DialogResult.OK) { GetFileInder(); if (images != null && images.Length > 0) { index = 0; picimage.Load(images[index].FullName); picimage.ImageLocation = images[index].FullName; isLoad = true; } else { if (picimage.Image != null) { picimage.Image = null; isLoad = false; } } } } private void btndelete_Click(object sender, EventArgs e) { FileInfo file = null; if (picimage .Image != null) { file = new FileInfo( picimage . ImageLocation.ToString()); file.Delete(); //代码实现 if (!file . Exists) { picimage.Load(images[index+1].FullName); } } } private void btnright_Click(object sender, EventArgs e) { if (index == images.Length - 1) { index = 0; } else { index += 1; } picimage.Load(images[index].FullName); picimage.ImageLocation = images[index].FullName; } private void btnleft_Click_1(object sender, EventArgs e) { if (index == 0) { index = images.Length - 1; } else { index -= 1; } picimage.Load(images[index].FullName); picimage.ImageLocation = images[index].FullName; } private void timer_Tick(object sender, EventArgs e) { if (isLoad) { if (index == images.Length - 1) { index = 0; } else { index += 1; } picimage.Load(images[index].FullName); picimage.ImageLocation = images[index].FullName; } } private void btnouter_Click(object sender, EventArgs e) { timer.Enabled = !timer.Enabled; } private void btnname_Click(object sender, EventArgs e) { if (picimage.Image != null) { FormRename renameForm = new FormRename(); renameForm.Images = images; renameForm.Current = index; renameForm.ShowDialog(); } } } }

1,221

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧