WM_NCHITTEST消息问题【已解决】
本帖最后由 kenan 于 2011-7-12 00:56 编辑我的程序中注册了WM_NCHITTEST和WM_MOVING两个消息,(注册WM_MOVING是为了拖动窗口时窗口会移动)
下面是WM_NCHITTEST函数
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
if ($hWnd = $hGUI ) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc
问题就是注册了WM_NCHITTEST消息后,$CursorInfo = GUIGetCursorInfo($hGUI2)无法捕获单击消息(也就是$CursorInfo==1这句不能成立)
所以请教各位如何修改这个WM_NCHITTEST函数
我试着改成if ($hWnd = $hGUI ) or ($hWnd = $hGUI2 ) then Return $HTCAPTION这样也不行
注:程序中有两个窗体$hGUI(父)和$hGUI2(子),我的程序在hGUI上画了一个png图片,然后再hGUI2上加了一个label,label是透明的,label位于png图片上面,程序是希望单我鼠标左键单击label时能够执行相应代码,而现在不知为什么单击不行,另我意外的是双击却可以 整理了下代码#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <Memory.au3>
Global Const $AC_SRC_ALPHA = 1
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile("meiko.png")
$Width=_GDIPlus_ImageGetWidth ($hImage)
$Height=_GDIPlus_ImageGetHeight($hImage)
$about_normal= _GDIPlus_ImageLoadFromFile( "about_normal.png")
$hGUI = GUICreate(" ", 250, 250, @DesktopWidth/2-$Width/2, @DesktopHeight/2-$Height/2, BitXOR($WS_POPUP,$GUI_SS_DEFAULT_GUI),$WS_EX_LAYERED)
$GC = _GDIPlus_ImageGetGraphicsContext($hImage)
$bkbitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $GC)
$newGC = _GDIPlus_ImageGetGraphicsContext($bkbitmap)
_GDIPlus_GraphicsDrawImageRect($newGC, $hImage, 0, 0, $Width, $Height)
_GDIPlus_GraphicsDrawImageRect($newGC, $about_normal, 315, 300, 50, 50)
SetBitMap($hGUI, $bkbitmap, 255)
GUISetState()
$hGUI2 = GUICreate("", 850, 450,-1,-1,$WS_POPUP,BitOR($WS_EX_LAYERED,$WS_EX_MDICHILD),$hGUI)
$Label1= GUICtrlCreateLabel("", 313,279,50,50,BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUISetBkColor(0xfffffe,$hGUI2)
_WinAPI_SetLayeredWindowAttributes($hGUI2, 0xfffffe, 255)
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
GUIRegisterMsg(0x0216, "WM_MOVING")
GUISetState()
While 1
$CursorInfo = GUIGetCursorInfo($hGUI2)
If $CursorInfo=$Label1 Then
Sleep(50)
If $CursorInfo==1 Then MsgBox(0,'','')
EndIf
If GUIGetMsg()=$GUI_EVENT_CLOSE Then Exit
WEnd
Func WM_MOVING($hWnd, $msg, $wParam, $lParam)
$tBuffer = DllStructCreate($tagRECT, $lParam)
$iLeft = DllStructGetData($tBuffer, "Left")
$iTop = DllStructGetData($tBuffer, "Top")
_WinAPI_MoveWindow($hWnd,$iLeft,$iTop,$Width,$Height)
Return $GUI_RUNDEFMSG
EndFunc
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
if ($hWnd = $hGUI ) and ($iMsg = $WM_NCHITTEST) then Return $HTCAPTION
EndFunc
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize )
;~ DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
;~ DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
DllStructSetData($tSize, "X", $Width)
DllStructSetData($tSize, "Y", $Height)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha" , $iOpacity )
DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
_WinAPI_ReleaseDC (0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC ($hMemDC)
EndFunc 本帖最后由 powerofos 于 2011-7-8 21:49 编辑
我的程序中注册了WM_NCHITTEST和WM_MOVING两个消息,(注册WM_MOVING是为了拖动窗口时窗口会移动)
下面是 ...
kenan 发表于 2011-7-8 20:36 http://www.autoitx.com/images/common/back.gif
我不懂的是你这句话:“,(注册WM_MOVING是为了拖动窗口时窗口会移动)
”
我的经验是:注册这个消息,是为了获取鼠标移动GUI时获取GUI的 X, Y
而WM_NCHITTEST,我之前使用过,好像注册后,鼠标HOVER在GUI上时会触发 再附上程序所需要的两张图片
回复 3# powerofos
这代码一部分是拿别人的,有一些我也不懂
刚才试了一下不注册WM_MOVING的话,窗体也是会移动的,只是画在窗体上的png图片不会跟着移动,当弹开鼠标的时候图片才移动过去
我以为不注册窗体就不会移动。。。。 回复powerofos
这代码一部分是拿别人的,有一些我也不懂
刚才试了一下不注册WM_MOVING的话,窗 ...
kenan 发表于 2011-7-8 22:05 http://www.autoitx.com/images/common/back.gif
对的,WM_MOVING是可以动态获取GUI的X,Y的, 由于应用了GDI,不懂得我就不多说什么了,建议先卸下GUI的 PNG 应用,先弄明白你DOWN来的脚本的各部分代码的作用,换句话说,就是对down来的脚本最小化,最简化,逐步试验 是这个意思?
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GuiConstantsEx.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <Memory.au3>
Global Const $AC_SRC_ALPHA = 1
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile("meiko.png")
$Width = _GDIPlus_ImageGetWidth($hImage)
$Height = _GDIPlus_ImageGetHeight($hImage)
$about_normal = _GDIPlus_ImageLoadFromFile("about_normal.png")
$hGUI = GUICreate(" ", 250, 250, @DesktopWidth / 2 - $Width / 2, @DesktopHeight / 2 - $Height / 2, $WS_POPUP, $WS_EX_LAYERED)
$GC = _GDIPlus_ImageGetGraphicsContext($hImage)
$bkbitmap = _GDIPlus_BitmapCreateFromGraphics($Width, $Height, $GC)
$newGC = _GDIPlus_ImageGetGraphicsContext($bkbitmap)
_GDIPlus_GraphicsDrawImageRect($newGC, $hImage, 0, 0, $Width, $Height)
_GDIPlus_GraphicsDrawImageRect($newGC, $about_normal, 315, 300, 50, 50)
SetBitMap($hGUI, $bkbitmap, 255)
$Label1 = GUICtrlCreateLabel("", 313, 279, 50, 50, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUISetState()
;~ $hGUI2 = GUICreate("", 850, 450, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hGUI)
;~ GUISetBkColor(0xfffffe,$hGUI2)
;~ _WinAPI_SetLayeredWindowAttributes($hGUI2, 0xfffffe, 255)
GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
;~ GUIRegisterMsg(0x0216, "WM_MOVING")
;~ GUISetState()
While 1
$CursorInfo = GUIGetCursorInfo()
If $CursorInfo = $Label1 Then
;Sleep(50)
If $CursorInfo == 1 Then MsgBox(0, '', '')
EndIf
If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd
Func WM_MOVING($hWnd, $msg, $wParam, $lParam)
$tBuffer = DllStructCreate($tagRECT, $lParam)
$iLeft = DllStructGetData($tBuffer, "Left")
$iTop = DllStructGetData($tBuffer, "Top")
_WinAPI_MoveWindow($hWnd, $iLeft, $iTop, $Width, $Height)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_MOVING
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
If ($hWnd = $hGUI) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
EndFunc ;==>WM_NCHITTEST
Func SetBitmap($hGUI, $hImage, $iOpacity)
Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
$hScrDC = _WinAPI_GetDC(0)
$hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
$hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
$hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
;~ DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth ($hImage))
;~ DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
DllStructSetData($tSize, "X", $Width)
DllStructSetData($tSize, "Y", $Height)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
DllStructSetData($tBlend, "Alpha", $iOpacity)
DllStructSetData($tBlend, "Format", $AC_SRC_ALPHA)
_WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
_WinAPI_ReleaseDC(0, $hScrDC)
_WinAPI_SelectObject($hMemDC, $hOld)
_WinAPI_DeleteObject($hBitmap)
_WinAPI_DeleteDC($hMemDC)
EndFunc ;==>SetBitmap
回复 6# powerofos
别人的那些代码我大概知道作用是什么,详细的细节我就不懂了
我原来的代码是很长,而且修改了很多,搞得我有些乱了,弄了一个下午才发现不注册WM_NCHITTEST就没问题,貌似这个问题涉及较深知识,所以我才来这里请教各位大大 你要的最终效果我这里是可以实现的,不过我个人觉得,你实现的手法。。。不太好吧:
While 1
$CursorInfo = GUIGetCursorInfo($hGUI2)
If $CursorInfo=$Label1 Then
Sleep(50)
If $CursorInfo==1 Then MsgBox(0,'','')
EndIf
If GUIGetMsg()=$GUI_EVENT_CLOSE Then Exit
WEnd
为了实现点击GUI2 的LABEL的点击,你使用了GUIGetCursorInfo($hGUI2),放到循环里实现也不划算,干脆全脚本使用 Onevent 模式 回复 7# 3mile
差不多是这个意思,但是我还要加其他控件上去,加上去的控件都看不见啊
我一开始也是这样干的,不行之后,就想到用子窗口 本帖最后由 kenan 于 2011-7-8 23:02 编辑
回复 9# powerofos
你真的有用2l的代码和4l的图片去运行吗
为什么我不行,难道是系统问题?
附件是非GDI方式实现的png GUI,我根据之前下载的别人的东西随便改得,你看看有没有用 回复 11# kenan
对的,是2楼的代码和你的PNG,单机弹出msgbox
本帖最后由 kenan 于 2011-7-8 23:25 编辑
回复 12# powerofos
这个我在论坛搜索时见过,那个L77png.au3也有SetBitmap这个函数也注册了WM_NCHITTEST,其他没去细看了。。。。
实际上它也是GDI方式吧
我的最终目的是为了做个png图片的窗体,上面放一些控件还有放几个png图片的按钮,有三种状态,能够响应那三种状态,分别显示三张图片,并且响应单击事件 回复 13# powerofos
不是吧,难道是我电脑的问题,我必须双击才会出现msgbox,而不注册WM_NCHITTEST就没问题
页:
[1]
2