Announcement

Collapse
No announcement yet.

Remove a style from a button at runtime

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • BOB MECHLER
    replied
    Thanks, Michael. Using the %BM_SETSTYLE returned the button to it's non-focused look and I could retain the code I was using without resorting to keybd_event.

    Code:
       CALLBACK FUNCTION NDateButtonProc
          STATIC OldProc AS LONG, OffsetWndExtra AS LONG
          LOCAL Txt AS ASCIIZ * %MAX_PATH, sTxt AS STRING
          LOCAL DateButtonID AS LONG, DateID AS LONG, DescID AS LONG
          LOCAL DateHandle AS LONG
          IF CBHNDL = 0 THEN OldProc = CBWPARAM: OffsetWndExtra = CBLPARAM: EXIT FUNCTION
          DateButtonID& = getdlgctrlid(CBHNDL)
          DateID& = DateButtonID& - (scr_NUM_FLD# * 2 )
          DateHandle& = GetDlgItem(GetParent(CBHNDL),DateID&)
          SELECT CASE CBMSG
            CASE %WM_LBUTTONDOWN
              Call SupDateGetDate()
              Txt = V_DateStr              
              SetWindowText DateHandle&,Txt
              sTxt = NEditDateFormat(DateHandle&)
              SetWindowText DateHandle&, BYCOPY sTxt
              SetFocus GetNextDlgTabItem(GetParent(CBHNDL), DateHandle&, 0)
              SendMessage CBHNDL, %BM_SETSTYLE, %BS_PUSHBUTTON, %TRUE
              EXIT FUNCTION
    '          keybd_event %VK_TAB, MapVirtualKey(%VK_TAB, 0), 0, 0: Sleep 0                'key_down msg
    '          keybd_event %VK_TAB, MapVirtualKey(%VK_TAB, 0), %KEYEVENTF_KEYUP, 0: Sleep 0 'key_up msg
    '          keybd_event %VK_TAB, MapVirtualKey(%VK_TAB, 0), 0, 0: Sleep 0                'key_down msg
    '          keybd_event %VK_TAB, MapVirtualKey(%VK_TAB, 0), %KEYEVENTF_KEYUP, 0: Sleep 0 'key_up msg
                
          END SELECT    
          FUNCTION = CallWindowProc(OldProc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
       END FUNCTION
    BOB MECHLER

    Leave a comment:


  • Michael Mattias
    replied
    That border might be a result of the BS_DEFPUSHUTTON style (vs BS_PUSHBUTTON)

    BS_DEFPUSHBUTTON
    Creates a push button that behaves like a BS_PUSHBUTTON style button, but also has a heavy black border. If the button is in a dialog box, the user can select the button by pressing the ENTER key, even when the button does not have the input focus. This style is useful for enabling the user to quickly select the most likely (default) option.
    I seem to recall something like, if you don't make one of your buttons this style, Windows does it for you. But you can change it with the BM_SETSTYLE message.

    But I cannot find this in my SDK doc this AM; maybe you will have better luck.

    MCM

    Leave a comment:


  • BOB MECHLER
    replied
    Well, the following does what I want and leaves no black rim around the button.
    Code:
       CALLBACK FUNCTION NDateButtonProc
          STATIC OldProc AS LONG, OffsetWndExtra AS LONG
          LOCAL Txt AS ASCIIZ * %MAX_PATH, sTxt AS STRING
          LOCAL DateButtonID AS LONG, DateID AS LONG, DescID AS LONG
          LOCAL DateHandle AS LONG
          IF CBHNDL = 0 THEN OldProc = CBWPARAM: OffsetWndExtra = CBLPARAM: EXIT FUNCTION
          DateButtonID& = getdlgctrlid(CBHNDL)
          DateID& = DateButtonID& - (scr_NUM_FLD# * 2 )
          DateHandle& = GetDlgItem(GetParent(CBHNDL),DateID&)
          SELECT CASE CBMSG
            CASE %WM_LBUTTONDOWN
              Call SupDateGetDate()
              Txt = V_DateStr              
              SetWindowText DateHandle&,Txt
              sTxt = NEditDateFormat(DateHandle&)
              SetWindowText DateHandle&, BYCOPY sTxt
              'SetFocus GetNextDlgTabItem(GetParent(CBHNDL), DateHandle&, 0)
              'EXIT FUNCTION
              keybd_event %VK_TAB, MapVirtualKey(%VK_TAB, 0), 0, 0: Sleep 0                'key_down msg
              keybd_event %VK_TAB, MapVirtualKey(%VK_TAB, 0), %KEYEVENTF_KEYUP, 0: Sleep 0 'key_up msg
              keybd_event %VK_TAB, MapVirtualKey(%VK_TAB, 0), 0, 0: Sleep 0                'key_down msg
              keybd_event %VK_TAB, MapVirtualKey(%VK_TAB, 0), %KEYEVENTF_KEYUP, 0: Sleep 0 'key_up msg
                
          END SELECT    
          FUNCTION = CallWindowProc(OldProc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
       END FUNCTION
    Don't know if it's the best solution, but it seems stable.

    BOB MECHLER

    Leave a comment:


  • BOB MECHLER
    replied
    I tried remarking out the EXIT FUNCTION and it just stayed focus on the button and didn't move to textbox and finish it's work. Here is the pertinent code.

    Code:
       CALLBACK FUNCTION NDateButtonProc
          STATIC OldProc AS LONG, OffsetWndExtra AS LONG
          LOCAL Txt AS ASCIIZ * %MAX_PATH, sTxt AS STRING
          LOCAL DateButtonID AS LONG, DateID AS LONG, DescID AS LONG
          LOCAL DateHandle AS LONG
          IF CBHNDL = 0 THEN OldProc = CBWPARAM: OffsetWndExtra = CBLPARAM: EXIT FUNCTION
          DateButtonID& = getdlgctrlid(CBHNDL)
          DateID& = DateButtonID& - (scr_NUM_FLD# * 2 )
          DateHandle& = GetDlgItem(GetParent(CBHNDL),DateID&)
          SELECT CASE CBMSG
            CASE %WM_LBUTTONDOWN
              Call SupDateGetDate()  'CALLS A DIALOG that contains a calendar control and buttons for date codes
              Txt = V_DateStr              
              SetWindowText DateHandle&,Txt
              sTxt = NEditDateFormat(DateHandle&) ' translates any codes returned to real dates (BOM - beginning of month etc)
              SetWindowText DateHandle&, BYCOPY sTxt
              SetFocus GetNextDlgTabItem(GetParent(CBHNDL), DateHandle&, 0)
              'EXIT FUNCTION
          END SELECT    
          FUNCTION = CallWindowProc(OldProc, CBHNDL, CBMSG, CBWPARAM, CBLPARAM)
       END FUNCTION
    BOB MECHLER
    Last edited by BOB MECHLER; 5 Aug 2008, 07:35 PM.

    Leave a comment:


  • BOB MECHLER
    replied
    To give more info this button is a superclassed button that calls a dialog with a 3 month ms calendar control. The calendar control is on a dialog that has several shortcut buttons that return codes like BOM/EOM (beginning of the current month, end of the current month). Clicking a date or one of the shortcut buttons returns either a date or a code for BOM/EOM to a buddy textbox. The button superclass then sets focus to the Date textbox, calls a function to validate the date and moves to the next field using SetFocus. It then does an Exit Function. Works fine except for the left over rim around the 12x12 button.

    Probably serves me right for doing some much in a Superclass.

    Bob Mechler

    Leave a comment:


  • Edwin Knoppert
    replied
    Maybe it has an id of #1 like %IDOK?

    Leave a comment:


  • jcfuller
    replied
    Originally posted by BOB MECHLER View Post
    After clicking a button that pops up another window and dismissing the window the button retains a small thin black line around the control like WS_BORDER puts there but it was not created with that style. Is there a way to get rid of it. Can you do a control send to the button control to remove a style?

    Bob Mechler
    Isn't that part of Focus??

    James

    Leave a comment:


  • BOB MECHLER
    started a topic Remove a style from a button at runtime

    Remove a style from a button at runtime

    After clicking a button that pops up another window and dismissing the window the button retains a small thin black line around the control like WS_BORDER puts there but it was not created with that style. Is there a way to get rid of it. Can you do a control send to the button control to remove a style?

    Bob Mechler
Working...
X