在Win32下让窗口居中

Python 将GUI窗口显示在屏幕中间,需要用到win32api 使用tkinter画GUI时需要让窗口自动居中,以下便是实现方法:# 通过win32api获取系统屏幕的分辨率 def get_system_metrics(): from win32api import GetSystemMetrics return GetSystemMetrics(0),GetSystemMetrics(1)# 传入窗口大小(分辨率)计算出窗口居中的位置 def 阅读详情
 
BOOL CenterWindow(HWND hwndWindow)
{
     HWND hwndParent;
     RECT rectWindow, rectParent;
 
     // make the window relative to its parent
     if ((hwndParent = GetParent(hwndWindow)) != NULL)
     {
         GetWindowRect(hwndWindow, &rectWindow);
         GetWindowRect(hwndParent, &rectParent);
 
         int nWidth = rectWindow.right - rectWindow.left;
         int nHeight = rectWindow.bottom - rectWindow.top;
 
         int nX = ((rectParent.right - rectParent.left) - nWidth) / 2 + rectParent.left;
         int nY = ((rectParent.bottom - rectParent.top) - nHeight) / 2 + rectParent.top;
 
         int nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
         int nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
 
         // make sure that the dialog box never moves outside of the screen
         if (nX < 0) nX = 0;
         if (nY < 0) nY = 0;
         if (nX + nWidth > nScreenWidth) nX = nScreenWidth - nWidth;
         if (nY + nHeight > nScreenHeight) nY = nScreenHeight - nHeight;
 
         MoveWindow(hwndWindow, nX, nY, nWidth, nHeight, FALSE);
 
         return TRUE;
     }
 
     return FALSE;
}

窗体居中 vc CenterWindow 窗体居中显示 vc CenterWindow 窗体居中 vc CenterWindow 窗体居中 vc CenterWindow 立即下载

相关推荐

FDTD脚本教程——结构的创建

文章目录结构的搭建创建长方体创建柱体多边形柱体(椭)圆柱体圆环柱自定义形状创建surface波导球棱锥 在lumerical中,可以使用脚本进行操作,可在右侧脚本编辑器运行,或者直接在下方shell输入。 结构的搭建 创建长方体 um = 1e-6; nm = 1e-7; addrect; set("name","myRect"); set("material","SiO2 (Glass) - Palik"); set("render type","wireframe"); # 默认是细节渲染,也就是det

战斗果冻的训练中心 2万+

MFC中窗口居中显示

对于一个窗体,可以使用其CenterWindow方法将其居中,CenterWindow方法有一个参数,通过其指定居中操作相对应的父窗口。如果要设置居中相对应的父窗体的话,可以将父窗体指针传入pAlternateOwner参数,如果pAlternateOwner参数为NULL,则将窗体在整个屏幕上居中。方法中调用,用于在窗口开始显示时居中,也可以在其他地方使用。方法有一个参数,通过其指定居中操作相对应的父窗口。对于一个窗体,可以使用其。

YoseZang的博客 1898

Xilinx VU+系列多DIE FPGA时序约束与跨DIE信号优化策略

本文深入探讨了Xilinx VU+系列多DIE FPGA的时序约束与跨DIE信号优化策略。针对2.5D/3D封装技术带来的时序挑战,详细解析了SLR区域约束、Laguna寄存器配置及跨时钟域约束等关键技术,提供了实用的TCL脚本和RTL优化示例,帮助开发者有效提升设计性能和时序收敛效率。

weixin_29209801的博客 667

置顶窗口SetWindowPos()的用法

SetWindowPos()        函数功能:该函数改变一个子窗口,弹出式窗口式顶层窗口的尺寸,位置和Z序。子窗口,弹出式窗口,及顶层窗口根据它们在屏幕上出现的顺序排序、顶层窗口设置的级别最高,并且被设置为Z序的第一个窗口。        函数原型:BOOL SetWindowPos(HWN hWnd,HWND hWndlnsertAfter,int X,int Y,int cx,in

熊小屁的专栏 2万+

ThinkPHP 8.1 + think-swoole 4.1 实战:5分钟搞定WebSocket聊天室(附完整代码)

本文详细介绍了如何使用ThinkPHP 8.1和think-swoole 4.1快速构建高并发WebSocket聊天室。通过5分钟实战教程,开发者可以轻松实现用户列表、消息广播等核心功能,支持2000+并发连接,适用于客服系统、在线协作等实时通信场景。

ol789012345的博客 135

读懂 403 Forbidden, the request has been blocked by UCON.:它不是浏览器渲染问题,而是后端安全闸门在拦截

摘要 403 Forbidden 错误表明服务器理解请求但拒绝执行,通常与权限或访问控制有关。当错误信息显示 "blocked by UCON" 时,说明请求被 SAP 体系中的统一连接管控框架拦截。UCON 采用白名单机制限制外部调用,通过记录、评估、强制三阶段流程实施管控。常见触发场景包括 HTTP 服务与通信场景配置不一致、白名单未更新等。排查时应通过 DevTools 确认服务器响应,使用 curl 排除浏览器干扰,并比较不同环境的行为差异。解决方案通常涉及调整配置传输顺序或更新

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 262

一个更好的CenterWindow()函数

下载演示项目- 42.2 kb图1。主CenterSample程序示例屏幕。 介绍 定心窗口在屏幕上是你通常可以做的 CWnd::CenterWindow()函数在MFC。CenterWindow () 获取一个指向CWnd的指针作为参数,并且假定是函数 是否会将调用它的窗口的中心与传递它的窗口相对 一个指针: 隐藏,复制CodepDlg->CenterWindow(AfxGetMainWnd()); // Centers pDlg against the main window? 清单1。演示使用C

DiyAbc 898

全面解读AI Infra:架构、生态与未来趋势

文章摘要 大模型时代下,AI基础设施(AI Infra)成为关键技术基建,涵盖从数据准备到模型服务的全栈技术体系。文章系统解构了AI Infra的四层架构(硬件资源层、资源管理调度层、开发框架层、平台工具层),并分析了全球AI Infra生态图谱,包括云计算巨头、芯片厂商等全栈服务商,以及中国特色的多元竞合格局。通过对比Data Infra与AI Infra的核心差异,指出AI Infra更关注智能应用的规模化与自动化。文章还探讨了从传统数据设施向AI基础设施的转型路径,强调自主可控、软硬协同等发展趋势,为

技术引领业务创新 622

win32设置窗口的居中显示

一 代码 POINT lefttop; lefttop.x = (GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2; lefttop.y = (GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2; rect.left += lefttop.x; rect...

字节跳动 1631

Unreal从入门到精通之 UE4 vs UE5 VR性能优化实战

这篇文章分享了UE5 VR项目的性能优化经验。作者通过对比UE4和UE5的VR模板性能,发现UE5默认帧率只有45FPS,远低于UE4的100FPS。主要性能瓶颈来自Lumen全局光照、虚拟阴影贴图等新特性。文章详细列出了12项关键优化设置,包括禁用Lumen、关闭虚拟阴影、使用前向渲染等,并分析了各项调整对性能的影响程度。特别指出删除默认的VolumetricCloud可立即提升5帧。最后建议根据场景需求平衡画质与性能,对于高帧率要求的VR项目,可能需要谨慎使用UE5或关闭其部分高级渲染功能。

TxNet 1398

电磁场仿真软件:COMSOL Multiphysics_(17).时域与频域分析

时域和频域分析是电磁场仿真中非常重要的两种方法,每种方法都有其独特的应用场景和优势。时域分析适用于瞬态响应和宽带信号的分析,而频域分析则适用于稳态响应和窄带信号的分析。在COMSOL Multiphysics中,通过合理设置物理场接口、材料属性、边界条件、网格划分和求解器,可以高效地进行这两种分析,并通过傅里叶变换将时域结果转换为频域结果,进一步拓展仿真应用的范围。合理的性能优化措施,如网格划分优化和并行计算,可以显著提高仿真的效率和准确性。

kkchenjj的博客 1990

IsIconic、CenterWindow()的用法 、LockWindowUpdate、CredUIParseUserName

一、Isiconic 功能 函数功能:该函数确定给定窗口是否是最小化(图标化)的窗口。函数原型:BOOL IsIconic(HWND hWnd); hWnd:被测试窗口的句柄。 返回值:如果窗口未最小化,返回值为零;如果窗口已最小化,返回值为非零。 函数isiconic返回值取决于指定窗口是否已经最小化。 BOOL IsIconic(

chenyujing1234的专栏 3183

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

win32 api 窗口居中

在网上搜是窗口居中显示的方法搜到了浪浪仔的win32 C/C++程序窗口居中,用了之后发现虽然窗口居中了,但是比原来变大了许多,后来发现是SetWindowPos时窗口的长宽设置错了,在此记录,并给需要的人。 void CenterWindow(HWND hWnd) { int scrWidth, scrHeight; RECT rect; //获得屏幕尺寸 s...

菜鸟的博客 1863

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

一个窗口居中的例子(Win32)

要实现窗口居中显示并不难,只要在窗体创建的时候我们设置窗口的位置就可以了.在这里我们主要用到3个API函数,分别是:GetSysMetrics,GetWindowRect,SetWindowPos.我们用GetSysMetrics来获的屏幕的宽度和高度,然后用GetWindowRect来获取窗口的坐标.通过运算后计算出居中窗口的位置,最后用SetWindowPos来设置窗体的位置.整个过程就是如此

编程人生的专栏 5719

win32窗口按照屏幕居中

RECT rc, rc1, rctomove;   int width = GetSystemMetrics(SM_CXSCREEN);   int height = GetSystemMetrics(SM_CYSCREEN);   rc.left = 0;   rc.top = 0;   rc.right = width;   rc.bottom = height;   GetCl

zdongfuyu的专栏 2335

win32 api 子窗口在父窗口居中的方法

如果要让窗口内的一个控件在父窗口的客户区居中,或在某一位置,可以用SetWindowPos,注意里面的第三个和第四个参数是相对于父窗口的客户区的坐标的,父窗口的客户区的坐标的左上角left,top都是0 如果在父窗口里弹出一个DialogBox子窗口,这时你可能希望这个DialogBox在父窗口的客户区居中显示,你只需要在这个DialogBox的WM_INITDIALOG处理函数里加入以

wuqiyinglang的专栏 4303

win32 设置窗口居中 API函数

//获取屏幕尺寸 scrWidth  = GetSystemMetrics(SM_CXSCREEN); scrHeight = GetSystemMetrics(SM_CYSCREEN); //获取窗体尺寸 CRect rect; // ::GetWindowRect(m_hWnd, &rect); rect.right =  WindowWidth; // 设置窗口宽高 re

非常道的博客 3467

win32窗口的大小,居中,拖动

参考 https://www.cnblogs.com/findumars/p/3948315.html 不让调整大小 窗口风格设置,后面两个是最大最小化按钮 dwStyle^WS_THICKFRAME^WS_MAXIMIZEBOX^WS_MINIMIZEBOX 不让拖动 消息循环里添加 case WM_NCLBUTTONDOWN: { switch (...

u011393161的博客 4556

win32 C/C++程序窗口居中

1、要实现窗口居中显示并不难,只要在窗体创建的时候我们设置窗口的位置就可以了.在这里我们主要用到3个API函数,分别是:GetSysMetrics,GetWindowRect,SetWindowPos. 我们用GetSysMetrics来获的屏幕的宽度和高度,然后用GetWindowRect来获取窗口的坐标.通过运算后计算出居中窗口的位置,最后用 SetWindowPos来设置窗体...

weixin_30328063的博客 1354

【转】win32窗口的大小,居中,拖动

参考 https://www.cnblogs.com/findumars/p/3948315.html 不让调整大小 窗口风格设置,后面两个是最大最小化按钮 dwStyle^WS_THICKFRAME^WS_MAXIMIZEBOX^WS_MINIMIZEBOX 不让拖动 消息循环里添加 case WM_NCLBUTTONDOWN: { switch (wParam) { case HTCAPTION: return 0; ...

sinolover的专栏 1862

WIN32项目中MFC程序窗口居中

//classCMainWindow:publicCFrameWnd voidCMainWindow::OnSize(UINTnType,intcx,intcy){CFrameWnd::OnSize(nType,cx,cy);//TODO:在此处添加消息处理程序代码//SIZE_RESTOREDWindowhasbeen...

267

Win32创建居中窗口 C/C++

在此记录 #define CreateCentralWindowEx(dwExStyle, lpClassName, lpWindowName, dwStyle, nWidth, nHeight,\ hWndParent, hMenu, hInstance, lpParam)\ CreateWindowExW(dwExStyle, lpClassName, lpWindowName, dwStyle, \ (GetSystemMetrics(SM_CXFULLSCREEN) - nWidth) / 2

szx0427的博客 1695

Python实现鼠标选定窗口位置居中

本文为满足强迫症需求(不是),通过Python实现鼠标选定窗口抓取句柄并实现窗口位置居中,或可通过输入对应的标题序号以选取句柄。 import imp import sys from webbrowser import get import win32gui import win32con import win32api import time def get_all_windows(): hWnd_list = [] win32gui.EnumWindows(lambda hWn

m0_59426411的博客 1035
上一篇: HTK3.4.1在Win7 下HSLab **.sig使用无效的解决办法
下一篇: 将MFC的CString 类型转化为C++标准数据类型std::string
xiaoding133
博客等级 码龄20年 415粉丝 159原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址