- NSIS Discussion
- Retrieving window handle from a plugin
Archive: Retrieving window handle from a plugin
rsegal
10th March 2005 21:18 UTC
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.
kichik
10th March 2005 21:28 UTC
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.
rsegal
10th March 2005 22:47 UTC
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.
rsegal
11th March 2005 16:58 UTC
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.
kichik
12th March 2005 10:31 UTC
Subclass the window and use TextOut in WM_PAINT.
Takhir
12th March 2005 17:40 UTC
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.
deguix
12th March 2005 21:05 UTC
@Takhir: Did you use "AnimateWindow" or something like that to get that result?
Takhir
13th March 2005 06:33 UTC
@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);
}
rsegal
14th March 2005 16:34 UTC
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.
Takhir
14th March 2005 18:59 UTC
Neighbour thread ;) http://forums.winamp.com/showthread....hreadid=210286
rsegal
14th March 2005 20:19 UTC
Originally posted by Takhir
Neighbour thread ;) http://forums.winamp.com/showthread....hreadid=210286
Sweet.
kichik
15th March 2005 18:32 UTC
Subclassing a window is what I was referring to.