| Description: |
OriginalBugID: 6244 Bug
Version: 8.3.2
SubmitDate: '2000-09-11'
LastModified: '2000-09-11'
Severity: MED
Status: UnAssn
Submitter: angie
ChangedBy: angie
OS: All Windows
Tk 8.3.2 Bug
Name: Rick Hedin
email: [email protected]
Support: None
Severity: 3
OperatingSystem: All Windows
Synopsis: Code to set icon under Windows.
ReproducibleScript:
This was discussed in the newsgroup, and it was decided that it would be good to put this in the bug database, so that the code wouldn't be lost.
It turns out though, that the main problem isn't setting the window's icon. The main problem is that the window is recreated when the user requests a change that can't be made to an already existing window, but can only be made at window creation time.
1st newgroup entry:
I have a simple routine that changes the icon in the corner of a Tk window.
It runs under Windows. I saw in a post by Jeffrey Hobbs last December, that
the steering committee (correct term?) hopes to put a simplified version of
winico into 8.4. Perhaps this code will help.
2nd newsgroup entry:
This would be a good thing to enter into the bug db so the patch isn't
lost. The tricky part though is making sure that the icon in the
corner stays there when the toplevel is manipulated (Tk on Windows
is constantly having to recreate the wrapper frame to allow you to do
all that flexible stuff that is just somewhat "unnatural" for Windows).
For example, see the bug report #5324.
Patch:
void SetIcon(char* windowName, int iconId, HINSTANCE hInstance) {
int result;
char workString[80];
int workInteger;
HWND windowHwnd;
HWND wrapHwnd;
static HICON hIcon;
static int previous_iconId = -1;
sprintf(workString, "winfo id %s", windowName);
// We could have used Tk_GetHWND(Tk_WindowId(windowHtk)) instead.
result = Tcl_Eval(theInterp, workString);
if (result != TCL_OK) death("SetIcon - winfo");
result = Tcl_GetInt(theInterp, theInterp->result, &workInteger);
if (result != TCL_OK) death("SetIcon - GetInt");
windowHwnd = (HWND) workInteger;
wrapHwnd = GetParent(windowHwnd);
if (!wrapHwnd) death("SetIcon - GetParent");
// I hate to do a file I/O repeatedly, and we probably are going to use
// the same icon for all the dialogs in the application.
if (iconId != previous_iconId) {
previous_iconId = iconId;
hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(iconId) );
if (!hIcon) death("SetIcon - LoadIcon");
}
SendMessage(wrapHwnd, WM_SETICON, (WPARAM) ICON_BIG, (LPARAM) hIcon);
// I tried a specifically made small icon, but if you let the system
// resize the big icon, you get good results.
// Interesting that passing a NULL icon leaves the old icon
// in place. The documentation says "If this parameter is NULL,
// the icon indicated by fType is removed."
}
// Often, it will be necessary to precede SetIcon with a call to
// Tcl_ServiceAll.
|