Combobox SDK help

Started by Frank Brübach, July 23, 2024, 08:13:43 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

Good morning.. hello Charles..,

I have built a little combobox SDK Style example. There are two ways I have explored. But I am Not Sure how use the items for displaying the combobox. My list IS still empty..

One little Thing of my Setup is wrong or I am Missing an important Thing for this running one.. , thanks frank


   ' demo test for combobox, sdk modus, by frank bruebach
  ' oxygenbasic, 23-07-2024
  '
  $ filename "t.exe"
  uses Winutil

  #lookahead ' for procedures

    %IDB_BUTTON=1001
    %IDB_COMBO=1002
    %CBS_SIMPLE=23456
    %CBS_SORT=24567
    %CBS_NOINTEGRALHEIGHT=24678
    %CBS_DROPDOWNLIST=24679
  '=========
  'MAIN CODE
  '=========
 
  dim cmdline as asciiz ptr, inst as sys
  @cmdline=GetCommandLine
  inst=GetModuleHandle 0
  '
  'WINDOWS START
  '=============
  '
  WinMain inst,0,cmdline,SW_NORMAL
  end

 
function combobox_addstring(byval hwndcombo as dword , byval ltext as string ) as string
function=sendMessage(hwndcombo,CB_ADDSTRING, 0, ltext ) 'strptr(ltext)
end function
   

sub combobox_setcursel(byval hwndcombo as dword , byval index as long )
sendMessage(hwndcombo,CB_SETCURSEL, index,0 )
end sub


  '--------------------------------------------------------------------
  Function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as sys
  '====================================================================

  WndClass wc
  MSG      wm

  sys hwnd, wwd, wht, wtx, wty, tax
  with wc
  .style = CS_HREDRAW or CS_VREDRAW
  .lpfnWndProc = @WndProc
  .cbClsExtra =0
  .cbWndExtra =0   
  .hInstance =inst
  .hIcon=LoadIcon 0, IDI_APPLICATION
  .hCursor=LoadCursor 0,IDC_ARROW
  .hbrBackground = GetStockObject WHITE_BRUSH
  .lpszMenuName =null
  .lpszClassName = strptr "Demo"
  end with
  sys r=RegisterClass (@wc)
 
  Wwd = 420 : Wht = 300
  Tax = GetSystemMetrics SM_CXSCREEN
  Wtx = (Tax - Wwd) /2
  Tax = GetSystemMetrics SM_CYSCREEN
  Wty = (Tax - Wht) /2
  '
  hwnd = CreateWindowEx 0,wc.lpszClassName,"OXYGEN BASIC",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
  if not hwnd
    mbox "Unable to create window"
    exit function
  end if
  '
  ShowWindow hwnd,SW_SHOW
  UpdateWindow hwnd
  '
  sys bRet
  '
  do while bRet := GetMessage (@wm, 0, 0, 0)
    if bRet = -1 then
      'show an error message
    else
      TranslateMessage @wm
      DispatchMessage @wm
    end if
  wend

  End Function

  '#recordof winmain
  '#recordof wndproc



  dim as rect crect 'for WndProc and TimerProc

  '------------------------------------------------------------------
  function WndProc ( sys hWnd, wMsg, wParam, lparam ) as sys callback
  '==================================================================

    static as sys hdc
    static as String txt
    static as PaintStruct Paintst
    'sys hfont as long
 
    '==========
    select wMsg
    '==========
       
      '--------------
      case WM_CREATE
      '=============

            SetWindowText(hwnd, "Button and Combobox")

            sys hInstance = GetWindowLongPtr(hWnd, GWL_HINSTANCE)

            sys hWndStdButton = CreateWindowEx(
            0,
            "BUTTON",
            "test button",
            WS_VISIBLE or WS_CHILD,
            10,  10,
            120, 24,
            hWnd,
            IDB_BUTTON,
            hInstance,
            NULL)

'            sys hfont
'            SendMessage(hWndStdCombo, WM_SETFONT, hFont, TRUE)

            sys hWndStdCombo = CreateWindowEx(
            0,
            "Combobox",
            "Test",
            WS_CHILD or WS_VISIBLE or WS_BORDER or ES_AUTOHSCROLL or WS_HSCROLL or WS_VSCROLL _
            OR ES_MULTILINE OR WS_TABSTOP OR CBS_SIMPLE OR CBS_SORT, ''_ '%CBS_DROPDOWNLIST,
            10,  130,
            120, 124,
            hWnd,
            IDB_COMBO,
            hInstance, 'GetWindowLongPtr(hWnd, GWL_HINSTANCE),
            NULL)

'---------------------------- 1. way ------------------------------------------------------------- //
           
        ' Add items to the combobox
            Dim combItem As String
            combItem = "Ironman"     : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Thor"        : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Spiderman"   : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Black Widow" : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Batman"      : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Captain America" : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Captain Marvel" : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
   
        ' Set the current selection
            SendMessage(hWndStdCombo, CB_SETCURSEL, 1, 0)
            SendMessage(hWndStdCombo, WM_SETREDRAW, true, 0) 'important


'---------------------------- 2. way ------------------------------------------------------------- //

    ' // Fill the control with some data
    ' Add items to the combobox using a loop
        'Dim wszText As String
        DIM wszText[80] AS STRING
        int i
        For i = 1 To 9
            wszText = "Marvel " + Right("00" + Str(i), 2)
            SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(wszText))
        Next

    ' Set the current selection
        SendMessage(hWndStdCombo, CB_SETCURSEL, 1, 0)
        SendMessage(hWndStdCombo, WM_SETREDRAW, true, 0) 'important


   case WM_COMMAND
            select case loword(wParam)
                case IDB_BUTTON
                    select case hiword(wParam)
                        case BN_CLICKED
                            MessageBox(NULL, "Selected Button", "testmy Button", MB_OK or MB_ICONINFORMATION)
                    end select
           end select

      '-------------- 
      case WM_DESTROY
      '===============
         
      PostQuitMessage 0
       
      '------------
      case WM_PAINT
      '============


      'TEXT
      'http://msdn.microsoft.com/en-us/library/dd144821(v=VS.85).aspx

      'DRAWING AND PAINTING
      'http://msdn.microsoft.com/en-us/library/dd162760(v=VS.85).aspx

      GetClientRect  hWnd,&cRect
      hDC=BeginPaint hWnd,&Paintst
      'style
      '0x20 DT_SINGLELINE
      '0x04 DT_VCENTER
      '0x01 DT_CENTER
      '0x25

       SetBkColor   hdc,yellow
       SetTextColor hdc,red
       DrawText hDC,"Hello World!",-1,&cRect,0x25
       EndPaint hWnd,&Paintst
       
      '--------------   
      case WM_KEYDOWN
      '==============

      '============           
      Select wParam
      '============

    Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE

      End Select
     

      '--------       
      case else
      '========
         
        function=DefWindowProc hWnd,wMsg,wParam,lParam
       
    end select

  end function

 

Charles Pegge

Hi Frank,

something wrong with your style codes:

            WS_CHILD or WS_VISIBLE or WS_BORDER or ES_AUTOHSCROLL or WS_HSCROLL or WS_VSCROLL, '*** ok
            'WS_CHILD or WS_VISIBLE or WS_BORDER or ES_AUTOHSCROLL or WS_HSCROLL or WS_VSCROLL _
            'OR ES_MULTILINE OR WS_TABSTOP OR CBS_SIMPLE OR CBS_SORT, ''_ '%CBS_DROPDOWNLIST,

Frank Brübach

Thanks Charles found the solution some minutes ago.. yes the Style Codes were wrong I placed them First  only AS Dummy but its so important I See

I looked at msdn Pages and found pub const %cbs_sort = 256i32 for example..

  ' demo test2 GO for combobox, sdk modus, by frank bruebach
  ' oxygenbasic, 23-07-2024
  '
  $ filename "t.exe"
  uses Winutil

  #lookahead ' for procedures

    %IDB_BUTTON=1001
    %IDB_COMBO=1002
   %cbs_sort= 256i32
   %CBS_DROPDOWN= 2i32
   %CBS_SIMPLE= dword 0x0001

   ' pub const %cbs_sort i32 = 256i32 commctrl.h
   ' cbs_simple dword = 0x0001
   ' cbs_dropdown i32 = 2i32
   ' 
  '=========
  'MAIN CODE
  '=========
 
  dim cmdline as asciiz ptr, inst as sys
  @cmdline=GetCommandLine
  inst=GetModuleHandle 0
  '
  'WINDOWS START
  '=============
  '
  WinMain inst,0,cmdline,SW_NORMAL
  end

 
function combobox_addstring(byval hwndcombo as dword , byval ltext as string ) as string
function=sendMessage(hwndcombo,CB_ADDSTRING, 0, ltext ) 'strptr(ltext)
end function
   

sub combobox_setcursel(byval hwndcombo as dword , byval index as long )
sendMessage(hwndcombo,CB_SETCURSEL, index,0 )
end sub


  '--------------------------------------------------------------------
  Function WinMain(sys inst, prevInst, asciiz*cmdline, sys show) as sys
  '====================================================================

  WndClass wc
  MSG      wm

  sys hwnd, wwd, wht, wtx, wty, tax
  with wc
  .style = CS_HREDRAW or CS_VREDRAW
  .lpfnWndProc = @WndProc
  .cbClsExtra =0
  .cbWndExtra =0   
  .hInstance =inst
  .hIcon=LoadIcon 0, IDI_APPLICATION
  .hCursor=LoadCursor 0,IDC_ARROW
  .hbrBackground = GetStockObject WHITE_BRUSH
  .lpszMenuName =null
  .lpszClassName = strptr "Demo"
  end with
  sys r=RegisterClass (@wc)
 
  Wwd = 420 : Wht = 300
  Tax = GetSystemMetrics SM_CXSCREEN
  Wtx = (Tax - Wwd) /2
  Tax = GetSystemMetrics SM_CYSCREEN
  Wty = (Tax - Wht) /2
  '
  hwnd = CreateWindowEx 0,wc.lpszClassName,"OXYGEN BASIC",WS_OVERLAPPEDWINDOW,Wtx,Wty,Wwd,Wht,0,0,inst,0
  if not hwnd
    mbox "Unable to create window"
    exit function
  end if
  '
  ShowWindow hwnd,SW_SHOW
  UpdateWindow hwnd
  '
  sys bRet
  '
  do while bRet := GetMessage (@wm, 0, 0, 0)
    if bRet = -1 then
      'show an error message
    else
      TranslateMessage @wm
      DispatchMessage @wm
    end if
  wend

  End Function

  '#recordof winmain
  '#recordof wndproc



  dim as rect crect 'for WndProc and TimerProc

  '------------------------------------------------------------------
  function WndProc ( sys hWnd, wMsg, wParam, lparam ) as sys callback
  '==================================================================

    static as sys hdc
    static as String txt
    static as PaintStruct Paintst
    'sys hfont as long
 
    '==========
    select wMsg
    '==========
       
      '--------------
      case WM_CREATE
      '=============

            SetWindowText(hwnd, "Button and Combobox")

            sys hInstance = GetWindowLongPtr(hWnd, GWL_HINSTANCE)

            sys hWndStdButton = CreateWindowEx(
            0,
            "BUTTON",
            "test button",
            WS_VISIBLE or WS_CHILD,
            10,  10,
            120, 24,
            hWnd,
            IDB_BUTTON,
            hInstance,
            NULL)

'            sys hfont
'            SendMessage(hWndStdCombo, WM_SETFONT, hFont, TRUE)

            sys hWndStdCombo = CreateWindowEx(
            0,
            "Combobox",
            "Test",
            WS_CHILD or WS_VISIBLE or WS_BORDER or ES_AUTOHSCROLL or WS_HSCROLL or WS_VSCROLL _
            OR ES_MULTILINE OR WS_TABSTOP OR CBS_SIMPLE OR CBS_SORT, ''_ '%CBS_DROPDOWNLIST,
            10,  130,
            120, 124,
            hWnd,
            IDB_COMBO,
            hInstance, 'GetWindowLongPtr(hWnd, GWL_HINSTANCE),
            NULL)

'---------------------------- 1. way ------------------------------------------------------------- //
           
        ' Add items to the combobox
            Dim combItem As String
            combItem = "Ironman"     : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Thor"        : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Spiderman"   : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Black Widow" : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Batman"      : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Captain America" : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
            combItem = "Captain Marvel" : SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(combItem))
   
        ' Set the current selection
            SendMessage(hWndStdCombo, CB_SETCURSEL, 1, 0)
            SendMessage(hWndStdCombo, WM_SETREDRAW, true, 0) 'important


'---------------------------- 2. way ------------------------------------------------------------- //

    ' // Fill the control with some data
    ' Add items to the combobox using a loop
        'Dim wszText As String
        DIM wszText[80] AS STRING
        int i
        For i = 1 To 9
            wszText = "Marvel " + Right("00" + Str(i), 2)
            SendMessage(hWndStdCombo, CB_ADDSTRING, 0, STRPtr(wszText))
        Next

    ' Set the current selection
        SendMessage(hWndStdCombo, CB_SETCURSEL, 1, 0)
        SendMessage(hWndStdCombo, WM_SETREDRAW, true, 0) 'important


   case WM_COMMAND
            select case loword(wParam)
                case IDB_BUTTON
                    select case hiword(wParam)
                        case BN_CLICKED
                            MessageBox(NULL, "Selected Button", "testmy Button", MB_OK or MB_ICONINFORMATION)
                    end select
           end select

      '-------------- 
      case WM_DESTROY
      '===============
         
      PostQuitMessage 0
       
      '------------
      case WM_PAINT
      '============


      'TEXT
      'http://msdn.microsoft.com/en-us/library/dd144821(v=VS.85).aspx

      'DRAWING AND PAINTING
      'http://msdn.microsoft.com/en-us/library/dd162760(v=VS.85).aspx

      GetClientRect  hWnd,&cRect
      hDC=BeginPaint hWnd,&Paintst
      'style
      '0x20 DT_SINGLELINE
      '0x04 DT_VCENTER
      '0x01 DT_CENTER
      '0x25

       SetBkColor   hdc,yellow
       SetTextColor hdc,red
       DrawText hDC,"Hello World!",-1,&cRect,0x25
       EndPaint hWnd,&Paintst
       
      '--------------   
      case WM_KEYDOWN
      '==============

      '============           
      Select wParam
      '============

    Case 27 : SendMessage hwnd, WM_CLOSE, 0, 0      'ESCAPE

      End Select
     

      '--------       
      case else
      '========
         
        function=DefWindowProc hWnd,wMsg,wParam,lParam
       
    end select

  end function