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++ Widgets - General questions or Mixed problems » Using InstallKeyHook
Using InstallKeyHook [message #10378] Wed, 04 July 2007 19:27 Go to next message
malaugh is currently offline  malaugh
Messages: 7
Registered: June 2007
Promising Member
I am trying to disable an entry field if the user types in another entry field. If the user enters data in the EditVakue control editVendData, then the EditValue control editVendLength, should be disabled. I thought I could do this with the Installkeyhook function. My basic logic is
1) Capture the key input for the application
2) In the key handler, if a key is hit when the user is in the editVendData, then disable editVendLength.

I have tried numerous methods, this is one of my attempts.

In the class
friend bool VendDataKeyHook(Ctrl *ctrl, dword key, int count);

In the constructor
InstallKeyHook(VendDataKeyHook);

The function
bool VendDataKeyHook(Ctrl *ctrl, dword key, int count)
{
USBConsole *panel = (USBConsole *)ctrl;

if(ctrl->GetFocusCtrl() == (Ctrl *)(&(panel->editVendData)))
{
panel->editVendLength.Disable();
}
return(FALSE);
}

The if statement is always FALSE, so editVendLength is never disabled. Also if I move the disable statement outside the if, the program crashes. What am I doing wrong?

I could not find any examples that use InstallKeyHook, is there one?
Re: Using InstallKeyHook [message #10379 is a reply to message #10378] Wed, 04 July 2007 20:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
This is very complicated approach for such simple task.

This is quite common situation. I usually solve that by adding Sync method that gets invoked on WhenAction of any widget that affects other widget. Usually, it is OK to setup every aspect there - it is not required to have special Sync for particular widget, just place all enable/disable logic into the single place (Sync) and get it invoked when user alters the widget (WhenAction).
Re: Using InstallKeyHook [message #10384 is a reply to message #10379] Thu, 05 July 2007 06:09 Go to previous messageGo to next message
malaugh is currently offline  malaugh
Messages: 7
Registered: June 2007
Promising Member
I guess I did not explain the problem too well. When the user enters characters in the data field, the requrement is to first disable the length field, and then add 1 to the length field for every character the user types. The length field should be updated immediately, the user hits the key.

I am not familier with the sync method you mention will it work in this case? Could you post a URL for the manual page, or even better, an example. I am new to Utlimate++.

Thanks
Re: Using InstallKeyHook [message #10389 is a reply to message #10384] Thu, 05 July 2007 11:39 Go to previous message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Something like this?

In window contructor
editVendData <<= THISBACK(SyncFields); // Sets WhenAction callback

Sync function:
SyncFields()
{
   if (editVendData.GetLength())
      // Disable length field and set data to length of data field
      editVendLength.Enable(false) <<= editVendData.GetLength();
   else 
      editVendLength.Enable(true);
}


James

[Updated on: Thu, 05 July 2007 11:39]

Report message to a moderator

Previous Topic: Enter turns WithDropChoice(LineEdit) into chaos
Next Topic: Refresh(), Paint(Draw& w), or something else nearby?
Goto Forum:
  


Current Time: Thu Apr 25 15:08:29 CEST 2024

Total time taken to generate the page: 0.02266 seconds