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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subclassing

Status
Not open for further replies.

johncp

Technical User
Aug 28, 2005
47
GB
Folks

I want to implement my own pop up menu box when the user right clicks the task bar at the top of a window, ie I want the windows of my app. to show my dialog box instead of the standard useless MS box showing the restore/move/minimise/maximise/close dialog.

I've looked at TPopupMenu and TForm::OnContextPopup() but these only fire when clicking in the client area, not the task bar.

Is subclassing the solution ?

I'm new to subclassing & haven't googled much stuff relevant to CBuilder. Best so far might be Butthead's post (31/7/05) here on TTs.

Don't spend time on this but if you already have the URL of a good subclassing tut./example then pls post it.

John
 
Hi James

Thanx for the links. Yes the C++ Dev. journal looks good. I've downloaded & am digesting "Extending the common dialogs" which is subscription free & shows subclassing.

John
 
James

After many problems, and the aid of Petzold's book "Programming Windows" which I came across on the net in pdf form - and which I think is a free download from his site - I arrived at a simple solution. The following adds 2 items to the system menu in positions 5 & 6 of Form9 and toggles the check mark against them. Thanks for your help.

//handler calls WndProc to insert menu item
void __fastcall TForm9::OnCreateWindow(TObject *Sender)
{
TMessage* Message ;
HWND WinHandle = Form9->Handle ;
HMENU MenuHandle = GetSystemMenu(WinHandle, false);

InsertMenu(MenuHandle, 5, MF_BYPOSITION | MF_CHECKED, 8, "Dock"); //or WM_APP+8 ?
InsertMenu(MenuHandle, 6, MF_BYPOSITION | MF_CHECKED, 9, "Stay On Top");
TForm::Dispatch(&Message) ;
}
//---------------------------------------------------------------------------
void __fastcall TForm9::WndProc(TMessage& Message)
{
HWND WinHandle = Form9->Handle ;
HMENU MenuHandle = GetSystemMenu(WinHandle, false);

//switch(Message.Msg) //only works for bugs in client areas
switch(Message.WParam) //system menu handle
{
case 8 :
if(GetMenuState(MenuHandle, 8, MF_BYCOMMAND)==MF_CHECKED)
ModifyMenu(MenuHandle, 5, MF_BYPOSITION | MF_STRING | MF_UNCHECKED, 8, "Dock") ; //MUST include MF_BYPOSITION
else
ModifyMenu(MenuHandle, 5, MF_BYPOSITION | MF_STRING | MF_CHECKED, 8, "Dock") ;
break ;
case 9 :
if(GetMenuState(MenuHandle, 9, MF_BYCOMMAND)==MF_CHECKED)
ModifyMenu(MenuHandle, 6, MF_BYPOSITION | MF_STRING | MF_UNCHECKED, 9, "Stay on Top") ;
else
ModifyMenu(MenuHandle, 6, MF_BYPOSITION | MF_STRING | MF_CHECKED, 9, "Stay on Top") ;
break ;
default : ;
}
TForm::WndProc(Message);
}
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top