I can't run through your code without the resource.h file (and the other resource files), but here are a few suspicious items:
1.
SendDlgItemMessage(hwnd,IDC_ALL_MSG_BOX,EM_SETSEL,-1,(LPARAM)-1);
You are sending this dialog message in the "default" case when you receive a dialog message. Possibly this would end up causing an infinite recursion, as you might receive a dialog message in response to this dialog item message.
2.
The documentation I read says either return TRUE or FALSE to a dialog message, I'm not sure why you are returning 2 (which would probably be the same as returning TRUE)
3.
for(a=0;a<=sizeof(new_name);a++)
sizeof(new_name) returns exactly 4 in a 32 bit environment. You need to use strlen to find the length of a string.
Other than that, I can only suggest running the program through a debugger, setting a breakpoint on the EM_REPLACESEL lines and stepping through from there.