   C++ Button problem
  Ok, i'm quite new to C++ and I've a problem I only half know how to solve, so heres the general jist.I'm connecting to mysql, and pulling mulitple records using a given SQL query, so the results are usually quite random as they are consistantly changed.I'm trying to create a list of records for the query, each has its own independant id, i wish to create a button for each (or just something clickable) to open the full record view into a new window, showing only that one record (hopefully explained that well enough for people to understand)Ok, now I have all the records displaying ok, so thats not the issue, its assigning a button for each (i can make the buttons show up fine as well), as they all have unique id's and no idea what way to do itThe last thing i attempted doing wasQuote:hButton = CreateWindow("BUTTON", row[col], WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_BITMAP,temp2, temp1, 135, 27, hwnd, 0, g_hInst,  0);The idea of this was to have the id as the value of the button, which would then be picked up byQuote:switch(HIWORD(wParam)){  case BN_CLICKED:  {    switch(LOWORD(wParam))    {    .... default: {   //ID PICKED UP HERE }Course I dont even know if this is possible for a start, obviously it would be crazy to assign independant names for each button as there could be dozens if id's used.Can anyone tell me if there is a way of finding the button value, or at least a more senisble way of doing this, the method i was working on was only thing i could come up with at the time and im sure theres a more efficent and less sloppy way of doing it. If this isnt the best place to be asking this, could you point me in the right direction of were i could obtain help, or at least a document to help, already google'd but obviously it's not the easiest thing to be looking for.I would paste the entire code but theres alot of it and most isnt relevant, also i would have put these in code tags but not sure how to do code tags on this forum.Thanks   
Quote:Original post by stevek2k...Quote:hButton = CreateWindow("BUTTON", row[col], WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_BITMAP,temp2, temp1, 135, 27, hwnd, 0, g_hInst,  0);The idea of this was to have the id as the value of the button, which would then be picked up byQuote:switch(HIWORD(wParam)){  case BN_CLICKED:  {    switch(LOWORD(wParam))    {    .... default: {   //ID PICKED UP HERE }...Can anyone tell me if there is a way of finding the button value, or at least a more senisble way of doing this, the method i was working on was only thing i could come up with at the time and im sure theres a more efficent and less sloppy way of doing it. What do you mean by "button value"?You already have the button's resource id with "LOWORD(wParam)"... and for most WM_COMMAND notifications, the value of the button's HWND is just the LPARAM (cast to HWND)Unfortunately this is just how Windows' messaging system delivers the button event to you.You can use std::map<> to map an event to a functorstd::map<UINT, functor_ptr_t> events;where "functor_ptr_t" is the type of your functor pointer... if you're talking about managing the "sloppyness" of the switch statement in WndProc()...If the map is used inside a class, the map should be static... and you'd have to register some type of "destroy" mechanism to empty the map when the program exits  (use atexit() to register a type void ( *)() function that will delete the pointers in the map)....If you're just talking about a different way to tell which button was pressed, use a different map that depends on the "LOWORD(wParam)", or resource ID of your button... std::map<WORD, functor_ptr_t>  button_events;You would set these mappings (buttons to events) in your set-up sequence in the application code... something like://pseudo-codebutton_events.insert(std::make_pair(IDC_BUTTON1, new functor_t(function ptr here...)));// probably not the safest way to create the functor; if the functor constructor fails, //it will place a null function pointer into the mapSome ideas for you anyway. Was this what you were asking anyway?Chad   ;  (reworded this a little so easier to understand)Ok can I just start by saying i'm fairly new to C++ so be gentle.So where to start, well, i'm attempting to develop a client that connects to a MySQL database and takes infomation of it, so far that has been fine and i've managed it. When you are on a particular window I want it to display various cutdown records, once again that has gone fine, on this particular page I want to give the user the option to view each record display in a seperate window with all details via the use of a button or something along those lines.Ok i'll give you an example of what I mean, say we have a table which holds user infomation, on the first form only a list of the usernames will be displayed, when a button is clicked a seperate window with all the details about that user e.g. first name, surname, address etc.Now this is were the issue arrises that I can't get my head around, basically using the user example, each user with have their own unique ID, which will be a number, say admin is 1, test 15, steve 135 etc. (much the same way forums work) how can I go about making the username on the first form clickable, I thought about adding a view button to the right of each username, but when you pass it through theswitch(HIWORD(wParam)){case BN_CLICKED:there is no way of knowing which username is clicked, obviously I could assign each button with a ID and called it viaswitch(LOWORD(wParam)){case ID_BUTTON:but obviously since the users id's are quite random and numerous at times it would require great effort and sloppyness to do it this way (unless theres a method I do not currently know)Now looking at this I decided prehaps it was possible to look at the value that was written on the button e.g.(ascii inturuptation of button ;p)------| 15 | <- value = 15------e.g. (where row[col]==15)hButton = CreateWindow("BUTTON", row[col], WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON|BS_BITMAP,temp2, temp1, 135, 27, hwnd, 0, g_hInst, 0);and place an image over it so you never seen the value, okay its not nice but it would do what i want it to do, but once again I have no idea who the WM_COMMAND would pick up the value.Ok now onto idea 3.Instead of displaying the usernames in a static text box or edit box display them in a list, each record of which is double clickable, once again I fall into the problem of knowing which record was actually clicked.Needless to say this is driving me crazy and I cant find anything on Google that would help, any alternatives or solutions to the current problems would be much appriecated.Hope this makes sense to someone, and hope someone can point me in right direction, and remember I'm learning from scratch as i'm doing this so dont make it to complicated.   ;  there are several ways to store extra data associated with a Windows control. Verg gave you one, but if you don't understand how to use a map then maybe using a Window property would be easier for you.after you create your button, simply call SetProp and pass along whatever info you want to store for the given button and property name. in your case you could store the record id. to later retrieve the record id for a given clicked button you would then call GetProp.HWND hWnd = CreateWindow(...);SetProp(hWnd, TEXT("RECORDID"), (HANDLE)record_id);...switch( HIWORD(wParam) ){    case BN_CLICKED:   {  int record_id = (int)GetProp((HWD)lParam, TEXT("RECORDID"));   }   break;};  ahh, sorry bout that verg, i tried reading what you had given me but couldnt really understand it that well, in my head it didnt assiocate to what i asked so guessed you had got the wrong end of the stick cus i'd explained it bad.I'm gonna give what mr. anonymous said there a go as well, but after fiddling all night this is what i ended up with so far and seem to be making a little progress, first I decided to go with the listboxso i created the listbox and then usedint index = SendMessage(list,LB_ADDSTRING,0,(LPARAM)(LPCSTR)tempQuery);to add the string to it, also grabbing the index, then with that passed itemdata that would represent the user_idSendMessage(list, LB_SETITEMDATA, index, user_id);Ok this kinda seems to work, however the problem is all itemdata seems to be the last user_id entered, even with fiddling with certain parameters it either stays like that, all user_ids become 0 or it just uses the first user_idNeedless to say ive got a messagebox that is continously going to alert me of what itemdata is being passed, it just doesnt seem to want to hold the info.Any idea whats wrong with this, as im eventually starting to get somewhere now i've chosen a path and got some documentation to help (all of which say what i have should work)If i cant move foward on this ill have to definately have to get my head around the advice given here previous and go on with that as best i can   ;  nevermind figured out the list bit :)was being really stupid, was usingint indexIs = SendMessage(list,LB_GETITEMDATA,0,0);so it never knew what index it was meant to be looking for soint indexIs = SendMessage(list,LB_GETCURSEL,0,0);int itemData = SendMessage(list,LB_GETITEMDATA,indexIs,0);and it works fine, i was to busy looking at how it was being put in rather than how it was looked up *slaps forehead*Thanks for help anyway, can really push foward now i know this   