#include <windows.h>
#include <stdio.h>LRESULT CALLBACK MyProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wnd;
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wnd.hCursor = LoadCursor(NULL,IDC_ARROW);
wnd.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wnd.hInstance = hInstance;
wnd.lpfnWndProc = MyProc;
wnd.lpszClassName = "MyWindow";
wnd.lpszMenuName = NULL;
wnd.style = CS_HREDRAW|CS_VREDRAW; RegisterClass(&wnd); HWND hwnd;
hwnd = CreateWindow("MyWindow","我的窗口",WS_OVERLAPPEDWINDOW,
200,200,400,300,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd); MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}LRESULT CALLBACK MyProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char str[20];
sprintf(str,"This keyCode is %d",wParam);
MessageBox(hwnd,str,"操作提示",MB_OK);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"您按下了鼠标左键","操作提示",MB_OK);
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc,0,50,"鼠标左键已经被按下过",strlen("鼠标左键已经被按下过"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDc;
PAINTSTRUCT ps;
hDc = BeginPaint(hwnd,&ps);
TextOut(hDc,0,10,"鼠标左键已经被按下过",strlen("鼠标左键已经被按下过"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if (IDOK==MessageBox(hwnd,"您真的要退出应用程序","提示",MB_OKCANCEL))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
#include <stdio.h>LRESULT CALLBACK MyProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // pointer to command line
int nCmdShow // show state of window
)
{
WNDCLASS wnd;
wnd.cbClsExtra = 0;
wnd.cbWndExtra = 0;
wnd.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wnd.hCursor = LoadCursor(NULL,IDC_ARROW);
wnd.hIcon = LoadIcon(NULL,IDI_WINLOGO);
wnd.hInstance = hInstance;
wnd.lpfnWndProc = MyProc;
wnd.lpszClassName = "MyWindow";
wnd.lpszMenuName = NULL;
wnd.style = CS_HREDRAW|CS_VREDRAW; RegisterClass(&wnd); HWND hwnd;
hwnd = CreateWindow("MyWindow","我的窗口",WS_OVERLAPPEDWINDOW,
200,200,400,300,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd); MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}LRESULT CALLBACK MyProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_CHAR:
char str[20];
sprintf(str,"This keyCode is %d",wParam);
MessageBox(hwnd,str,"操作提示",MB_OK);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"您按下了鼠标左键","操作提示",MB_OK);
HDC hdc;
hdc = GetDC(hwnd);
TextOut(hdc,0,50,"鼠标左键已经被按下过",strlen("鼠标左键已经被按下过"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
HDC hDc;
PAINTSTRUCT ps;
hDc = BeginPaint(hwnd,&ps);
TextOut(hDc,0,10,"鼠标左键已经被按下过",strlen("鼠标左键已经被按下过"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if (IDOK==MessageBox(hwnd,"您真的要退出应用程序","提示",MB_OKCANCEL))
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}
LRESULT CALLBACK MyProc(
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
......
default:
DefWindowProc(hwnd,uMsg,wParam,lParam);
}
// return 0; 里改成下面语句,在没有说明如何处理消息时,都交给系统默认处理.
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return DefWindowProc(hwnd,uMsg,wParam,lParam);