静态子窗口类型

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. elk收集tomcat日志

    1.elk收集tomcat普通日志: 只在logstash节点增加如下文件,重启logstash即可: cat >>/home/logstash-6.3.0/config/tomcat_t ...

  2. Spring Cloud(7.1):安装Kafka和Redis

    Kafka安装 (1)从官方(http://kafka.apache.org/downloads)下载安装包.kafka安装包和一般安装包的命名方式不一样,我们看一个kafka包命名:kafka_2. ...

  3. 【搬运】Visual Studio vs2017 vs2019 中文离线安装包下载,替代ISO镜像

    原文地址[侵删]:https://blog.csdn.net/fromfire2/article/details/81104648 以下为搬运内容: 官档地址 https://docs.microso ...

  4. 最新 荔枝java校招面经 (含整理过的面试题大全)

    从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.荔枝等10家互联网公司的校招Offer,因为某些自身原因最终选择了荔枝.6.7月主要是做系统复习.项目复盘.LeetCode ...

  5. [转载]Oracle触发器详解

    转载自http://blog.csdn.net/indexman/article/details/8023740/ 触发器是许多关系数据库系统都提供的一项技术.在oracle系统里,触发器类似过程和函 ...

  6. 封装Json+日志

    /** * 输出json * @param $msg * @param int $errno */ public function printOutError($msg = '操作失败', $errn ...

  7. fiddler手机抓包1

    1.手机抓包配置教程:https://www.jianshu.com/p/724097741bdf 2.

  8. WUSTOJ 1235: 计算矩阵的鞍点(Java)

    1235: 计算矩阵的鞍点 题目   输出二维数组中行上为最大,列上为最小的元素(称为鞍点)及其位置(行列下标).如果不存在任何鞍点,请输出"404 not found"(不带引号 ...

  9. 跟我一起学编程—《Scratch编程》第24课:幸运大转盘

    同学你好,欢迎来到<跟我一起学编程>,我是包老师.这是<Scratch3.0编程>课程的第24课,我这节课教你做一个抽奖游戏:幸运大转盘. 学习目标: 1. 能够熟练使用造型工 ...

  10. jenkins 打安卓包 cpu使用过高处理操作

    登录两个控制台 打包开始后 在其中一台机器执行ps -ef |grep jenkins 找到执行打包的主进程复制pid 在另一个终端上执行 top -H -p pid 将最耗cpu的线程id转换为16 ...