home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / mswindo / programm / misc / 5253 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  4.0 KB

  1. Path: sparky!uunet!mcsun!uknet!brunel!cyrillus.brunel.ac.uk!cs92njc
  2. From: cs92njc@cyrillus.brunel.ac.uk.ac.uk (Nicholas J Clayton)
  3. Newsgroups: comp.os.ms-windows.programmer.misc
  4. Subject: Bitmaps on a dialog box
  5. Message-ID: <C18E7x.J8M@brunel.ac.uk>
  6. Date: 22 Jan 93 01:16:43 GMT
  7. Sender: news@brunel.ac.uk (News supervisor)
  8. Reply-To: cs92njc@cyrillus.brunel.ac.uk.ac.uk
  9. Organization: Sun Microsystems, Inc.
  10. Lines: 78
  11. Nntp-Posting-Host: cyrillus.brunel.ac.uk
  12.  
  13. A while ago I asked if anyone knew how draw a bitmap onto a dialog box, to achieve the same sort of affect as the large 'icon' in the WinWord About box. Thanks to everyone who replied. The following is the method I used:
  14.  
  15. [ABOUT.DLG - The dialog definition file]
  16. DLGINCLUDE RCDATA DISCARDABLE
  17. BEGIN
  18.     "ABOUT.H\0"
  19. END
  20. /* ABOUT.H #defines IDI_ABOUT 101 */
  21.  
  22. /* This line references a bitmap file to be used on the dialog    */
  23. About BITMAP c:\coverage\help\coverage.bmp
  24.  
  25. 100 DIALOG 84, 44, 152, 64
  26. STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
  27. CAPTION "About Coverage Chart Generator"
  28. FONT 8, "MS Sans Serif"
  29. BEGIN
  30.     DEFPUSHBUTTON   "OK", IDOK, 56, 44, 40, 14
  31.     LTEXT           "Program name here", -1, 44, 8, 96, 12
  32.     LTEXT           "Copyright message here", -1, 44, 32, 95, 8
  33.     LTEXT           "Version number here", -1, 44, 20, 92, 8
  34. /* This is the important line. We define a control, with ID IDI_ABOUT. This */
  35. /* control is an ownerdrawn control so that Windows will send us messages   */
  36. /* saying when the picture on the control needs to be drawn. AFAIK, the     */
  37. /* dialog editor will not create this line correctly. You need to edit the  */
  38. /* file and add the window style parameters yourself.                       */   
  39.     CONTROL         "", IDI_ABOUT, "BUTTON", BS_OWNERDRAW | WS_CHILD | WS_VISIBLE, 4, 4, 32,
  40.                     32
  41. END
  42. [END ABOUT.DLG]
  43.  
  44. Each dialog box in my program has a seperate .C source file. The following is excerpted from ABOUT.C
  45.  
  46. [ABOUT.C]
  47.     case WM_DRAWITEM:
  48.     {
  49.         HBITMAP hAboutBitmap;
  50.     HDC hDCAbout;
  51.     HDC hDCMem;
  52.  
  53.     /* Get a DC for the about frame                */
  54.     hDCAbout = GetDC(GetDlgItem(hWndDlg, IDI_ABOUT));
  55.  
  56.     /* Create a compatible DC from the frame                */
  57.     hDCMem = CreateCompatibleDC(hDCAbout);
  58.  
  59.     hAboutBitmap = LoadBitmap(hInst, "About");
  60.  
  61.         /* Select the bitmap into the memory DC            */
  62.         SelectObject(hDCMem, hAboutBitmap);
  63.  
  64.     /* Blit it onto the box                    */
  65.     BitBlt(hDCAbout, 0, 0, 64, 64, hDCMem, 0, 0, SRCCOPY);
  66.  
  67.     /* Delete the two DCs and the bitmap            */
  68.         DeleteDC(hDCAbout);
  69.         DeleteDC(hDCMem);
  70.     DeleteObject(hAboutBitmap);
  71.     }
  72.     return FALSE;
  73.  
  74. Hopefully, the above code is fairly simple to follow. The first 3 lines initialise the working variables for this section of code. hAboutBitmap is a handle to the bitmap, while hDCAbout and hDCMem are DCs for the About box and a memory block respectively.
  75.  
  76. The next line is the only method I could use to get a DC for the about frame. If anyone knows of less ugly method, please let me know (I have an aversion to functions which use information from functions in their parameter list). Then the program creates a compatible memory DC into which the bitmap can be selected.
  77.  
  78. The bitmap is then loaded. Note that "About" is the name assigned to the bitmap in the .dlg file earlier. We then select the bitmap into memory DC, ready for blitting. Bitblt then blits the contents of the memory DC (the bitmap) onto the about frame DC. Is this the simplest way of doing it, or is there a method of blitting without the need to first select the bitmap into the memory DC? It does seem to be a longwinded way of going about it.
  79.  
  80. The last three lines just delete the three resources that were used by the program.
  81.  
  82. My thanks again to those who responded to my original posting.
  83.  
  84. Rgds, Nik
  85. ---
  86. _/     _/ _/_/_/ _/  _/  For those who are wondering why,
  87. _/_/   _/   _/   _/ _/   What we call SF ain't Sci-Fi,    
  88. _/  _/ _/   _/   _/_/         It's just there a fine line 
  89. _/   _/_/   _/   _/ _/        Between Robert Heinlein,      
  90. _/     _/ _/_/_/ _/  _/  And "Son of the Two Headed Fly"  
  91.