473,626 Members | 3,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

I am trying to register my interface with IConnectionPoin t of outlook
reminders to capture some Outlook Reminder events and having some
issues. Here goes the pseudo code

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

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

// And Main message loop:
while (GetMessage(&ms g, NULL, 0, 0))
{
if (!TranslateAcce lerator(msg.hwn d, hAccelTable, &msg))
{
TranslateMessag e(&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

Dec 11 '06 #1
4 2858

Uday Bidkar wrote:
I am trying to register my interface with IConnectionPoin t of outlook
reminders to capture some Outlook Reminder events and having some
issues. Here goes the pseudo code

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

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

// And Main message loop:
while (GetMessage(&ms g, NULL, 0, 0))
{
if (!TranslateAcce lerator(msg.hwn d, hAccelTable, &msg))
{
TranslateMessag e(&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

Dec 11 '06 #2
Uday Bidkar wrote:
while (GetMessage(&ms g, 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
Dec 11 '06 #3
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(&ms g, 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.

Dec 12 '06 #4
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(&ms g, 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(&ms g, ...' 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
Dec 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7802
by: Jim | last post by:
Im getting way too many rows retured..what its trying to do is insert a 0 for revenue for months 7 - 12 (aka July through December) for each of these cost centers for each payor type..Im getting a lot of repeats and the concatenation field date always comes back as January 2003 instead of the month and date its supposed to --Fiscal Year
3
9468
by: RobG | last post by:
A little while ago I opined that do/while loops are harder to read than for loops, and therefore I preferred using for loops. However, it was pointed out that do/while has significant performance benefits as evidenced by: <URL:http://www.websiteoptimization.com/speed/10/10-2.html> (There's a bug in the page, testLoop is both a function name and the name of the form but if you download the page & rename
8
7584
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the looping function the window becomes unmovable and cannot close under its own direction (the upper right "close 'X'") My first attempt to solve the problem was to have the looping function execute as its own thread, the idea being this would...
21
2830
by: Rich | last post by:
I was considering C# for developing a scientific application, but I have noticed a ~30% difference between VC++ .NET and C# on the same machine, under identical conditions: double a = 0,b = 0, c = 0, d = 0, e = 0; for(int n = 0; n != 6000000; n++) { a = n % 5 *2 / 3 - 4 + 6 / 3 - n + n * 2; b = n * 2.3 - 1 *2 / 3 - 4 + 6 / 3 - n + n * 2; c = n * 3 / 3.5 *2 / 3 - 4 + 6 / 3 - n + n * 2;
8
1628
by: buc | last post by:
I have a simple combox on the screen that is bound via a datareader to a stored proc in sql that returns a simple string. The code is 'load stored proc then dReader = tmpSQL.SQLcmd.ExecuteReader() combobox1.DataSource = dReader dReader.Read() combobox1.DataTextField = dReader.GetName(0) combobox1.DataBind()
6
71961
by: John Pass | last post by:
What is the difference between a While and Do While/Loop repetition structure. If they is no difference (as it seems) why do both exist?
28
72448
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and 2005 Test Environments. What is the purpose of a view if I can just copy the vode from a view and put it into a stored procedure? Should I be accessing views from stored procedures?
10
2313
by: rohitjogya | last post by:
Can anyone tell me the difference bet for loop and while loop execution? ____________________ for (i=0 ; i<10 ; i++) ; /* Do nothing*/ print i; ___________________ i=0;
26
3825
by: Muzammil | last post by:
whats the beauty of "malloc" over "new" why its helpful for programmer.for its own memory area.??
0
8266
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8199
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8638
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8365
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7196
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2626
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.