win32 listbox, fix the function please

hello, The only thing i need is this:

I need to get a var int value of the curently selected value.
example: listbox displays byte-transfer rates aka 1 byte a sec/1 kb a sec/mb etc.
Its for a copy program. The gui is my problem!
----------------------------code--------------------
BOOL APIENTRY Configuration_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

  switch(uMsg) {

  case WM_INITDIALOG:
Do_registry(&Sselected/*<< struct */)

// not for listbox, ignore pls
      SetCheckedOptions(hWnd);


int i;  // count
// check if it works!
  for (i = 0; i < 15;i++ ) {
      //  iCur_transfermode=i;

Sselected.iCur_transfermode=i; // struct
// contains char name[16]
// int number
        


        SendMessage(GetDlgItem(hWnd, IDC_LIST1 ), LB_ADDSTRING, 0,
                    (LPARAM) TransferMode[i].tchName);
                SendMessage(GetDlgItem(hWnd, IDC_LIST1 ), LB_SETITEMDATA, i, (LPARAM) i);             

  }       



        UpdateWindow(hWnd);
        return TRUE;



case WM_COMMAND:


      switch (LOWORD(wParam)) {
 
                case IDC_LIST1:
 
                    switch (HIWORD(wParam)) {

 
                        case LBN_SELCHANGE:
 
 
                            hWnd = GetDlgItem(hWnd, IDC_LIST1);
                            SendMessage(hWnd, LB_GETCURSEL,
                                Sselected.iCur_transfermode, 0);
                             SendMessage(GetDlgItem(hWnd, IDC_LIST1),
                                LB_SETCURSEL, Sselected.iCur_transfermode, 0);
// up is struct for holding the transfermode
// its a number from 1 to 15
// all i get is number 0 when i
// test the number.
// it would be verry great if
// i could get a INT value of the currently
// sellected row of the listbox.
                     
                         
                         
                            return TRUE;
          }}





      switch(wParam) {
                  case IDOK:
// assign various vars :
//ExtremeCopy.Bitsize=iCur_transfermode;
      
// test all checked options! checkboxes // works!)
the listbox NOT!

CheckOptions(hWnd);
SetCheckedOptions(hWnd);


 
         CloseWindow(hWnd);
             DestroyWindow(hWnd);
B_options_active=FALSE;
Do_registry(&Sselected);

             return TRUE;



            }
            return 0;

    }
    return FALSE;
        UNREFERENCED_PARAMETER(lParam);
}

--------- end code -------------------

I need to get a int selected=listbox???? row???
the int represents a number like a,b,c or 123
if i can determine that you get a lot of points!

Just correct the win32 function NOT MFC i use assembler too for lowlevel copy.
The gUI is the problem for me, always was.




marco_coderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AlexFMCommented:
int n = SendMessage(hWnd, LB_GETCURSEL, 0, 0);   // n is number of selected item in listbox hWnd
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
marco_coderAuthor Commented:
It did not work, but thanks.

Curently i need to make the listbox blue.
(hell i try`d)
----------- code snipit here --------------------
// --------------- BUG --------------
// configuration dialog messages
// the listbox has one bug:
// i need to make the listbox blue by clicking on it!
// if i dont click i get a selected value of 0
// if i click on it (double click) it returns a number from 0-15
// i need that number for config purposes.
// it is NOT a multiple selection , its single.
// for questions mailto marco1974@zeelandnet.nl


BOOL APIENTRY Configuration_WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

int item;
HWND Hlistbox;
  switch(uMsg) {

  case WM_INITDIALOG:
Do_registry(&Sselected);
SetCheckedOptions(hWnd);


int i;
// check if it works!
  for (i = 0; i < 15;i++ ) {
      //  iCur_transfermode=i;
        
Hlistbox=GetDlgItem(hWnd, IDC_LIST1);

      item= SendMessage(GetDlgItem(hWnd, IDC_LIST1 ), LB_ADDSTRING, i,
                    (LPARAM) TransferMode[i].tchName);
              SendMessage(GetDlgItem(hWnd, IDC_LIST1 ), LB_SETITEMDATA, item,0);             

     
      }       

   SetFocus(Hlistbox);
         SendMessage(Hlistbox, LB_SETCURSEL, 0, 0);


        //UpdateWindow(hWnd);
        return TRUE; //FALSE;

case WM_COMMAND:

      switch  (LOWORD(wParam))
        {

   
       
        case IDOK:



 SetFocus(Hlistbox);
         SendMessage(Hlistbox, LB_SETCURSEL, 0, 0);

       UpdateWindow(GetDlgItem(hWnd, IDC_LIST1));

Sselected.iCur_transfermode = SendMessage(GetDlgItem(hWnd, IDC_LIST1),

                        LB_GETCURSEL, item, (LPARAM) 0);




           // test all checked options!

CheckOptions(hWnd);  // checkboxes
SetCheckedOptions(hWnd); // set them if they corespndent with registry
 //= item;
char buffer[10];
itoa(Sselected.iCur_transfermode,buffer,10);
MBOX(buffer); // this returns 0 if i dont click on the checkbox before clicking on OK.


         CloseWindow(hWnd);
             DestroyWindow(hWnd);
B_options_active=FALSE;
Do_registry(&Sselected);

             return TRUE;



            }
            return 0;

    }
    return FALSE;
        UNREFERENCED_PARAMETER(lParam);
}

--------------- end code ---------------

I need to get the selected row of the checkbox,
numbered 0-15 all i get is number 0.

Not 2,3,4 except if i double click instead of using the updown slider to adjust the value.
I need to click inside the checkbox.

Its a nasty BUG!
Man i hate windows.





0
georg74Commented:
hi marco_coder,

there are several problems:

> HWND Hlistbox;
you're setting this variable only in the WM_INITDIALOG branch,
but you're using it also in WM_COMMAND branch.

> SetFocus(Hlistbox);
comment all of these lines out;
why did you want to set / change focus?

> SendMessage(Hlistbox, LB_SETCURSEL, 0, 0);
in the WM_COMMAND branch, you're _probably_not_ setting the index,
because Hlistbox probably does not contain valid handle, but if yes, then
it is no wonder that you'll get 0 for the current selection afterwards.

> SendMessage(..., LB_GETCURSEL, item, (LPARAM) 0);
it should be SendMessage(..., LB_GETCURSEL, 0, (LPARAM) 0);
(check win32 reference)

> char buffer[10];
itoa can return up to 33 bytes, so use buffer[33] to be sure,
even if your walue will always(?) a small number.

gl,
georg
0
georg74Commented:
well, well ... :-/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.