application.postmessage
是form的子类
控制台程序通常没有form
请问如何实现上面功能?
谢谢

解决方案 »

  1.   

    没有Form 也没有消息循环,你自然用不了application.postmessage.
      

  2.   

    postMessage是个API,uses windows; 就能用.
      

  3.   

    int APIENTRY WinMain(HINSTANCE hInstance,
     HINSTANCE hPrevInstance,
     LPSTR lpCmdLine,
     int nCmdShow)
    {
    MSG msg; // Initialize global strings
    MyRegisterClass(hInstance); // my initialization
    ZeroMemory(g_szFileNamePath, 200); // surppose lstrlen(szCmdLine) < 200
    memcpy(g_szFileNamePath, lpCmdLine, lstrlen(lpCmdLine)); // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow)) 
    {
    return FALSE;
    }

    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    } return msg.wParam;
    }
    win32的程序框架如上 
    入口 WinMain , 需要注册自己的窗口类 然后 指定窗口处理函数
    然后就获取消息循环 翻译 转发消息 然后对不同的消息的处理 就需要你的窗口处理函数中实现 如果你不想处理某些消息 那么就 调用 
    DefWindowProc(hWnd, message, wParam, lParam); 即可
      

  4.   

    非常抱歉我的问题是
    application.ProcessMessages
    就是相当于vb的Doevents的
      

  5.   

    VB 的DoEvent是在有消息循环的前提下使用的,
    你要首先却你的控制台程序有没有消息循环,没有的话,这个过程是没用的
      

  6.   

    to: beyondtkl(大龙驹<逝追.弗瑞德>) 不错。能不能再详细点?
    不如说如何在dephi的控制台程序中使用这个函数。或者整个程序比必须使用纯api构建吗
      

  7.   

    能不能用 ProcessMessages 不是取决于是否用API,台,而是取决于是否有消息循环。ProcessMessages的等效代码可以简化等效于 TranslateMessage(Msg);
     DispatchMessage(Msg);也就是前面 while (GetMessage(&msg, NULL, 0, 0))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }就类似实现 ProcessMessages 了,
    知道了他的含义,自己写一个不就行了。
    感兴趣你可以看一下 VCL 中这部分的代码。
      

  8.   

    感谢楼上的解答!!!
    ======================================================while (GetMessage(&msg, NULL, 0, 0))
    TranslateMessage(&msg);
    DispatchMessage(&msg);======================================================
    你把上面的接受消息的句柄设置为null?
    是指接受所有windows的消息  还是指不接受消息?
    是不是我的控制台程序中必须先创建一个句柄啊?
      

  9.   

    楼主真够懒的,DELPHI F1按下去都可以看到的东西。。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.