Anyone want to help me with ZDL3 real quick?
Posted: Sat Nov 19, 2005 10:46
I got bored with PHP and decided to pick up and work on ZDL3 for a while.
I coded up his block and I'm wondering if anyone can try to shrink it a bit.
[spoiler][/spoiler]
I coded up his block and I'm wondering if anyone can try to shrink it a bit.
- All code must be C compatible.
- You may use seperate functions if you wish.
- Try to keep it memory efficent as well.
[spoiler]
Code: Select all
LRESULT CALLBACK ConfigProc(HWND Dlg,UINT Msg,WPARAM wParam,LPARAM lParam){
int i=0;
PORT *tmpp;
IWAD *tmpi;
switch(Msg){
case WM_COMMAND:switch(LOWORD(wParam)){
// Buttons
// Add/Deleting buttons
case BTN_ADD:
i=SendMessage(GetDlgItem(Dlg,LST_PORT),LB_GETCOUNT,0,0);
port[i]=malloc(sizeof(PORT));
strcpy(port[i]->name,"New Port");
strcpy(port[i]->path,"(NONE)");
SendMessage(GetDlgItem(Dlg,LST_PORT),LB_ADDSTRING,0,(LPARAM)port[i]->name);
break;
case BTN_IADD:
i=SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_GETCOUNT,0,0);
iwad[i]=malloc(sizeof(IWAD));
strcpy(iwad[i]->name,"New IWAD");
strcpy(iwad[i]->path,"(NONE)");
SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_ADDSTRING,0,(LPARAM)iwad[i]->name);
break;
case BTN_REM:
if((i=SendMessage(GetDlgItem(Dlg,LST_PORT),LB_GETCURSEL,0,0))!=LB_ERR){
free(port[i]);
SendMessage(GetDlgItem(Dlg,LST_PORT),LB_DELETESTRING,i,0);
for(i;port[i]&&i<MAX_PORT;i++){port[i]=port[i+1];}
SendMessage(GetDlgItem(Dlg,EDT_NAME),WM_SETTEXT,0,(LPARAM)"");
SendMessage(GetDlgItem(Dlg,EDT_FILE),WM_SETTEXT,0,(LPARAM)"");
}
break;
case BTN_IREM:
if((i=SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_GETCURSEL,0,0))!=LB_ERR){
free(iwad[i]);
SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_DELETESTRING,i,0);
for(i;iwad[i]&&i<MAX_IWAD;i++){iwad[i]=iwad[i+1];}
SendMessage(GetDlgItem(Dlg,EDT_INAME),WM_SETTEXT,0,(LPARAM)"");
SendMessage(GetDlgItem(Dlg,EDT_IFILE),WM_SETTEXT,0,(LPARAM)"");
}
break;
// Moving buttons
case BTN_UP: // Move port up
if((i=SendMessage(GetDlgItem(Dlg,LST_PORT),LB_GETCURSEL,0,0))!=LB_ERR&&i!=0){
// Move the entry in the window
SendMessage(GetDlgItem(Dlg,LST_PORT),LB_INSERTSTRING,i-1,(LPARAM)port[i]->name);
SendMessage(GetDlgItem(Dlg,LST_PORT),LB_DELETESTRING,i+1,0);
// Move the memory item
tmpp = port[i-1];
port[i-1] = port[i];
port[i] = tmpp;
SendMessage(GetDlgItem(Dlg,LST_PORT),LB_SETCURSEL,i-1,0);
}
break;
case BTN_IUP: // Move IWAD up
if((i=SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_GETCURSEL,0,0))!=LB_ERR&&i!=0){
// Move the entry in the window
SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_INSERTSTRING,i-1,(LPARAM)iwad[i]->name);
SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_DELETESTRING,i+1,0);
// Move the memory item
tmpi = iwad[i-1];
iwad[i-1] = iwad[i];
iwad[i] = tmpi;
SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_SETCURSEL,i-1,0);
}
break;
case BTN_DWN: // Move port down
i=SendMessage(GetDlgItem(Dlg,LST_PORT),LB_GETCURSEL,0,0);
if((i=SendMessage(GetDlgItem(Dlg,LST_PORT),LB_GETCURSEL,0,0))!=LB_ERR&&i!=SendMessage(GetDlgItem(Dlg,LST_PORT),LB_GETCOUNT,0,0)-1){
// Move the entry in the window
SendMessage(GetDlgItem(Dlg,LST_PORT),LB_INSERTSTRING,i+2,(LPARAM)port[i]->name);
SendMessage(GetDlgItem(Dlg,LST_PORT),LB_DELETESTRING,i,0);
// Move the memory item
tmpp = port[i+1];
port[i+1] = port[i];
port[i] = tmpp;
SendMessage(GetDlgItem(Dlg,LST_PORT),LB_SETCURSEL,i+1,0);
}
break;
case BTN_IDWN: // Move IWAD down
i=SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_GETCURSEL,0,0);
if((i=SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_GETCURSEL,0,0))!=LB_ERR&&i!=SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_GETCOUNT,0,0)-1){
// Move the entry in the window
SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_INSERTSTRING,i+2,(LPARAM)iwad[i]->name);
SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_DELETESTRING,i,0);
// Move the memory item
tmpi = iwad[i+1];
iwad[i+1] = iwad[i];
iwad[i] = tmpi;
SendMessage(GetDlgItem(Dlg,LST_IWAD),LB_SETCURSEL,i+1,0);
}
break;
}break;
}return 0;
}