Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WM_QUERYENDSESSION problem!!!

Status
Not open for further replies.

petyo

Programmer
Feb 28, 2001
5
BG
Hello!
I use windows 98 and BCB 5.
My program is password protected and resides in system tray. I wrote my own message handler for messages from the tray:
//in main.h

struct TWMTrayMessage //struct for WM_TRAYMESSAGE
{
Cardinal Msg; // first parameter is the message ID
WPARAM wParam; // this is the first wParam
LPARAM lParam; // this is the lParam
int Result; // this is the result data member
};
class TMainForm : public TForm
{
...
public:
...
void __fastcall WMTrayMessage(TWMTrayMessage &Msg);
virtual void WndProc(TMessage &Msg);

BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_TRAYMESSAGE, TWMTrayMessage, WMTrayMessage);
END_MESSAGE_MAP(TForm)
}

//in main.cpp
void __fastcall TMainForm::WMTrayMessage(TWMTrayMessage &Msg)
{
switch ( Msg.lParam )
{
case WM_LBUTTONDBLCLK:
if ( MainForm->Visible )
return;

try {
PasswordDlg->Show();
}
catch (Exception &E) {}
if ( bCorrectPass ) //it is set from password dialog
{
MainForm->Visible = true;
::ShowWindow(Application->Handle, SW_SHOW);
}
return;

//------------------------------
case WM_RBUTTONDOWN:
POINT Point;
GetCursorPos(&Point);
SetForegroundWindow( Handle);
TrayPopupMenu->Popup( (int)Point.x, (int)Point.y);
PostMessage( Handle, WM_NULL, 0, 0);
return;

//------------------------------
default:
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::WndProc( TMessage &Msg)
{
switch ( Msg.Msg )
{
case WM_QUERYENDSESSION:
ShowMessage("WM_QUERYENDSESSION");
Msg.Result = true;
return;

//*********************************
case WM_ENDSESSION:
ShowMessage( "WM_ENDSESSION");
if ( (bool)Msg.WParam )
{
Msg.Result = true;
Close();
}
return;

//*********************************
default:
break;
}
inherited::WndProc( Msg);
}

As you can see the password dialog is shown only when user double clicks the icon in tray or selects a function from the popup menu.
The problem is: my program DO NOT RECEIVES WM_QUERYENDSESSION message till the password is entered correctly at least one time. I supposed the problem is in password form so I put a WndProc for PasswordDlg form:


//in pass.cpp
void __fastcall TPasswordDlg::WndProc( TMessage& Msg)
{
switch ( Msg.Msg )
{
case WM_QUERYENDSESSION:
ShowMessage("WM_QUERYENDSESSION in password dialog.");
Msg.Result = true;
break;

//*********************************
case WM_ENDSESSION:
ShowMessage( "WM_ENDSESSION in password dialog.");
if ( (bool)Msg.WParam )
{
Msg.Result = true;
Close();
}
break;

//*********************************
default:
break;
}
inherited::WndProc( Msg);
}


The problem here is: PasswordDlg window receives WM_QUERYENDSESSION only if it is shown at least once?! Main window receives that message only if it is shown at least once too?! If I exclude password dialog from my project my program DO NOT RECEIVE WM_QUERYENDSESSION at all?!
Where I am wrong?
Thanks in advance!

Sincerely,
Petyo Milotinov
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top