#include <windows.h>
#include <stdio.h> LRESULT CALLBACK WinSunProc(
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, // command line
int nCmdShow // show state
)
{
WNDCLASS wndcls;
wndcls.cbClsExtra=0;
wndcls.cbWndExtra=0;
wndcls.hbrBackground=(HBRUSH)GetStockObject(GRAY_BRUSH);
wndcls.hCursor=LoadCursor(NULL,IDC_WAIT);
wndcls.hIcon=LoadIcon(NULL,IDI_ASTERISK);
wndcls.hInstance=hInstance;
wndcls.lpfnWndProc=WinSunProc;
wndcls.lpszClassName="waru123";
wndcls.lpszMenuName=NULL;
wndcls.style=CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndcls); HWND hwnd;
hwnd=CreateWindow("waru123","我的VC++学习之旅",WS_GROUP,
100,100,800,600,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 WinSunProc( //上面有了,为什么这里又出现一遍?
HWND hwnd, // handle to window
UINT uMsg, // message identifier
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg) //为什么是uMsg switch选择的是信息,写Msg却是错误的
{
case WM_CHAR:
char szChar[20]; //这数组里面数为20,这个是怎么确定的?
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"你好",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","再见",0);
HDC hdc;
hdc=GetDC(hwnd);
TextOut(hdc,0,50,"恭喜你成功左击",strlen("恭喜你成功左击"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT: //这个WM_PAINT到底是个什么样的消息??说明看的不太懂。是重绘吗?不对啊,重绘应该是updateWindow吧?
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,"啦啦啦啦,第一个小窗口",strlen("啦啦啦啦,第一个小窗口"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"是否真的结束?","再见",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
} //最后,还有两个问题不是很明白,一个是wParam和lparam的区别,还有一个是_stdcall和_cdecl这两个的区别。
//另外,我看孙老师编程的时候,wndcls.hbrBackground 比如说这程序,他就打了几个字,然后能自动弹出下拉菜单选择需要定义的参数,这个是怎么做到的?是输入法还是VC里面设置的呢?