📄 dlgproc.cpp
字号:
if (sel!=0)
{
SendDlgItemMessage(hDlg,IDC_COMBO_TIME,CB_GETLBTEXT,sel,(LPARAM)Buff);
lstrcat(tp->SendBuffer,_T("+and+"));
lstrcatutf8(tp->SendBuffer,_T("(上课节次='"));
lstrcatutf8(tp->SendBuffer,Buff);
lstrcatutf8(tp->SendBuffer,_T("')"));
}
lstrcat(tp->SendBuffer,_T("&nrow_min=0&nrow_max=2000"));
lstrcat(tp->SendBuffer,_T(" HTTP/1.1\r\n"));
lstrcat(tp->SendBuffer,_T("Referer: http://"));
lstrcat(tp->SendBuffer,now_http_head->Host );
lstrcat(tp->SendBuffer,now_http_head->Path );
lstrcat(tp->SendBuffer,_T("qcb.kc\r\n"));
lstrcat(tp->SendBuffer,_T("Accept-Language: zh-cn\r\n"));
lstrcat(tp->SendBuffer,_T("Content-Type: application/x-www-form-urlencoded\r\n"));
lstrcat(tp->SendBuffer,_T("User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0;)\r\n"));
lstrcat(tp->SendBuffer,_T("Host: "));
lstrcat(tp->SendBuffer,now_http_head->Host );
lstrcat(tp->SendBuffer,_T("\r\nConnection: close\r\n"));
lstrcat(tp->SendBuffer,UserCookie);
lstrcat(tp->SendBuffer,_T("Cache-Control: no-cache\r\n\r\n"));
tp->hProgress =GetDlgItem(hDlg,IDC_PROGRESS);
tp->Analysis =1;
tp->NeedBuffer2=false;
CloseHandle((HANDLE)_beginthreadex(0,0,SendThread,(void*)tp,0,0));
break;
}
break;
}
return FALSE;
}
// Mesage handler for Login box.
LRESULT CALLBACK WndProcDlgLogin(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
hDlgLogin=hDlg;
SetDlgItemText(hDlg,IDC_EDITID,UserName);
SetDlgItemText(hDlg,IDC_EDITPASSWORD,PassWord);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
EndDialog(hDlg, LOWORD(wParam));
return false;
case IDOK:
if (mystatus.Busy & 10 || mystatus.Busy & 4)
{
MessageBox(0,_T("登录中,请稍候..."),szTitle,MB_ICONWARNING);
break;
}
if (GetDlgItemText(hDlgLogin,IDC_EDITID,UserName,sizeof(UserName))==0)
{
MessageBox(0,_T("请输入用户名"),szTitle,MB_ICONWARNING);break;
}
if (GetDlgItemText(hDlgLogin,IDC_EDITPASSWORD,PassWord,sizeof(PassWord))==0)
{
MessageBox(0,_T("请输入密码"),szTitle,MB_ICONWARNING);break;
}
switch ( g_iServer )
{
case IDM_SERVER_NJTU:
now_http_head = &http_head2;
LogIN();
break;
case IDM_SERVER_TSINGHUA:
now_http_head = &http_head1;
LogIN();
break;
case IDM_SERVER_CUSTOM:
now_http_head = &http_head_custom;
LogIN();
break;
case IDM_SERVER_DEBUG:
now_http_head = &http_head_debug;
LogIN();
break;
default:// IDM_SERVER_AUTO
now_http_head=&http_head3;
thread_param *tp=new thread_param;
lstrcpy(tp->SendBuffer,_T("GET /bjtujwc/SystemServlet?action=showCatInfor&cat_id=5 HTTP/1.1\r\n"));
lstrcat(tp->SendBuffer,_T("Accept: */*\r\n"));
lstrcat(tp->SendBuffer,_T("Referer: http://jgjwc.njtu.edu.cn:8080/bjtujwc/index.jsp\r\n"));
lstrcat(tp->SendBuffer,ACCEPT_LANGUAGE);
lstrcat(tp->SendBuffer,ACCEPT_ENCODING);
lstrcat(tp->SendBuffer,USER_AGENT);
lstrcat(tp->SendBuffer,_T("Host: jgjwc.njtu.edu.cn:8080\r\n"));
lstrcat(tp->SendBuffer,_T("Connection: close\r\n\r\n"));
tp->hProgress =GetDlgItem(hDlg,IDC_PROGRESS);
tp->NeedBuffer2 =false;
tp->Analysis =10;
CloseHandle((HANDLE)_beginthreadex(0,0,SendThread,(void*)tp,0,0));
}
}
break;
}
return FALSE;
}
// Mesage handler for about box.
LRESULT CALLBACK WndProcDlgAuto(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND h;
int i;
switch (message)
{
case WM_INITDIALOG:
UDACCEL myudaccel;
for (i=0;i<3;i++) //设置课程号最多7个字符,课序号最多2个字符
SendDlgItemMessage(hDlg,IDC_EDIT1+i,EM_LIMITTEXT,7,0);
for (i=0;i<3;i++)
SendDlgItemMessage(hDlg,IDC_EDIT4+i,EM_LIMITTEXT,2,0);
/* 提交间隔 */
h=GetDlgItem(hDlg,IDC_EDIT_INTERVAL);
SendDlgItemMessage(hDlg,IDC_SPIN1,UDM_SETBUDDY,(WPARAM)h,0); //把SPIN和EDIT绑定
SendDlgItemMessage(hDlg,IDC_SPIN1,UDM_SETRANGE,0,(LPARAM)MAKELONG(3500,10000)); //设置SPIN的范围是3500-10000
myudaccel.nInc =100;
myudaccel.nSec =0;
SendDlgItemMessage(hDlg,IDC_SPIN1,UDM_SETACCEL,1,(LPARAM)&myudaccel); //设置SPIN的步进为100
SendDlgItemMessage(hDlg,IDC_SPIN1,UDM_SETPOS,0,(LPARAM)MAKELONG(3500,0)); //设置SPIN的初值为3500
/* 提交超时 */
h=GetDlgItem(hDlg,IDC_EDIT_TIMEOUT);
SendDlgItemMessage(hDlg,IDC_SPIN2,UDM_SETBUDDY,(WPARAM)h,0); //把SPIN和EDIT绑定
SendDlgItemMessage(hDlg,IDC_SPIN2,UDM_SETRANGE,0,(LPARAM)MAKELONG(1,300)); //设置SPIN的范围是3500-10000
SendDlgItemMessage(hDlg,IDC_SPIN2,UDM_SETPOS,0,(LPARAM)MAKELONG(20,0)); //设置SPIN的初值为3500
/* 最大线程 */
h=GetDlgItem(hDlg,IDC_EDIT_MAXTHREAD);
SendDlgItemMessage(hDlg,IDC_SPIN3,UDM_SETBUDDY,(WPARAM)h,0); //把SPIN和EDIT绑定
SendDlgItemMessage(hDlg,IDC_SPIN3,UDM_SETRANGE,0,(LPARAM)MAKELONG(1,100)); //设置SPIN的范围是3500-10000
SendDlgItemMessage(hDlg,IDC_SPIN3,UDM_SETPOS,0,(LPARAM)MAKELONG(30,0)); //设置SPIN的初值为3500
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDCANCEL:
//if 正在挂机则不能退出
EndDialog(hDlg, LOWORD(wParam));
return false;
case IDC_START:
if (mystatus.Busy )
{
MessageBox(0,_T("您正在进行另一个操作,请稍候再试"),szTitle,MB_ICONWARNING);
break;
}
for (i=0;i<6;i++)
{
h=GetDlgItem(hDlgAuto,IDC_EDIT1+i);
EnableWindow(h,false);
}
mystatus.post =1;
EnableDlgItem(hDlg,IDC_START,false);
EnableDlgItem(hDlg,IDC_STOP,true);
NOTIFYICONDATA tnd;
tnd.cbSize=sizeof(NOTIFYICONDATA);
tnd.hWnd=hMain;
tnd.uID=IDR_MAINFRAME;
tnd.uFlags=NIF_MESSAGE | NIF_ICON |NIF_TIP | 0x10; //NIF_INFO==0x10
lstrcpy(tnd.szInfo,_T("程序现在最小化到了这里"));
lstrcpy(tnd.szInfoTitle ,szTitle);
tnd.uTimeout = 10;
tnd.dwInfoFlags =0x01; //NIIF_INFO==0x01
tnd.uCallbackMessage=WM_TRAY; //用户自定义的消息,即鼠标在任务栏上程序图标上动作时图标发送的消息
tnd.hIcon=LoadIcon(hInst, (LPCTSTR)IDI_YBJJ);
lstrcpy(tnd.szTip ,szTitle);
Shell_NotifyIcon(NIM_ADD,&tnd);//向任务栏添加图标
#ifndef _DEBUG
ShowWindow(hMain,false);
ShowWindow(hDlgAuto,false);
#endif
Analysis7(0);
//GetDefault("XK1.CourseInput",7);
break;
case IDC_STOP:
mystatus.Autoing =false;
for (i=0;i<6;i++)
{
h=GetDlgItem(hDlgAuto,IDC_EDIT1+i);
EnableWindow(h,true);
}
NOTIFYICONDATA tnid;
KillTimer(hMain,2);
tnid.cbSize=sizeof(NOTIFYICONDATA);
tnid.hWnd=hMain;
tnid.uID=IDR_MAINFRAME;//保证删除的是我们的图标
Shell_NotifyIcon(NIM_DELETE,&tnid);
EnableDlgItem(hDlg,IDC_START,true);
EnableDlgItem(hDlg,IDC_STOP,false);
PostMessage(hMain,WM_COMMAND,IDM_TRAY_RETURN,0);
break;
case IDC_BUTTON_HELP1:
MessageBox(hDlg,_T("意义:每隔多少毫秒,将上述三门课程提交一次\r\n范围:3500-10000\r\n建议值:3500\r\n副作用:取值太小,可能会导致服务器崩溃;取值太大,可能课就被别人选走了"),szTitle,MB_ICONINFORMATION);
break;
case IDC_BUTTON_HELP2:
MessageBox(hDlg,_T("意义:每次提交后,多少秒内没有收到服务器返回的数据,即认为提交失败\r\n范围:1-300\r\n建议值:20\r\n副作用:取值太小,可能会频繁失败;取值太大,可能白白等待浪费时间;请视您的网络状况而定。"),szTitle,MB_ICONINFORMATION);
break;
case IDC_BUTTON_HELP3:
MessageBox(hDlg,_T("意义:线程好比选课网页。同时开启30个线程就好比同时开了30个网页不断提交。\r\n范围:1-100\r\n建议值:30\r\n副作用:取值太小,可能会抢不到课;取值太大,可能拖慢机器速度;请视您的机器配置而定。"),szTitle,MB_ICONINFORMATION);
break;
}
break;
case WM_VSCROLL:
if ( (HWND)lParam == GetDlgItem(hDlg,IDC_SPIN1) )
{
if (mystatus.Autoing )
{
SetTimer(hMain,2,SendDlgItemMessage(hDlgAuto,IDC_SPIN1,UDM_GETPOS,0,0),0);
}
}
else if ( (HWND)lParam == GetDlgItem(hDlg,IDC_SPIN2) )
{
g_iTimeOut = SendDlgItemMessage(hDlgAuto,IDC_SPIN2,UDM_GETPOS,0,0);
}
else if ( (HWND)lParam == GetDlgItem(hDlg,IDC_SPIN3) )
{
g_iMaxThread = SendDlgItemMessage(hDlgAuto,IDC_SPIN3,UDM_GETPOS,0,0);
}
break;
}
return FALSE;
}
// Mesage handler for about box.
LRESULT CALLBACK WndProcDlgCustom(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
short int wmId,wmEvent;
char szNum[10];
switch (message)
{
case WM_INITDIALOG:
SetDlgItemText(hDlg,IDC_EDIT_HOST,http_head_custom.Host );
SetDlgItemText(hDlg,IDC_EDIT_IP, http_head_custom.IPA);
if ( http_head_custom.PORT )
{
ZeroMemory(szNum,sizeof(szNum));
_itot(http_head_custom.PORT,szNum,10);
SetDlgItemText(hDlg,IDC_EDIT_PORT, szNum);
}
SetDlgItemText(hDlg,IDC_EDIT_PATH,http_head_custom.Path );
SendDlgItemMessage(hDlg,IDC_COMBO,CB_INSERTSTRING,-1,(LPARAM)_T("交大服务器配置"));
SendDlgItemMessage(hDlg,IDC_COMBO,CB_INSERTSTRING,-1,(LPARAM)_T("清华服务器配置"));
return TRUE;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
switch(wmId)
{
case IDC_COMBO:
if ( wmEvent == CBN_SELENDOK )
{
/* NJTU */
if ( SendDlgItemMessage(hDlg,IDC_COMBO,CB_GETCURSEL,0,0) == 0 )
{
SetDlgItemText(hDlg,IDC_EDIT_HOST,http_head2.Host );
SetDlgItemText(hDlg,IDC_EDIT_PATH,http_head2.Path );
SetDlgItemText(hDlg,IDC_EDIT_IP,http_head2.IPA );
ZeroMemory(szNum,sizeof(szNum));
_itot(http_head2.PORT ,szNum,10);
SetDlgItemText(hDlg,IDC_EDIT_PORT,szNum );
}
else /* TSINGHUA */
{
SetDlgItemText(hDlg,IDC_EDIT_HOST,http_head1.Host );
SetDlgItemText(hDlg,IDC_EDIT_PATH,http_head1.Path );
SetDlgItemText(hDlg,IDC_EDIT_IP,http_head1.IPA );
ZeroMemory(szNum,sizeof(szNum));
_itot(http_head1.PORT ,szNum,10);
SetDlgItemText(hDlg,IDC_EDIT_PORT,szNum );
}
}
break;
case IDOK:
int iLen;
/* IP */
if ( http_head_custom.IPA )
{
delete[] http_head_custom.IPA ;
}
iLen = GetWindowTextLength(GetDlgItem(hDlg,IDC_EDIT_IP)) + 1;
http_head_custom.IPA = new char[iLen];
if ( http_head_custom.IPA )
{
GetDlgItemText(hDlg,IDC_EDIT_IP,http_head_custom.IPA ,iLen);
if ( inet_addr(http_head_custom.IPA ) == INADDR_NONE)
{
MessageBox(hDlg,_T("非法的IP地址,请重新输入"),szTitle,MB_ICONWARNING);
break;
}
}
/* PORT */
ZeroMemory(szNum,sizeof(szNum));
GetDlgItemText(hDlg,IDC_EDIT_PORT,szNum,sizeof(szNum)-1);
http_head_custom.PORT = _ttoi(szNum);
if ( http_head_custom.PORT <= 0 || http_head_custom.PORT > 65535 )
{
MessageBox(hDlg,_T("非法的端口号,请重新输入"),szTitle,MB_ICONWARNING);
break;
}
/* Host */
if ( http_head_custom.Host )
{
delete[] http_head_custom.Host ;
}
iLen = GetWindowTextLength(GetDlgItem(hDlg,IDC_EDIT_HOST)) + 1;
http_head_custom.Host = new char[iLen];
if ( http_head_custom.Host )
{
GetDlgItemText(hDlg,IDC_EDIT_HOST,http_head_custom.Host ,iLen);
}
/* PATH */
if ( http_head_custom.Path )
{
delete[] http_head_custom.Path ;
}
iLen = GetWindowTextLength(GetDlgItem(hDlg,IDC_EDIT_PATH)) + 1;
http_head_custom.Path = new char[iLen];
if ( http_head_custom.Path )
{
GetDlgItemText(hDlg,IDC_EDIT_PATH,http_head_custom.Path ,iLen);
}
g_iServer = IDM_SERVER_CUSTOM;
HMENU hMenu;
hMenu = GetMenu(hMain);
CheckMenuItem(hMenu,IDM_SERVER_CUSTOM,MF_CHECKED | MF_BYCOMMAND);
CheckMenuItem(hMenu,IDM_SERVER_AUTO,MF_UNCHECKED | MF_BYCOMMAND);
CheckMenuItem(hMenu,IDM_SERVER_NJTU,MF_UNCHECKED | MF_BYCOMMAND);
CheckMenuItem(hMenu,IDM_SERVER_TSINGHUA,MF_UNCHECKED | MF_BYCOMMAND);
case IDCANCEL:
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -