News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

New drive list test piece

Started by hutch--, March 15, 2020, 11:29:36 AM

Previous topic - Next topic

hutch--

The control is a drop down combo box that loads the current drives into a combo box. The two algos that do the work are a combo box set as a drop down list and another (load_drives) to load the current drives into the combo box. The same algo can be used to refresh the drive list if something changes like inserting or removing a USB drive or similar. It currently puts the selected drive on the title bar but its normal use would be to change drives.

The method of getting the notification that the combo drop down box has close is an obscure WM_COMMAND interface testing the lParam member of the WM_COMMAND message but it works fine.

There is a commented out MACRO at the top of the source file as I have added the MACRO to the master MACRO file which I have not posted yet. Just uncomment it to build the example.

This code will also work in a dialog when you create a drop down combo box, as long as you provide the control handle in the dialog.

hutch--

Slight mod in the source code. More accurate tracking of the notification method.

      ; ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

        .switch lParam
          .case hCombo                                              ; combo notification via WM_COMMAND
          ; -------------------------------------------------
          ; get the HIWORD of wParam for notification message
          ; -------------------------------------------------
            mov rax, wParam                                         ; load wParam
            xor rcx, rcx                                            ; zero ecx
            ror rax, 16                                             ; rotate right to get high word
            mov cx, ax                                              ; copy ax to cx
          .if rcx == CBN_SELCHANGE                                  ; the notification message
            mov pbuf, ptr$(buff)                                    ; get buffer address
            mov indx, rvcall(SendMessage,hCombo,CB_GETCURSEL,0,0)   ; get the selected combo index
            rcall SendMessage,hCombo,CB_GETLBTEXT,indx,pbuf         ; get text from item at index
            mov pbuf, ltrim$(pbuf)                                  ; trim leading space
            mov pbuf, left$(pbuf,3)                                 ; get 1st 3 characters
            rcall SetWindowText,hWin,pbuf                           ; display text on title bar
            ret
          .endif
        .endsw

      ; ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

jj2007

Simpler:
  .if word ptr wParam[2] == CBN_SELCHANGE
...
  .endif

hutch--

 :biggrin:

        .switch lParam
          .case hCombo                                              ; combo notification via WM_COMMAND
          ; -------------------------------------------------
          ; get the HIWORD of wParam for notification message
          ; -------------------------------------------------
            mov rax, wParam                                         ; load wParam into rax
            ror rax, 16                                             ; rotate to get high word into ax
          .if ax == CBN_SELCHANGE                                   ; the notification message
            mov pbuf, ptr$(buff)                                    ; get buffer address
            mov indx, rvcall(SendMessage,hCombo,CB_GETCURSEL,0,0)   ; get the selected combo index
            rcall SendMessage,hCombo,CB_GETLBTEXT,indx,pbuf         ; get text from item at index
            mov pbuf, ltrim$(pbuf)                                  ; trim leading space
            mov pbuf, left$(pbuf,3)                                 ; get 1st 3 characters
            rcall SetWindowText,hWin,pbuf                           ; display text on title bar
            ret
          .endif
        .endsw

jj2007


hutch--

Nah, just wanted the comparison to be a register.

jj2007

If that is important:

movsx rax, word ptr wParam[2] ; load hiword of wParam into rax
.if rax == CBN_SELCHANGE ; the notification message