Archive: Retrieving window handle from a plugin


Retrieving window handle from a plugin
I need to get the window handle to one of the controls on one of the pages in my installer. I'm thinking the correct way to do this is to get the window handle in script, set a user variable to hold that value then call my plugin function querying that variable in code with a call to getuservariable.

This doesn't seem to be working but I am not comletely convinced of that yet. Here is what I've discovered so far. The call to getuservariable in my plugin does return some kind of valid memory address. I can type cast this value to an HWND which as I understand things is what my variable should be holding although it is returned as a "char *". Once casted the HWND still appears to have a valid memory address but when I call any functions to query info about the window from within the plugin I get garbage information, it's all completely wrong which makes me think I don't actually have a valid window handle. Thoughts, suggestions and questions are most welcome.


There is no need to save the HWND in any variable. The first plug-in function parameter is hwndParent which is exactly the same as $HWNDPARENT.

getuservariable returns strings. You need to use atoi to convert the string to a number before using it as a handle.


There is no need to save the HWND in any variable. The first plug-in function parameter is hwndParent which is exactly the same as $HWNDPARENT.
Oh kichik you're so smart. Indeed you are correct, thanks.

Ok so I can get the window handle of any control from within the plugin. Now I also need to get the device context for a specific control. That seems to be done with a call to GetDC passing the window handle of the control I need to modify. The DC I am returned does seem to be valid however after getting the DC any function I use to apply changes to that DC doesn't seem to do anything. Specifically I've been using the TextOut function which you can read about here...

http://msdn.microsoft.com/library/de...ntext_5yd0.asp

Only it doesn't seem to do anything when I use it. I'm working my way through trying to figure out why I can't see any text on screen after calling this function but if anyone has any hints/tips please feel free to post.


Subclass the window and use TextOut in WM_PAINT.


Something simple like <marquee> 30 ms repaint is also possible, see attachment. Do not forget to put dll to plug-ins folder. Have fun. If this is interesting for big installations, I can write a plug-in with a full set of parameters including text color, size, target rect., speed, type (arial, verdana), movement direction (top or right), what else ;)
Tested on XP only.


@Takhir: Did you use "AnimateWindow" or something like that to get that result?


@deguix: No, direct draw to dialog window :)


while(!terminate)
{
if(--textPos + sz.cx < rc.left)
textPos = rc.right;
hDc = GetDC(childwnd); // client area dc
// TextOut(hDc, textPos, rc.top, marquee, strlen(marquee));
SetBkColor(hDc, bkColor);
SetTextColor(hDc, textColor);
SelectObject(hDc, (HGDIOBJ)hFont);
ExtTextOut(hDc, textPos, rc.top, ETO_CLIPPED | ETO_OPAQUE, &rc, marquee, strlen(marquee), NULL);
ReleaseDC(childwnd, hDc);
Sleep(20);
}

Originally posted by kichik
Subclass the window and use TextOut in WM_PAINT.
Thanks for the feedback everyone. kichik I am slighly unsure at what point you mean to subclass that window. Would this be something like creating a CWnd subclass within my plugin initializing it to have the window handle that I retrieve from the installer and handling the WM_PAINT message there? Maybe I'm totally off track.

Originally posted by Takhir
Something simple like <marquee> 30 ms repaint is also possible, see attachment. Do not forget to put dll to plug-ins folder. Have fun. If this is interesting for big installations, I can write a plug-in with a full set of parameters including text color, size, target rect., speed, type (arial, verdana), movement direction (top or right), what else
Tested on XP only.
Some cool stuff Takhir, do you have source available for Marquee? I'd love to take a look at that.

Neighbour thread ;) http://forums.winamp.com/showthread....hreadid=210286


Originally posted by Takhir
Neighbour thread ;) http://forums.winamp.com/showthread....hreadid=210286
Sweet.

Subclassing a window is what I was referring to.