一个对话框程序dlg1
MainDlg.cpp
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"
//程序写的不够完善,还有待优化
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
}
return FALSE;
}
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 IDC_OK:
{
MessageBox(hwnd,TEXT("欢迎,欢迎,热烈欢迎,你好!祝你非常好!"),TEXT("问好"),MB_OK);
}
break;
case IDC_CHUNGE:
{
MessageBox(hwnd,TEXT("信春哥,得永生"),TEXT("李宇春"),MB_OK);
}
break;
case ID_MENUITEMOPEN:
{
FILE* fp=fopen("./op_file.txt","r+");
char fstr[1024]="";
//char * fstr;
//while()
//int i;
int j=0;
char ch;
while(ch!=EOF)
{
ch=fgetc(fp);
fstr[j]=ch;
//i=fscanf(fp,"%d",fstr[j]);
j++;
}//fstr[j]="HT";
/*for(j;j<10240;j++)
{
if(EOF!=fscanf(fp,"%d",fstr+j))
continue;
}*/
fclose(fp);
SetDlgItemText(hwnd,IDC_RICHEDIT,TEXT(fstr));
SetDlgItemText(hwnd,IDC_EDIT,TEXT(fstr));
}break;
case ID_MENUITEMQUIT:
{
EndDialog(hwnd,IDD_MAIN);
MessageBox(hwnd,TEXT("[退出]菜单被调用!"),TEXT("提示"),MB_OK);
}break;
default:
break;
}
}
void Main_OnClose(HWND hwnd)
{
EndDialog(hwnd, 0);
}
截图: