静态子窗口类型

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. (七)Centos之链接命令

    一.链接命令:ln  (link) ln -s [源文件] [目标文件] 功能描述:生成链接文件 选项: -s 创建软链接 二.硬链接 硬链接特征: 1,拥有相同的i节点和存储block块,可以看作是 ...

  2. 微信支付 composer 方法 --- 实测有效

    <h1 align="center">Pay</h1> <p align="center"> <a href=&quo ...

  3. AFN使用etag进行网络缓存

    前提:后台返回的接口带etag 第一步 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( ...

  4. 网络损伤仪细分市场:eCPRI网络损伤的技术要求

    关于“网络损伤仪”的叫法 网络损伤仪,也称作为广域网仿真仪,广域网损伤仪,WAN Emulation,Network Impairment Emulator. 为什么会带WAN广域网这个限定词? 应该 ...

  5. C/C++查漏补缺(常更)

    一.#define宏定义 如下程序段,则输出结果为: #define MAX 12 int main(){ cout << "20\0MAX019" << ...

  6. 使用runtime完成解档归档

    简单的创建一个Person对象,并声明几个属性 @interface Person : NSObject<NSCoding> // 归档问题 必须遵守该协议 /** */ @propert ...

  7. Python中的并行编程速度

    这里主要想记录下今天碰到的一个小知识点:Python中的并行编程速率如何? 我想把AutoTool做一个并行化改造,主要目的当然是想提高多任务的执行速度.第一反应就是想到用多线程执行不同模块任务,但是 ...

  8. ${__setProperty(row,rowNum)};不能在import XXX后面使用;

    如下 ${__javaScript只能用一次调用 excel.CWResultFile.CWOutputFile.wOutputFile("/Users/iot/1.xls", & ...

  9. libevent实现TCP 服务端

    libevent实现Tcp Server基于bufferevent实现 /******************************************************** Copyri ...

  10. FZU2018级算法第二次作业 2.10 逆序数(权值线段树)

    题目: Nk 最近喜欢上了研究逆序数,给出一个由 1…n 组成的数列 a1,a2,a3…an, a1的逆序数就是在 a2…an 中,比 a1 小的数的数量,而 a2 的逆序数就是 a3….an 中比 ...