Microsoft KB Archive/49888
Article ID: 49888
Article Last Modified on 1/9/2003
- Microsoft QuickBasic Compiler for Macintosh 1.0
This article was previously published under Q49888
This article describes how to access all the patterns in the System resource PAT#. The sample program shows all the patterns on the screen and gives the corresponding pattern number in the list of patterns.
This information applies to Microsoft QuickBASIC Version 1.00 for the Apple Macintosh.
The example below gets the resource handle for the PAT# resource from the System file. The handle is used to point to where the system patterns are loaded in memory.
PEEKing at the first word at this location gives you the number of patterns located in the System resource PAT#. The next eight bytes contain the first pattern, and each following eight bytes contains a pattern until all the patterns are looked at.
Each pattern can be put into a four-dimensional integer array and can be displayed using the FILLRECT routine. Once the pattern is in the array, you could then put it in any resource file with a new handle.
id% = 0 ' The Systems Pattern has an ID of zero. h& = 0 ' Initialize h&. sysref%=0 ' Zero can be used as the System's reference number. ' No OpenResFile statement is necessary, since the ' the resource fork of the System file is always open. getres sysref%,"PAT#",id%,h& ' Get the handle to resource PAT#. lockRes h& StartPatternList&=PEEKL(h&) ' Get the starting address of where ' resource PAT# is located in memory. NumOfPattern%= PEEKW(StartPatternList&) ' Get the number of patterns ' stored in the PAT# list. DIM pat%(3) ' An array to hold the current pattern being displayed. ' It takes only 8 bytes to store a pattern. DIM rect%(4*NumOfPattern%) 'An array to hold the dimensions of the 'rectangle to be filled with the pattern ' The following FOR loop sets up all the rectangle regions. Each ' rectangle region is 50 x 50 pixels and each will be filled with one ' pattern. XCount% = 1 YCount% = 1 FOR i = 1 TO NumOfPattern% IF XCount%= 10 THEN YCount% = YCount% + 1 XCount% = 1 END IF SetRect rect%(i*4-4),XCount%*50-50+1,YCount%*50-50+1,XCount%*50,YCount%*50 XCount% = XCount% + 1 NEXT i ' The following FOR loop loads a different pattern into each ' rectangular region. As each rectangle is filled with a pattern, ' it will be displayed on the screen. FOR i = 1 TO NumOfPattern% PatternOffset% = (i * 8) - 8 ' Each pattern is 8 bytes long. pat%(0) = PEEKW(StartPatternList& + 2 + PatternOffset%) pat%(1) = PEEKW(StartPatternList& + 4 + PatternOffset%) pat%(2) = PEEKW(StartPatternList& + 6 + PatternOffset%) pat%(3) = PEEKW(StartPatternList& + 8 + PatternOffset%) CALL FILLRECT(VARPTR(rect%(i*4-4)),VARPTR(pat%(0))) NEXT i ' The following FOR loop puts the pattern number of each pattern ' in the corner of the rectangle containing the pattern. XCount% = 1 YCount% = 1 FOR i = 1 TO NumOfPattern% IF XCount%= 10 THEN YCount% = YCount% + 1 XCount% = 1 END IF CALL MOVETO (XCount%*50-50+1,YCount%*50-3) XCount% = XCount% + 1 PRINT i; NEXT i LOCATE 15,20 PRINT "Here is the list of all the system patterns"; LOCATE 16,20 PRINT "and their corresponding pattern Number"; WHILE MOUSE(0) <> 1 :WEND END
Additional query words: MQuickB