Sudoku puzzles screen capture
I love doing crossword puzzles: I’m a huge fan of Merle Reagle (I have all his books www.sundaycrosswords.com) and I love the NY Times Sunday puzzles, both of which come in the Seattle Times. We also love listening to the NPR Sunday Puzzle by Puzzlemaster Will Shortz, from whom we first heard about Sudoku a few weeks ago.
Crossword puzzles require a fairly large amount of prior knowledge to solve. Sudoku requires almost no prior knowledge: just logic and deduction.
My family has been enjoying Sudoko puzzles. In fact, about a month ago, both the newspapers to which we subscribe started carrying daily Sudoku puzzles within a week of each other (USA Today, Seattle Times). If you haven’t tried one give it a whirl. A Sudoku puzzle consists of a 3x3 grid of 3x3 grids of squares, some of which are prefilled with digits. Sudoku rules are simple. Enter digits from 1-9 in blank spaces. Each row, column and 3x3 square must have 1 of each digit. Each Sudoku has a unique solution that can be reached logically without guessing.
Before I wrote a program to generate Sudoku puzzles, I needed to learn about them first. There are many web sites that provide Sudoku puzzles. I started by copying them to a word document (using Alt-PrtScrn to capture to the clipboard), resizing them to fit many on a page, then printing them out. That became rather tedious, so I automated the process.
Here is some code to capture Sudoku puzzles from a web site and add them to a Word document, 9 to a page. Why 9 to a page? Because Sudoku is all about 3x3<g>.
The code automates Internet Explorer and Word. Just change the URL to a web site that produces Sudoku puzzles and adjust the x,y,width,height coordinates. Be sure to heed any copyright notices.
I’ll post code that helps solve a Sudoku puzzle next.
*Start IE in upper left,
PUBLIC oie AS internetexplorer.application
oIE = CREATEOBJECT("internetexplorer.application")
oIE.visible=1
oIE.top=0
oIE.left=0
oIE.width=650
oIE.height=650
DECLARE integer Sleep IN WIN32API integer
public oW as Word.Application
oW=CREATEOBJECT("word.application")
ow.WindowState= 0 && wdWindowStateNormal
oW.visible=1
oW.left=650
ow.Top=0
oW.Documents.Add
*!* oW.ActiveWindow.ActivePane.View.Zoom.Percentage = 75
*!* oW.ActiveWindow.ActivePane.View.Type= 3 && wdPrintView
With ow.ActiveDocument.PageSetup as Word.PageSetup
.TopMargin = 12.25
.BottomMargin = 12.25
.LeftMargin = 12.25
.RightMargin = 12.25
ENDWITH
* oW.ActiveDocument.Sections(1).Footers(1).PageNumbers.Add(2)
FOR i = 1 TO 2*9 && # of pages @ 9 per page
oIE.Navigate2("https://blogs.msdn.com/calvin_hsia") &&Adjust this URL to point to a sudoku web site
DO WHILE oIE.ReadyState!=4 &&READYSTATE_COMPLETE
sleep(1000)
ENDDO
sleep(200) && allow enough time for ie to render page
ScrnScrape()
IF MOD(i-1,9)=0
IF i>1
oW.Selection.InsertBreak(7) &&pagebreak
ENDIF
oW.Selection.InsertAfter("Sudoku rules are simple. Enter digits from 1-9 in blank spaces. Each row, column and 3x3 square must have 1 of each digit.")
oW.Selection.InsertAfter("Each Sudoku has a unique solution that can be reached logically without guessing."+CHR(13))
oW.Selection.InsertAfter(REPLICATE(CHR(13),3))
oW.Selection.EndKey(6)
endif
oW.Selection.InlineShapes.AddPicture("c:\temp.jpg",.f.,.t.)
oW.Selection.EndKey(6)
oW.Selection.MoveLeft(1,1,1)
oW.Selection.InlineShapes(1).Width= 190
oW.Selection.InlineShapes(1).Height= 210
oW.Selection.EndKey(6)
ENDFOR
ow.Left=0 && move word left
ow.Selection.HomeKey(6) && go to top of doc
PROCEDURE ScrnScrape()
CLEAR
TRY
cFileName="c:\temp.jpg"
ERASE (cFileName)
SET CLASSLIB TO HOME()+"ffc\_gdiplus"
LOCAL og as gpgraphics
LOCAL oImage as gpimage
x=308 && adjust these coordinates
y=230
w=310
h=378
oImage=GetRegion(0,x,y,w,h)
og=CREATEOBJECT("gpgraphics")
og.CreateFromImage(oImage)
og.DrawImageScaled(oImage,0,0,100,100)
oImage.SaveToFile(cFileName,"image/jpeg")
oImage=CREATEOBJECT("gpimage","c:\temp.jpg")
og.CreateFromHWND(_screen.HWnd)
og.DrawImageAt(oImage,0,0)
oImage.SaveToFile(cFileName,"image/jpeg")
CATCH TO oerr
?oerr.message
ENDTRY
fDoingScrape=.f.
RETURN
PROCEDURE GetRegion(hWnd as Integer, nLeft as Integer, nTop as Integer, nWidth as Integer, nHeight as Integer)
LOCAL hdc, hbSave, hdcCompat, hbm
DECLARE integer GetDC IN user32 integer hWnd
DECLARE integer ReleaseDC IN user32 integer hWnd, integer hDC
DECLARE integer CreateCompatibleDC IN gdi32 integer hDC
DECLARE integer CreateCompatibleBitmap IN gdi32 integer hDC, integer Width, integer Height
DECLARE integer SelectObject IN gdi32 integer hdc, integer
DECLARE integer DeleteObject IN gdi32 integer hdc,
DECLARE integer BitBlt IN gdi32 integer hdc, integer nXDest, integer nYDest, integer nWidth, integer nHeight, ;
integer hdcSrc, integer nXSrc, integer nYSrc, integer nRop
DECLARE INTEGER GdipCreateBitmapFromHBITMAP in gdiplus integer hbm,integer hpal,integer @ bitmap
DECLARE INTEGER GdipCloneBitmapAreaI in gdiplus integer X,integer Y,integer Width,integer Height,integer enumPixelFormats_format,integer srcBitmap,integer @ dstBitmap
#define SRCCOPY 0x00CC0020 && from wingdi.h /* dest = source */
LOCAL og as gpgraphics,ofont as gpfont,nBitMap, nTemp
og=CREATEOBJECT("gpgraphics")
og.CreateFromHWND(_screen.HWnd)
oImage=CREATEOBJECT("gpimage")
hdc = GetDC(hWnd)
hdcCompat = CreateCompatibleDC(hDC)
hbm = CreateCompatibleBitmap(hDC, nWidth, nHeight)
hbSave=SelectObject(hdcCompat,hbm)
BitBlt(hdcCompat,0,0,nWidth,nHeight,hdc, nLeft, nTop, SRCCOPY)
SelectObject(hdcCompat, hbSave)
nBitMap=0
GdipCreateBitmapFromHBITMAP(hbm,0, @nBitMap)
nTemp=0
GdipCloneBitmapAreaI(0,0,nWidth, nHeight, 0, nBitMap, @ntemp)
oImage.SetHandle(nTemp)
DeleteObject(hbm)
ReleaseDC(hWnd, hdcCompat)
ReleaseDC(hWnd, hDC)
RETURN oImage
Comments
Anonymous
September 08, 2005
Cool... I found another script that allow include a sudoku puzzle in my own website, just paste a bit of code on my site, it's cool... check it here http://sudoku.yosmany.netAnonymous
February 21, 2006
"Computer Aided Sudoku" free excel game helper solver to be searched on Google or to download at http://perso.wanadoo.fr/sudoku.laviron
Also in french "Sudoku assisté par ordinateur" jeu gratuit excelAnonymous
March 07, 2006
Play Sudoku for free : http://www.misterfast.com/grille-sudoku.htmlAnonymous
April 03, 2006
Several months ago, I wrote The mechanics of Sudoku and Sudoku puzzles screen capture. As a result, Stephen...Anonymous
April 06, 2006
The comment has been removedAnonymous
April 06, 2006
I am addicted to Sudoku! I made an inventory of methods for solving even the most difficult Sudoku. Start with looking for duo's, it's an eye opener!
Check http://www.sudokuhints.nl/en/ for details.
Good luck!Anonymous
April 21, 2006
Play Sudoku Online : http://sudoku.arrelnet.com/Anonymous
April 23, 2006
Download free Sudoku Excel with generator of Sudoku puzzles to print or play, powerful helper, fast solver at http://perso.wanadoo.fr/sudoku.laviron/
You get SURPRISES when sudoku solved, HISTORIC to record the game and partial replay, CLINIC to analyse your Sudoku.
Enjoy.Anonymous
January 09, 2007
I found a great video that will show you how to solve any sudoku watch it it's great. http://www.metacafe.com/watch/348621/how_to_solve_any_sudoko_puzzel/ If you are not in love with sudoko then forget about it. PeaceAnonymous
February 27, 2007
I solved a series of Sudoku in last many days and i can teach you how to solve ANY SUDOKU in this world. A very simple trick. Get me at : nprahul@NOSPAMgmail.comAnonymous
December 05, 2007
The comment has been removedAnonymous
December 05, 2007
The comment has been removedAnonymous
March 04, 2008
PingBack from http://ossmall.info/2008/03/04/using-microsoft-visual-foxpro-to-add-images-to-a-microsoft-word-2003-or-2007-inlineshapes-collection/Anonymous
June 07, 2008
I love doing crossword puzzles: I’m a huge fan of Merle Reagle (I have all his books www.sundaycrosswords.com ) and I love the NY Times Sunday puzzles, both of which come in the Seattle Times. We also love listening to the NPR Sunday Puzzle by PuzzlemasteAnonymous
February 14, 2009
My wife and I like to listen to PuzzleMaster Will Shortz.on NPR. This week’s challenge is from one ofAnonymous
February 21, 2009
I try to modify your ScrnScrape() function to capture a web page into one image (jpg,png,bmp,gif,...) done with its URL...without success. That code is already functionnal in other softs(c++..). Can you adapt it for this circonstance with conjonction in gdiplus ? I see that uses a VB function DrawToBitmap who is not implemented in VFP (. Thanks in advance. this is my code :
publi apIE do locfile("system.app") &&gdiplusX apIE=createObject("internetexplorer.application") apIE.visible=.f. apIE.navigate("http://msdn.technetweb3.orcsweb.com/calvin_hsia/default.aspx?p=17") do while apIE.busy or apIE.readystate#4 enddo local scrollwidth,scrollHeight scrollHeight = apIE.Document.Body.offsetHeight scrollWidth = apIE.Document.Body.offsetWidth with _screen.system.drawing bm=.bitmap.new(scrollWidth,scrollHeight) apIE.DrawToBitmap(bm, .Rectangle.new(0, 0, bm.Width, bm.Height)) &&dont work in VFP9 bm.Save("c:ywebcapture.png",.Imaging.ImageFormat.Png) endwith run/n "explorer" c:ywebcapture.png apIE.quit return
- Anonymous
June 19, 2009
PingBack from http://debtsolutionsnow.info/story.php?id=12400