我想在线程中接收其它应用程序发送来的自定义消息,程序如下:在Excute中,
Threadtest.Excute();
begin 
    while ...
    begin
        if GetMessage(.., self.handle, WM_USER+100, WM_USER+100) then
            printGraph;//(这是一个打印图形的过程)
    end;
end
启动线程后,程序运行没有任何结果,而我如果单独将if语句放在一个按钮中就可以打出图形,为什么?

解决方案 »

  1.   

    printGraph;//(这是一个打印图形的过程)
    函数可能需要同步。
      

  2.   

    跟踪过,可程序走到if语句时就不知去向了,还没有到printGraph
      

  3.   

    你先peekmessage看看消息队列中有没有你的消息?还是你直接发给你的窗口了?关注先
      

  4.   

    跟踪程序发现当程序没接收到上面所说的用户自定义消息WM_USER+100时,GetMessage就无任何返回,程序运行的不知去向了。
    GetMessage难道有什么特性吗?我看API介绍其返回值为三类:0(接收到的是WM_QUIT),-1(出错),非零(接收到WM_QUIT之外的消息)。可是起返回类型又是BOOL型,如何让GetMessage每次都能又返回值?
    高手快说话啊!
      

  5.   

    在调用GetMessage时有问题了,
    你跟踪进去GetMessage看看
      

  6.   

    BOOL GetMessage(    LPMSG lpMsg, // address of structure with message
        HWND hWnd, // handle of window
        UINT wMsgFilterMin, // first message
        UINT wMsgFilterMax  // last message
       );
     ParameterslpMsgPoints to an MSG structure that receives message information from the thread's message queue. hWndIdentifies the window whose messages are to be retrieved. One value has a special meaning: Value Meaning
    NULL GetMessage retrieves messages for any window that belongs to the calling thread and thread messages posted to the calling thread via PostThreadMessage.
     wMsgFilterMinSpecifies the integer value of the lowest message value to be retrieved. wMsgFilterMaxSpecifies the integer value of the highest message value to be retrieved
      

  7.   

    while not Terminated do begin
        if PeekMessage(Msg,0,0,0,PM_NOREMOVE) then
          if Msg.message = MM_MESSAGE then
            Form1.Edit1.Text := 'catch message';
      end;
      

  8.   

    In the thread to which the message will be posted, call PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE) to force the system to create the message queue.
      

  9.   

    --->>HWND hWnd, // handle of window你传的是self.Hande, 这个self是线程啊, 这里的Self.Handle是线程句柄, 不是窗口句柄, 因此GetMessage永远也取不到对应这个句柄(GetMessage把它当成窗口句柄了)的消息, 当然也就执行不下去了