随笔 - 34, 文章 - 3, 评论 - 10, 引用 - 0
数据加载中……

vc 孙鑫 的第一讲 创建windows窗体代码

#include<windows.h>

#define null NULL

LRESULT CALLBACK WinProc( HWND hwnd,UINT uMsg,
WPARAM wParam, LPARAM lParam);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,
  LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASS wndClass;
wndClass.cbClsExtra = 0;
wndClass.cbWndExtra = 0;
wndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.hCursor = LoadCursor(null,IDC_CROSS);
wndClass.hIcon = LoadIcon(null,IDI_INFORMATION);
wndClass.hInstance = hInstance;
wndClass.lpfnWndProc = WinProc;
wndClass.lpszClassName = L"bmp";
wndClass.lpszMenuName = null;
wndClass.style = CS_HREDRAW|CS_VREDRAW;
RegisterClass(&wndClass);

HWND hwnd;
hwnd = CreateWindow(wndClass.lpszClassName , L"bmp" , WS_OVERLAPPEDWINDOW 
,0,0,500,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 WinProc( HWND hwnd,UINT uMsg,
WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_LBUTTONDOWN:
break;
case WM_PAINT:
HDC hDC;
PAINTSTRUCT ps;
hDC=BeginPaint(hwnd,&ps);
TextOut(hDC,0,0,L"维新培训",strlen("维新培训"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:            //关闭时响应
if(IDYES==MessageBox(hwnd,L"是否真的结束?",L"question",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);
}
return 0;
}

posted on 2008-09-13 00:29 wsy6634 阅读(355) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理