Windows编程

#include <windows.h>

//窗口处理函数
//CALLBACK 调用约定
LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam);

//窗口程序的入口函数WinMain
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR lpCmdLine, int nCmdshow)
{
	//int n = MessageBox(NULL,L"Hello World",L"第一个窗口程序",MB_OK|MB_ICONERROR);
	//API:应用程序编程接口 Application Interface
	//windows api 函数
	//SDK 软件开发包 Software Development Kit
	//包含API函数库,帮助手册,辅助工具,使用文档

	//什么是窗口,包含标题栏,菜单栏,系统菜单,最小化框,最大化框,滚动
	//句柄
	//窗口句柄,图标句柄,光标句柄,进程句柄,线程句柄
	//typedef struct tagWNDCLASSW {
	//	UINT        style;
	//	WNDPROC     lpfnWndProc;
	//	int         cbClsExtra;
	//	int         cbWndExtra;
	//	HINSTANCE   hInstance;
	//	HICON       hIcon;
	//	HCURSOR     hCursor;
	//	HBRUSH      hbrBackground;
	//	LPCWSTR     lpszMenuName;
	//	LPCWSTR     lpszClassName;
	//} WNDCLASSW, *PWNDCLASSW, NEAR *NPWNDCLASSW, FAR *LPWNDCLASSW;
	//1.设计窗口类
	wchar_t szAppClassName[255] = L"我的第一个窗口程序";
	wchar_t szWindowsName[255] = L"我是大帅比";
	WNDCLASS wc;
	wc.style = CS_HREDRAW|CS_VREDRAW;						//窗口类的风格
	wc.lpfnWndProc = WindowProc;							//窗口处理函数
	wc.cbClsExtra = 0;										//窗口类的额外扩展空间(字节)
	wc.cbWndExtra = 0;										//窗口的额外拓展空间大小(字节)
	wc.hInstance = hInstance;								//当前应用程序实例句柄
	wc.hIcon = NULL;										//窗口图标句柄 NULL无图标
	wc.hCursor = NULL;										//光标句柄
	wc.hbrBackground = CreateSolidBrush(RGB(255,255,255));	//背景画刷
	wc.lpszMenuName = NULL;								//
	wc.lpszClassName = szAppClassName; 						//窗口类型名

	//2.注册窗口类
	if (0 == RegisterClass(&wc))
	{
		MessageBox(NULL,L"注册失败!",L"温馨提示",MB_OK);
	}

	//3.创建窗口
	HWND mywindow = CreateWindow(
		szAppClassName,									//窗口类型名
		szWindowsName,									//窗口的标题
		WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX|WS_MINIMIZE,		//窗口的风格
		200,											//窗口的x坐标
		200,											//窗口的y坐标
		800,											//窗口的宽
		600,											//窗口的高
		NULL,											//父窗口句柄
		NULL,											//菜单的句柄
		hInstance,										//应用程序实例句柄
		NULL											//创建的返回值
	); 
	if (mywindow == NULL)
	{
		MessageBox(NULL, L"窗口创建失败!", L"温馨提示", MB_OK);
	}
	//4.显示窗口
	ShowWindow(mywindow,SW_SHOW);

	//5.更新窗口
	UpdateWindow(mywindow);
	//6.消息循环
//	typedef struct tagMSG {
//		HWND        hwnd;
//		UINT        message;
//		WPARAM      wParam;
//		LPARAM      lParam;
//		DWORD       time;
//		POINT       pt;
//#ifdef _MAC
//		DWORD       lPrivate;
//#endif
//	} MSG, *PMSG, NEAR *NPMSG, FAR *LPMSG;
	MSG msg;
	while (GetMessage(&msg, NULL, 0, 0))
	{
		//将虚拟键消息转为字符消息
		TranslateMessage(&msg);
		//将消息分发给窗口处理函数
		DispatchMessage(&msg);
	}
	//msg.hwnd = mywindow;					//消息发给哪一个窗口句柄
	//msg.message = ;							//消息编号
	//msg.wParam = ;							//附加信息
	//msg.lParam = ;							//附加信息
	//msg.time = ;							//消息投放到队列里面的时间
	//msg.pt = ;								//消息放入消息时鼠标的位置
}

//hwnd:窗口句柄,uMsg:消息编号 wParam:窗口附加信息 lParam: 窗口附加信息
LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	return  DefWindowProc(hwnd,uMsg,wParam,lParam);//操作系统默认处理消息的函数
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Forger 推荐的学习windows 编程的所有书籍都在这儿: windows 编程 windows MFC入门到精通 windows 高级编程 windows 网络编程 Programming Windows Programming Windows with MFC Programming Applications for Windows Network Programming for Microsoft Windows Programming Windows by Charles Petzold. The book to get on Win32 API. If you want to write programs using just the API (which is what this tutorial covers), you need this book. 如果你想只用windows API编程,这本书是入门经典,你需要这本书。 Programming Windows with MFC by Jeff Prosise. If you want to venture into MFC (AFTER becoming fully accustomed to using the Win32 API), this is the book for you. If you don't like MFC but intend on getting a job doing windows developement, get this anyway, it's better to know than not. 如果你想用MFC这本书是你想要的 Programming Applications for Windows by Jeffrey Richter. Not for newbies, if you want to be up on managing processes and threads, dlls, windows memory management, exception handling, and hooking into the system, then this is the book for you. 如果你想了解操作系统内幕,这本书是经典,书中包含了进程,线程,动态库,windows内存管理,异常处理。。。 Visual C++ Windows Shell Programming by Dino Esposito. For anyone interested in the visual and user-friendly aspects of windows, this book covers writing extentions to the windows shell, working efficiently with files and drag and drop, customizing the taskbar and windows explorer, and numerous other tricks. Well worthwhile for anyone writing GUI apps in windows. Network Programming for Microsoft Windows Up to date information on network programming, including NetBIOS, mailslots and pipes, and of course the ever important windows sockets, complete with winsock2 and raw sockets. Also contains specific information on the various windows platforms including 2000 and CE.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值