一个简单的窗口程序,在他的基础上就可以很容易的创建界面了
#include <windows.h> //这个程序所要包含的头文件
//这个是win32界面的helo world
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; //对消息处理函数的声明
#define ID_TIMER 1
#define BUTTON_ID 100
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow) //主函数,程序的入口点
{
HWND hwnd ;
MSG msg ;
WNDCLASS wndclass ;
//设计窗口类样式
wndclass.style = CS_HREDRAW | CS_VREDRAW ; //样式为水平和垂直重画
wndclass.lpfnWndProc = (WNDPROC)WndProc ; //指定消息处理函数
wndclass.cbClsExtra = 0 ; //不使额外空间
wndclass.cbWndExtra = 0 ; //不使额外空间
wndclass.hInstance = hInstance ; //程序的执行实体句柄
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;//加载图标
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;//加载光标
wndclass.hbrBackground =(HBRUSH)GetStockObject(WHITE_BRUSH) ;//取得画刷对象
wndclass.lpszMenuName = NULL ; //无窗口菜单,注:不是无系统菜单
wndclass.lpszClassName = "Lei"; //窗口类类名,必需与下文一致
//注册窗口类
RegisterClass (&wndclass) ;
//创建窗口
hwnd = CreateWindow ("Lei", // window class name
TEXT ("The Hello Program"), // window caption
WS_OVERLAPPEDWINDOW, // window style
240, // initial x position
240, // initial y position
400, // initial x size
400, // initial y size
NULL, // parent window handle
NULL, // window menu handle
hInstance, // program instance handle
NULL) ; // creation parameters
ShowWindow (hwnd, iCmdShow) ;//显示窗口
UpdateWindow (hwnd) ;//更新窗口
//消息循环
while (GetMessage (&msg, NULL, 0, 0)) //从消息对列中取得一条消息
{
TranslateMessage (&msg) ;// 将msg结构传给Windows,进行一些键盘转换
DispatchMessage (&msg) ;// 又将msg结构回传给Windows。然后,Windows
//将该消息发送给适当的窗口消息处理程序,让它进行处理
}
return msg.wParam ;// 结构的wParam字段是传递给PostQuitMessage函数的值(通// 常是0)。然后return叙述将退出WinMain并终止程序
}
//窗口消息处理函数
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HBRUSH hBrush ;
HDC hdc ;
PAINTSTRUCT ps ;
RECT rc ;
HWND hButton;
switch (message)
{
case WM_CREATE:
hButton= CreateWindow(TEXT("BUTTON"), //控件"类名称"
TEXT("按钮"),
WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON,10,10,50,50,hwnd,(HMENU)BUTTON_ID,//控件ID
((LPCREATESTRUCT) lParam)->hInstance,NULL);
case WM_COMMAND:
switch (LOWORD(wParam))
{
case BUTTON_ID:
MessageBox(hwnd, "按钮Clicked", "", MB_OK);
break;
}
return 0 ;
case WM_PAINT :
hdc = BeginPaint (hwnd, &ps) ;
GetClientRect (hwnd, &rc) ;
hBrush = CreateSolidBrush (RGB(222,255,222));
FillRect (hdc, &rc, hBrush) ;
EndPaint (hwnd, &ps) ;
DeleteObject (hBrush) ;
return 0 ;
case WM_DESTROY :
PostQuitMessage (0) ;
return 0 ;
}
return DefWindowProc (hwnd, message, wParam, lParam) ;// 。窗口消息处理//程序不予处理的所有消息应该被传给名为DefWindowProc的Windows函数
}
温馨提示:内容为网友见解,仅供参考