   WinApi Question
  Good evening programmers  I've always enjoyed the pseudo debugging of putting getch()s in my console programs, and I wanted to bring it to my windows programming. I'm implementing my own version of getch() and goes something like this.  char getch(){   char c;   while (1)   { if (c = KeyDown())    break;   }   return c;}Now here's my question. After execution I realized I needed to handle messages while the program is waiting for keyboard input. I'm not exactly sure how to do this. I tried copying the basic peekmessage function->   char win_getch(){char c;MSG msg;while(1){if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){// translate any accelerator keys<-?TranslateMessage(&msg);// send the message to the window procDispatchMessage(&msg);// test if quit}if (c = KeyDown())break;}return c;}Everything works well, except when I close the program, it doesn't end the process. How do I implement message handling into arbitrary function such as this? Thank you advance! [edited by - xorjesus on February 19, 2004 1:39:03 AM]
  char c; while (1)  {if (c == KeyDown()) break;  }   return c; } -char c is not assigned a value and is being compared to the return value of KeyDown().-then your returning c when no assignment was done to the varibal;  uh.. That has nothing to do with what I posted. I coded the if statement like that on purpose. If there is no key currently being pressed, KeyDown() returns 0, and c is assigned that value, the if function THEN tests the variable c, and seeing that it is 0, fails, and the loop is repeated. If there''s a key being pressed down, c is assigned a code of my choice and since it will be greater than one, the loop will break and everything will behave as I have planned it. My question is about windows programming, not the logic in my code. ;  wrong ;quote:Original post by commander keen  wrong   How can a question I define be wrong? Are you actually even looking at the code? Do you know how an if statement behaves?  ;  Use a breakpoint, not a getch().You shouldn''t hijack the message loop like that, either. It seems disconcerting to run the message loop from elsewhere in your program besides WinMain().As for not quitting, that has been covered to death on these forums so I''ll let you learn how to search them. 