I developed the code below based on some samples off of the forum, and has been working great until I just realized it won't draw in the non-client area of a window in Vista. This also works ok in Themed XP, but it doesn't display anything in Vista. If I extend the button rectangle down into the window itself, it will display on the window, and nothing shows through in the non-client portion of the window. Any suggestions?
Code:
#PBFORMS CREATED V1.51 '----------------------------------------------------------------------------------------------------------------- ' The first line in this file is a PB/Forms metastatement. ' It should ALWAYS be the first line of the file. Other ' PB/Forms metastatements are placed at the beginning and ' end of "Named Blocks" of code that should be edited ' with PBForms only. Do not manually edit or delete these ' metastatements or PB/Forms will not be able to reread ' the file correctly. See the PB/Forms documentation for ' more information. ' Named blocks begin like this: #PBFORMS BEGIN ... ' Named blocks end like this: #PBFORMS END ... ' Other PB/Forms metastatements such as: ' #PBFORMS DECLARATIONS ' are used by PB/Forms to insert additional code. ' Feel free to make changes anywhere else in the file. '----------------------------------------------------------------------------------------------------------------- #COMPILE EXE "SCHELP.EXE" #DIM ALL '----------------------------------------------------------------------------------------------------------------- ' ** Includes ** '----------------------------------------------------------------------------------------------------------------- #PBFORMS BEGIN INCLUDES #IF NOT %DEF(%WINAPI) #INCLUDE "WIN32API.INC" #ENDIF #PBFORMS END INCLUDES '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- ' ** Constants ** '----------------------------------------------------------------------------------------------------------------- #PBFORMS BEGIN CONSTANTS %IDD_DIALOG1 = 101 %IDC_BUTTON1 = 102 #PBFORMS END CONSTANTS '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- ' ** Declarations ** '----------------------------------------------------------------------------------------------------------------- DECLARE CALLBACK FUNCTION ShowDIALOG1Proc() DECLARE FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG #PBFORMS DECLARATIONS '----------------------------------------------------------------------------------------------------------------- %CUSTOMMSG_CLICKEDHELP = %WM_USER+2048 %LASTDRAW_SELECTED = 1 %LASTDRAW_UNSELECTED = 2 '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- ' ** Main Application Entry Point ** '----------------------------------------------------------------------------------------------------------------- FUNCTION PBMAIN() ShowDIALOG1 %HWND_DESKTOP END FUNCTION '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- ' ** CallBacks ** '----------------------------------------------------------------------------------------------------------------- CALLBACK FUNCTION ShowDIALOG1Proc() SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG ' Initialization handler CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN ' Save control focus hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %CUSTOMMSG_CLICKEDHELP MSGBOX "Clicked Help_DLG" CASE %WM_COMMAND ' Process control notifications SELECT CASE AS LONG CBCTL END SELECT END SELECT END FUNCTION '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- ' ** Dialogs ** '----------------------------------------------------------------------------------------------------------------- FUNCTION ShowDIALOG1(BYVAL hParent AS DWORD) AS LONG LOCAL lRslt AS LONG #PBFORMS BEGIN DIALOG %IDD_DIALOG1->-> LOCAL hDlg AS DWORD DIALOG NEW hParent, "Dialog1", 70, 70, 201, 121, %WS_POPUP OR %WS_BORDER OR %WS_DLGFRAME OR %WS_SYSMENU OR _ %WS_MAXIMIZEBOX OR %WS_MINIMIZEBOX OR %WS_CLIPSIBLINGS OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK _ OR %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR %WS_EX_LTRREADING OR _ %WS_EX_RIGHTSCROLLBAR, TO hDlg CONTROL ADD BUTTON, hDlg, %IDC_BUTTON1, "Button1", 5, 5, 50, 15 #PBFORMS END DIALOG SetProp hDlg, "OldProc", SetWindowLong(hDlg, %GWL_WNDPROC, CODEPTR(DlgSubClass)) DIALOG SHOW MODAL hDlg, CALL ShowDIALOG1Proc TO lRslt #PBFORMS BEGIN CLEANUP %IDD_DIALOG1 #PBFORMS END CLEANUP FUNCTION = lRslt END FUNCTION '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- MACRO GetPoints() GetWindowRect hWnd, rc pt.x=LO(INTEGER, lParam)-rc.nLeft pt.y=HI(INTEGER, lParam)-rc.nTop END MACRO '----------------------------------------------------------------------------------------------------------------- MACRO GetRect() dStyle = GetWindowLong(hWnd, %GWL_STYLE) dExStyle = GetWindowLong(hWnd, %GWL_EXSTYLE) IF (dStyle AND %WS_THICKFRAME) = %WS_THICKFRAME THEN cx = GetSystemMetrics(%SM_CXSIZEFRAME) cy = GetSystemMetrics(%SM_CYSIZEFRAME) ELSE cx = GetSystemMetrics(%SM_CXFIXEDFRAME) cy = GetSystemMetrics(%SM_CYFIXEDFRAME) END IF xEdge=GetSystemMetrics(%SM_CXEDGE) GetWindowRect hWnd, rcCaption rcCaption.nBottom = rcCaption.nBottom - rcCaption.nTop rcCaption.nRight = rcCaption.nRight - rcCaption.nLeft rcCaption.nTop = cy rcCaption.nLeft = cx rcCaption.nRight = rcCaption.nRight - cx rcCaption.nBottom = rcCaption.nTop + GetSystemMetrics(%SM_CYCAPTION) - _ GetSystemMetrics(%SM_CYBORDER) cxBtn = GetSystemMetrics(%SM_CXSIZE) cyBtn = GetSystemMetrics(%SM_CYSIZE) dx = rcCaption.nRight IF (dStyle AND %WS_SYSMENU) = %WS_SYSMENU THEN dx = dx - cxBtn - 2 IF ((dStyle AND %WS_MAXIMIZEBOX) = %WS_MAXIMIZEBOX) OR _ ((dStyle AND %WS_MINIMIZEBOX) = %WS_MINIMIZEBOX) THEN _ dx = dx - 2 * cxBtn - 2 END IF hDC=GetWindowDC(hWnd) hFont = CreateFont(cyBtn * .64, 0, 0, 0, %FW_NORMAL, 0, 0, 0, _ %ANSI_CHARSET, %OUT_TT_PRECIS, %CLIP_DEFAULT_PRECIS, _ %DEFAULT_QUALITY, %FF_DONTCARE, "Arial") hFontOld=SelectObject(hDC, hFont) szBuf="Screen Help" GetTextExtentPoint32 hDC, szBuf, LEN(szBuf), sz rcCaption.nLeft=dx-sz.cx rcCaption.nRight=dx InflateRect rcCaption, xEdge*2, -2 END MACRO '----------------------------------------------------------------------------------------------------------------- MACRO CreateBrush() lb.lbStyle = %BS_SOLID lb.lbColor = GetSysColor(%COLOR_3DFACE) hBrush1 = CreateBrushIndirect(lb) END MACRO '----------------------------------------------------------------------------------------------------------------- MACRO CleanItUp() SelectObject hDC, hFontOld ReleaseDC hWnd, hDC DeleteObject hFont END MACRO '----------------------------------------------------------------------------------------------------------------- MACRO DeleteBrush() DeleteObject hBrush1 END MACRO '----------------------------------------------------------------------------------------------------------------- MACRO DrawIt() FrameRect hDc, rcCaption, GetStockObject(%BLACK_BRUSH) FillRect hDc, rcCaption, hBrush1 IF ISTRUE(MouseDown) THEN IF PtInRect(rcCaption, pt.x, pt.y) THEN LastDraw=%LASTDRAW_SELECTED DrawEdge hDC, rcCaption, %EDGE_SUNKEN, %BF_RECT OR %BF_SOFT ELSE LastDraw=%LASTDRAW_UNSELECTED DrawEdge hDC, rcCaption, %EDGE_RAISED, %BF_RECT OR %BF_SOFT END IF ELSE LastDraw=%LASTDRAW_UNSELECTED DrawEdge hDC, rcCaption, %EDGE_RAISED, %BF_RECT OR %BF_SOFT END IF SetBkMode hDC, %TRANSPARENT SetTextColor hDC, %BLACK DrawText hDC, szBuf, -1, rcCaption, %DT_SINGLELINE OR %DT_CENTER OR %DT_VCENTER END MACRO '----------------------------------------------------------------------------------------------------------------- MACRO TurnOffMouseDown() IF ISTRUE(MouseDown) AND ISFALSE(IsLButtonDown) THEN MouseDown=%FALSE IF LastDraw=%LASTDRAW_SELECTED THEN GetPoints() GetRect() CreateBrush() DrawIt() DeleteBrush() CleanItUp() END IF END IF END MACRO '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- FUNCTION IsLButtonDown() AS LONG LOCAL lRet AS LONG LOCAL iRet AS INTEGER iRet=GetAsyncKeyState(IIF&(ISTRUE(GetSystemMetrics(%SM_SWAPBUTTON)), %VK_RBUTTON, %VK_LBUTTON)) IF ISTRUE(BIT(iRet,15)) THEN lRet=%TRUE ELSE lRet=%FALSE END IF FUNCTION=lRet END FUNCTION '----------------------------------------------------------------------------------------------------------------- '----------------------------------------------------------------------------------------------------------------- FUNCTION DlgSubClass(BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, BYVAL wParam AS LONG, BYVAL lParam AS LONG) AS LONG LOCAL OldProc AS LONG LOCAL hDC AS DWORD LOCAL dStyle AS LONG LOCAL dExStyle AS LONG LOCAL cx AS LONG LOCAL cy AS LONG LOCAL dx AS LONG LOCAL cyBtn AS LONG LOCAL cxBtn AS LONG LOCAL hFontOld AS LONG LOCAL hBrush1 AS LONG LOCAL hFont AS LONG LOCAL lb AS LOGBRUSH LOCAL szBuf AS ASCIIZ * 100 LOCAL rcCaption AS RECT LOCAL sz AS SIZEL LOCAL xEdge AS LONG LOCAL lRslt AS LONG LOCAL pt AS POINTAPI LOCAL rc AS RECT LOCAL NeedToRefresh AS LONG LOCAL RetText AS STRING LOCAL x AS LONG LOCAL tmpt AS STRING LOCAL RIAStuff AS STRING STATIC LastDraw AS LONG STATIC MouseDown AS LONG OldProc=GetProp(hWnd, "OldProc") SELECT CASE wMsg CASE %WM_DESTROY RemoveProp hWnd, "OldProc" SetWindowLong hWnd, %GWL_WNDPROC, OldProc CASE %WM_NCLBUTTONDOWN, %WM_NCMOUSEMOVE, %WM_NCLBUTTONUP, %WM_NCHITTEST, %WM_SETTEXT lRslt=CallWindowProc(OldProc, hWnd, wMsg, wParam, lParam) GetPoints() GetRect() IF wMsg=%WM_NCLBUTTONDOWN THEN IF PtInRect(rcCaption, pt.x, pt.y) THEN MouseDown=%TRUE NeedToRefresh=%TRUE END IF END IF IF wMsg=%WM_NCMOUSEMOVE THEN TurnOffMouseDown() IF ISTRUE(MouseDown) THEN NeedToRefresh=%TRUE END IF END IF IF wMsg=%WM_NCLBUTTONUP THEN IF ISTRUE(MouseDown) THEN MouseDown=%FALSE NeedToRefresh=%TRUE IF PtInRect(rcCaption, pt.x, pt.y) THEN PostMessage hWnd, %CUSTOMMSG_CLICKEDHELP, 0, 0 END IF END IF END IF IF ISTRUE(NeedToRefresh) THEN CreateBrush() DrawIt() DeleteBrush() END IF CleanItUp() IF wMsg=%WM_NCHITTEST THEN IF lRslt=%HTCAPTION THEN IF PtInRect(rcCaption, pt.x, pt.y) THEN lRslt=9999 END IF END IF END IF FUNCTION=lRslt EXIT FUNCTION CASE %WM_LBUTTONUP IF ISTRUE(MouseDown) THEN MouseDown=%FALSE GetPoints() GetRect() CreateBrush() DrawIt() DeleteBrush() CleanItUp() END IF CASE %WM_MOUSEMOVE TurnOffMouseDown() IF ISTRUE(MouseDown) THEN IF LastDraw=%LASTDRAW_SELECTED THEN GetPoints() GetRect() CreateBrush() DrawIt() DeleteBrush() CleanItUp() END IF END IF CASE %CUSTOMMSG_CLICKEDHELP MSGBOX "Clicked Button" CASE %WM_NCPAINT, %WM_NCACTIVATE FUNCTION=CallWindowProc(OldProc, hWnd, wMsg, wParam, lParam) GetPoints() GetRect() CreateBrush() DrawIt() DeleteBrush() CleanItUp() EXIT FUNCTION END SELECT FUNCTION=CallWindowProc(OldProc, hWnd, wMsg, wParam, lParam) END FUNCTION '----------------------------------------------------------------------------------------------------------------- '-----------------------------------------------------------------------------------------------------------------
Comment