如题,声明Application的OnMinimize不行,自己响应WMSysCommand消息也不行

解决方案 »

  1.   

    qinmaofan兄我用Spy++看了一下,基本上就是WM_SIZE、WM_SIZEING、WM_NOTIFY等等没一个合用的,有些消息我也不太常用,不知能否直接指点一下
      

  2.   

    public
        { Public declarations }
        ...
        procedure AppMsg(var Msg: TMsg; var Handled: Boolean);
        ...
      end;
     
    procedure TForm1.AppMsg(var Msg: TMsg; var Handled: Boolean);
    begin
      if Msg.wParam  = SC_MINIMIZE then
      begin
        showmessage('fdfdf');
      end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Application.OnMessage := AppMsg;
    end; 
      

  3.   

    lion_lh(xmanx)兄,这种写法在最小化窗口时都不触发呀,别说最小化所有窗口了
      

  4.   

    AWolfBoy兄:窗口过程我也试了,在里截获WM_SYSCOMMAND想在短参为SC_SC_MINIMIZE时响应可是还是不行。
      有没有高手写个能响应的例子给我,我可以另开贴给分!!
      

  5.   

    procedure TForm1.WndProc(var Message: TMessage);
    var
      WndPosFlag: Integer;
    begin
      if Message.Msg = WM_WINDOWPOSCHANGED then
      begin
        WndPosFlag := PWindowPos(Message.LParam)^.flags;
        case WndPosFlag of
          6295: Windows.Beep(333, 500);
        end;
      end;
      inherited;
    end;
      

  6.   

    我找遍 WM_WINDOWPOSCHANGED 事件所有情况 SWP_XXX
    都没有与上面的消息值 6295 对应的消息名称
    更为吃惊的是在头文件中居然没有找到值为 6295($1897)的消息名称……
    不过搂主所要的效果还是可以达到地下面一个例子是我从网上搜来的资料
    我试了试
    对于主窗口真的不起作用
    对于非主窗口只有最小化按钮时才起作用
    单击“显示桌面”或选择“最小化所有窗口”都不会引起下面的事件我发现有很多对应的消息都没有文档
    比如说 WM_SIZE 吧,MSDN 中只有下面几个对应的情况。
    SIZE_MAXHIDE
    SIZE_MAXIMIZED
    SIZE_MAXSHOW
    SIZE_MINIMIZED 
    SIZE_RESTORED 
    我发现只有用鼠标或键盘选择相应的动作时才会出现这些情况。
    但是当我们用鼠标拖动边框时,却没有与之对应的情况。
    uMsg    WM_SIZE
    拖动左边框改变大小   wParam 对应的值是 WM_SIZE + 1
    拖动右边框改变大小   wParam 对应的值是 WM_SIZE + 2
    拖动上边框改变大小   wParam 对应的值是 WM_SIZE + 3
    拖动左上边框改变大小 wParam 对应的值是 WM_SIZE + 4
    拖动右上边框改变大小 wParam 对应的值是 WM_SIZE + 5
    拖动下边框改变大小   wParam 对应的值是 WM_SIZE + 6
    拖动左下边框改变大小 wParam 对应的值是 WM_SIZE + 7
    拖动右下边框改变大小 wParam 对应的值是 WM_SIZE + 8不知道是没有对应的消息名称还是我没找到
    (很可能我是孤陋寡闻了,由谁知道请告诉我,谢谢啦。)说远了,就此打住。
    '====================================================================To check when a form is minimized you can catch the WM_SIZE message... TForm1 = class(TForm)
     private
       procedure WMSize(var Message: TWMSize); message WM_SIZE;
     end;procedure TForm1.WMSize(var Message: TWMSize);
    begin
     if (Message.SizeType = SIZE_MINIMIZED) then
       ShowMessage('MINIMIZED');
    end;BUT... There is a bit of a trick here in that if the form you minimize is the project's main form then you will not get a WM_SIZE message, because you are really minimizing the application.  This will result in ALL of your forms being minimized.  That means it's tricky because what you may need is a way to switch which is the main form.If this is what you're after let me know and I'll elaborate.
      

  7.   

    procedure TForm1.WndProc(var Message: TMessage);
    var
      WndPosFlag: Integer;
    begin
      if Message.Msg = WM_WINDOWPOSCHANGED then
      begin
        WndPosFlag := PWindowPos(Message.LParam)^.flags;
        ListBox1.Items.Add(IntToStr(WndPosFlag));
        case WndPosFlag of
          6295: Windows.Beep(131, 500);
          6147: Windows.Beep(147, 500);
        end;
      end;
      inherited;
    end;