Update of /cvsroot/perl-win32-gui/Win32-GUI
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7193
Modified Files:
CHANGELOG GUI.pm GUI.xs
Log Message:
Enhanced resouce loaing for Icons/Bitmaps and Cursors
Index: GUI.xs
===================================================================
RCS file: /cvsroot/perl-win32-gui/Win32-GUI/GUI.xs,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -d -r1.57 -r1.58
*** GUI.xs 16 May 2006 18:57:25 -0000 1.57
--- GUI.xs 1 Jun 2006 19:46:11 -0000 1.58
***************
*** 1448,1451 ****
--- 1448,1452 ----
#my $hourglass=Win32::GUI::LoadCursor(32514);
#
+ #NOTE: it is better to use Win32::GUI::Cursor->new(ID);
void
LoadCursor(ID)
***************
*** 1482,1487 ****
# (@)INTERNAL:LoadImage(FILENAME, [TYPE, X, Y, FLAGS])
HBITMAP
! LoadImage(filename,iType=IMAGE_BITMAP,iX=0,iY=0,iFlags=LR_LOADFROMFILE)
! LPCTSTR filename
UINT iType
int iX
--- 1483,1488 ----
# (@)INTERNAL:LoadImage(FILENAME, [TYPE, X, Y, FLAGS])
HBITMAP
! LoadImage(filename,iType=IMAGE_BITMAP,iX=0,iY=0,iFlags=LR_DEFAULTCOLOR)
! SV *filename
UINT iType
int iX
***************
*** 1490,1509 ****
PREINIT:
HINSTANCE moduleHandle;
! HBITMAP bitmap;
CODE:
moduleHandle = GetModuleHandle(NULL);
! // Attempt to load from current EXE:
! bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle, filename, iType,
iX, iY, LR_DEFAULTCOLOR);
! // Try OEM ressource
! /* Can't use filename (a string pointer) as a resource id - should be
able to use
! * a filename like '#1' to get resource from EXE - TODO: test this
! if(bitmap == NULL) {
! bitmap = (HBITMAP) LoadImage((HINSTANCE) NULL,
MAKEINTRESOURCE(filename), iType, iX, iY, LR_DEFAULTCOLOR);
}
! */
! if(bitmap == NULL) {
! // Ok, that failed. So attempt to load from file:
! bitmap = (HBITMAP) LoadImage((HINSTANCE) NULL, filename, iType, iX,
iY, iFlags);
}
RETVAL = bitmap;
OUTPUT:
--- 1491,1554 ----
PREINIT:
HINSTANCE moduleHandle;
! HBITMAP bitmap = NULL;
CODE:
+ /* Try to find the resource in the current EXE */
moduleHandle = GetModuleHandle(NULL);
!
! /* If filename looks like a string, attempt to load from current EXE: */
! if((bitmap ==NULL) && SvPOK(filename) && !(iFlags & LR_LOADFROMFILE)) {
! bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
! SvPV_nolen(filename), iType, iX, iY, iFlags);
}
!
! /* If filename looks like a number, try it as a resource id from the
current EXE */
! if((bitmap == NULL) && SvIOK(filename) && !(iFlags & LR_LOADFROMFILE)) {
! bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
! MAKEINTRESOURCE(SvIV(filename)), iType, iX, iY, iFlags);
}
+
+ /* Try to find the resource from GUI.dll */
+ moduleHandle = GetModuleHandle("GUI.dll");
+
+ /* If filename looks like a string, try it as a resource name from
GUI.dll */
+ if((bitmap == NULL) && SvPOK(filename) && !(iFlags & LR_LOADFROMFILE)) {
+ bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
+ SvPV_nolen(filename), iType, iX, iY, iFlags);
+ }
+
+ /* If filename looks like a number, try it as a resource id from GUI.dll
*/
+ if((bitmap == NULL) && SvIOK(filename) && !(iFlags & LR_LOADFROMFILE)) {
+ bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
+ MAKEINTRESOURCE(SvIV(filename)), iType, iX, iY, iFlags);
+ }
+
+ /* Try to load from file or as an OEM resource */
+ moduleHandle = NULL;
+
+ /* if filename looks like a string, try it as a file name */
+ if((bitmap == NULL) && SvPOK(filename)) {
+ bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
+ SvPV_nolen(filename), iType, iX, iY, iFlags|LR_LOADFROMFILE);
+ }
+
+ /* If filename looks like a number, try it as an OEM resource id */
+ if((bitmap == NULL) && SvIOK(filename) && !(iFlags & LR_LOADFROMFILE)) {
+ bitmap = (HBITMAP) LoadImage((HINSTANCE) moduleHandle,
+ MAKEINTRESOURCE(SvIV(filename)), iType, iX, iY, iFlags);
+ }
+
+ /* Finally, if it looks like a number, try it as a pre-defined resource */
+ if((bitmap == NULL) && SvIOK(filename)) {
+ if(iType == IMAGE_BITMAP) {
+ bitmap = LoadBitmap(NULL, MAKEINTRESOURCE(SvIV(filename)));
+ }
+ else if (iType == IMAGE_ICON) {
+ bitmap = LoadIcon(NULL, MAKEINTRESOURCE(SvIV(filename)));
+ }
+ else if (iType == IMAGE_CURSOR) {
+ bitmap = LoadCursor(NULL, MAKEINTRESOURCE(SvIV(filename)));
+ }
+ }
+
RETVAL = bitmap;
OUTPUT:
Index: GUI.pm
===================================================================
RCS file: /cvsroot/perl-win32-gui/Win32-GUI/GUI.pm,v
retrieving revision 1.45
retrieving revision 1.46
diff -C2 -d -r1.45 -r1.46
*** GUI.pm 30 May 2006 18:20:57 -0000 1.45
--- GUI.pm 1 Jun 2006 19:46:11 -0000 1.46
***************
*** 366,369 ****
--- 366,378 ----
# You can eventually specify your desired size for the image with X and
# Y and pass some FLAGS to the underlying LoadImage API (at your own risk)
+ #
+ # If FILENAME is a string, then it is first tried as a resource
+ # name, then a filename. If FILENAME is a number it is tried
+ # as a resource identifier.
+ #
+ # Resources are searched for in the current exe (perl.exe unless
+ # you have packed your application using perl2exe, PAR or similar),
+ # then in the Win32::GUI GUI.dll, and finally as an OEM resource
+ # identifier
sub new {
my $class = shift;
***************
*** 372,375 ****
--- 381,385 ----
my $handle = Win32::GUI::LoadImage(@_);
+ # TODO: this gives us a bitmap object, even if we ask for a cursor!
if($handle) {
$self->{-handle} = $handle;
***************
*** 390,393 ****
--- 400,412 ----
# (@)METHOD:new Win32::GUI::Icon(FILENAME)
# Creates a new Icon object reading from FILENAME.
+ #
+ # If FILENAME is a string, then it is first tried as a resource
+ # name, then a filename. If FILENAME is a number it is tried
+ # as a resource identifier.
+ #
+ # Resources are searched for in the current exe (perl.exe unless
+ # you have packed your application using perl2exe, PAR or similar),
+ # then in the Win32::GUI GUI.dll, and finally as an OEM resource
+ # identifier
sub new {
my $class = shift;
***************
*** 426,429 ****
--- 445,457 ----
# (@)METHOD:new Win32::GUI::Cursor(FILENAME)
# Creates a new Cursor object reading from FILENAME.
+ #
+ # If FILENAME is a string, then it is first tried as a resource
+ # name, then a filename. If FILENAME is a number it is tried
+ # as a resource identifier.
+ #
+ # Resources are searched for in the current exe (perl.exe unless
+ # you have packed your application using perl2exe, PAR or similar),
+ # then in the Win32::GUI GUI.dll, and finally as an OEM resource
+ # identifier
sub new {
my $class = shift;
Index: CHANGELOG
===================================================================
RCS file: /cvsroot/perl-win32-gui/Win32-GUI/CHANGELOG,v
retrieving revision 1.84
retrieving revision 1.85
diff -C2 -d -r1.84 -r1.85
*** CHANGELOG 16 May 2006 19:18:30 -0000 1.84
--- CHANGELOG 1 Jun 2006 19:46:11 -0000 1.85
***************
*** 6,9 ****
--- 6,21 ----
Win32-GUI ChangeLog
===================
+ + [Robert May] : 01 June 2006 - Icon/Cursor/Bitmap enhancement
+ --- Win32::GUI core ---
+ - GUI.xs,GUI.pm enhanced LoadImage to search more files for
+ resources, and to allow passing a resource ID. Update
+ documentation for Icon, Cursor and Bitmap constructors
+ to reflect additions.
+ - samples/standard_images.pl add sample that allows browsing of
+ all the standard resources.
+ --- Win32::GUI::Constants ---
+ - Constants.PL add IDI_, IDC_, OBM_, OCR_ and OIC_ constants
+ to load pre-defined resources.
+
+ [Robert May] : 16 May 2006 - More Win32::GUI::Constants
--- Win32::GUI core ---