
SystemWindowsFormsSystemInformationWorkingAreaWidth 屏幕宽度SystemWindowsFormsSystemInformationWorkingAreaHeight屏幕高度(去系统任务栏,如果你有的话)
thisSizeWidth自己窗体的宽度,thisSizeWidth自己窗体的高度
thisLocation自己窗体左上角相当于屏幕左上角的位置,根据上面的数据算出位置给这个值赋值就可以了。
比如thisLocation=new Size(SystemWindowsFormsSystemInformationWorkingAreaWidth-thisSizeWidth,0);
就是屏幕右边最上方
其实不是你想的那么复杂。Windows窗体中有个属性他是设置他在窗体第一次出现的位置的。StartPosition的属性就是,你把它设置成centerScreen就可以了。这是将窗体设置成第一次打开时窗体在屏幕的中间位置。
GetWindowsRect获取的是窗口矩形范围,其中RECT的left和top就是窗口左上角的坐标,也就是你所说的窗口位置
GetWindowsRect返回的是屏幕坐标
楼上的应该是ScreenToClient,将屏幕坐标转换为窗口坐标
ClientToScreen是将窗口坐标转换为屏幕坐标
#include "stdioh"
#include "windowsh"
void main()
{
// 获取活动窗口
HWND h=GetForegroundWindow();
printf("0x%X\n",h);
// 获取窗口标题
char text[200];
GetWindowText(h,text,200);
printf("%s\n",text);
// 获取屏幕鼠标坐标
POINT pt;
GetCursorPos(&pt);
printf("%d %d\n",ptx,pty);
// 获取窗口鼠标坐标
ScreenToClient(h,&pt);
printf("%d %d\n",ptx,pty);
}
代码如下。
=============
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Dim h As Long, r As RECT
h = FindWindow(vbNullString, "酷狗") '这里写上你的窗口标题,必须一字不差
GetWindowRect h, r
MsgBox "左上角坐标(" & rLeft & "," & rTop & ")" & vbCrLf & "右下角坐标(" & rRight & "," & rBottom & ")" & vbCrLf & "窗口高" & rBottom - rTop & "窗口宽" & rRight - rLeft
End
End Sub
以上就是关于如何定位窗体在屏幕中的位置全部的内容,包括:如何定位窗体在屏幕中的位置、C#WinFrom中如何得到Windows窗体的位置、如何获得窗口位置VC等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)