jugador Posted June 18 Posted June 18 (edited) I am not quite sure if this is the right place to post, but I am not looking for code or specific help; this is just for discussion. Is a concept like this actually possible? If so, what would be the advantages? server:: Local $hCallBack = ......... Local $hGUI = GUICreate("Server", 400, 120) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func __subclassing($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) ;........... Return DllCall('comctl32.dll', 'lresult', 'DefSubclassProc', .....................)[0] EndFunc Client:: Local $hCallBack = ......... Local $hGUI = GUICreate("Client", 450, 250) Local $idListView = GUICtrlCreateListView("Items|Column 1|Column 2", 10, 10, 430, 230, -1, $LVS_EX_DOUBLEBUFFER) Local $hListView = GUICtrlGetHandle($idListView) Local $hHeader = GUICtrlSendMsg($idListView, $LVM_GETHEADER, 0, 0) For $i = 1 To 5 GUICtrlCreateListViewItem("row" & $i & "|dataA" & $i & "|dataB" & $i, $idListView) Next _WinAPI_SetWindowSubclass($hHeader, $hCallBack, 2000) GUISetState() Do Until GUIGetMsg() = $GUI_EVENT_CLOSE _WinAPI_RemoveWindowSubclass($hHeader, $hCallBack, 2000) Edited June 18 by jugador
MattyD Posted June 18 Posted June 18 I wouldn't over complicate things... Here's a snippet of something I was playing with at some point. In my main script, I just include the file and call the ApplySubclass func. #include-once #include <WinAPI.au3> Global $__g_hCanvasProc = DllCallbackRegister("Canvas_WndProc", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr") OnAutoItExitRegister("Canvas_FinalCleanup") Func Canvas_WndProc($hWnd, $iMsg, $wParam, $lParam, $iIdSubclass, $dwRefData) #forceref $hWnd, $iMsg, $wParam, $lParam, $iIdSubclass, $dwRefData Switch $iMsg Case $WM_CLOSE Return Canvas_Close($hWnd, $iMsg, $wParam, $lParam, $iIdSubclass) ; etc... Case Else Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndSwitch EndFunc ;==>Canvas_WndProc Func Canvas_ApplySubclass($hWnd) _WinAPI_SetWindowSubclass($hWnd, DllCallbackGetPtr($__g_hCanvasProc), 0) EndFunc ;==>Canvas_ApplySubclass Func Canvas_Close($hWnd, $iMsg, $wParam, $lParam, $iIdSubclass) #forceref $hWnd, $iMsg, $wParam, $lParam _WinAPI_RemoveWindowSubclass($hWnd, DllCallbackGetPtr($__g_hCanvasProc), $iIdSubclass) Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>Canvas_Close Func Canvas_FinalCleanup() DllCallbackFree($__g_hCanvasProc) EndFunc PS. For a control, I usually remove the subclass on $WM_DESTROY.
jugador Posted June 18 Author Posted June 18 (edited) Thanks, but its just for fun, nothing serious. It just the bug within me of doing multi-threading and multi-processing in AutoIt. My take, doing it this way is possible. But how practical it is and what the advantages are, I don't know. Edited June 18 by jugador
MattyD Posted June 18 Posted June 18 (edited) nah, not very practical. Your ptrs are only valid for the process where you define it - so you can't call your proc (or likely defsubclassproc) across process boundaries. To intercept window messages from another exe you'd probably be looking at a hook. And if memory serves, that type of hook must be written within a dll. Even if we were to get that all working, its going to be more efficient to deal with the messages in process Edit: more to the last point, the underlying dispachmessage in a msg loop is synchronous - so your "client" process is going to sit and wait for the "server" to finish. You get all the overhead without a performance gain. Edited June 18 by MattyD jugador 1
jugador Posted June 20 Author Posted June 20 (edited) main problem: HDC, HBITMAP, HPEN, and HBRUSH are process-specific tokens. So, GDI handles like HDC are strictly local to the host process and cannot be used cross-process. GetDC may work, but will flicker too much and lacks synchronization. Edit: so to make HDC work, you have to do it from client side.... but somewhat sluggish. Local $tRect = DllStructCreate($tagRECT) _WinAPI_SetBkMode($hDC, 1) _WinAPI_SetTextColor($hDC, 0xFFFFFF) Local $hBrush = _WinAPI_CreateSolidBrush($iColor) _WinAPI_InflateRect($tRect, -1, 0) _WinAPI_FillRect($hDC, $tRect, $hBrush) _WinAPI_DeleteObject($hBrush) _WinAPI_InflateRect($tRect, -5, -2) _WinAPI_DrawText($hDC, $text, $tRect, BitOR($DT_LEFT, $DT_NOCLIP, $DT_VCENTER, $DT_SINGLELINE)) Edited June 22 by jugador
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now