• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

Three Easy questions, I'm a begginer

Using Visual C++ 6.0
How do I make the backround black on a dialog box?
How do you get the dementions of a bitmap or control?
For example like Bitmap.top and Bitmap.left in Visual Basic
How do you play simple sound waves?
  • 3
  • 2
  • 2
1 Solution
1. MFC program - background dialog color - stick in InitInstance
SetDialogBkColor( RGB(0,0,0), RGB(255,255,255) ) ; // background to black, text to white (black on black is not to readable :-))

2. Get Dimensions of a bitmap
GetObject( hBitmap, sizeof bm, bm ) ;
// where hBitmap = HBITMAP of the bitmap
// bm.bmWidth and bm.bmHeight hold the bitmap size

3. Get Dimensions of a control
CRect rect ;
pWnd->GetWindowRect( &rect ) ;
// pWnd = the control, if you're in a dialog try
//GetDlgItem( IDC_EDIT )->GetWindowRect( &rect ) ;

coords go into rect in screen units.  Typically you want them in client coords (relative to the window, you can convert to these using)
ScreenToClient( &rect ) ;

3. Playing sound waves - see next comment
Playing sound

1. To play a .WAV file

     PlaySound( "file.wav", NULL, SND_FILENAME ) ;
     sndPlaySound( "file.wav", 0 ) ;

     for file name make sure you specify the full path.  If you use \ in string literals, then make sure you escape it
     "C:\\WINDOWS\\file.wav"  in C, means "C:\WINDOWS\file.wav" in DOS

     2. To play from resources

     i. Insert a .wav file into your resources
     - Go to resource tree on workspace
     - Right click
     - Pick "Import..."
     - Browse the WAV file
     - Assign an arbitary id, e.g. "IDC_WAVE"

     ii. Play the wave file with
     PlaySound( MAKEINTRESOURCE(IDC_WAVE),  AfxGetResourceHandle(), SND_RESOURCE ) ;

Make sure you #include <mm.h> (e.g. add this to stdafx.h) and link to winmm.lib (project settings)
Solution 2 and 3 are OK. I have a few queries about solution number. Won't SetDialogBkColor change the background color of all dialog boxes in the application.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

bradsobleskyAuthor Commented:
Thanks for your help :)
pagla - yes

u r okay with this ?
bradsobleskyAuthor Commented:
I'm not really...I just want the background.But it's better than nothing.
Do you want the background of any particular dialog box of your app to be different?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now