孙鑫c++教程笔记(1)
来源:互联网 发布:sql删除重复保留唯一 编辑:程序博客网 时间:2024/06/05 18:20
一、句柄类型
图标句柄HICO、光标句柄HCURSOR、窗口句柄HWND、应用程序实例句柄类型HINSTANCE
二、Windows程序的入口函数
int WINAPI WinMain(
HINSTANCE hInstance, // handle to current instance
HINSTANCE hPrevInstance, // handle to previous instance
LPSTR lpCmdLine, // command line类似于传入参数 LP开头为长指针类型 int nCmdShow // show state窗口如何显示
);
三、创建完整窗口步骤:
1. 设计一个窗口类
窗口类:WNDCLASS
typedef struct _WNDCLASS {
UINT style;
WNDPROC lpfnWndProc; //指定回调函数
int cbClsExtra;
int cbWndExtra; //通常设为0
HANDLE hInstance; //实例号
HICON hIcon; //图标句柄
HCURSOR hCursor; //光标句柄
HBRUSH hbrBackground; //画刷,窗口背景颜色
LPCTSTR lpszMenuName; //菜单栏名字
LPCTSTR lpszClassName; //窗口名字
} WNDCLASS;
回调函数:WindowProc
LRESULT CALLBACK WindowProc( _In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam);
2. 注册窗口类
RegisterClass(窗口类指针)
3. 创建窗口
HWDN hwdn;
Hwdn=CreateWindows(classname,title,style,x,y,width,父窗口,菜单,实例号,多文档附加参数)
4. 显示及更新窗口
ShowWindow(hwdn,status);
UpdateWindow(hwnd)
四、GetMessage()获得窗口消息
csdn在线查询:https://msdn.microsoft.com/en-us/library/ms950410.aspx
第一节代码:
#include <windows.h>#include <stdio.h>LRESULT CALLBACK WinSunProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter);int WINAPI WinMain( HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPSTR lpCmdLine, // command line int nCmdShow // show state){WNDCLASS wndcls;wndcls.cbClsExtra=0;wndcls.cbWndExtra=0;wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);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,0,0,600,400,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 WinSunProc( HWND hwnd, // handle to window UINT uMsg, // message identifier WPARAM wParam, // first message parameter LPARAM lParam // second message parameter){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);TextOut(hdc,0,50,"计算机编程语言培训",strlen("计算机编程语言培训"));ReleaseDC(hwnd,hdc);break;case WM_PAINT: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);//quit windows}break;case WM_DESTROY:PostQuitMessage(0);//Getmessage() return 0;quit app ;break;default:return DefWindowProc(hwnd,uMsg,wParam,lParam);//default mes deal}return 0;}
- 孙鑫c++教程笔记(1)
- [Books]《C语言教程》笔记
- C语言设计教程笔记_概述
- C语言程序设计教程笔记_编译预处理
- c语言实训教程笔记
- 孙鑫VC教程学习笔记1
- 简明python教程自学笔记(1)
- 《AngularJS权威教程》笔记(1-2)
- 【笔记】Python算法教程(1)
- Git简易教程笔记(1)
- Git教程(笔记)
- git 教程(笔记)
- 0.《新概念51单片机C语言教程》(郭天祥)学习笔记
- c++primer笔记(1)
- C/C++笔记(1)
- C/C++笔记(1)
- Visual C++(笔记1)
- C语言笔记(1)
- 使用JDK自带HttpsURLConnection发送HTTPS请求
- postgresql 结束进程
- Kotlin 踩坑日记(三) Android Studio 3.0.0 Canary 编译错误
- js ——假值和sort
- 《大型网站技术架构:核心原理与案例分析》拜读总结,第七章——随需应变:网站的可扩展架构
- 孙鑫c++教程笔记(1)
- intelij idea快捷键
- React-Native之iOS集成支付宝支付
- android内存优化
- String相关知识点
- ionic用插件(cordova-plugin-baidumaplocation)定位并调百度地图在上面显示
- android 动画 过渡动画 transition
- MTK6735 竖屏横用、旋转90度、MTK_LCM_PHYSICAL_ROTATION
- mvc——从客户端(content="<p> &nb...")中检测到有潜在危险的 Request.Form