Announcement

Collapse
No announcement yet.

SDK equivalent for CONTROL ENABLE/DISABLE

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

  • Michael Mattias
    replied
    These are examples of what is working for me:
    Code:
    EnableWindow (GetDlgItem (hDlg, 612), 1)
    EnableWindow (GetDlgItem (hDlg, 610), 0)
    That might be working for you, but I really really really think you should get out of the habit of using in-line numeric literals - aka "magic numbers" - in your code.

    When you have to go back to that code in six months, won't t be a lot easier to understand were it to read....
    Code:
    EnableWindow (GetDlgItem (hDlg, %ID_NAME), %TRUE)
    EnableWindow (GetDlgItem (hDlg, %ID_ADDRESS), %FALSE)
    ????

    Leave a comment:


  • Edwin Knoppert
    replied
    You may somewhat think as windows and their controls are often accessed by hWnd's only.
    For dialogs the combination hDlg+CtrlID is more common.
    Therefore the calls contain 'dlg' in these names.

    This is a no-discussion though since in practise these calls are very exchangable.
    I think i can find a few real dlg-only calls but for the usual stuff it works on custom window classes as dialogboxes.

    I think the hDlg+CtrlID is more or less invented for use with dialog resources/templates.
    Using plain SDK windows stuff usually CreateWindow() is used, eventually without controlid.

    You won't see much code without ctrl-id's nowadays (if any).

    This is all speculative, just forget..

    Leave a comment:


  • Gary Peek
    replied
    Now I get it.

    OK, I get it now. I was confused by your use of "cbhndl"

    These are examples of what is working for me:
    EnableWindow (GetDlgItem (hDlg, 612), 1)
    EnableWindow (GetDlgItem (hDlg, 610), 0)

    I knew about EnableWindow, I was just lacking the GetDlgItem part.

    Leave a comment:


  • Fred Harris
    replied
    Also, at...

    http://www.powerbasic.com/support/pb...ad.php?t=36717

    is a fun little program that ties about 20 check boxes to a bit field variable and shows the status (checked/unchecked) and numeric value of variable in an output window simultaneously. When the output window is open it EnableWindow(hButton, %FALSE) 's the button that created the output window so you can only create one output window. If you are just getting into SDK style maybe it'll help.

    Also, here is another program that uses EnableWindow()

    Code:
    #Compile           Exe
    #Dim               All
    #Include           "Win32api.inc"
    %IDC_BUTTON1       =  2000
    %IDC_BUTTON2       =  2005
    %IDC_BUTTON3       =  2010
    
    
    Type WndEventArgs
      wParam           As Long          'Package parameters to Window Procedure in TYPE
      lParam           As Long
      hWnd             As Dword
      hInst            As Dword
    End Type
    
    
    Function fnForm1_WndProc(Byval hWnd As Long,Byval wMsg As Long,Byval wParam As Long,Byval lParam As Long) As Long
      Select Case As Long wMsg
        Case %WM_CREATE
           Local lpCreateStruct As CREATESTRUCT Ptr          'Window Procedure For Form1.  Form1 Disables
           Local ptrMain As Dword Ptr                        'THe Main Window here in WM_CREATE.  Note that
           lpCreateStruct=lParam                             'It Receives A Pointer To The hWnd of The Main
           [email protected]            'Window In lpCreateParams, Which It Stores in
           Call SetWindowLong(hWnd,0,@ptrMain)               'Its cbWndExtra Bytes.
           EnableWindow(@ptrMain,%FALSE)
           fnForm1_WndProc=0
           Exit Function
        Case %WM_PAINT
          Local iLEN As Long, hDC As Long
          Local LpPaint As PAINTSTRUCT
          Local rc As Rect
          hDC = BeginPaint(hWnd, LpPaint)
          rc.nTop=0 : rc.nBottom=16 : rc.nLeft=0 : rc.nRight=300
          Call DrawText(hDC,"This Is Form1.  It Disables The Main",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Window, And That Makes It Modal.",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Note That A Pointer To The Main hWnd",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Was Received During %WM_CREATE ",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"And Stored In The cbWndExtra Bytes.",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"We'll Need That To Call EnableWindow()",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Upon Destruction Of This Dialog.",-1,rc,%DT_SINGLELINE)
          Call EndPaint(hWnd,LpPaint)
          fnForm1_WndProc = 0
          Exit Function
        Case %WM_CHAR
          If Lowrd(wParam)=27 Or Lowrd(wParam)=13 Then           'Send WM_CLOSE Message
             Call SendMessage(hWnd,%WM_CLOSE,wParam,lParam)      'If [ESC] Or [ENTER]
          End If                                                 'Comes 
        Case %WM_CLOSE
          Local hMain As Dword
          If MsgBox("Do You Wish To Destroy This Window?",%MB_YESNO,"Destroy Window")=%IDYES Then
             hMain=GetWindowLong(hWnd,0)
             EnableWindow(hMain,%TRUE)
             fnForm1_WndProc=0
             Call DestroyWindow(hWnd)
          End If
          Exit Function
      End Select
    
      fnForm1_WndProc=DefWindowProc(hWnd, wMsg, wParam, lParam)
    End Function
    
    
    Function fnForm2_WndProc(Byval hWnd As Long,Byval wMsg As Long,Byval wParam As Long,Byval lParam As Long) As Long
      Select Case As Long wMsg
        Case %WM_CREATE
          Local lpCreateStruct As CREATESTRUCT Ptr          'Window procedure for Form2.  This
          Local ptrMain As Dword Ptr                        'Window SW_HIDEs The Main Window
          lpCreateStruct=lParam                             'In WM_CREATE.  It Also Stores 
          [email protected]            'The hWnd Main Window in cbWndExtra
          Call SetWindowLong(hWnd,0,@ptrMain)               'Bytes
          Call ShowWindow(@ptrMain,%SW_HIDE)
          fnForm2_WndProc=0
          Exit Function
        Case %WM_CHAR
          If Lowrd(wParam)=27 Or Lowrd(wParam)=13 Then
             Call SendMessage(hWnd,%WM_CLOSE,wParam,lParam)
          End If   
        Case %WM_PAINT
          Local hDC As Long
          Local LpPaint As PAINTSTRUCT                 
          Local rc As Rect
          hDC = BeginPaint(hWnd, LpPaint)
          rc.nTop=0 : rc.nBottom=16 : rc.nLeft=0 : rc.nRight=300
          Call DrawText(hDC,"This Is Form2.  It %SW_HIDEs The",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Main Window, And %SW_SHOWs It",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Upon Closing.  The Technique Can",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Be Used Similiarly To A Modal ",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Dialog If It Isn't Necessary To",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"View Simultaneously A Form Under-",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"neath The Dialog With Which You",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Can't Interact Anyway.",-1,rc,%DT_SINGLELINE)
          Call EndPaint(hWnd,LpPaint)
          fnForm2_WndProc = 0
          Exit Function
        Case %WM_CLOSE
          Local hMain As Dword
          If MsgBox("Do You Wish To Destroy This Window?",%MB_YESNO,"Destroy Window")=%IDYES Then
             hMain=GetWindowLong(hWnd,0)
             Call ShowWindow(hMain,%TRUE)
             Call DestroyWindow(hWnd)
             fnForm2_WndProc=0
          Else
             Exit Function
          End If
      End Select
    
     fnForm2_WndProc=DefWindowProc(hWnd,wMsg,wParam,lParam)
    End Function
    
    
    Function fnForm3_WndProc(Byval hWnd As Long,Byval wMsg As Long,Byval wParam As Long,Byval lParam As Long) As Long
      Local lpCreateStruct As CREATESTRUCT Ptr
      Local iLEN As Long, hDC As Long                    'These Windows Are Produced By 
      Local LpPaint As PAINTSTRUCT                       'Clicking Button #3 On Main
      Local rc As Rect                                   'Form.  You Can Create As Many
                                                         'Of Them As You Like, But They
      Select Case wMsg                                   'Will Be Created In The Same
        Case %WM_CHAR                                    'Place, So To See Them You Have
          If Lowrd(wParam)=27 Or Lowrd(wParam)=13 Then   'To Drag Them From on Top Of One
             Call SendMessage(hWnd,%WM_CLOSE,wParam,lParam)  'And Other
          End If  
        Case %WM_PAINT
          hDC = BeginPaint(hWnd, LpPaint)
          rc.nTop=0 : rc.nBottom=16 : rc.nLeft=0 : rc.nRight=300
          Call DrawText(hDC,"This Is Form3.  Not Only Does It",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Neither Hide Nor Disable The Main",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Window, But You'll Find That You",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Can Create As Many Of These As You",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Want By Continually Clicking Button",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Number Three!  Only Thing Is, You'll",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Have To Drag Them From On Top Of Each",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Other, As They All Appear In The Same",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Location.  You May Further Note That",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Since These Windows Are Neither",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"Disabled Nor Hidden At Any Time, You",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"May Interact With Them Irregardless Of",-1,rc,%DT_SINGLELINE)
          rc.nTop=rc.nTop+16 : rc.nBottom=rc.nTop+16
          Call DrawText(hDC,"The State Of Form1 Or Form2",-1,rc,%DT_SINGLELINE)
          Call EndPaint(hWnd,LpPaint)
          fnForm3_WndProc = 0
          Exit Function
      End Select
    
      fnForm3_WndProc=DefWindowProc(hWnd, wMsg, wParam, lParam)
    End Function
    
    
    Function fnWndProc_OnCreate(Wea As WndEventArgs) As Long       'Creates the three buttons and registers window
      Local lpCreateStruct As CREATESTRUCT Ptr                     'classes for the three Forms/Windows/Dialogs the
      Local szClassName As Asciiz*16                               'app will create if the corresponding button is
      Local winclass As WndClassEx                                 'pressed
      Local hWnd As DWORD
    
      lpCreateStruct=Wea.lParam   'Can use GetModuleHandle() here instead, or, use Global (Hate Globals!)
      [email protected]
      hWnd=CreateWindow("button","Button 1",%WS_CHILD Or %WS_VISIBLE,50,25,125,25,Wea.hWnd,%IDC_BUTTON1,Wea.hInst,Byval 0)
      hWnd=CreateWindow("button","Button 2",%WS_CHILD Or %WS_VISIBLE,50,60,125,25,Wea.hWnd,%IDC_BUTTON2,Wea.hInst,Byval 0)
      hWnd=CreateWindow("button","Button 3",%WS_CHILD Or %WS_VISIBLE,50,95,125,25,Wea.hWnd,%IDC_BUTTON3,Wea.hInst,Byval 0)
      'Register Window Classes For Form1, Form2 and Form3
      winclass.cbSize=Sizeof(winclass)
      winclass.style=%CS_HREDRAW Or %CS_VREDRAW
      winclass.cbClsExtra=0
      winclass.cbWndExtra=4
      winclass.hInstance=Wea.hInst
      winclass.hIcon=LoadIcon(%NULL, Byval %IDI_APPLICATION)
      winclass.hCursor=LoadCursor(%NULL, Byval %IDC_ARROW)
      winclass.hbrBackground=GetStockObject(%WHITE_BRUSH)
      winclass.lpszMenuName=%NULL
      szClassName="Form1"                                          'Register Form1 Class
      winclass.lpszClassName=Varptr(szClassName)
      winclass.lpfnWndProc=Codeptr(fnForm1_WndProc)
      Call RegisterClassEx(winclass)
      szClassName="Form2"                                          'Register Form2 Class
      winclass.lpszClassName=Varptr(szClassName)
      winclass.lpfnWndProc=Codeptr(fnForm2_WndProc)
      Call RegisterClassEx(winclass)
      szClassName="Form3"                                          'Register Form3 Class
      winclass.lpszClassName=Varptr(szClassName)
      winclass.lpfnWndProc=Codeptr(fnForm3_WndProc)
      Call RegisterClassEx(winclass)
      
      fnWndProc_OnCreate=0
    End Function
    
    
    Function fnWndProc_OnCommand(Wea As WndEventArgs) As Long
      Local hWnd As Dword   
      
      Select Case Lowrd(Wea.wParam)
        Case %IDC_BUTTON1                  'Button 1 was clicked
          hWnd=CreateWindow("Form1","Form1",%WS_OVERLAPPEDWINDOW,50,25,300,175,Wea.hWnd,0,Wea.hInst,Varptr(Wea.hWnd))
          Call ShowWindow(hWnd,%SW_SHOWNORMAL)
          Call UpdateWindow(hWnd)
        Case %IDC_BUTTON2                  'Button 2 was clicked
          hWnd=CreateWindow("Form2","Form2",%WS_OVERLAPPEDWINDOW,150,150,300,175,Wea.hWnd,0,Wea.hInst,Varptr(Wea.hWnd))
          Call ShowWindow(hWnd,%SW_SHOWNORMAL)
          Call UpdateWindow(hWnd)
        Case %IDC_BUTTON3                  'Button 3 was clicked
          hWnd=CreateWindow("Form3","Form3",%WS_OVERLAPPEDWINDOW,300,500,300,250,Wea.hWnd,0,Wea.hInst,Varptr(Wea.hWnd))
          Call ShowWindow(hWnd,%SW_SHOWNORMAL)
          Call UpdateWindow(hWnd)
      End Select
      
      fnWndProc_OnCommand=0
    End Function
    
    
    Function fnWndProc_OnClose(Wea As WndEventArgs) As Long   'Windows will send this message when the 'x' is clicked
      Call DestroyWindow(Wea.hWnd)
      Call PostQuitMessage(0)
      
      fnWndProc_OnClose=0
    End Function
    
    
    Function fnWndProc(Byval hWnd As Long,Byval wMsg As Long,Byval wParam As Long,Byval lParam As Long) As Long
      Static Wea As WndEventArgs
    
      Select Case wMsg
        Case %WM_CREATE
          Wea.hWnd=hWnd : Wea.wParam=wParam : Wea.lParam=lParam
          fnWndProc=fnWndProc_OnCreate(Wea)
          Exit Function
        Case %WM_COMMAND
          Wea.hWnd=hWnd : Wea.wParam=wParam : Wea.lParam=lParam
          fnWndProc=fnWndProc_OnCommand(Wea)
          Exit Function
        Case %WM_CLOSE
          Wea.hWnd=hWnd : Wea.wParam=wParam : Wea.lParam=lParam
          fnWndProc=fnWndProc_OnClose(Wea)
          Exit Function
      End Select
    
      fnWndProc=DefWindowProc(hWnd, wMsg, wParam, lParam)
    End Function
    
    
    Function WinMain(Byval hIns As Long, Byval hPrev As Long,Byval lpCL As Asciiz Ptr,Byval iShow As Long) As Long
      Local Msg As tagMsg
      Local winclass As WndClassEx
      Local szAppName As Asciiz * 16
      Local hWnd As Dword
    
      szAppName="Form9"
      winclass.lpszClassName=Varptr(szAppName)               : winclass.lpfnWndProc=Codeptr(fnWndProc)
      winclass.cbSize=Sizeof(winclass)                       : winclass.style=%CS_HREDRAW Or %CS_VREDRAW
      winclass.cbClsExtra=0                                  : winclass.cbWndExtra=0
      winclass.hInstance=hIns                                : winclass.hIcon=LoadIcon(%NULL, Byval %IDI_APPLICATION)
      winclass.hCursor=LoadCursor(%NULL, Byval %IDC_ARROW)   : winclass.hbrBackground=%COLOR_BTNFACE+1
      winclass.lpszMenuName=%NULL                            : winclass.hIconSm=LoadIcon(hIns, Byval %IDI_APPLICATION)
      Call RegisterClassEx(winclass)
      hWnd=CreateWindow(szAppName,"Form9",%WS_OVERLAPPEDWINDOW,450,300,240,190,0,0,hIns,Byval 0)
      Call ShowWindow(hWnd,iShow)
      Call UpdateWindow(hWnd)
      While GetMessage(Msg,%NULL,0,0)
        Call TranslateMessage(Msg)
        Call DispatchMessage(Msg)
      Wend
    
      Function=msg.wParam
    End Function

    Leave a comment:


  • Edwin Knoppert
    replied
    >If that's the only way to do it
    it is..

    Sending the message is a no-no, since Windows will send this message when you use this api.
    It's a response by Windows.

    Leave a comment:


  • Fred Harris
    replied
    Just use the handle of the control for the 1st param, and %TRUE/%FALSE for the 2nd...

    Code:
    EnableWindow
    
    The EnableWindow function enables or disables mouse and keyboard input to the specified window or 
    control. When input is disabled, the window does not receive input such as mouse clicks and key 
    presses. When input is enabled, the window receives all input. 
    
    BOOL EnableWindow
    (
      HWND hWnd,     // handle to window
      BOOL bEnable   // flag for enabling or disabling input
    );
     
    Parameters
    hWnd      Handle to the window to be enabled or disabled. 
    bEnable   Specifies whether to enable or disable the window. If this parameter is TRUE, the window is 
                 enabled. If the parameter is FALSE, the window is disabled.
     
    Return Values
    
    If the window was previously disabled, the return value is nonzero.  If the window was not previously 
    disabled, the return value is zero. To get extended error information, callGetLastError.

    Leave a comment:


  • Gary Peek
    replied
    "cbhndl" however is a DDT thing. How does one specify the control within the window in SDK style? (If that's the only way to do it, I believe you, and thank you, but it seems there should be an SDK method.
    )

    Leave a comment:


  • Edwin Knoppert
    replied
    To be clear:

    EnableWindow( GetDlgItem( cbhndl, %ID.. ), 0 )

    Or 1 to enable

    Leave a comment:


  • Kev Peel
    replied
    EnableWindow

    Leave a comment:


  • Gary Peek
    started a topic SDK equivalent for CONTROL ENABLE/DISABLE

    SDK equivalent for CONTROL ENABLE/DISABLE

    I searched a while in the forums but did not find anything.

    CONTROL ENABLE hDlg, id&
    and
    CONTROL DISABLE hDlg, id&
    work great for DDT.

    I am trying to do the equivalent for SDK.
    I found the following can enable and disable text boxes (EDITTEXT):
    SendDlgItemMessage hDlg, id&, %WM_ENABLE, 0, 0
    and
    SendDlgItemMessage hDlg, id& %WM_ENABLE, 1, 0

    but is not working for a CONTROL with the attribute BS_AUTOCHECKBOX.

    Any suggestions?
Working...
X