C 语言 学习---丑陋的记事本

BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
    return TRUE;
}

void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
    switch(id)
    {
        case ID_MENUITEMOPEN:
		{
			//FILE *fp=fopen("F:/workspace/1.txt","r");
			//循环读取多行文本文件?
			//char line[256];
			//fgets(line,sizeof(line),fp);
			//fclose(fp);
			//SetDlgItemText(hwnd,IDC_EDIT1,TEXT(line));
			OPENFILENAME ofn;
			char szFile[MAX_PATH];
			ZeroMemory(&ofn,sizeof(ofn));//memset给一段内存设值
			//ZeroMemory是memset取0的特值。
			ofn.lStructSize = sizeof(ofn);
			ofn.lpstrFile = szFile;
			ofn.lpstrFile[0] = TEXT('\0');
			ofn.nMaxFile = sizeof(szFile);
			//ofn.lpstrFilter = TEXT("ALL\0*.*\0Text\0*.TXT\0");
			ofn.lpstrFilter = TEXT("ALL\0*.*\0Text\0*.TXT\0C++\0*.cpp\0");
			ofn.nFilterIndex = 1;//默认选择的过滤器的序号
			ofn.lpstrFileTitle = NULL;
			ofn.nMaxFileTitle = 0;
			ofn.lpstrInitialDir = NULL;
			ofn.hwndOwner = hwnd;//自学能力、探索能力、猜测能力
			ofn.Flags = OFN_EXPLORER |OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
			if (GetOpenFileName(&ofn))
			{
				//MessageBox(NULL,szFile,"",MB_OK);
				FILE *fp =fopen(szFile,"r");
				char line[256];
				fgets(line,sizeof(line),fp);
				fclose(fp);
				SetDlgItemText(hwnd,IDC_EDIT1,line);
			}
		}
        break;
        default:
		break;
    }
}

 
C 语言 学习---丑陋的记事本

 

你可能感兴趣的:(记事本)