⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 ftplink
💻 CPP
字号:
#include <windows.h>
#include <stdio.h>
#include "resource.h"

HINSTANCE hInstan;

OPENFILENAME ofn;
char PcName[260];
char Name[17];
char Path[60];
char Mode[10];

extern HWND DlgHwnd;
extern char com[10];
extern DWORD WINAPI tmain(void *p);

void GetPcFileName(HWND hWnd)
{
	char *p,*ext;
	int i;
	ZeroMemory(&ofn,sizeof(OPENFILENAME));
	ofn.lStructSize=sizeof(OPENFILENAME);
	ofn.hwndOwner=hWnd;
	ofn.hInstance=hInstan;
	ofn.lpstrDefExt="zip";
	ofn.lpstrFilter="所有文件 (*.*)\0*.*\0";
	ofn.lpstrFile=PcName;
	ofn.nMaxFile=260;
	ofn.Flags=OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|
              OFN_LONGNAMES|OFN_EXPLORER|OFN_HIDEREADONLY;
	ofn.lpstrTitle="打开电脑文件";
	if (GetOpenFileName(&ofn)==0) {
		PcName[0]=0;
		return;
	}
	if (ofn.nFileExtension) {
		ext=PcName+ofn.nFileExtension;
		for (i=0;ext[i];i++) ext[i]=tolower(ext[i]);
	}
	p=PcName+ofn.nFileOffset;
	if (strlen(p)<14) strcpy(Name,p);
	else if (ofn.nFileExtension) {
		for (i=0;i<10;i++) {
			if (*p=='.') break;
			Name[i]=*p++;
			if (Name[i]&0x80) {
				if (i==9) break;
				else Name[++i]=*p++;
			}
		}
		Name[i]='.';
		i++;
		p=PcName+ofn.nFileExtension;
		for (;i<14;i++) {
			if (*p) Name[i]=*p++;
			else break;
		}
		Name[i]=0;
	} else {
		memcpy(Name,p,14);
		Name[14]=0;
	}

	if (ofn.nFileExtension) {
		if (!strcmp(ext,"ski")) strcpy(Path,"开机画面");
		else if (!strcmp(ext,"flm")) strcpy(Path,"开机画面");
		else if (!strcmp(ext,"b16")) strcpy(Path,"开机画面");
		else if (!strcmp(ext,"gbk")) strcpy(Path,"开机画面");
		else if (!strcmp(ext,"bmp")) strcpy(Path,"我的图片");
		else if (!strcmp(ext,"bas")) strcpy(Path,"BASIC文件");
		else if (!strcmp(ext,"dat")) strcpy(Path,"LavaData");
		else if (!strcmp(ext,"sav")) strcpy(Path,"LavaData");
		else if (!strcmp(ext,"txt")) strcpy(Path,"文本文件");
		else if (!strcmp(ext,"gtx")) strcpy(Path,"文本文件");
		else if (!strcmp(ext,"bin")) strcpy(Path,"应用程序");
		else if (!strcmp(ext,"lav")) strcpy(Path,"LAVA");
		else if (!strcmp(ext,"wav")) strcpy(Path,"音乐之声");
		else if (!strcmp(ext,"pac")) {
			strcpy(Name,"下载包");
			strcpy(Path,"*");
		} else
			strcpy(Path,"移动硬盘");
	} else
		strcpy(Path,"移动硬盘");
}

static CenterWindow(HWND hWnd)
{
	RECT rect;
	int x,y;
	GetWindowRect(hWnd,&rect);
	x=(GetSystemMetrics(SM_CXFULLSCREEN)-rect.right+rect.left)/2;
	y=(GetSystemMetrics(SM_CYFULLSCREEN)-rect.bottom+rect.top)/2;
	SetWindowPos(hWnd,0,x,y,0,0,SWP_NOSIZE|SWP_NOZORDER);
	InvalidateRect(hWnd,NULL,FALSE);
}

LRESULT CALLBACK Ftp(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
	unsigned long ThreadID;
	int id;

	DlgHwnd=hWnd;
	switch (message) {
	case WM_CLOSE:
		EndDialog(hWnd,0);
		break;
	case WM_INITDIALOG:
		CenterWindow(hWnd);
		SendDlgItemMessage(hWnd,IDC_NAME,EM_SETLIMITTEXT,260,0);
		SendDlgItemMessage(hWnd,IDC_NAME,EM_SETLIMITTEXT,14,0);
		SendDlgItemMessage(hWnd,IDC_PATH,EM_SETLIMITTEXT,14,0);
		SendDlgItemMessage(hWnd,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM)"COM1");
		SendDlgItemMessage(hWnd,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM)"COM2");
		SendDlgItemMessage(hWnd,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM)"COM3");
		SendDlgItemMessage(hWnd,IDC_COMBO1,CB_ADDSTRING,0,(LPARAM)"COM4");
		SendDlgItemMessage(hWnd,IDC_COMBO1,CB_SETCURSEL,0,0);
		SendDlgItemMessage(hWnd,IDC_PATH,CB_ADDSTRING,0,(LPARAM)"LAVA");
		SendDlgItemMessage(hWnd,IDC_PATH,CB_ADDSTRING,0,(LPARAM)"LavaData");
		break;
	case WM_COMMAND:
		if ((wParam>>16)==BN_CLICKED) {
			switch (wParam&0xffff) {
			case IDC_LOOK:
				GetPcFileName(hWnd);
				if (PcName[0]) {
					SendDlgItemMessage(hWnd,IDC_PCNAME,WM_SETTEXT,0,(LPARAM)(LPCTSTR)PcName);
					SendDlgItemMessage(hWnd,IDC_NAME,WM_SETTEXT,0,(LPARAM)(LPCTSTR)Name);
					SendDlgItemMessage(hWnd,IDC_PATH,WM_SETTEXT,0,(LPARAM)(LPCTSTR)Path);
				}
				break;
			case IDC_DOWN:
				SendDlgItemMessage(hWnd,IDC_PCNAME,WM_GETTEXT,260,(LPARAM)(LPCTSTR)PcName);
				SendDlgItemMessage(hWnd,IDC_NAME,WM_GETTEXT,15,(LPARAM)(LPCTSTR)Name);
				SendDlgItemMessage(hWnd,IDC_PATH,WM_GETTEXT,15,(LPARAM)(LPCTSTR)Path);
				if (Name[0] && Path[0] && PcName[0] && strchr(Name,' ')==NULL && strchr(Path,' ')==NULL) {
					id=SendDlgItemMessage(hWnd,IDC_COMBO1,CB_GETCURSEL,0,0);
					sprintf(com,"COM%d",id+1);
					strcpy(Mode,"down");
					CloseHandle(CreateThread(NULL,NULL,tmain,NULL,0,&ThreadID));
				}
				break;
			case IDC_UP:
				SendDlgItemMessage(hWnd,IDC_PCNAME,WM_GETTEXT,260,(LPARAM)(LPCTSTR)PcName);
				SendDlgItemMessage(hWnd,IDC_NAME,WM_GETTEXT,15,(LPARAM)(LPCTSTR)Name);
				SendDlgItemMessage(hWnd,IDC_PATH,WM_GETTEXT,15,(LPARAM)(LPCTSTR)Path);
				if (Name[0] && Path[0] && PcName[0] && strchr(Name,' ')==NULL && strchr(Path,' ')==NULL) {
					strcpy(Mode,"up");
					id=SendDlgItemMessage(hWnd,IDC_COMBO1,CB_GETCURSEL,0,0);
					sprintf(com,"COM%d",id+1);
					CloseHandle(CreateThread(NULL,NULL,tmain,NULL,0,&ThreadID));
				}
				break;
			case IDC_EXIT:
				EndDialog(hWnd,0);
				break;
			}
		}
		break;
	default:
		return FALSE;
	}
	return TRUE;
}

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	hInstan=hInstance;
	DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,(DLGPROC)Ftp);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -