Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Keyboard shortcut
Keyboard shortcut [message #21572] Wed, 27 May 2009 18:31 Go to next message
darthspawn is currently offline  darthspawn
Messages: 58
Registered: February 2009
Member
I need to create a keyboard shortcut like "ctrl + h", that hide the menu bar.. is possible do it? and is possible hide a button and cut the window to optimize space? thanks!
Re: Keyboard shortcut [message #21608 is a reply to message #21572] Fri, 29 May 2009 11:34 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
darthspawn wrote on Wed, 27 May 2009 12:31

I need to create a keyboard shortcut like "ctrl + h", that hide the menu bar.. is possible do it? and is possible hide a button and cut the window to optimize space? thanks!


Sure.

To hide the menu, it depends on how the menu is incorporated, but in most cases you can just call Hide or Show(false). The same for the buttom.

To catch Ctrl+H: If it is a menu command, it would happen automatically (if you add Key) (but not if menu is hidden).

You can also override Key method and catch it yourself.

Mirek
Re: Keyboard shortcut [message #21611 is a reply to message #21608] Fri, 29 May 2009 12:06 Go to previous messageGo to next message
darthspawn is currently offline  darthspawn
Messages: 58
Registered: February 2009
Member
I tried now to add a key accelerator to the menu' bar, but when menu is not showed is not possible call again CTRL_H for make visible the menu bar (I tried to put some breakpoint, the function is not called). The shortcut function works when the bar is visible.

[Updated on: Fri, 29 May 2009 12:11]

Report message to a moderator

Re: Keyboard shortcut [message #21760 is a reply to message #21572] Thu, 04 June 2009 14:00 Go to previous messageGo to next message
darthspawn is currently offline  darthspawn
Messages: 58
Registered: February 2009
Member
It's my fault or I must user another way?
Sorry for the up!

Sam
Re: Keyboard shortcut [message #21762 is a reply to message #21760] Thu, 04 June 2009 15:09 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
The accerator is being ignored because the menu is invisible. This is the correct behaviour.

You can pick up the event in your TopWindow's Key function instead.
Re: Keyboard shortcut [message #21763 is a reply to message #21760] Thu, 04 June 2009 15:10 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
Hello, Sam.

I can provide you some example.
HideMenuExample.h:
#ifndef _HideMenuExample_HideMenuExample_h
#define _HideMenuExample_HideMenuExample_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class HideMenuExample : public TopWindow {
public:
	typedef HideMenuExample CLASSNAME;
	HideMenuExample();

	FrameRight<Button> btn;
	MenuBar menu;
	// Bars
	void MainBar(Bar& bar);
	void FileBar(Bar& bar);
	// GUI Events
	void OnHideMenu();
	void OnHideButton();
	void OnButtonClick();
	// Input Events
	virtual bool Key(dword key, int count);
	// Methods
	String ShowButtonLabel(bool show) { if (show) return "Hide button"; else return "Show button"; }
};

#endif

HideMenuExample.cpp:
#include "HideMenuExample.h"

HideMenuExample::HideMenuExample()
{
	Title("Hide menu example");
	MaximizeBox().MinimizeBox().Sizeable().CenterScreen();

	btn.SetLabel("?");
	btn.WhenPush = THISBACK(OnButtonClick);

	AddFrame(menu);
	//AddFrame(TopSeparatorFrame());
	menu.Set(THISBACK(MainBar));
	menu.AddFrame(btn);
	
	SetRect(0, 0, 640, 480);
}

void HideMenuExample::MainBar(Bar& bar)
{
	bar.Add("File", THISBACK(FileBar));
}

void HideMenuExample::FileBar(Bar& bar)
{
	bar.Add("Hide this menu", THISBACK(OnHideMenu)).Key(K_CTRL_H);
	bar.Add(ShowButtonLabel(btn.IsVisible()), THISBACK(OnHideButton)).Key(K_CTRL_B);
	bar.MenuSeparator();
	bar.Add("Exit", THISBACK(Close)).Key(K_CTRL_Q);
}

void HideMenuExample::OnHideMenu()
{
	menu.Show(!menu.IsVisible());
}

void HideMenuExample::OnHideButton()
{
	btn.Show(!btn.IsVisible());
}

void HideMenuExample::OnButtonClick()
{
	PromptOK("Clicked");
}

bool HideMenuExample::Key(dword key, int count)
{
	if (!menu.IsVisible())
	{
		if (key == K_CTRL_H)
		{
			OnHideMenu();
			return true;
		}
		else if (key == K_CTRL_Q)
		{
			Close();
			//return true;
		}
	}

	return TopWindow::Key(key, count);
}

GUI_APP_MAIN
{
	HideMenuExample().Run();
}

[Updated on: Thu, 04 June 2009 15:54]

Report message to a moderator

Re: Keyboard shortcut [message #21771 is a reply to message #21763] Thu, 04 June 2009 17:35 Go to previous messageGo to next message
darthspawn is currently offline  darthspawn
Messages: 58
Registered: February 2009
Member
Thank you very much! your example it was greatly appreciate!

Another little question: is possible to hide the blue bar?
it's not a great problem if I can't. I've searched some information about "SetSkin()", it's that the way?
Thank you again!

Sam
Re: Keyboard shortcut [message #21838 is a reply to message #21771] Mon, 08 June 2009 03:26 Go to previous message
Sender Ghost is currently offline  Sender Ghost
Messages: 301
Registered: November 2008
Senior Member
darthspawn wrote on Thu, 04 June 2009 17:35

Thank you very much! your example it was greatly appreciate!

Another little question: is possible to hide the blue bar?
it's not a great problem if I can't. I've searched some information about "SetSkin()", it's that the way?
Thank you again!

Sam

This is another question and should be placed in appropriate topic.

Anyway, if I understood you correctly, yes it's possible to hide the main title bar of the window. For this purpose, e.g. in the Windows operating system, you can change Window Style to not include WS_CAPTION. In U++ we use TopWindow class. It have SyncCaption0 method that changes window styles. FrameLess method can be placed in window constructor. In my opinion, it is not very flexible, because you don't have system menu in this mode and must implement own areas for window placement, close, maximize, minimize buttons, etc.

SetSkin method changes how U++ widget(s) (inherited from Ctrl) looks.

[Updated on: Mon, 08 June 2009 04:10]

Report message to a moderator

Previous Topic: Why struct instead of class?
Next Topic: PromptYesNo = 1|0 not IDYES|IDNO ?
Goto Forum:
  


Current Time: Fri Mar 29 14:10:43 CET 2024

Total time taken to generate the page: 0.01731 seconds