#include <windows.h>
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM); //窗口函数说明
//---------------以下初始化窗口类----------------------
int WINAPI WinMain(HINSTANCE hInstance, //窗口函数说明
HINSTANCE hPrevInst,
LPSTR lpszCmdLine,
int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
char lpszClassName[]="窗口"; //窗口类名
char lpszTitle[]="My_Windows"; //窗口标题
//窗口类的定义
wndclass.style = 0; //窗口类型为默认类型
wndclass.lpfnWndProc = WndProc; //窗口处理函数为WndProc
wndclass.cbClsExtra = 0; //窗口类无扩展
wndclass.cbWndExtra = 0; //窗口实例无扩展
wndclass.hInstance = hInstance; //当前实例句柄
wndclass.hIcon = LoadCursor(NULL,IDI_APPLICATION); //窗口的最小化图标为默认图标
wndclass.hCursor = loadCursor(NULL,IDC_ARROW); //窗口采用箭头光标
wndclass.hbrBackground = GetStockobject(WHITE_BRUSH);// 窗口背景为白色
wndclass.lpsMenuName = NULL; //窗口中无菜单
wndclass.lpszClassName = lpszClassName; //窗口类名为"窗口示例"
//-------------------------------------以下进行窗口类的注册------------------------------------
if (! registerClass(&wndclass)) //如果注册失败则发出警告
{
MessageBeep(0);
return FALSE;
}
//创建窗口
hwnd = CreateWindow(lpszClassName, //窗口类名
lpszTitle, //窗口实例的标题名
WS_OVERLAPPEDWINDOW //窗口的风格
CW_USEDEFAULT,
CW_USEDEFAULT, //窗口左上角坐标为默认值
CW_USEDEFAULT,
CW_USEDEFAULT, //窗口的高和宽为默认值
NULL,
NULL,
hInstance, //创建此窗口的应用程序的当前句柄
NULL);
//显示窗口
ShowWindow(hwnd,nCmdShow);
//绘制用户区
UpdateWindow(hwnd);
//消息循环
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
return Msg.wParam;
}
//
LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
switch (message)
{
case WM_D ESTROY:
PostQuitMessage(0);
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd , UINT message ,WPARAM wParam,LPARAM lParam){
switch (message){
case WM_PAINT: {
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd,&ps);
TextOut(hdc,10,20,"haha" ,28);
EndPaint(hwnd,&ps);
return 0;
}
case WM_DESTROY:{
PostQuitMessage(0);
return 0;
}
}
return DefWindowProc(hwnd ,message ,wParam ,lParam);
// return 0;
};
BOOL RegisterClassB(CONST WNDCLASS *lpWndClass);
int WINAPI WinMain(HINSTANCE hThisInst ,HINSTANCE hPrevInst ,LPSTR lpszCmdLine ,int nShowCmd);
HWND CreateWindowB
(
LPCTSTR lpszClassName ,
LPCTSTR lpszTitle ,
DWORD dwStyle ,
int x , int y ,
int nWidth , int nHeight ,
HWND hwndParent ,
HMENU hMenu ,
HINSTANCE hInstance ,
LPVOID lpParame
);
int APIENTRY WinMain(
HINSTANCE hInstance,HINSTANCE hPrevInstance ,LPSTR lpCmdLine , int nCmdShow)
{
WNDCLASS wndclass;
HWND hwnd;
MSG msg;
/*
wndclass.style = CS_HREDRAW|CS_VREDRAW;
wndclass.lpfnWndProc = 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(1);
*/
wndclass.style = 0; //窗口类型为默认类型
wndclass.lpfnWndProc = WndProc; //窗口处理函数为WndProc
wndclass.cbClsExtra = 0; //窗口类无扩展
wndclass.cbWndExtra = 0; //窗口实例无扩展
wndclass.hInstance = hInstance; //当前实例句柄
wndclass.hIcon = LoadCursor(NULL,IDI_APPLICATION); //窗口的最小化图标为默认图标
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW); //窗口采用箭头光标
wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);// 窗口背景为白色
wndclass.lpszMenuName = NULL; //窗口中无菜单
wndclass.lpszClassName = "windwos"; //窗口类名为"窗口示例"
if (! RegisterClass(&wndclass)) //如果注册失败则发出警告
{
MessageBeep(0);
return FALSE;
}
/*
hwnd = CreateWindow("lpszClassName", //窗口类名
"lpszTitle", //窗口实例的标题名
WS_OVERLAPPEDWINDOW, //窗口的风格
CW_USEDEFAULT,
CW_USEDEFAULT, //窗口左上角坐标为默认值
CW_USEDEFAULT,
CW_USEDEFAULT, //窗口的高和宽为默认值
NULL,
NULL,
hInstance, //创建此窗口的应用程序的当前句柄
NULL
);
*/
hwnd = CreateWindow(
"windwos" ,
"窗口创建" ,
WS_OVERLAPPEDWINDOW ,
CW_USEDEFAULT , CW_USEDEFAULT,
CW_USEDEFAULT , CW_USEDEFAULT,
NULL ,
NULL ,
hInstance ,
NULL );
ShowWindow(hwnd,nCmdShow);
UpdateWindow(hwnd);
while(GetMessage (&msg ,NULL ,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}