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

Keyboard Accelerators 1

Status
Not open for further replies.

zigular

Technical User
Jun 29, 2004
18
DE
did somebody ever try to use key accelerators in dialog-based applications?

have a nice weekend
cheers h.
 
Yepper,

Create an accelerator object.
Add your keyboard inputs.
Then in the code...

Code:
[green]
//Define an accelerator object in your .h
[/green]
[blue]HACCEL myAccelerator[/blue]

[green]
//In your OnInitDialog Function in the cpp file, add this
[/green]
[blue]myAccelerator=LoadAccelerators(AfxGetInstanceHandle(),MAKEINTRESOURCE(MENU_PRIMARY_ACCEL));[/blue]
[green]
//Where MENU_PRIMARY_ACCEL is the resource name of the accelerator object
[/green]


Hope that helps!
-Ron

/**************
Me: When will the project be finished?
Them: What project?
Me: The one you have been working on for the last 3 years!
Them: Ohh, we can't finish it?
Me: Why?
Them: We don't know how to program...
 
Haha Whoops! I forgot the most import part!

Code:
[blue]
[green]//Add this function your class
//This is the Prototype for the .h[/green]
[red] BOOL PreTranslateMessage(Msg* pMsg);[/red]

BOOL CYourClass::PreTranslateMessage(MSG* pMsg) {
   if (myAccelerator) {
	   if (::TranslateAccelerator(this->m_hWnd,myAccelerator, pMsg)) {
         return(TRUE);
      }
   }
   return CDialog::PreTranslateMessage(pMsg);

}
[/blue]

cout << "If you don't know where you want to go, we'll make sure you get taken";
 
@ronnyjljr

absolutely greatly stuff!!
no, honestly.. it works really fine.

thanx a lot!
h.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top