C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old March 15th, 2003, 03:50 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 26
creating a skin

I want to make the background of my window be set to .bmp file my friend made for me. i have been scouring the web for how to do this, and all i have encountered is a vague description of using CWndImage that i really cant understand too well. From what i've been able to comprehend, it seems as though i have to create a seperate dialog box just to do this??? Can i not just set the background to that bmp without doing that??

Reply With Quote
  #2  
Old March 15th, 2003, 03:58 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
... you seem to be using MFC ... i can only tell you the WinAPI way, but maybe this still helps:

you load the bitmap via LoadBitmap(). In the WndProc, you capture WM_PAINT and there you BitBlt()/StretchBlt() the bitmap to the DC you get via GetDC(handle) where "handle" is your window´s HWND.
(maybe select() first? not sure - i am at home and don´t have any code about this around and i am too lazy right now to look it up on the MSDN)

...don´t forget to ReleaseDC() the device context after this
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old March 15th, 2003, 04:04 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 26
thnks for ur response, i am still kind of confused though b/c i am new to api programming. here is my code could u tell me a little more info plz..

PHP Code:
// cMortMain.cpp  -- main file for mortgage calculator

#include <fstream.h>
#include <iomanip.h>
#include "cMortgage.h"
#include <cstdlib>
#include <afxwin.h>
#include "resource.h"
#include <commdlg.h>  // for color dialog
// - - - prototype - - - 

LRESULT CALLBACK MyWndProc (HWND handleUINT msg,
                             
WPARAM wPLPARAM lP) ;

BOOL    CALLBACK DialogProc HWND handleUINT msg,
                             
WPARAM wPLPARAM lP) ;

HINSTANCE hInst;
cMort Mortgage1;

int WINAPI WinMain (HINSTANCE hInstanceHINSTANCE hPrevInstance,
                    
PSTR sCmdLineint iCmdShow)
{
  
HWND         hWnd ;
  
MSG          msg ;
  
WNDCLASS     wc // This is just a struct
  
TCHAR wcName[] = TEXT("Mortgage Calculator") ;

  
hInst hInstance;
  
// Step 1: Register a window 'class'
  
wc.lpszClassName wcName ;
  
wc.lpfnWndProc   MyWndProc// Name of function that handles messages
                                   // to windows based on this 'class'
  
wc.style         CS_HREDRAW CS_VREDRAW CS_DBLCLKS  ;
  
wc.hIcon         LoadIcon   (NULLIDI_APPLICATION) ;
  
wc.hCursor       LoadCursor (NULLIDC_ARROW) ;
  
// Option 1 for specifying a white window background
  // wc.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  // Option 2 for specifying a nice window background color 
   
HBRUSH  hBrush;
   
hBrush CreateSolidBrush (RGB(25,5,150));
   
wc.hbrBackground hBrush
  
// End window background options
  
wc.lpszMenuName  MAKEINTRESOURCE (IDR_MENU1);
  
wc.hInstance     hInstance ;
  
wc.cbClsExtra    ;
  
wc.cbWndExtra    ;

  if (!
RegisterClass (&wc)) return 0;

  
// Step 2: Create window based on above registered 'class'
  
hWnd CreateWindow
         
(
          
wcName,        // The name specifying the registed class
          
TEXT ("Mortgage Calculator"), // The window caption
          
WS_OVERLAPPEDWINDOW// window style
          
20,             // window position, left edge
          
30,             // window position, top edge
          
500,            // initial window width
          
300,            // initial window height
          
NULL,           // parent window handle
          
NULL,           // window menu handle
          
hInstance,      // program instance handle
          
NULL            // creation parameters
         
) ;                     
     
  
// Step 3: Show and update the window
  
ShowWindow (hWndiCmdShow) ;
  
UpdateWindow (hWnd) ;

  
// Step 4: Retrieve messages from message queue.
  
while (GetMessage (&msgNULL00))
  {
     
TranslateMessage (&msg) ;
     
DispatchMessage (&msg) ;// Give message back to OS.
                             // Sends to appro 'WndProc'
  
}
  
DeleteObject (hBrush); // Comment out 
                         // if use background option 1
  
return msg.wParam ;
}


// Note: Variables global so both
// MyWndProc() and DialogProc() can access them.
#define   IDC_MYLISTBOX    764


LRESULT CALLBACK MyWndProc (HWND hWndUINT message,
                            
WPARAM wParamLPARAM lParam)
{
  static 
COLORREF mTextColor RGB(255,0,0);
  static 
HFONT    hFont;
  static 
LOGFONT  lf;  // struct hold font details
  
static HWND hListBox1;
  
// - - - - - - - - -
        
  
UINT           NotificationCode;
  
int            idx;    
  
CString        tS;   // temp string
  
HDC            hDC ;  // 
  
PAINTSTRUCT    ps  ;  // Invalid window info
  
double pay1 0IntAmt 0Owe 0Balance 0;
  
int t 1;
  
char s[100], tSv[100];
  
ofstream fout;
     
  switch (
message)
  {
  case 
WM_CREATE:
       
hListBox1 CreateWindow (TEXT("listbox"), NULL,
                            
WS_CHILD WS_VISIBLE |WS_BORDER |WS_VSCROLL |LBS_NOTIFY,
                            
40,30400200,
                            
hWnd, (HMENU)IDC_MYLISTBOXhInstNULL);
                        
       return 
;
          
  case 
WM_PAINT:  // Code must update the window COMPLETELY
       
hDC BeginPaint (hWnd, &ps) ; // Get the device context handle
       
TextOut (hDC,40,10,"Payment Schedule",16);
       
SelectObject (hDChFont);
       
SetTextColor (hDCmTextColor);
       
SetBkMode (hDC,TRANSPARENT) ; 
       
EndPaint (hWnd, &ps) ;
       return 
;

  case 
WM_CHAR:   
       
InvalidateRect (hWndNULLTRUE); // send WM_PAINT msg
       
return 0;

  case 
WM_KEYDOWN
       return 
0;

  case 
WM_LBUTTONDOWN :
       return 
0;
  case 
WM_COMMAND:
      
// LOWORD(wParam) is id of menu option
      
switch (LOWORD (wParam))
      {
      case 
ID_EXIT:    
          
SendMessage(hWndWM_DESTROY0,0);
          return 
0;
      case 
ID_OPTIONS_ENTER:
          
DialogBox(hInstMAKEINTRESOURCE(IDD_DIALOG1),
                    
hWndDialogProc);
          
InvalidateRect(hWndNULL,TRUE);
          
pay1 Mortgage1.calcPayment();
          
sprintf(s,"%-10s %-12s %-10s %-12s %-14s""Pay #""Interest($)""Owe($)""Payment($)"
                    
"New Balance($)");
          
tS s;
          
SendMessage (hListBox1LB_ADDSTRING0,(LPARAM)(LPCTSTR)tS);
          
tS "--------------------------------------------------------------------------------------------------";
          
SendMessage (hListBox1LB_ADDSTRING0,(LPARAM)(LPCTSTR)tS);
          
Balance Mortgage1.getBorrowed();
          for (
t<= (Mortgage1.getNumPayments()*Mortgage1.getYears()); t++)
          {
            
IntAmt = (1.0/(Mortgage1.getNumPayments())*Mortgage1.getRate()*Balance);
            
Owe Balance IntAmt;
            
Balance Owe pay1;
            
sprintf(s,"%10i %12.2f %10.2f %12.2f %14.2f"tIntAmtOwepay1Balance);
            
tS s;
            
SendMessage (hListBox1LB_ADDSTRING0,(LPARAM)(LPCTSTR)tS);
          }

          return 
0;
      case 
ID_CLEAR:
          
SendMessage (hListBox1LB_RESETCONTENT0,0);
          return 
0;
      case 
ID_OPTIONS_SAVE:  //*****RIGHT HERE IS WHERE FILE IS SAVED***********************
          
fout << setprecision(2)<< setiosflags(ios::fixed);
          
fout.open ("LoanSchedule.txt");
          
fout << "  Loan Repayment Schedule\n";
          
fout << "\n            Amount borrowed ? " << Mortgage1.getBorrowed();
          
fout << "\n       Annual interest rate ? " << Mortgage1.getRate();
          
fout << "\nNumber of payments per year ? " << Mortgage1.getNumPayments();
          
fout << "\n            Number of years ? " << Mortgage1.getYears();
          
fout << "\n\n Each payment is : " << Mortgage1.getPayment() << "\n";
          
Balance Mortgage1.getBorrowed();
          
fout << "\nPay #   Interest    Owe      Payment    New balance\n";
          
fout << setprecision(2)<< setiosflags(ios::fixed);

          for ( 
1<= (Mortgage1.getNumPayments()*Mortgage1.getYears()); t++)
          {
            
IntAmt = (1.0/(Mortgage1.getNumPayments())*Mortgage1.getRate()*Balance);
            
Owe Balance IntAmt;
            
Balance Owe pay1;
            
fout << "\n" << setw(4) << t
                 
<< setw(10) << IntAmt 
                 
<< setw(12) << Owe
                 
<< setw(10) << Mortgage1.getPayment()
                 << 
setw(12) << Balance;
          }
          
MessageBox(hWnd,"File has been saved""Message",MB_OK);
          return 
0;
      case 
IDC_MYLISTBOX:
          
NotificationCode HIWORD(wParam);
          if (
NotificationCode ==LBN_SELCHANGE )
          {
            
idx SendMessage (hListBox1LB_GETCURSEL,0,0);
            
SendMessage (hListBox1LB_GETTEXTidx, (LPARAM)tSv);
          }
          return 
0;

      }
  case 
WM_DESTROY:
       
PostQuitMessage (0);
       
fout.close();
       return 
;
  }

  
  return 
DefWindowProc (hWndmessagewParamlParam) ;
}

BOOL    CALLBACK DialogProc HWND hDlgUINT msg,
                             
WPARAM wPLPARAM lP)
{
  
char   tmpStr[100];        //temp string
  
const int Z 0;            //zero constant
  
char *dPointer NULL;    //pointer for atof()
  
double tempDub 0;        //temp variables for utility
  
int tempInt 0;

  switch (
msg)
  {
  case 
WM_INITDIALOG:        //zero all edit boxes
    
SetDlgItemInt  (hDlgIDC_MBORROWEDZTRUE);
    
SetDlgItemInt  (hDlgIDC_MRATEZTRUE    );
    
SetDlgItemInt  (hDlgIDC_MPAYMENTSZTRUE);
    
SetDlgItemInt  (hDlgIDC_MYEARSZTRUE   );
    return 
TRUE;

  case 
WM_COMMAND:
    switch(
LOWORD(wP))
    {
     case 
IDOK :            //extract values from edit boxes to mortgage class variables
       
GetDlgItemText (hDlg,IDC_MBORROWEDtmpStr100);
       
dPointer tmpStr;
       
tempDub atof(dPointer);
       
Mortgage1.setBorrowed(tempDub);
       
GetDlgItemText (hDlg,IDC_MRATEtmpStr100);  
       
dPointer tmpStr;
       
tempDub atof(dPointer);
       
Mortgage1.setRate(tempDub);
       
tempInt GetDlgItemInt (hDlg,IDC_MPAYMENTSNULL100);
       
Mortgage1.setNumPayments(tempInt);
       
tempInt GetDlgItemInt (hDlg,IDC_MYEARSNULL100);
       
Mortgage1.setYears(tempInt);
       
EndDialog (hDlg,TRUE);
       return 
TRUE;

     case 
IDCANCEL:
       
EndDialog (hDlg,FALSE);
       return 
TRUE;
    }
    break;
  }
  return 
FALSE;


Reply With Quote
  #4  
Old March 15th, 2003, 04:12 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 39 m 55 sec
Reputation Power: 184
So it is WinAPI and not MFC that you are doing

Quote:
hWnd = CreateWindow ...

this is the HWND i refered to
Quote:
case WM_PAINT: // Code must update the window COMPLETELY
hDC = BeginPaint (hWnd, &ps) ; // here you have the HDC already, no need for getDC() then.
// here goes the function to paint the bmp to the DC
TextOut (hDC,40,10,"Payment Schedule",16);
SelectObject (hDC, hFont);
SetTextColor (hDC, mTextColor);
SetBkMode (hDC,TRANSPARENT) ; // not sure if/how this could interfere with the bitmap... ?
EndPaint (hWnd, &ps) ;
return 0 ;

[/quote]
I modifed the comments...

The blitter functions (BitBlt, StretchBlt) look confusing at the first view because of the many parameters. But they are IMHO self-explaining on the second view.

Load the bitmap in the WM_CREATE part and free it in the WM_DESTROY part.

Reply With Quote
  #5  
Old March 15th, 2003, 04:49 PM
infamous41md's Avatar
infamous41md infamous41md is offline
not a fan of fascism (n00b)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Feb 2003
Location: ct
Posts: 2,756 infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level)infamous41md User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 11 h 4 m 29 sec
Reputation Power: 26
i appreciate ur help, but excuse my stupidity plz. i thought that i had to go to file<open and open the bmp, but when i try to do this it says " the file has been loaded correctly but b/c it contains more than 256 colors it cannot be loaded into the bitmap editor."

Reply With Quote