?
Solved

win32 listbox, fix the function please

Posted on 2004-11-27
4
Medium Priority
?
945 Views
Last Modified: 2008-01-16
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.




0
Comment
Question by:marco_coder
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 1000 total points
ID: 12688924
int n = SendMessage(hWnd, LB_GETCURSEL, 0, 0);   // n is number of selected item in listbox hWnd
0
 

Author Comment

by:marco_coder
ID: 12692089
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
 
LVL 3

Expert Comment

by:georg74
ID: 12692214
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
 
LVL 3

Expert Comment

by:georg74
ID: 12794280
well, well ... :-/
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question