16,472
社区成员
发帖
与我相关
我的任务
分享
#include <Windows.h>
#include <tchar.h>
#include <wchar.h>
#include <stdio.h>
LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam);
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance,
__in LPSTR lpCmdLine, __in int nShowCmd )
{
WNDCLASS wndclass;
static TCHAR szWndName[]=TEXT("MyClass");
wndclass.style=CS_VREDRAW|CS_HREDRAW;
wndclass.lpszClassName=szWndName;
wndclass.lpszMenuName=NULL;
wndclass.lpfnWndProc=WinProc;
wndclass.hInstance=hInstance;
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hCursor=LoadCursor(NULL,IDI_APPLICATION);
wndclass.hbrBackground=(HBRUSH)(COLOR_WINDOW+1);
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
//if (!RegisterClass(&wndclass))
//{
// MessageBox(NULL,_T("Register Class Failed!"),_T("Waring!"),MB_OKCANCEL);
// return 1;
//}
RegisterClass(&wndclass);
HWND hwnd=CreateWindow(szWndName,_T("The Hello World Application"),WS_OVERLAPPEDWINDOW/*&~WS_MAXIMIZEBOX*/,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,hInstance,0);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
MSG msg;
while (GetMessage(&msg,0,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WinProc(HWND hwnd,UINT message,WPARAM wparam,LPARAM lparam)
{
HDC hdc;
PAINTSTRUCT ps;
switch(message)
{
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
LPCWSTR szText=TEXT("Hello World");
TextOut(hdc,0,0,szText,wcslen(szText));
EndPaint(hwnd,&ps);
break;
case WM_CHAR:
char buffer[10];
sprintf(buffer,"char is %d",wparam);
MessageBox(hwnd,LPCWSTR(buffer),TEXT("haolly"),MB_OKCANCEL);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,TEXT("Mouse Clicked"),TEXT("Message"),0);
HDC hDc=GetDC(hwnd);
TextOut(hDc,0,50,TEXT("Hello World2"),strlen("Hello World2"));
ReleaseDC(hwnd,hDc);
break;
case WM_CLOSE:
if (IDYES==MessageBox(hwnd,TEXT("Are you sure?"),TEXT("message"),0))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,message,wparam,lparam);
}
return 0;
}