13 Windows编程——系统内置窗口子类型之静态子窗口
静态子窗口类型
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编程——系统内置窗口子类型之静态子窗口的更多相关文章
- 15 Windows编程——系统内置窗口子类型之button
button子类型BS_3STATE.BS_AUTO3STATE.BS_AUTOCHECKBOX 源码 #include<Windows.h> #include<Windowsx.h ...
- 16 Windows编程——系统内置窗口子类型之edit、ComboBox、ownerbutton、listbox
edit类型的子窗口 ES_MULTILINE:多行输入文本框 窗口的消息: WL_COMMAND: EN_CHANGE:当edit窗口内的文本内容改变的时候,edit子窗口给父窗口发送一个WL_CO ...
- 12 Windows编程——子窗口和系统内置窗口类“BUTTON”
创建子窗口类,使得子窗口有自己的处理过程. 子窗口类型WS_CHILD不能和WS_POPUP一起使用!为什么子窗口要有自己的处理过程?如果使用主窗口类来创建子窗口,那么子窗口和主窗口将公用窗口处理过程 ...
- windows 编程 —— 子窗口 与 子窗口控件
目录: 子窗口与主窗口的交互 子窗口控件 按钮类别 button 滚动条类别 scrollbar 静态类别 static 编辑框类别 edit 清单方块 listbox 子窗口与主窗口的交互 创建窗 ...
- 07 Windows编程——窗口滚动条
两个函数:GetScrolnfo和SetScrollnfo一个结构:SCROLLINFO两个消息:WM_CREATE和WM_SIZE 滚动条结构体 typedef struct tagSCROLLIN ...
- 【Windows编程】入门篇——win 32窗口的hello word!
✍ Windows编程基础 1.Win 32应用程序基本类型 1) 控制台程序 不需要完善的windows窗口,可以使用DOS窗口方式显示 2) Win 32窗口程序 包含窗口的程序,可以通过窗 ...
- 设置windows窗口ICON 【windows 编程】【API】【原创】
1. ICON介绍 最近开始接触windows 编程,因此将自己所接触的一些零散的知识进行整理并记录.本文主要介绍了如何更改windows对话框窗口的ICON图标.这里首先介绍一下windows IC ...
- Windows 编程中恼人的各种字符以及字符指针类型
在Windows编程中,很容易见到这些数据类型:LPSTR,LPTSTR,LPCTSTR... 像很多童鞋一样,当初在学Windows编程的时候,对着些数据类型真的是丈二和尚,摸不着头脑,长时间不用就 ...
- Windows编程___创建窗口
创建Windows窗口不难,可以简要的概括为: 1,# 注册一个窗口类 填充WNDCLASS结构 书写窗口消息处理函数WinProc 2,# 创建一个窗口 填写基本的窗口信息 3,# 显示窗口 4,# ...
随机推荐
- Java测试当前应用所占用的内存示例
package test; import java.util.HashMap; import java.util.Map; public class TestMemory { public stati ...
- mysql删除某一个数据库中所有的表
SELECT concat('DROP TABLE IF EXISTS ', table_name, ';') FROM information_schema.tables WHERE table_s ...
- Object.defineProperty()方法学习笔记
这是js中一个非常重要的方法,ES6中某些方法的实现依赖于它,VUE通过它实现双向绑定 此方法会直接在一个对象上定义一个新属性,或者修改一个已经存在的属性, 并返回这个对象 参数 Object.def ...
- SpringBoot中使用 RabbitMQ -测试
本章主要建立在已经安装好Erlang以及RabbitMQ的基础上,接下来,简单介绍一下使用 1.首先到RabbitMQ的管理界面新建一个队列(Direct模式) 2.测试项目的基础结构如下: 这里为了 ...
- c#,简单的冒泡排序
冒泡排序 ,,,,,,,,,}; //bool IsSort; //do //{ // IsSort = true; // for (int i = 0; i < Nums.Length - 1 ...
- vue-cli webpack打包后加载资源的路径问题
vue项目,访问打包后的项目,输入路径后,页面加载空白.这时会有两类问题,都是路径问题. 1.一个是css,js,ico等文件加载不到,是目录里少了dist 打开页面时一片空白 解决办法: confi ...
- TypeScript 枚举
我们常常会有这样的场景,比如与后端开发约定订单的状态开始是0,未结账是1,运输中是2,运输完成是3,已收货是4.这样的纯数字会使得代码缺乏可读性.枚举就用于这样的场景.枚举可以让我们定义一些名字有意义 ...
- windows MinGW gcc 编译乱码问题
问题描述 一般很多编辑器默认都是保存成utf-8文件,然而在输出中文的时候出现了乱码?另外试了其他方法,有的乱码,有的不乱? MinGW gcc 编译 utf-8 文件的时候乱码 MinGW gcc ...
- consul 初体验
consul server: 192.168.48.134: #!/bin/bash cd /data/server/consuls nohup /data/server/consuls/consul ...
- 网络编程[第一篇]基于tcp协议的套接字编程
将服务端-客户端的连接比作双方打电话的过程 2019-07-24 一.客户端 主动的一方: 客户端实例化一个socket对象--> 主动像服务端发送连接请求--> (服务端接受请求后即可进 ...