Plex 2E

Expand all | Collapse all

How to get the control name of a pressed button

  • 1.  How to get the control name of a pressed button

    Posted May 27, 2016 08:18 AM

    Hi,

     

    I have a panel (C++) with a lot of buttons representing images a user can select.

     

    My idea is, to prevent me for defining an event per button, to use the same event for every button when pressed and to get the Control Name of the pressed button, to know which image was selected.

    Is there a possibility to get the Control Name of the pressed button?



  • 2.  Re: How to get the control name of a pressed button

    Posted May 27, 2016 08:31 AM

    I don't think you are going to save much time here...as you have to create a button for every image, give the button a unique control name, then attach to a logical event...why not create a unique logical event and have an Events Case Handler...

     

    But you could use this source to check if a control with the passed control name has focus.

     

     

     

    {
      HWND fhWnd;
      HWND hWnd = ObPanelAPI::GetControlHandleByName(&(1:));
      fhWnd = GetFocus();
      if (fhWnd == hWnd)
      {
       &(2:) = "1";
      }
    }
    

     

    Will search around for some source like GetControNameOfControlInFocus or something similar



  • 3.  Re: How to get the control name of a pressed button

    Posted May 27, 2016 08:43 AM

    what we need is something like:

     

      HWND fhWnd; 

      fhWnd = GetFocus();

      &(1:)  = ObPanelAPI::GetControlNameByHandle(fhWnd); 

     

    Just need to find "GetControlNameByHandle"  if it exists or not by CA



  • 4.  Re: How to get the control name of a pressed button

    Posted May 27, 2016 09:21 AM

    maybe some vb CodeGuru Forums yuk

     

    but on a train so cant really test..laters



  • 5.  Re: How to get the control name of a pressed button

    Posted May 27, 2016 09:07 AM

    Hi,

     

    Try this ,

     

     

    HWND hwndCtrl = ObPanelAPI::GetControlHandleByName("*Event Source"); //Event Source

     

    or

     

    HWND hwndCtrl = ObPanelAPI::GetControlHandleByName("*Focus");



  • 6.  Re: How to get the control name of a pressed button

    Posted May 27, 2016 09:10 AM

    why? We have the HANDLE of the current focused control but we want to get the Control NAME by the HANDLE



  • 7.  Re: How to get the control name of a pressed button

    Posted May 28, 2016 08:18 AM

    Those two are special values, useful for generic process or creating patterns.



  • 8.  Re: How to get the control name of a pressed button

    Posted May 27, 2016 09:32 AM

    Add event to the panel - Control Defaults.

     

    Use the Control handle from either (*Event Source) or (*Focus) to get other control properties.

     

     

    The following got me Left label of all fields when mouse was moved over it.

     

    #include "OBCTRL.H"

     

    HWND hwndCtrl = ObPanelAPI::GetControlHandleByName("*Event Source"); //Event Source

    int length=GetWindowTextLength(hwndCtrl);

    char Text[260];

    if (Text) GetWindowText(hwndCtrl,(LPSTR)Text,length+2);

    Text[length+2]='\0';

    &(3:)=ObCharFld(Text);

    AfxMessageBox(Text);



  • 9.  Re: How to get the control name of a pressed button

    Posted May 27, 2016 09:46 AM

    does GetWindowText get the ControlName of a button? Maybe Markus could add text to the button to determine which button was pressed but really adding dedicated logical events seem easier than anything else but still fun to try



  • 10.  Re: How to get the control name of a pressed button

    Posted May 28, 2016 08:21 AM

    GetWindowText would get the text on the control.

     

    Using  control handle, you may get most properties asociated with control.

     

    May be Markus needs to get the image name or source for the control using its handle.



  • 11.  Re: How to get the control name of a pressed button

    Posted May 30, 2016 03:51 AM

    First, thanks to ashfaq.m.ahmed  and  GeorgeJeffcock for the help.

     

    Ashfaq, I tried your code, but I only get the "Text" and not the "Control Name" of the button.

    If it's not possible to get the Contro Name, how can I get the image name (as you mentionned above)?



  • 12.  Re: How to get the control name of a pressed button

    Posted Jun 02, 2016 09:28 AM

    Hi Markus,

     

    Try with this .....

     

    HBM_GETPIC

    HBM_GETBITMAP

    HBM_GETPALETTE

     

    Regards

    AA