|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 126
Rep Power: 4 
|
Ok now I really need help, ive gotten everything designed in the abbriviation dialog, and so far most of the stuff is working (remove and add). But now heres what I have to do:
- Make it so abbrivating for is associated with abbriviation, which I think I did already correctly, I just cant get the code to read any of it to work (I dont even know how to do it ive just been messing around with stuff)
- Make it so when you click something in the list it sets IDC_TEXT1 (abbriviation) and IDC_TEXT2 (abbriviating) to there values in the textbox.
Theres still more but this is all im having trouble with at this point.
To start off heres the whole dialog code:
// Dialog Abbreviation Manager
BOOL CALLBACK DialogABBR(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
// Define Global Variables
HWND hList = GetDlgItem(hwnd, IDC_LIST);
HWND bRemove = GetDlgItem(hwnd, IDC_REMOVE);
HWND bEdit = GetDlgItem(hwnd, IDC_EDIT);
switch(Message)
{
case WM_INITDIALOG:
SetDlgItemText(hwnd, IDC_TEXT1, "Abbriviation");
SetDlgItemText(hwnd, IDC_TEXT2, "Abbriviation For");
return TRUE;
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_CANCEL:
EndDialog(hwnd, IDCANCEL);
break;
case IDC_LIST:
{
// It's our listbox, check the notification code
switch(HIWORD(wParam))
{
case LBN_SELCHANGE: // Something is selected / Selection Changes
{
// Check to see if you set value in boxes
int count = SendMessage(hList, LB_GETSELCOUNT, 0, 0);
if(count == 1) {
int index;
int err = SendMessage(hList, LB_GETSELITEMS, (WPARAM)1, (LPARAM)&index);
if(err != LB_ERR)
{
// Get the data we associated with the item above
// What it abbriviates
int i;
int *buf = (int*)GlobalAlloc(GPTR, sizeof(int) * count);
char* buffer1 = buf[i];
MessageBox(hwnd, buffer1, "Notice", MB_OK);
// buf1 = (char*)GlobalAlloc(GPTR, len + 1);
// char* data = SendMessage(hList, LB_GETITEMDATA, (WPARAM)index, 0);
// SetDlgItemText(hwnd, IDC_TEXT2, data, FALSE);
}
}
if(!(EnableWindow(bRemove, true)) && !(IsWindowEnabled(bRemove))) {
MessageBox(hwnd, "Error, Unable to enable remove button", "Notice", MB_OK | MB_ICONINFORMATION);
}
if(!(EnableWindow(bEdit, true)) && !(IsWindowEnabled(bEdit))) {
MessageBox(hwnd, "Error, Unable to enable edit button", "Notice", MB_OK | MB_ICONINFORMATION);
}
}
break;
}
}
break;
case IDC_REMOVE: // Hit Remove Button
{
int count = SendMessage(hList, LB_GETSELCOUNT, 0, 0);
if(count != 0) {
// Only want to do something if more than 0 is selected
// Allocate memory for selected items
int i;
int* buf;
buf = (int*)GlobalAlloc(GPTR, sizeof(int)*count);
SendMessage(hList, LB_GETSELITEMS, (WPARAM)count, (LPARAM)buf);
// Now we loop through the list and remove each item that was
// selected.
// WARNING!!!
// We loop backwards, because if we removed items
// from top to bottom, it would change the indexes of the other
// items!!!
for(i = count - 1; i >= 0; i--)
{
SendMessage(hList, LB_DELETESTRING, (WPARAM)buf[i], 0);
}
GlobalFree(buf);
if(EnableWindow(bRemove, false)) {
MessageBox(hwnd, "Error, Unable to disable remove button", "Notice", MB_OK | MB_ICONINFORMATION);
}
if(EnableWindow(bEdit, false)) {
MessageBox(hwnd, "Error, Unable to disable edit button", "Notice", MB_OK | MB_ICONINFORMATION);
}
}
}
break;
case IDC_ADD: // Hit add button
{
// Find out how long the string is to allocate memory
int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_TEXT1));
if(len > 0)
{
// Now we allocate, and get the string into our buffer
int i;
char* buf;
char* buf2;
buf = (char*)GlobalAlloc(GPTR, len + 1);
buf2 = (char*)GlobalAlloc(GPTR, len + 1);
GetDlgItemText(hwnd, IDC_TEXT1, buf, len + 1);
GetDlgItemText(hwnd, IDC_TEXT2, buf2, len + 1);
// Send the item to the list
int index = SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, 0, (LPARAM)buf);
SendDlgItemMessage(hwnd, IDC_LIST, LB_SETITEMDATA, (WPARAM)index, (LPARAM)buf2);
GlobalFree((HANDLE)buf); // Free the memory
}
}
break;
case IDOK:
EndDialog(hwnd, IDOK);
break;
case IDCANCEL:
EndDialog(hwnd, IDCANCEL);
break;
}
break;
default:
return FALSE;
}
return TRUE;
}
Since I doubt you want to look through all of it, Ill just give you the function that im having trouble with
if(count == 1) {
int index;
int err = SendMessage(hList, LB_GETSELITEMS, (WPARAM)1, (LPARAM)&index);
if(err != LB_ERR)
{
// Get the data we associated with the item above
// What it abbriviates
int i;
int *buf = (int*)GlobalAlloc(GPTR, sizeof(int) * count);
char* buffer1 = buf[i];
MessageBox(hwnd, buffer1, "Notice", MB_OK);
// buf1 = (char*)GlobalAlloc(GPTR, len + 1);
// char* data = SendMessage(hList, LB_GETITEMDATA, (WPARAM)index, 0);
// SetDlgItemText(hwnd, IDC_TEXT2, data, FALSE);
}
}
Where theres 3 things commented out in a row is where I was working. I cant get this to work. If theres anything else you need just tell me. But I cant figure out how to size the variable correctly, and put the values in it, then output in a messagebox (which is just for test, really in the end it will be changing the text in the editboxes)
Sorry for the code messyness, I hate dev-c++'s idea of "autostructuring" code for you with a burning pation, it doesnt help at all I spend more time trying to get the stupid things to tab out evenly than they did developing the stupid feature... well probably not, but I spend a lot of time having to organize it, and its impossible to keep the code organized with it.
Last edited by brokenhope; May 1st, 2005 at 4:49 PM.
|