#2
风车转风车892015-04-26 12:21
回复 3楼 C3程序猿
|
程序代码:
#include"windows.h"
#include"stdio.h"
#include"tchar.h"
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd )
{
BOOL msg_flag;
MSG msg;
HWND hwnd;
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);
wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WndProc;
wndcls.lpszClassName=_T("C PROGRAM DESIGN");
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wndcls);
hwnd=CreateWindow(_T("C PROGRAM DESIGN"),_T("HELLO 大家好!"),WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,0, CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_NORMAL);
UpdateWindow(hwnd);
msg_flag=GetMessage(&msg,hwnd,0,0);
while(msg_flag)
{
if(msg_flag==-1)
return -1;
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam
)
{
HDC hdc;
PAINTSTRUCT ps;
switch(msg)
{
case WM_CHAR:
MessageBox(hwnd,TEXT("这是对话空"),_T("您好!"),0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,TEXT("这是对话空"),_T("您好!"),0);
hdc=GetDC(hwnd);
TextOut(hdc,0,0,_T("这是程序员之家"),strlen("这是程序员之家"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hdc;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,_T("这是程序员之家"),strlen("这是程序员之家"));
EndPaint(hwnd,&ps);
ReleaseDC(hwnd,hdc);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,TEXT("是否真的结束?"),_T("message"),MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,wparam,lparam);
return 0;
}
}
#include"stdio.h"
#include"tchar.h"
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam);
int WINAPI WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd )
{
BOOL msg_flag;
MSG msg;
HWND hwnd;
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_ARROW);
wndcls.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WndProc;
wndcls.lpszClassName=_T("C PROGRAM DESIGN");
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wndcls);
hwnd=CreateWindow(_T("C PROGRAM DESIGN"),_T("HELLO 大家好!"),WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,0, CW_USEDEFAULT,0,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_NORMAL);
UpdateWindow(hwnd);
msg_flag=GetMessage(&msg,hwnd,0,0);
while(msg_flag)
{
if(msg_flag==-1)
return -1;
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
LRESULT CALLBACK WndProc(
HWND hwnd,
UINT msg,
WPARAM wparam,
LPARAM lparam
)
{
HDC hdc;
PAINTSTRUCT ps;
switch(msg)
{
case WM_CHAR:
MessageBox(hwnd,TEXT("这是对话空"),_T("您好!"),0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,TEXT("这是对话空"),_T("您好!"),0);
hdc=GetDC(hwnd);
TextOut(hdc,0,0,_T("这是程序员之家"),strlen("这是程序员之家"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hdc;
hdc=BeginPaint(hwnd,&ps);
TextOut(hdc,0,0,_T("这是程序员之家"),strlen("这是程序员之家"));
EndPaint(hwnd,&ps);
ReleaseDC(hwnd,hdc);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,TEXT("是否真的结束?"),_T("message"),MB_YESNO))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,msg,wparam,lparam);
return 0;
}
}