Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么不能从windows消息队列中打印_C_Windows_Conemu - Fatal编程技术网

C 为什么不能从windows消息队列中打印

C 为什么不能从windows消息队列中打印,c,windows,conemu,C,Windows,Conemu,第一条消息hello world 1打印,但第二条消息hello world 2不打印 它就像windowsAPI调用正在对我的运行时环境进行外部更改一样:(GetMessage将等待来自与当前线程关联的窗口的窗口消息。如果没有消息或没有窗口,等待是不确定的 如果您确实有一个窗口,并且生成了消息,则会按预期调用printf。但您不应将printf放入消息循环中。而是应响应窗口过程中的特定消息 printf("hello world 1 \n"); while (GetMessage(&

第一条消息
hello world 1
打印,但第二条消息
hello world 2
不打印


它就像windows
API
调用正在对我的运行时环境进行外部更改一样:(

GetMessage
将等待来自与当前线程关联的窗口的窗口消息。如果没有消息或没有窗口,等待是不确定的

如果您确实有一个窗口,并且生成了消息,则会按预期调用
printf
。但您不应将
printf
放入消息循环中。而是应响应窗口过程中的特定消息

  printf("hello world 1 \n");

  while (GetMessage(&Msg, NULL, 0, 0) > 0 ) {

    printf("hello world 2\n");


    TranslateMessage(&Msg);

   DispatchMessage(&Msg);
  }
#包括
LRESULT回调WndProc(HWND HWND,UINT msg,WPARAM WPARAM,LPARAM LPARAM)
{
开关(msg)
{
案例WM_销毁:
PostQuitMessage(0);
返回0;
}
返回DefWindowProc(hwnd、msg、wparam、lparam);
}
int main()
{
printf(“hello world 1\n”);
WNDCLASSEX wcex={sizeof(wcex)};
wcex.lpfnWndProc=WndProc;
wcex.lpszClassName=“classname”;
注册类别(&wcex);
CreateWindow(wcex.lpszClassName,0,WS|u可见| WS|u重叠窗口,
0, 0, 300, 200, 0, 0, 0, 0);
味精;
while(GetMessage(&Msg,NULL,0,0)>0)
{

printf(“hello world 2\n”);//您是在制作控制台程序还是Windows程序?这不是一个很好的例子。这是一个控制台程序,它有一个自动附加的控制台窗口吗?请学习如何创建。我也建议您。如果您没有将程序创建为控制台应用程序,或者没有显式附加控制台,那么现在就没有了e代表
printf
打印任何东西。这不是像这样的教程的真正网站,但这里有一个简短的版本:在Windows中有两种类型的程序:控制台程序和GUI程序。控制台程序有一个附加到控制台的控制台,带有写入控制台的
stdout
。GUI程序根本没有控制台连接到它们,因此所有到
stdout
的输出都会被讨论,因为没有地方可以编写它。如果这确实是你的整个程序,难怪你从来没有在循环中看到打印。你期望什么会导致
GetMessage
甚至返回,更不用说返回以使while条件为真?你停止了吗od没有windows,所以只有应用程序线程队列在那里,除非你在其中发布一些东西,否则循环体将永远不会被输入。Barmak Shemirani,谢谢你!我不是windows编程人员,所以这让我非常困惑-原因是我在一个需要进行comp的应用程序的深度多线程设置中使用它无法忍受windows。所以我认为我在某个地方犯了一些疯狂的错误,或者更糟的是,某个地方出现了比赛条件!所以谢谢你让我感到轻松!
  printf("hello world 1 \n");

  while (GetMessage(&Msg, NULL, 0, 0) > 0 ) {

    printf("hello world 2\n");


    TranslateMessage(&Msg);

   DispatchMessage(&Msg);
  }
#include <Windows.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
    switch (msg)
    {
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hwnd, msg, wparam, lparam);
}

int main()
{
    printf("hello world 1 \n");

    WNDCLASSEX wcex = { sizeof(wcex) };
    wcex.lpfnWndProc = WndProc;
    wcex.lpszClassName = "classname";
    RegisterClassEx(&wcex);
    CreateWindow(wcex.lpszClassName, 0, WS_VISIBLE | WS_OVERLAPPEDWINDOW, 
            0, 0, 300, 200, 0, 0, 0, 0);

    MSG Msg;
    while (GetMessage(&Msg, NULL, 0, 0) > 0 )
    {
        printf("hello world 2\n");//<- don't put anything here in the message loop
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }
    return 0;
}