Windowsフォームプログラム開発基本プロセス
孫鑫先生のVC++シリーズ第一課から
#include <windows.h>
#include <stdio.h>
// , , ,CALLBACK __stdcall
LRESULT CALLBACK WinSunProc(
HWND hwnd, //
UINT uMsg, //
WPARAM wParam, //
LPARAM lParam //
);
//WinMain ,
int WINAPI WinMain(
HINSTANCE hInstance, //
HINSTANCE hPrevInstance, //
LPSTR lpCmdLine, // Cmd
int nCmdShow // ,
)
{
//
WNDCLASS wndcls;
wndcls.cbClsExtra=0;// , 0
wndcls.cbWndExtra=0;// , 0
wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);// ( HGDIOBJ )
wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);//
wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);//
wndcls.hInstance=hInstance;//
wndcls.lpfnWndProc=WinSunProc;//
wndcls.lpszClassName="Weixin2003";//
wndcls.lpszMenuName=NULL;//
wndcls.style=CS_HREDRAW | CS_VREDRAW;//
RegisterClass(&wndcls);//
HWND hwnd;
// , , ,
hwnd=CreateWindow("Weixin2003"," ",WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,SW_SHOWNORMAL);//
UpdateWindow(hwnd);//
MSG msg;
//
while(GetMessage(&msg,NULL,0,0))// WM_QUIT, ; WM_QUIT,
{
TranslateMessage(&msg);// , WM_KEYDOWN WM_KEYUP WM_CHAR
DispatchMessage(&msg);//
}
return 0;
}
LRESULT CALLBACK WinSunProc(
HWND hwnd, //
UINT uMsg, //
WPARAM wParam, //
LPARAM lParam //
)
{
switch(uMsg)//
{
case WM_CHAR:
char szChar[20];
sprintf(szChar,"char is %d",wParam);
MessageBox(hwnd,szChar,"weixin",0);
break;
case WM_LBUTTONDOWN:
MessageBox(hwnd,"mouse clicked","weixin",0);
HDC hdc;
hdc=GetDC(hwnd);//GetDC ReleaseDC
TextOut(hdc,0,50," ",strlen(" "));
ReleaseDC(hwnd,hdc);// HDC,
break;
case WM_PAINT://
/* width height ( ) ,
, 。
BeginPaint EndPaint , */
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0," ",strlen(" "));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd," ?","weixin",MB_YESNO))
{
DestroyWindow(hwnd);// WM_DESTROY ,
}
break;
case WM_DESTROY:
PostQuitMessage(0);// WM_QUIT ,
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);// , ,
}
return 0;
}