This is the mail archive of the cygwin-xfree@cygwin.com mailing list for the Cygwin XFree86 project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: question about multiwindow mode and application icons


Ralf Habacker wrote:

> 1. Setting the icon is only necessary in winCreateWindowsWindow() through a
> LoadImage() call (see the function GetWindowIcon() below) which loads the icon
file
                                         ^^^^
Ups, I've forgotten the diff file, sorry. I will send it soon, let me first
clear some thing you have written

>>A. currently all win32 windows of the multi-window mode shares the same window
>>class, which means, that changing a single windows icon will change *all*
icons.
>>As a hack I have implemented different window classes for each windows. This
>>isn't very good, because x applications uses an icon only for the main window,
>>which means that additional opened windows will display the default 'x' icon.
>>A better solution is to use one window class for all windows of one
>>application -> Unfortunally I don't know to implement this.
-----------------
>Instead of using the class icon, how about doing your own WM_NCPAINT
>handling?  You can set the class icon to NULL or a blank icon when you
>register the class, and in the WM_NCPAINT first call the default
>handler to draw the title/etc, and then DrawIcon(fn(x-class)) in the
>non client region, after getting the icon x/y from GetSysMetrics.

But what about the taskbar and ALT-TAB window handling ? The win32 build in
handling of windows require a registered icon, which requires different
WindowClasses for each application.
Otherwise I have to do all stuff manual, which seems not so easy. :-)

Do you see a problem using different RegisterClass, which would make it very
simple (initialize icon and forget) ?

I'm very near at this goal. The only thing I'm missing is how to get a WMInfoPtr
and Window reference from the WindowPtr.  See the source below:

hw/xwin/winmultiwindowwm.c

int
GetWindowClass(WindowPtr pWin, char *basename, char *windowClass)
{
  WMInfoPtr pWMInfo = /* pWin -- ??? */ ;
  Window iWin =  /* pWin -- ??? */ ;
  char appName[1024];

  GetClientApplicationName (pWMInfo->pDisplay, iWin, appName);
  if (windowClass)
  	sprintf(windowClass,"%s-%s",basename,appName);

	return 1;
}

HICON
GetWindowIcon(WindowPtr pWin)
{
  WMInfoPtr pWMInfo = /* pWin -- ??? */ ;
  Window iWin =  /* pWin -- ??? */ ;
  Atom atmType;
  int fmtRet;
  unsigned long items, remain;
  HWND *retHwnd, hWnd;
  XWindowAttributes		attr;
  HICON hIcon;

  hWnd = 0;
  /* See if we can get the cached HWND for this window... */
  if (XGetWindowProperty(pWMInfo->pDisplay,
			 iWindow,
			 pWMInfo->atmPrivMap,
			 0,
			 1,
			 False,
			 pWMInfo->atmPrivMap,
			 &atmType,
			 &fmtRet,
			 &items,
			 &remain,
			 (unsigned char **)&retHwnd ) == Success) {
    hWnd = *retHwnd;
    XFree(retHwnd);
  }

  /* Some sanity checks */
  if (!hWnd) return;
  if (!IsWindow(hWnd)) return;

  /* Get the window attributes */
  XGetWindowAttributes (pWMInfo->pDisplay,
		  iWindow,
		  &attr);

  if (!attr.override_redirect)
  	{
			char appName[1024];

			GetClientApplicationName(pWMInfo->pDisplay,iWindow,appName);
			if (!*appName)
				return;

			strcat(appName,".ico");
			hIcon = LoadImage(0,appName,IMAGE_ICON, 0,0,LR_DEFAULTSIZE| LR_LOADFROMFILE |
LR_SHARED );
		}
	return hIcon;
}


/hw/xwin/winmultiwindowwindow.c

extern int
GetWindowClass(WindowPtr pWin, char *basename, char *windowClass);

extern HICON
GetWindowIcon(WindowPtr pWin);

static void
winCreateWindowsWindow (WindowPtr pWin)
{
  int                   iX, iY;
  int			iWidth;
  int			iHeight;
  int                   iBorder;
  HWND			hWnd;
  WNDCLASS		wc;
  winWindowPriv(pWin);
  char windowClass[1024];

	if (!GetWindowClass(pWin,WINDOW_CLASS_X,windowClass))
		strcpy(windowClass,WINDOW_CLASS_X);

#if CYGMULTIWINDOW_DEBUG
  ErrorF ("winCreateWindowsWindow - pWin: %08x windowClass: %s\n",
pWin,windowClass);
#endif

  iBorder = wBorderWidth (pWin);

  iX = pWin->drawable.x;
  iY = pWin->drawable.y;

  iWidth = pWin->drawable.width;
  iHeight = pWin->drawable.height;

  /* Setup our window class */
  wc.style = CS_HREDRAW | CS_VREDRAW;
  wc.lpfnWndProc = winTopLevelWindowProc;
  wc.cbClsExtra = 0;
  wc.cbWndExtra = 0;
  wc.hInstance = g_hInstance;
  wc.hIcon = GetWindowIcon(pWin);
  if (!wc.hIcon)
     wc.hIcon = LoadIcon (g_hInstance, MAKEINTRESOURCE(IDI_XWIN));
  wc.hCursor = 0;
  wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
  wc.lpszMenuName = NULL;
  wc.lpszClassName = windowClass;
  RegisterClass (&wc);

  /* Create the window */
  hWnd = CreateWindowExA (WS_EX_TOOLWINDOW,			/* Extended styles */
			  windowClass,			  /* Class name */
			  WINDOW_TITLE_X,			/* Window name */
			  WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
			  iX,					/* Horizontal position */
			  iY,					/* Vertical position */
			  iWidth,				/* Right edge */
			  iHeight,				/* Bottom edge */
			  (HWND) NULL,				/* No parent or owner window */
			  (HMENU) NULL,				/* No menu */
			  GetModuleHandle (NULL),		/* Instance handle */
			  pWin);				/* ScreenPrivates */
  if (hWnd == NULL)
    {
      ErrorF ("winCreateWindowsWindow - CreateWindowExA () failed: %d\n",
	      GetLastError ());
    }

  pWinPriv->hWnd = hWnd;


  SetProp (pWinPriv->hWnd, WIN_WID_PROP, (HANDLE) winGetWindowID(pWin));

  /* Flag that this Windows window handles its own activation */
  SetProp (pWinPriv->hWnd, WIN_NEEDMANAGE_PROP, (HANDLE) 0);
}





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]