静态子窗口类型

wndclass:static

源码

 #include<Windows.h>
#include<Windowsx.h> HINSTANCE G_h;
LRESULT CALLBACK WindProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); int WinMain(HINSTANCE hInst, HINSTANCE tmp, LPSTR szCmd, int nShow)
{
WNDCLASS WndClass;
TCHAR* ClassName = TEXT("MyClass");
HWND hwnd;
MSG msg;
HBRUSH hBrush = CreateSolidBrush(RGB(, , )); G_h = hInst;
WndClass.cbClsExtra = ;
WndClass.cbWndExtra = ;
WndClass.hbrBackground = hBrush;
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hInstance = hInst;
WndClass.lpfnWndProc = WindProc;
WndClass.lpszClassName = ClassName;
WndClass.lpszMenuName = NULL;
WndClass.style = CS_VREDRAW | CS_HREDRAW; if (!RegisterClass(&WndClass))
{
MessageBox(NULL, TEXT("Gegister Class Fail!!"), TEXT("error"), MB_OK);
return ;
} //CreateWindow返回之前,会发送WM_CREATE消息
hwnd = CreateWindow(ClassName, TEXT("Hello"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, , , NULL, NULL, hInst, NULL);
if (hwnd == NULL)
{
MessageBox(NULL, TEXT("Create Window Fail!!"), TEXT("error"), MB_OK);
return ;
}
ShowWindow(hwnd, nShow);
UpdateWindow(hwnd); while (GetMessage(&msg, NULL, , ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return ;
} LRESULT CALLBACK WindProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT pt;
static HWND chwnd;
int cx, cy;
HBRUSH hBrush = CreateSolidBrush(RGB(, , ));
switch (message)
{
case WM_CREATE:
//法1 获得主程序句柄
chwnd = CreateWindow(TEXT("static"), TEXT("中国"), WS_CHILD | WS_VISIBLE|SS_CENTER, , , , , hwnd, (HMENU), ((LPCREATESTRUCT)lParam)->hInstance, NULL);
//法2 获得主程序句柄
//hwnd = CreateWindow(TEXT("static"), TEXT("中国"), WS_CHILD | WS_VISIBLE, 0, 0, 50, 50, hwnd, (HMENU)1, G_h, NULL);
//发3 获得主程序句柄
//hwnd = CreateWindow(TEXT("static"), TEXT("中国"), WS_CHILD | WS_VISIBLE, 0, 0, 50, 50, hwnd, (HMENU)1, GetModuleHandle(NULL), NULL);
return ;
case WM_SIZE:
cx = LOWORD(lParam);
cy = HIWORD(lParam);
MoveWindow(chwnd, cx / ,cy / , cx / , cy / , TRUE);
return ;
case WM_CTLCOLORSTATIC:
SetTextColor((HDC)wParam, RGB(, , ));
SetBkMode((HDC)wParam, TRANSPARENT);
return (LRESULT)hBrush;
case WM_COMMAND:
return ;
case WM_DESTROY:
PostQuitMessage();
return ;
default:
break;
} return DefWindowProc(hwnd, message, wParam, lParam);
}

替换子窗口窗口处理过程,源码

 #include<Windows.h>
#include<Windowsx.h>
//#define _AFXDLL
//#include<afx.h> HINSTANCE G_h;
LRESULT CALLBACK WindProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MyProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); int WinMain(HINSTANCE hInst, HINSTANCE tmp, LPSTR szCmd, int nShow)
{
WNDCLASS WndClass;
TCHAR* ClassName = TEXT("MyClass");
HWND hwnd;
MSG msg;
HBRUSH hBrush = CreateSolidBrush(RGB(, , )); G_h = hInst;
WndClass.cbClsExtra = ;
WndClass.cbWndExtra = ;
WndClass.hbrBackground = hBrush;
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hInstance = hInst;
WndClass.lpfnWndProc = WindProc;
WndClass.lpszClassName = ClassName;
WndClass.lpszMenuName = NULL;
WndClass.style = CS_VREDRAW | CS_HREDRAW; if (!RegisterClass(&WndClass))
{
MessageBox(NULL, TEXT("Gegister Class Fail!!"), TEXT("error"), MB_OK);
return ;
} //CreateWindow返回之前,会发送WM_CREATE消息
hwnd = CreateWindow(ClassName, TEXT("Hello"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, , , NULL, NULL, hInst, NULL);
if (hwnd == NULL)
{
MessageBox(NULL, TEXT("Create Window Fail!!"), TEXT("error"), MB_OK);
return ;
}
ShowWindow(hwnd, nShow);
UpdateWindow(hwnd); while (GetMessage(&msg, NULL, , ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return ;
} LRESULT CALLBACK WindProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT pt;
static HWND chwnd;
int cx, cy;
HBRUSH hBrush = CreateSolidBrush(RGB(, , ));
switch (message)
{
case WM_CREATE:
//法1 获得主程序句柄
chwnd = CreateWindow(TEXT("static"), TEXT("中国"), WS_CHILD | WS_VISIBLE | SS_CENTER, , , , , hwnd, (HMENU), ((LPCREATESTRUCT)lParam)->hInstance, NULL);
//法2 获得主程序句柄
//hwnd = CreateWindow(TEXT("static"), TEXT("中国"), WS_CHILD | WS_VISIBLE, 0, 0, 50, 50, hwnd, (HMENU)1, G_h, NULL);
//发3 获得主程序句柄
//hwnd = CreateWindow(TEXT("static"), TEXT("中国"), WS_CHILD | WS_VISIBLE, 0, 0, 50, 50, hwnd, (HMENU)1, GetModuleHandle(NULL), NULL);
//这个函数将窗口chwnd的窗口处理过程改变为MyProc。这个函数的作用,相当于把static窗口类中的lpfnWndProc值设置为MyProc
SetWindowLong(chwnd, GWL_WNDPROC, (LONG)MyProc);
return ;
case WM_SIZE:
cx = LOWORD(lParam);
cy = HIWORD(lParam);
MoveWindow(chwnd, cx / , cy / , cx / , cy / , TRUE);
return ;
case WM_CTLCOLORSTATIC:
//TRACE("WM_CTLCOLORSTATIC\n");
SetTextColor((HDC)wParam, RGB(, , ));
SetBkMode((HDC)wParam, TRANSPARENT);
return (LRESULT)hBrush;
case WM_COMMAND:
return ;
case WM_DESTROY:
PostQuitMessage();
return ;
default:
break;
} return DefWindowProc(hwnd, message, wParam, lParam);
} LRESULT CALLBACK MyProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//TRACE("MyProc\n");
PAINTSTRUCT ps;
HDC hdc;
static int cx, cy;
switch (message)
{
case WM_SIZE:
cx = LOWORD(lParam);
cy = HIWORD(lParam);
return ;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
Rectangle(hdc, , , cx, cy);
TextOut(hdc, , , TEXT("child"), );
EndPaint(hwnd, &ps);
return ;
case WM_DESTROY:
PostQuitMessage();
return ;
default:
break;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}

拦截窗口处理消息

 #include<Windows.h>
#include<Windowsx.h>
//#define _AFXDLL
//#include<afx.h> DWORD proc;
HINSTANCE G_h;
LRESULT CALLBACK WindProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
LRESULT CALLBACK MyProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); int WinMain(HINSTANCE hInst, HINSTANCE tmp, LPSTR szCmd, int nShow)
{
WNDCLASS WndClass;
TCHAR* ClassName = TEXT("MyClass");
HWND hwnd;
MSG msg;
HBRUSH hBrush = CreateSolidBrush(RGB(, , )); G_h = hInst;
WndClass.cbClsExtra = ;
WndClass.cbWndExtra = ;
WndClass.hbrBackground = hBrush;
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hInstance = hInst;
WndClass.lpfnWndProc = WindProc;
WndClass.lpszClassName = ClassName;
WndClass.lpszMenuName = NULL;
WndClass.style = CS_VREDRAW | CS_HREDRAW; if (!RegisterClass(&WndClass))
{
MessageBox(NULL, TEXT("Gegister Class Fail!!"), TEXT("error"), MB_OK);
return ;
} //CreateWindow返回之前,会发送WM_CREATE消息
hwnd = CreateWindow(ClassName, TEXT("Hello"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, , , NULL, NULL, hInst, NULL);
if (hwnd == NULL)
{
MessageBox(NULL, TEXT("Create Window Fail!!"), TEXT("error"), MB_OK);
return ;
}
ShowWindow(hwnd, nShow);
UpdateWindow(hwnd); while (GetMessage(&msg, NULL, , ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
} return ;
} LRESULT CALLBACK WindProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT pt;
static HWND chwnd;
int cx, cy;
HBRUSH hBrush = CreateSolidBrush(RGB(, , ));
switch (message)
{
case WM_CREATE:
//法1 获得主程序句柄
chwnd = CreateWindow(TEXT("static"), TEXT("中国"), WS_CHILD | WS_VISIBLE | SS_CENTER|SS_NOTIFY, , , , , hwnd, (HMENU), ((LPCREATESTRUCT)lParam)->hInstance, NULL);
//法2 获得主程序句柄
//hwnd = CreateWindow(TEXT("static"), TEXT("中国"), WS_CHILD | WS_VISIBLE, 0, 0, 50, 50, hwnd, (HMENU)1, G_h, NULL);
//发3 获得主程序句柄
//hwnd = CreateWindow(TEXT("static"), TEXT("中国"), WS_CHILD | WS_VISIBLE, 0, 0, 50, 50, hwnd, (HMENU)1, GetModuleHandle(NULL), NULL);
//这个函数将窗口chwnd的窗口处理过程改变为MyProc。这个函数的作用,相当于把static窗口类中的lpfnWndProc值设置为MyProc
proc=SetWindowLong(chwnd, GWL_WNDPROC, (LONG)MyProc);
return ;
case WM_SIZE:
cx = LOWORD(lParam);
cy = HIWORD(lParam);
MoveWindow(chwnd, cx / , cy / , cx / , cy / , TRUE);
return ;
case WM_CTLCOLORSTATIC:
//TRACE("WM_CTLCOLORSTATIC\n");
SetTextColor((HDC)wParam, RGB(, , ));
SetBkMode((HDC)wParam, TRANSPARENT);
return (LRESULT)hBrush;
case WM_COMMAND:
return ;
case WM_DESTROY:
PostQuitMessage();
return ;
default:
break;
} return DefWindowProc(hwnd, message, wParam, lParam);
} LRESULT CALLBACK MyProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//TRACE("MyProc\n");
PAINTSTRUCT ps;
HDC hdc;
static int cx, cy;
//TRACE("%d %d %d\n", message, wParam, lParam);
switch (message)
{
case WM_SIZE:
cx = LOWORD(lParam);
cy = HIWORD(lParam);
//return 0;
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
Rectangle(hdc, , , cx, cy);
TextOut(hdc, , , TEXT("child"), );
EndPaint(hwnd, &ps);
//return 0;
break;
default:
break;
}
return ((LRESULT (CALLBACK*)(HWND , UINT , WPARAM , LPARAM ))proc)(hwnd, message, wParam, lParam);
}

13 Windows编程——系统内置窗口子类型之静态子窗口的更多相关文章

  1. 15 Windows编程——系统内置窗口子类型之button

    button子类型BS_3STATE.BS_AUTO3STATE.BS_AUTOCHECKBOX 源码 #include<Windows.h> #include<Windowsx.h ...

  2. 16 Windows编程——系统内置窗口子类型之edit、ComboBox、ownerbutton、listbox

    edit类型的子窗口 ES_MULTILINE:多行输入文本框 窗口的消息: WL_COMMAND: EN_CHANGE:当edit窗口内的文本内容改变的时候,edit子窗口给父窗口发送一个WL_CO ...

  3. 12 Windows编程——子窗口和系统内置窗口类“BUTTON”

    创建子窗口类,使得子窗口有自己的处理过程. 子窗口类型WS_CHILD不能和WS_POPUP一起使用!为什么子窗口要有自己的处理过程?如果使用主窗口类来创建子窗口,那么子窗口和主窗口将公用窗口处理过程 ...

  4. windows 编程 —— 子窗口 与 子窗口控件

    目录: 子窗口与主窗口的交互 子窗口控件 按钮类别 button 滚动条类别 scrollbar 静态类别  static 编辑框类别 edit 清单方块 listbox 子窗口与主窗口的交互 创建窗 ...

  5. 07 Windows编程——窗口滚动条

    两个函数:GetScrolnfo和SetScrollnfo一个结构:SCROLLINFO两个消息:WM_CREATE和WM_SIZE 滚动条结构体 typedef struct tagSCROLLIN ...

  6. 【Windows编程】入门篇——win 32窗口的hello word!

    ✍  Windows编程基础 1.Win 32应用程序基本类型 1)  控制台程序 不需要完善的windows窗口,可以使用DOS窗口方式显示 2)  Win 32窗口程序 包含窗口的程序,可以通过窗 ...

  7. 设置windows窗口ICON 【windows 编程】【API】【原创】

    1. ICON介绍 最近开始接触windows 编程,因此将自己所接触的一些零散的知识进行整理并记录.本文主要介绍了如何更改windows对话框窗口的ICON图标.这里首先介绍一下windows IC ...

  8. Windows 编程中恼人的各种字符以及字符指针类型

    在Windows编程中,很容易见到这些数据类型:LPSTR,LPTSTR,LPCTSTR... 像很多童鞋一样,当初在学Windows编程的时候,对着些数据类型真的是丈二和尚,摸不着头脑,长时间不用就 ...

  9. Windows编程___创建窗口

    创建Windows窗口不难,可以简要的概括为: 1,# 注册一个窗口类 填充WNDCLASS结构 书写窗口消息处理函数WinProc 2,# 创建一个窗口 填写基本的窗口信息 3,# 显示窗口 4,# ...

随机推荐

  1. RocketMQ共包含9个模块

    rocketmq-common:通用的枚举.基类方法.或者数据结构,包名有admin.consumer.filter.hook.message rocketmq-remoting:使用netty的客户 ...

  2. Eclipse导入Spring Boot项目后pom.xml出现红叉的解决办法

    胸怀难的问题是:程序能正常运行,但是pom.xml下面有一个红叉. 解决办法: 右键项目 --> Update project...

  3. CentOS设置交换分区swap

    环境查看 查看未设置交换分区之前 free -h 新加一块磁盘用于交换分区/dev/sdc 格式化 mkswap /dev/sdc 设置为交换分区 swapon /dev/sdc 再次查看 设置为重启 ...

  4. 20190923-基于Python3的RobotFramework的配置是初次使用

    因为最近改自动化框架在网上找了很多框架,发现RobotFramework不错,但是网上的资料很杂,现在将自己配置框架的学习笔记分享 Python配置RobotFramework的seleniumlib ...

  5. Bilibili用户需求分析报告

    一.产品简介 哔哩哔哩(英文名称:bilibili,简称B站)是国内知名的弹幕视频分享站,也是国内领先的年轻人文化社区 二.用户需求分析 (一)目标用户 根据百度指数,bilibili的主要用户遍布沿 ...

  6. 解决用cmd编译运行java时的错误

    最近上java课程,平时都是用IDEA打代码的,但老师要我们用cmd编译运行,于是在IDEA撸完代码用cmd编译,但却老是编译不出来,有很多乱码.,提示着“错误:GBK的不可映射字符”,又试了几次,着 ...

  7. python邮件发送自动化测试报告

    话不多说直接贴代码 # encoding: utf-8import smtplib #发送邮件模块from email.mime.text import MIMEText #邮件内容from emai ...

  8. luogu1972:HH的项链

    题目描述 HH 有一串由各种漂亮的贝壳组成的项链.HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH 不断地收集新的贝壳,因此,他的项链变得越来越长. ...

  9. CardView的使用(可以实现圆角控件)

    简介:ardView继承自FrameLayout,它是一个带圆角背景和阴影的FrameLayout 一些什么实现方式就不赘述了,直接上用法 CardView的常用属性   1.设置背景颜色  app: ...

  10. websocket抓包

    https://www.cnblogs.com/xiaoniuzai/p/7588739.html http://blog.sina.com.cn/s/blog_12df1b9e60102vyeq.h ...