Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Whats the difference between while loop in Windows message loop and while(1)

Reply
Thread Tools

Whats the difference between while loop in Windows message loop and while(1)

 
 
Uday Bidkar
Guest
Posts: n/a
 
      12-11-2006
I am trying to register my interface with IConnectionPoint of outlook
reminders to capture some Outlook Reminder events and having some
issues. Here goes the pseudo code

int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
//Register class CMyEventHandler : public IDispatch with
IConnectionPoint of Outlook reminder

//Removed Wizard generated code for registering the widow class and
initializing the window

// And Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}

return (int) msg.wParam;
}

If this is the code I do get control back in CMyEventHandler::Invoke()
when some Reminder event occurs as a notification from outlook.

But if I replace the message loop with while(1){} I dont get any such
notifications, instead outlook hangs.

Looking at the Main message loop, it seems that its also a infinite
loop unless GetMessge() returns Zero for WM_QUIT. What I want to know
is why i dont get notified by Outlook if there is actual infinite loop
instead of message loop? What make message loop different than
while(1){} ?

Thanks in advance

 
Reply With Quote
 
 
 
 
Salt_Peter
Guest
Posts: n/a
 
      12-11-2006

Uday Bidkar wrote:
> I am trying to register my interface with IConnectionPoint of outlook
> reminders to capture some Outlook Reminder events and having some
> issues. Here goes the pseudo code
>
> int APIENTRY _tWinMain(HINSTANCE hInstance,
> HINSTANCE hPrevInstance,
> LPTSTR lpCmdLine,
> int nCmdShow)
> {
> //Register class CMyEventHandler : public IDispatch with
> IConnectionPoint of Outlook reminder
>
> //Removed Wizard generated code for registering the widow class and
> initializing the window
>
> // And Main message loop:
> while (GetMessage(&msg, NULL, 0, 0))
> {
> if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
> {
> TranslateMessage(&msg);
> DispatchMessage(&msg);
> }
> }
>
> return (int) msg.wParam;
> }
>
> If this is the code I do get control back in CMyEventHandler::Invoke()
> when some Reminder event occurs as a notification from outlook.
>
> But if I replace the message loop with while(1){} I dont get any such
> notifications, instead outlook hangs.
>
> Looking at the Main message loop, it seems that its also a infinite
> loop unless GetMessge() returns Zero for WM_QUIT. What I want to know
> is why i dont get notified by Outlook if there is actual infinite loop
> instead of message loop? What make message loop different than
> while(1){} ?
>
> Thanks in advance


None of the above is C++. Please post your question in a relevent
newsgroup that deals with that particular operating system.
[5.9] Which newsgroup should I post my questions?
http://www.parashift.com/c++-faq-lite/how-to-post.html

 
Reply With Quote
 
 
 
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      12-11-2006
Uday Bidkar wrote:

> while (GetMessage(&msg, NULL, 0, 0))


> But if I replace the message loop with while(1){} I dont get any such
> notifications, instead outlook hangs.
> Looking at the Main message loop, it seems that its also a infinite
> loop unless GetMessge() returns Zero for WM_QUIT. What I want to know
> is why i dont get notified by Outlook if there is actual infinite loop
> instead of message loop? What make message loop different than
> while(1){} ?


The main difference is that '1' is not the same as 'GetMessage (....)'.
Thinking a bit, the name 'GetMessage' suggests that it gets a message, so
the difference is that with 'while (1)' you never get a message. The next
logical step is to read something about Windows messages.

--
Salu2
 
Reply With Quote
 
Uday Bidkar
Guest
Posts: n/a
 
      12-12-2006
Thanks Julián for responding.

The documentation for GetMessage say that if the function retrieves a
message other than WM_QUIT, the return value is nonzero and if the
function retrieves the WM_QUIT message, the return value is zero. This
means that while (GetMessage(&msg, NULL, 0, 0)) is same as while(1)
unless WM_QUIT is the message retrieved from message queue so why the
difference in behavior?

I apologize for posting this in wrong newsgroup.

 
Reply With Quote
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      12-12-2006
Uday Bidkar wrote:

> The documentation for GetMessage say that if the function retrieves a
> message other than WM_QUIT, the return value is nonzero and if the
> function retrieves the WM_QUIT message, the return value is zero. This
> means that while (GetMessage(&msg, NULL, 0, 0)) is same as while(1)
> unless WM_QUIT is the message retrieved from message queue so why the
> difference in behavior?


The difference is that '1' does nothing with 'msg'
but 'GetMessage(&msg, ...' does something with it. Read about Windows
messages in any article, book or help file about Windows programming.

If you come from some functional programming language, forget all about "no
secondary effects".

--
Salu2
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Difference between while and do while Logan Lee C Programming 9 12-25-2007 12:26 PM
whats the difference between point to point(HDLC and PPP) network and frame replay network? bfot123@gmail.com Wireless Networking 0 05-29-2007 10:53 PM
while loop in a while loop Steven Java 5 03-30-2005 09:19 PM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57