To Derek: Win32lib ComboBoxEx

new topic     » topic index » view thread      » older message » newer message

Hi Derek,

I think ComboBoxEx does not work correctly in Win32lib. I tried to add
Hints for the ComboBoxEx example in the Demo folder of Win32lib, which
does not work. I also did not manage to add SetHandlers in the example
program. In the Combo.exw demo I changed Cmbo to type ComboBoxEx and
made the changes for onClick_ABtn and addItem() but the events for
onChange_Cmbo will not work either. (w32HEvent in some cases)

Probably subClassControl in createEx() does not work quite correctly in
the case of ComboBoxEx, no matter if applying as EditText or
DropDownList. I learned that ComboBoxEx combines a combo control and an
edit control. I know that I can get the handles by sending
CBM_GETCOMBOCONTROL and CBM_GETEDITCONTROL messages. Actually there are
two Hints possible, one for the edit field and one for picture and
button. The way Win32lib works in the moment, for some reason the notify
messages are not processed in fDoNotify and fDoTTN_GETDISPINFO (missing
id(s)?).

Maybe the subClassControl function should be adapted a little bit for
getting the ids and hwnds of a ComboBoxEx? But maybe it is necessary to
do a similar approach as with TrewView using something like tv_id?

I have added an example of a working ComboBoxEx to show the expected
results. I coded in the 'WinFunA' style which is easier for me to
understand and saves me some lines of code. If not using the WinFunA
functions there should be no problem to convert into plain Euphoria. The
function ao() returns the address of a structure. The program can be run
with or without bitmap. Perhaps this example could be of some help in
some way?

-- Roland Stowasser


-- ComboEx2
-- two examples ported from BCX and joined together
-- tooltips in ComboBoxEx

include WinFuna.ew

-- perhaps missing function in wfa_comctl32.ew
constant ImageList_LoadImage_ =
         def_c_func(comctl32, "ImageList_LoadImage",
                              {HINSTANCE,LPCSTR,INT,INT,
                             COLORREF,UINT,UINT}, HIMAGELIST)

global function ImageList_LoadImage(atom hi,atom lpbmp,atom cx,
                       atom cGrow, atom crMask,atom uType,atom uFlags)
      return call_c_func(ImageList_LoadImage_, {hi,lpbmp,cx,
                                        cGrow,crMask,uType,uFlags} )
end function
--

constant MAX_ITEMS = 10
constant NUM_ICONS = 10
constant CX_ICON = 24


atom hWnd_ToolTip hWnd_ToolTip = NULL
atom TTType

function ToolTip_Create(atom hWnd)

       TTType = TTS_ALWAYSTIP + 64      -- cartoon-like captions
       if hWnd_ToolTip = NULL  then
          if hWnd = NULL  then
             hWnd=GetActiveWindow()
          end if
          if hWnd = NULL  then
              return 0
          end if
        hWnd_ToolTip=CreateWindowEx( 0,TEXT("tooltips_class32"),TEXT(""),
                                       TTType,0,0,0,0,hWnd,0,
                                  GetWindowLong( hWnd,GWL_HINSTANCE ),0 )
       end if
       return hWnd_ToolTip

end function

procedure ToolTip_SetToolTip(atom hWnd, sequence Text)
cstruct ti

       ti=struct(TOOLINFO)
       SetLastError( 0 )
       if ToolTip_Create(GetParent( hWnd )) = 0  then
          return
       end if

       store(ti,"cbSize",sizeOf(ti))
       store(ti,"uFlags",TTF_SUBCLASS + TTF_IDISHWND)
       store(ti,"hwnd",GetParent( hWnd ))
       store(ti,"uId",hWnd)
       if SendMessage( hWnd_ToolTip,TTM_GETTOOLINFO,0,ao(ti) ) then
          VOID = SendMessage( hWnd_ToolTip,TTM_DELTOOL,0,ao(ti) )
       end if
       store(ti,"cbSize",sizeOf(ti))
       store(ti,"uFlags",TTF_SUBCLASS + TTF_IDISHWND)
       store(ti,"hwnd",GetParent( hWnd ))
       store(ti,"uId",hWnd)
       store(ti,"lpszText",Text)
       VOID = SendMessage( hWnd_ToolTip,TTM_ADDTOOL,0,ao(ti) )

end procedure


atom Form1
atom CBE
sequence AppClassName

procedure Show(atom Window)
       RedrawWindow(Window,0,0,0)
       ShowWindow(Window,SW_SHOW)
end procedure


atom WndProc

function create_Form(sequence Caption,
                        atom left,atom top,atom width,atom height,
                        atom Style,atom Exstyle)
atom Win

       if Style = 0 then
          Style= WS_MINIMIZEBOX + WS_SIZEBOX + WS_CAPTION +
                 WS_MAXIMIZEBOX + WS_POPUP   + WS_SYSMENU
       end if
       Win = CreateWindowEx(Exstyle,TEXT(AppClassName),TEXT(Caption),
                                         Style, left, top, width, height,
                                         NULL,NULL,instance(),NULL)
       if not Win then
          VOID = message_box("Cannot CreateWindowEx " & AppClassName,
                             "Error", MB_OK + MB_ICONERROR)
          abort(0)
       end if

       free_TEXT()
       return Win

end function

function create_Control(sequence Class,atom hWnd,sequence Caption,
                      atom id, atom left,atom top,atom width,atom height,
                           atom Style,atom Exstyle)
atom control

       if Style = 0 then
         Style = WS_CHILD+WS_VISIBLE+WS_CLIPCHILDREN+WS_CLIPSIBLINGS
       end if
       control=CreateWindowEx(Exstyle,TEXT(Class),TEXT(Caption),Style,
                              left, top, width, height,
                              hWnd, id, instance(), NULL)

       if not control then
          VOID = message_box("Cannot CreateWindowEx " & AppClassName,
                             "Error", MB_OK + MB_ICONERROR)
          abort(0)
       end if

       free_TEXT()

       return control

end function


--//struct ITEMINFO

global constant ITEMINFO = {
{ "iImage",
     "iSelectedImage",
     "iIndent",
     "pszText"},
{{  0, INT_   },  -- iImage
    {  4, INT_   },  -- iSelectedImage
    {  8, INT_   },  -- iIndent
    { 12, LPSZ_  }}, -- pszText
16,  -- size
0   -- address
}

--//end struct ITEMINFO


procedure AddItems()
cstruct cbei
cstruct IInf
atom himl

       cbei = struct(COMBOBOXEXITEM)
       store(cbei,"mask", CBEIF_TEXT+CBEIF_INDENT
                         +CBEIF_IMAGE+CBEIF_SELECTEDIMAGE)

       IInf = array_struct(ITEMINFO, MAX_ITEMS)

       fill_struct(IInf[1], {0,3,0,"first"} )
       fill_struct(IInf[2], {1,4,1,"second"} )
       fill_struct(IInf[3], {2,5,2,"third"} )
       fill_struct(IInf[4], {0,3,0,"fourth"} )
       fill_struct(IInf[5], {1,4,1,"fifth"} )
       fill_struct(IInf[6], {2,5,2,"sixth"} )
       fill_struct(IInf[7], {0,3,0,"seventh"} )
       fill_struct(IInf[8], {1,4,1,"eighth"} )
       fill_struct(IInf[9], {2,5,2,"ninth"} )
       fill_struct(IInf[10], {0,3,0,"tenth"} )


--    himl = ImageList_LoadImage(NULL, TEXT(""), CX_ICON, NUM_ICONS,
--                          CLR_NONE, IMAGE_BITMAP, LR_LOADFROMFILE)
      himl = ImageList_LoadImage(NULL,TEXT("hand.bmp"),CX_ICON,NUM_ICONS,
                               CLR_NONE, IMAGE_BITMAP, LR_LOADFROMFILE)

       for iCnt =1 to MAX_ITEMS do

           store(cbei,"iItem",iCnt-1) -- zero based
           store(cbei,"pszText",fetch(IInf[iCnt],"pszText"))
           store(cbei,"cchTextMax",length(fetch(IInf[iCnt],"pszText")))
--      store(cbei,"iImage",iCnt-1)
--      store(cbei,"iSelectedImage",iCnt-1)
           store(cbei,"iIndent",fetch(IInf[iCnt],"iIndent"))

           if SendMessage(CBE, CBEM_INSERTITEM, 0, ao(cbei)) = -1 then
              VOID = message_box("Cannot insert item", "Error",0)
              return
           end if

       end for

       VOID = SendMessage(CBE, CBEM_SETIMAGELIST, 0, himl)
       VOID = SendMessage(CBE, CB_SETCURSEL, 5, 0)  --index 6
       SetLastError(0)
       DeleteObject(himl)
       SetWindowPos(CBE,NULL,20,20,200,120,SWP_NOACTIVATE)

       cbei = free_struct(cbei)

end procedure


procedure WinMain()
atom hwnd_cbexcombo,hwnd_cbexedit
cstruct Wc, Msg, iccex

       Wc=struct(WNDCLASS)
       Msg=struct(MSG)

       AppClassName = "ComboBoxEx"

       store(Wc,"style"         ,  CS_HREDRAW + CS_VREDRAW + CS_OWNDC)
       store(Wc,"lpfnWndProc"   ,  WndProc)
       store(Wc,"cbClsExtra"    ,  0)
       store(Wc,"cbWndExtra"    ,  0)
       store(Wc,"hInstance"     ,  instance())
       store(Wc,"hIcon"         ,  LoadIcon(NULL,IDI_WINLOGO))
       store(Wc,"hCursor"       ,  LoadCursor(NULL,IDC_ARROW))
       store(Wc,"hbrBackground" ,  COLOR_BTNFACE+1)
       store(Wc,"lpszMenuName"  ,  NULL)
       store(Wc,"lpszClassName" ,  TEXT(AppClassName))

       if not RegisterClass(ao(Wc)) then
          VOID = message_box("Cannot RegisterClass Wc",
                             "Error",MB_OK + MB_ICONERROR)
          abort(0)
       end if

       iccex = struct(INITCOMMONCONTROLSEX)

       store(iccex,"dwSize" , sizeOf(INITCOMMONCONTROLSEX))

       store(iccex,"dwICC",
          ICC_LISTVIEW_CLASSES +
          ICC_TREEVIEW_CLASSES +
          ICC_BAR_CLASSES      +
          ICC_TAB_CLASSES      +
          ICC_UPDOWN_CLASS     +
          ICC_PROGRESS_CLASS   +
          ICC_USEREX_CLASSES   +
          ICC_DATE_CLASSES)

       InitCommonControlsEx(ao(iccex))

       Form1=create_Form("ComboBoxEx Demo",0,0,320,240,0,0)
       CBE=create_Control(WC_COMBOBOXEX,Form1,"",200,
                          0,0,0,100,
                          WS_BORDER+WS_VISIBLE+WS_CHILD+CBS_DROPDOWN,0)
       AddItems()
       Show(Form1)

       hwnd_cbexcombo = SendMessage(CBE, CBEM_GETCOMBOCONTROL, 0, 0)
       ToolTip_SetToolTip(hwnd_cbexcombo," Tip 1 ")
       hwnd_cbexedit = SendMessage(CBE, CBEM_GETEDITCONTROL, 0, 0)
       ToolTip_SetToolTip(hwnd_cbexedit," Tip 2 ")

       while GetMessage(ao(Msg),NULL,0,0) do

           TranslateMessage(ao(Msg))
           DispatchMessage(ao(Msg))

       end while

       Msg=free_struct(Msg)
       free_TEXT()

end procedure

function getWindowText(atom hWnd)
integer len
atom pText
sequence result

       len = GetWindowTextLength(hWnd) + 1
       pText = allocate(len)
       mem_set(pText,0,len)
       VOID = GetWindowText(hWnd,pText,len)
       result = peek_string(pText)
       free(pText)
       return result

end function

function WndProc_(atom hWnd, atom Msg, atom wParam, atom lParam)

       if Msg = WM_COMMAND then
          if HIWORD(wParam) = CBN_SELCHANGE then
           VOID = message_box(" You selected " & getWindowText(CBE),"",0)
          end if

       elsif Msg = WM_CLOSE then
           DestroyWindow(Form1)

       elsif Msg = WM_DESTROY then
          PostQuitMessage(0)

       else
          return DefWindowProc(hWnd,Msg,wParam,lParam)

       end if
       return 0

end function
WndProc=call_back(routine_id("WndProc_"))

-- start program
WinMain()



new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu