5.实验4win32应用程序求一元二次方程的根创建编辑框逗号截取按钮
#include
#include
#include
charstr[10];
LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);
intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,
LPSTRlpCmdLine,intnCmdShow)
{
HWNDhWnd;
MSGMsg;
WNDCLASSWndClass;
WndClass.style=CS_HREDRAW|CS_VREDRAW;
WndClass.lpfnWndProc=WndProc;
WndClass.cbClsExtra=0;
WndClass.cbWndExtra=0;
WndClass.hInstance=hInstance;
WndClass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName=NULL;
WndClass.lpszClassName="HelloWin";//窗口类名
//注册窗口
if(!
RegisterClass(&WndClass))
{
MessageBox(NULL,"窗口注册失败!
","HelloWin",0);
return0;
}
//创建窗口
hWnd=CreateWindow("HelloWin",
"MyWindow",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
//显示窗口
ShowWindow(hWnd,nCmdShow);
//更新窗口
UpdateWindow(hWnd);
//进入消息循环:
当从应用程序消息队列中捡取的消息是WM_QUIT时,则推出循环
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);//转换键盘消息
DispatchMessage(&Msg);//分发消息
}
returnMsg.wParam;
}
LRESULTCALLBACKWndProc(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam)
{
HDChDC;
PAINTSTRUCTPs;
charstrEdit[10];
charstrsub[10];
staticHWNDhWndButton,hWndEdit;
switch(message)
{
caseWM_CREATE:
hWndEdit=CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,
10,60,100,25,hWnd,NULL,NULL,NULL);
hWndButton=CreateWindow("button","Display",WS_CHILD|WS_VISIBLE|WS_BORDER,
340,60,100,25,hWnd,NULL,NULL,NULL);
return0;
caseWM_COMMAND:
if(((HWND)lParam==hWndButton)&&(HIWORD(wParam)==BN_CLICKED))
//按下按键
{
GetWindowText(hWndEdit,strEdit,10);//获取编辑框控件的内容
待续
sprintf(str,"Theresultis:
%s",strEdit);
InvalidateRect(hWnd,NULL,TRUE);
}
caseWM_PAINT:
//设计编辑框
hDC=BeginPaint(hWnd,&Ps);
TextOut(hDC,10,10,"Pleaseentrythenum:
",21);
TextOut(hDC,10,40,"三个序数",1);
待续
TextOut(hDC,10,90,strsub,strlen(strsub));
EndPaint(hWnd,&Ps);
return0;
caseWM_DESTROY:
PostQuitMessage(0);
return0;
}
returnDefWindowProc(hWnd,message,wParam,lParam);
}
6.对话框和控件有关上网信息任务等、、、、
//Ex_ResearchDlg.cpp:
implementationfile
//
#include"stdafx.h"
#include"Ex_Research.h"
#include"Ex_ResearchDlg.h"
#ifdef_DEBUG
#definenewDEBUG_NEW
#undefTHIS_FILE
staticcharTHIS_FILE[]=__FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
//CAboutDlgdialogusedforAppAbout
classCAboutDlg:
publicCDialog
{
public:
CAboutDlg();
//DialogData
//{{AFX_DATA(CAboutDlg)
enum{IDD=IDD_ABOUTBOX};
//}}AFX_DATA
//ClassWizardgeneratedvirtualfunctionoverrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport
//}}AFX_VIRTUAL
//Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg:
:
CAboutDlg():
CDialog(CAboutDlg:
:
IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
voidCAboutDlg:
:
DoDataExchange(CDataExchange*pDX)
{
CDialog:
:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg,CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//Nomessagehandlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CEx_ResearchDlgdialog
CEx_ResearchDlg:
:
CEx_ResearchDlg(CWnd*pParent/*=NULL*/)
:
CDialog(CEx_ResearchDlg:
:
IDD,pParent)
{
//{{AFX_DATA_INIT(CEx_ResearchDlg)
//NOTE:
theClassWizardwilladdmemberinitializationhere
//}}AFX_DATA_INIT
//NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32
m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
voidCEx_ResearchDlg:
:
DoDataExchange(CDataExchange*pDX)
{
CDialog:
:
DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEx_ResearchDlg)
//NOTE:
theClassWizardwilladdDDXandDDVcallshere
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEx_ResearchDlg,CDialog)
//{{AFX_MSG_MAP(CEx_ResearchDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
//CEx_ResearchDlgmessagehandlers
BOOLCEx_ResearchDlg:
:
OnInitDialog()
{
CDialog:
:
OnInitDialog();
CheckRadioButton(IDC_AGE_L18,IDC_AGE_M38,IDC_AGE_18TO27);
CheckRadioButton(IDC_CM_FTTL,IDC_CM_OTHER,IDC_CM_FTTL);
CButton*pBtn=(CButton*)GetDlgItem(IDC_DO_POP);
pBtn->SetCheck
(1);
CheckRadioButton(IDC_TIME_L1,IDC_TIME_M3,IDC_TIME_L1);
//Add"About..."menuitemtosystemmenu.
//IDM_ABOUTBOXmustbeinthesystemcommandrange.
ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX<0xF000);
CMenu*pSysMenu=GetSystemMenu(FALSE);
if(pSysMenu!
=NULL)
{
CStringstrAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if(!
strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu);
}
}
//Settheiconforthisdialog.Theframeworkdoesthisautomatically
//whentheapplication'smainwindowisnotadialog
SetIcon(m_hIcon,TRUE);//Setbigicon
SetIcon(m_hIcon,FALSE);//Setsmallicon
//TODO:
Addextrainitializationhere
returnTRUE;//returnTRUEunlessyousetthefocustoacontrol
}
voidCEx_ResearchDlg:
:
OnSysCommand(UINTnID,LPARAMlParam)
{
if((nID&0xFFF0)==IDM_ABOUTBOX)
{
CAboutDlgdlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog:
:
OnSysCommand(nID,lParam);
}
}
//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow
//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,
//thisisautomaticallydoneforyoubytheframework.
voidCEx_ResearchDlg:
:
OnPaint()
{
if(IsIconic())
{
CPaintDCdc(this);//devicecontextforpainting
SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0);
//Centericoninclientrectangle
intcxIcon=GetSystemMetrics(SM_CXICON);
intcyIcon=GetSystemMetrics(SM_CYICON);
CRectrect;
GetClientRect(&rect);
intx=(rect.Width()-cxIcon+1)/2;
inty=(rect.Height()-cyIcon+1)/2;
//Drawtheicon
dc.DrawIcon(x,y,m_hIcon);
}
else
{
CDialog:
:
OnPaint();
}