RE: window icons

[email protected] Fri, 14 Feb 2003 15:47:35 -0000
Newsgroups gmane.comp.video.gimp.windows.devel
Message-ID <B1F38D7B53615140BCEA6677DF9F2F8C0111123C@i2km11-ukbr.domain1.systemhost.net>
Here is the file (couldnt previously send it):

#include <windows.h> 

#include <stdio.h>

#define IDB_SET_ICON	100
 
// Global variable 
HINSTANCE hinst; 
 
// Function prototypes. 
int APIENTRY WinMain(HINSTANCE, HINSTANCE, LPSTR, int); 
BOOL InitApplication(HINSTANCE); 
BOOL InitInstance(HINSTANCE, int); 
LRESULT CALLBACK MainWndProc(HWND, UINT, WPARAM, LPARAM); 
BOOL SetIconForClass(HWND hWnd);
 
// Application entry point. 
int APIENTRY WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, 
		     LPSTR lpCmdLine, int nCmdShow) 
{ 
  MSG msg; 
 
  if (!InitApplication(hinstance)) 
    return FALSE; 
 
  if (!InitInstance(hinstance, nCmdShow)) 
    return FALSE; 
 
  while(GetMessage(&msg, (HWND) NULL, 0, 0) != 0 && 
	GetMessage(&msg, (HWND) NULL, 0, 0) != -1) 
    { 
      TranslateMessage(&msg); 
      DispatchMessage(&msg); 
    } 
  return msg.wParam; 
  UNREFERENCED_PARAMETER(lpCmdLine); 
} 
 
BOOL InitApplication(HINSTANCE hinstance) 
{ 
  WNDCLASSEX wcx; 
 
  // Fill in the window class structure with parameters 
  // that describe the main window. 
 
  wcx.cbSize = sizeof(wcx);                          // size of structure 
  wcx.style = CS_HREDRAW | CS_VREDRAW;               // redraw if size
changes 
  wcx.lpfnWndProc = MainWndProc;                     // points to window
procedure 
  wcx.cbClsExtra = 0;                                // no extra class
memory 
  wcx.cbWndExtra = 0;                                // no extra window
memory 
  wcx.hInstance = hinstance;                         // handle to instance 
  wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);       // predefined app. icon

  wcx.hCursor = LoadCursor(NULL, IDC_ARROW);         // predefined arrow 
  wcx.hbrBackground = GetStockObject(WHITE_BRUSH);   // white background
brush 
  wcx.lpszMenuName =  "MainMenu";                    // name of menu
resource 
  wcx.lpszClassName = "MainWClass";                  // name of window class

  wcx.hIconSm = LoadImage(hinstance,                 // small class icon 
			  MAKEINTRESOURCE(5),
			  IMAGE_ICON, 
			  GetSystemMetrics(SM_CXSMICON), 
			  GetSystemMetrics(SM_CYSMICON), 
			  LR_DEFAULTCOLOR); 
 
  // Register the window class. 
  return RegisterClassEx(&wcx); 
} 
 
BOOL InitInstance(HINSTANCE hinstance, int nCmdShow) 
{ 
  HWND hwnd1; 
  HWND hwnd2; 
 
  // Save the application-instance handle. 
  hinst = hinstance; 
 
  // Create the main window. 
  hwnd1 = CreateWindow("MainWClass",        // name of window class 
		       "Sample",            // title-bar string 
		       WS_OVERLAPPEDWINDOW, // top-level window 
		       CW_USEDEFAULT,       // default horizontal position 
		       CW_USEDEFAULT,       // default vertical position 
		       300,                 // default width 
		       300,                 // default height 
		       (HWND) NULL,         // no owner window 
		       (HMENU) NULL,        // use class menu 
		       hinstance,           // handle to application
instance 
		       (LPVOID) NULL);      // no window-creation data 
  
  // Create the **SECOND** main window. 
  hwnd2 = CreateWindow("MainWClass",        // name of window class 
		       "Sample",            // title-bar string 
		       WS_OVERLAPPEDWINDOW, // top-level window 
		       CW_USEDEFAULT,       // default horizontal position 
		       CW_USEDEFAULT,       // default vertical position 
		       300,                 // default width 
		       300,                 // default height 
		       (HWND) NULL,         // no owner window 
		       (HMENU) NULL,        // use class menu 
		       hinstance,           // handle to application
instance 
		       (LPVOID) NULL);      // no window-creation data 

  if (!hwnd1 || !hwnd2) 
    return FALSE; 
 
  // Show the window and send a WM_PAINT message to the window 
  // procedure. 
  ShowWindow(hwnd1, nCmdShow); 
  UpdateWindow(hwnd1); 

  ShowWindow(hwnd2, nCmdShow); 
  UpdateWindow(hwnd2); 

  return TRUE; 
} 

LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM
lParam)
{
  static HWND hButton;

/*   printf("hWnd:0x%.8x, uMsg:%d\n",(int)hWnd,uMsg); */
/*   fflush(stdout); */

  switch(uMsg) 
    {
      // Create and show two PushButton Controls
    case WM_CREATE: 
      // ... first PushButton Control
      hButton = CreateWindow ("BUTTON", "Set Icon for Class",
			      WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
			      60, 160, 160, 60, 
			      (HWND) hWnd, 
			      (HMENU) IDB_SET_ICON,
			      hinst,
			      (LPVOID) NULL);
      ShowWindow (hButton, SW_SHOW);
      break;
      
      // ... we need the current size of the client area
    case WM_SIZE:
      UpdateWindow (hWnd);
      return (0);
      
      // ... set focus always to main window
    case WM_COMMAND: 
      switch(wParam)
	{
	case IDB_SET_ICON:
	  printf("button clicked\n");
	  fflush(stdout);
	  SetIconForClass(hWnd);
	}
      break;

      // ... destroy window
    case WM_DESTROY: 
      PostQuitMessage (0);
      return (0);
    }

  return (DefWindowProc (hWnd, uMsg, wParam, lParam));
}

BOOL SetIconForClass(HWND hWnd)
{
  WNDCLASSEX wcx; 
  HANDLE newicon;

  printf("setting icon...\n");
  fflush(stdout);

  if(GetClassInfoEx(hinst, 
		    "MainWClass",
		    &wcx) == 0)
    {
      printf("failed to set icon, could not get window class");
      fflush(stdout);
      return FALSE;
    }  

  newicon = LoadImage(hinst,                 // small class icon 
		      "icon1.ico",           // load from filename
		      IMAGE_ICON, 
		      GetSystemMetrics(SM_CXSMICON), 
		      GetSystemMetrics(SM_CYSMICON), 
		      LR_LOADFROMFILE);   

#ifdef NEW
  // this will be used and SetClassLong will be deprecated
  // currently this function is not available under MinGW's Win32 API 
  SetClassLongPtr(hinst,
		  GCLP_HICON,
		  HANDLE);
#else
  SetClassLong((HWND)hWnd,
	       GCL_HICONSM,
	       (LONG) newicon);
#endif

  UpdateWindow(hWnd);

  printf("icon set!");
  fflush(stdout);

  // do i need to set the class again?

  return TRUE;
}



> -----Original Message-----
> From: [email protected] [mailto:[email protected]]
> Sent: 14 February 2003 15:45
> To: [email protected]
> Subject: RE: [gimpwin-dev] window icons
> 
> 
> >
> > If I get time tomorrow, I will knock up a test application to 
> > see if the
> > changing the details of a class for 2 or more windows, 
> changes all the
> > windows.
> > 
> 
> I have knocked up this quick test application to set the icon 
> of a class
> which is being used by TWO different windows.  Unfortunately 
> when the icon
> changed for the class, both window icons changed to reflect 
> this.  As a
> result, having a different icon for each window *WILL* 
> require a separate
> class per gtkwindow.
> 
> Just a thought, but if you employ this, you are likely to 
> break the function
> which sets the icon for all windows of an application (because they no
> longer will share the same class).
> 
> Do you think you could do this Tor?
> 
> Is there a bug for this? Should I report one?
> 
> Note: the application I have created doesn't respond to 
> clicks on the button
> very well, you may need to click the button a couple of times 
> before it will
> respond.
> 
> Regards,
> Martyn
> 
> 
> 
> 
> 
> [Non-text portions of this message have been removed]
> 
> 
> ------------------------ Yahoo! Groups Sponsor 
> ---------------------~-->
> Get 128 Bit SSL Encryption!
> http://us.click.yahoo.com/FpY02D/vN2EAA/xGHJAA/NhFolB/TM
> --------------------------------------------------------------
> -------~->
> 
> To Post a message, send it to: [email protected]
> To Unsubscribe, send a blank message to: 
> [email protected] 
> 
> Your use of Yahoo! Groups is subject to 
http://docs.yahoo.com/info/terms/