Interactive PowerBasic Forum

General Category => General Discussion => Topic started by: Frederick J. Harris on December 29, 2012, 09:04:43 PM

Title: SetBkMode Function Question
Post by: Frederick J. Harris on December 29, 2012, 09:04:43 PM
Hi Patrice!

     I'd value your or anyone's opinion or thinking on whether its necessary to save the return value from the SetBkMode() function frequently used in the WM_PAINT handler to set background window painting to OPAQUE or TRANSPARENT.  These are the only two values, I believe, and they are equal to 1 and 2.

     I just did a search on this and found a code snippet from Microsoft where they indeed do reset the background mode to the default, which is OPAQUE.  So I'm thinking maybe it should be done...

http://msdn.microsoft.com/en-us/library/windows/desktop/dd162965(v=vs.85).aspx

I always save GDI object handles and return them into the device context, but I never did this with SetBkMode, because, obviously, OPAQUE and TRANSPARENT aren't handles.  They are just equates equal to 1 and 2.  Thinking on this???

Fred
Title: Re: SetBkMode Function Question
Post by: José Roca on December 29, 2012, 10:13:17 PM
I don't see any need for saving it.
Title: Re: SetBkMode Function Question
Post by: Christopher Boss on December 29, 2012, 10:36:09 PM
Not quite correct.

Yes, you should always reset any states of a DC, when you change them, particularly in any WM_PAINT or WM_DRAWITEM code.

Rather than do what the Microsoft code does, I prefer to use the standard method of using the return value of the function call. SetBKMode's return value is the current state, before you change it. Simply store that value and use it in another SetBKmode call once done.

Why ?

The reason is the window DC's in particular often uses a shared system DC, which means other windows may use the same DC for drawing. Because Windows uses shared DC's one should always reset them to the original state once done drawing into them.

Now this would not apply to DC's you create, such as a memory DC or printer DC, but it is still good habit to get into.

The Microsoft code is simply using what they know to be the default of a shared window DC, rather than the rteurn value of SetBKMode, but it is doing the same thing basically.
Title: Re: SetBkMode Function Question
Post by: Frederick J. Harris on December 30, 2012, 12:11:26 AM
What you said makes sense Chris.  I occasionally use that function in TextOut() calls if I'm painting to a window with a background color other than white, because as you know, the TextOut() call's text background will look rather horrible without it.  The reason I asked the question is because a C++ coder questioned me about it in one of my example programs, and its something I had always glossed over.  So I'm going to have to be careful about that.   
Title: Re: SetBkMode Function Question
Post by: Christopher Boss on December 30, 2012, 05:03:14 AM
The reason for always restoring a DC to the way you received it is because of Windows use of shared DC's.

It is easy to assume that each window has its own unique DC, but this is not the case. To save on resources the OS creates a number of sharable DC's which it uses. While how the OS impliments in different versions of Windows may be slightly different, likely it still continues to share some DC's. For example a Dialog would share its DC with all of its children (unless the class is registered to use a private or class DC), so multiple windows on a dialog will share the same DC when drawing during WM_PAINT.

Title: Re: SetBkMode Function Question
Post by: José Roca on December 30, 2012, 05:44:10 AM
I misunderstood the question. I thought that he was asking if it was needed to save the return value to free it, as we do with handles and other objects. It is advisable to save it to restore it.
Title: Re: SetBkMode Function Question
Post by: Patrice Terrier on December 30, 2012, 12:13:27 PM
It all depends if you are using your own control class or a generic control class.
If you are processing all the painting yourself then you can do whatever your want,
other way use something like this:

' Print a string using colors, font, and X Y coordinates.
SUB skPrint(BYVAL hDC AS LONG, BYVAL sTxt AS STRING, BYVAL X AS LONG, BYVAL Y AS LONG, BYVAL nFore AS LONG, BYVAL nBack AS LONG, BYVAL hFont AS LONG, BYVAL BkMode AS LONG)

    LOCAL OldFont, OldFore, OldBack , OldMode AS LONG

    OldFont = SelectObject(hDC, hFont)
    OldFore = SetTextColor(hDC, nFore)
    OldBack = SetBkColor(hDC, nBack)
    OldMode = SetBkMode(hDC, BkMode)

    TextOut(hDC, X, Y, BYVAL STRPTR(sTxt), LEN(sTxt))

    SelectObject(hDC, OldFont)
    SetTextColor(hDC, OldFore)
    SetBkColor(hDC, OldBack)
    SetBkMode(hDC, OldMode)

END SUB
Title: Re: SetBkMode Function Question
Post by: Frederick J. Harris on December 30, 2012, 05:43:55 PM
Thanks for the input on this Chris, Jose and Patrice.  I do believe I'll 'mend my ways' and start returning the original background mode back into the DC before exiting the WM_PAINT handler.  This kind of snuck up on me.  I had first learned this function back in Windows 95 days and hadn't really thought much about it since then.  The code that doesn't do this I have posted here in the C and C++ section on my board, so I'll fix it.

Actually, what prompted me to go through this code is that I believe I'll finally convert it to 64 bit - a topic that I know is one of your favorites Patrice!  I bought Visual Studio 2008 several years back and one of the things I wanted to experiment with was 64 bit compiling with C or C++.  Well, that was one big non - event - kind of like the Y2K bug or Mayan Calander Final date plus 1!  One selects '64 bit Platform' from a list box, Visual Studio creates a new directory for the 64 bit binary outputs, and that's it.  Everything turned out as expected.  My primary computer at the time was WinXP 32 bit which however, had a 64 bit processor.  Of course, the 64 bit executable wouldn't run on it, although I could use my Visual Studio installation on that computer to create the 64 bit executable.  Since then I got a 64 bit Win7 OS, and they run fine on that, of course.  But I suppose I'll convert all my code, because sometimes C++ coders wanting to learn SDK use my examples, and lots of folks now want to do 64 bit.

Just taking a quick look at the situation, it looks like the major thing that needs to change is SetWindowLongPtr() instead of SetWindowLong() and GetWindowLongPtr() instead of GetWindowLong().  Also, when allocating WNDCLASSEX::cbWndExtra bytes use something like sizeof(void*) or sizeof(size_t) or sizeof(ptrdiff_t).  The variable types really look confusing.  I was surprised to see that ints, UINTs, and so on, still retain their 32 bit size.  I learned C back in DOS days and the 16 bit int was promoted to 32 bits, somewhat unlike PowerBASIC where INTEGERs remained the same and we used LONGs instead.  But for backward compatibility they left ints and a lot of the same stuff alone.

Here is a GUI program similiar to the one I have posted here that displays to its window the dimensions of a box and its volume, that is correct in every way I think (and hope).   It compiles and operates correctly with VC++9 and mingw Code::Blocks.  CodeBlocks is compiling as 32 bit and VC9 as 64 bit.  Note I used an iBkMode variable in the WM_PAINT handler to save and restore whatever was in the DC.  Also, it opens an output file where I print that stuff out, along with various variable sizes when running as a 64 bit program.  First, here is the output from it ...


Entering WM_CREATE Case!
  sizeof(void*)      = 8
  sizeof(size_t)     = 8
  sizeof(int)        = 4
  sizeof(long)       = 4
  sizeof(UINT)       = 4
  sizeof(HDC)        = 8
  sizeof(DWORD32)    = 4
  sizeof(DWORD64)    = 8
  sizeof(ptrdiff_t)  = 8
  pBox               = 30304624
  OPAQUE             = 2
  TRANSPARENT        = 1
Leaving WM_CREATE Case!

Entering Case WM_PAINT!
  iBkMode = 2   (OPAQUE, Which Is Equal To 2, Was Just Taken Out, And TRANSPARENT, Equal To 1, Was Just Put In)
  iBkMode = 1   (Now TRANSPARENT, Which Is Equal To 1, Has Just Been Removed, And OPAQUE - The Default, Replaced.
Leaving Case WM_PAINT

Entering WM_DESTROY Case!
  pBox = 30304624
Leaving WM_DESTROY Case!


And here's the other necessary code ...


//Main.cpp
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include "CBox.h"
FILE* fp = NULL;


LRESULT CALLBACK WndProc(HWND hWnd, unsigned int msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
    case WM_CREATE:
      {
         fp=fopen("Output.txt","w");
         if(fp)
         {
            fprintf(fp,"Entering WM_CREATE Case!\n");
            fprintf(fp,"  sizeof(void*)      = %d\n",sizeof(void*));
            fprintf(fp,"  sizeof(size_t)     = %d\n",sizeof(size_t));
            fprintf(fp,"  sizeof(int)        = %d\n",sizeof(int));
            fprintf(fp,"  sizeof(long)       = %d\n",sizeof(long));
            fprintf(fp,"  sizeof(UINT)       = %d\n",sizeof(UINT));
            fprintf(fp,"  sizeof(HDC)        = %d\n",sizeof(HDC));
            fprintf(fp,"  sizeof(DWORD32)    = %d\n",sizeof(DWORD32));
            fprintf(fp,"  sizeof(DWORD64)    = %d\n",sizeof(DWORD64));
            fprintf(fp,"  sizeof(ptrdiff_t)  = %d\n",sizeof(ptrdiff_t));
           
            CBox* pBox=NULL;
            pBox=new CBox(2.0,3.0,4.0);
            if(pBox)
            {
               SetWindowLongPtr(hWnd,0,(long)pBox);
               fprintf(fp,"  pBox               = %d\n",(int)pBox);
               fprintf(fp,"  OPAQUE             = %d\n",OPAQUE);
               fprintf(fp,"  TRANSPARENT        = %d\n",TRANSPARENT);
               fprintf(fp,"Leaving WM_CREATE Case!\n");
               return 0;
            }
            else
               return -1;
         }
         else
            return -1;
      }
    case WM_PAINT:
      {
         CBox* pBox=NULL;
         HFONT hFont,hTmp;
         PAINTSTRUCT ps;
         HDC hDC;
         TCHAR szBuffer[128];

         fprintf(fp,"\nEntering Case WM_PAINT!\n");
         hDC=BeginPaint(hWnd,&ps);
         int iBkMode=SetBkMode(hDC,TRANSPARENT);      // This Is What I Had  >> SetBkMode(hDC,TRANSPARENT);
         fprintf(fp,"  iBkMode = %d   (OPAQUE, Which Is Equal To 2, Was Just Taken Out, And TRANSPARENT, Equal To 1, Was Just Put In)\n",iBkMode);
         hFont=CreateFont(-1*(18*GetDeviceCaps(hDC,LOGPIXELSY))/72,0,0,0,FW_HEAVY,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,DEFAULT_PITCH,_T("Courier New"));
         hTmp=(HFONT)SelectObject(hDC,hFont);
         pBox=(CBox*)GetWindowLongPtr(hWnd,0);
         _stprintf(szBuffer,_T("Box.GetLength() = %6.2f"),pBox->GetLength());
         TextOut(hDC,25,30,szBuffer,(int)_tcslen(szBuffer));
         _stprintf(szBuffer,_T("Box.GetWidth()  = %6.2f"),pBox->GetWidth());
         TextOut(hDC,25,60,szBuffer,(int)_tcslen(szBuffer));
         _stprintf(szBuffer,_T("Box.GetHeight() = %6.2f"),pBox->GetHeight());
         TextOut(hDC,25,90,szBuffer,(int)_tcslen(szBuffer));
         _stprintf(szBuffer,_T("Box.Volume()    = %6.2f"),pBox->Volume());
         TextOut(hDC,25,120,szBuffer,(int)_tcslen(szBuffer));
         SelectObject(hDC,hTmp);
         DeleteObject(hFont);
         iBkMode=SetBkMode(hDC,iBkMode);              // I didn't do this before 
         fprintf(fp,"  iBkMode = %d   (Now TRANSPARENT, Which Is Equal To 1, Has Just Been Removed, And OPAQUE - The Default, Replaced.\n",iBkMode);
         EndPaint(hWnd,&ps);
         fprintf(fp,"Leaving Case WM_PAINT\n");
         return 0;

      }
    case WM_DESTROY:
      {
         fprintf(fp,"\nEntering WM_DESTROY Case!\n");
         CBox* pBox=NULL;
         pBox=(CBox*)GetWindowLongPtr(hWnd,0);   //termination.
         fprintf(fp,"  pBox = %d\n",(int)pBox);
         if(pBox)
            delete pBox;
         PostQuitMessage(0);
         fprintf(fp,"Leaving WM_DESTROY Case!\n");
         fclose(fp);
         return 0;
      }
}

return (DefWindowProc(hWnd, msg, wParam, lParam));
}


int WINAPI WinMain(HINSTANCE hIns, HINSTANCE hPrevIns, LPSTR lpszArgument, int iShow)
{
TCHAR szClassName[]=_T("CBox7");
MSG messages;
WNDCLASS wc;
HWND hWnd;

wc.lpszClassName=szClassName;                wc.lpfnWndProc=WndProc;
wc.style=0,                                  wc.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wc.hInstance=hIns,                           wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)COLOR_BTNSHADOW;    wc.cbWndExtra=sizeof(size_t);  //sizeof(size_t);
wc.lpszMenuName=NULL;                        wc.cbClsExtra=0;
RegisterClass(&wc);
hWnd=CreateWindow(szClassName,szClassName,WS_OVERLAPPEDWINDOW^WS_MAXIMIZEBOX,100,100,400,300,0,0,hIns,0);
ShowWindow(hWnd,iShow);
while(GetMessage(&messages,NULL,0,0))
{
       TranslateMessage(&messages);
       DispatchMessage(&messages);
}

return (int)messages.wParam;
}


/*
DWORD32      32-bit unsigned integer
DWORD64      64-bit unsigned integer
INT32      32-bit signed integer
INT64      64-bit signed integer
LONG32      32-bit signed integer
LONG64      64-bit signed integer
UINT32      Unsigned INT32
UINT64      Unsigned INT64
ULONG32      Unsigned LONG32
ULONG64      Unsigned LONG64

DWORD_PTR    Unsigned long type for pointer precision.
HALF_PTR     Half the size of a pointer. Use within a structure that contains a pointer and two small fields.
INT_PTR      Signed integer type for pointer precision.
LONG_PTR     Signed long type for pointer precision.
SIZE_T      The maximum number of bytes to which a pointer can refer. Use for a count that must span the full range of a pointer.
SSIZE_T      Signed SIZE_T.
UHALF_PTR    Unsigned HALF_PTR.
UINT_PTR     Unsigned INT_PTR.
ULONG_PTR    Unsigned LONG_PTR.

Term Description
====================================================================================================================================
POINTER_32 A 32-bit pointer. On 32-bit Windows, this is a native pointer. On 64-bit Windows, this is a truncated 64-bit pointer.
POINTER_64 A 64-bit pointer. On 64-bit Windows, this is a native pointer. On 32-bit Windows, this is a sign-extended 32-bit pointer.
*/



//CBox.h
#ifndef CBox_h
#define CBox_h

class CBox
{
public:
CBox(double,double,double);  //Constructor
~CBox();                     //Destructor
double GetLength() const;    //m_Length accessor
double GetWidth()  const;    //m_Width accessor
double GetHeight() const;    //m_Height accessor
double Volume()    const;    //Returns Volume() of Box

private:
double m_Length;
double m_Width;
double m_Height;
};
#endif



//CBox.cpp
#include "CBox.h"

CBox::CBox(double dblLength, double dblWidth, double dblHeight)
{
this->m_Length=dblLength;
this->m_Width=dblWidth;
this->m_Height=dblHeight;
}

CBox::~CBox()
{
//destructor
}

double CBox::GetLength() const
{
return this->m_Length;
}

double CBox::GetWidth()  const
{
return this->m_Width;
}

double CBox::GetHeight() const
{
return this->m_Height;
}

double CBox::Volume()    const
{
return m_Length*m_Width*m_Height;
}


I had to put casts in several places to eliminate warnings from the VC9 compiler.  The strangest one was the return from winmain() because WPARAM is now 64 bits!  Also strlen() returns 64 bit lengths apparently, but the TextOut() function wants a 32 bit quantity for the length of string to output, so I needed casts there too.
Title: Re: SetBkMode Function Question
Post by: James C. Fuller on December 30, 2012, 08:07:30 PM
Fred,

  To compile with MinGWTDM64 in both 32/64 I needed to make the following changes

In WM_CREATE
  SetWindowLongPtr(hWnd,0,(long)pBox);
   To
  SetWindowLongPtr(hWnd,0,(LONG_PTR)pBox);
             
  fprintf(fp,"  pBox               = %d\n",(int)pBox);
    To
  fprintf(fp,"  pBox               = %d\n",(LONG_PTR)pBox);


In WM_DESTROY

fprintf(fp,"  pBox = %d\n",(int)pBox);
To
fprintf(fp,"  pBox = %d\n",(LONG_PTR)pBox);


To compile I just needed to use -m32 or -m64.

James
Title: Re: SetBkMode Function Question
Post by: Frederick J. Harris on December 30, 2012, 10:42:38 PM
Wow!  Thanks a lot for checking that James.  That should have been deduceable by me from my outputting the size of a long, which is still only 4 bytes in x64.  Tomorrow perhaps I can start updating some of my code.
Title: Re: SetBkMode Function Question
Post by: James C. Fuller on December 31, 2012, 02:00:08 AM
Sorry Fred I just could not resist. I have this love hate relationship with c++
I can not stand the nomanclature!
My Bc9 version.
I don't know the whys for the this-> and const.
I cannot use const with bc9 but I can use this-> but I don't know why I should?

James


bc9CBox.bi

'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'CBox declaration
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
Class CBox
    public:
        Dim Constructor CBox(dblLength As double,dblWidth As double,dblHeight As double)
        Dim Destructor ~CBox()
        Dim Function GetLength() As double
        Dim Function GetWidth() As double
        Dim Function GetHeight() As double
        Dim Function Volume() As double
    private:
        Raw As double m_Length, m_Width, m_Height   
End Class


bc9Cbox.bas

'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'bc9Cbox.bas
' Definitions for the Cbox class
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$INCLUDE "bc9Cbox.bi"

Constructor CBox::CBox(dblLength As double,dblWidth As double,dblHeight As double)
    m_Length = dblLength
    m_Width =  dblWidth
    m_Height = dblHeight
End Constructor
'------------------------------------------------------------------------------
Destructor CBox::~CBox()
   
End Destructor
'------------------------------------------------------------------------------
Function CBox::GetLength() As double
    Function = m_Length
End Function
'------------------------------------------------------------------------------
Function CBox::GetWidth() As double
    Function = m_Width
End Function
'------------------------------------------------------------------------------
Function CBox::GetHeight() As double
    Function = m_Height
End Function
'------------------------------------------------------------------------------
Function CBox::Volume() As double
    Function = m_Length * m_Width * m_Height
End Function



bc9Main.bas

'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'bc9Main
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$CPP
$ONEXIT "GWG++.BAT $FILE$ -m32 gui"
#include <windows.h>
#include <tchar.h>
$INCLUDE "bc9cbox.bas"
Dim AppName$
GLOBAL fp As FILE
$IPRINT_OFF
Function WinMain

    Raw Wc  AS WNDCLASS
    Raw Msg AS MSG
    Raw hWnd AS HWND

    AppName$ = _T("CBox7")

   
    Wc.style           = CS_HREDRAW OR CS_VREDRAW
    Wc.lpfnWndProc     = WndProc
    Wc.cbClsExtra      = 0
    Wc.cbWndExtra      = sizeof(size_t)
    Wc.hInstance       = hInst
    Wc.hIcon           = LoadIcon   ( NULL,IDI_APPLICATION )
    Wc.hCursor         = LoadCursor    ( NULL, IDC_ARROW )
    Wc.hbrBackground   = (HBRUSH)COLOR_BTNSHADOW
    Wc.lpszMenuName    = NULL
    Wc.lpszClassName   = AppName$
    RegisterClass(&Wc)
   
    hWnd=CreateWindow(AppName$,AppName$,WS_OVERLAPPEDWINDOW OR WS_MAXIMIZEBOX,100,100,400,300,0,0,hInst,0)
    ShowWindow(hWnd,SW_SHOW)
    While GetMessage (&Msg,NULL,0,0)
      TranslateMessage  (&Msg)
      DispatchMessage   (&Msg)
    Wend
   
    Function = Msg.wParam
   
End Function
'==============================================================================
Callback Function WndProc()
    Select Case CBMSG
        Case WM_CREATE
            Open "Output.txt" FOR OUTPUT AS fp
            FPrint fp,"Entering WM_CREATE Case!"
            FPrint fp,"  sizeof(void)       = ",sizeof(void*)
            FPrint fp,"  sizeof(size_t)     = ",sizeof(size_t)
            FPrint fp,"  sizeof(int)        = ",sizeof(int)
            FPrint fp,"  sizeof(long)       = ",sizeof(long)
            FPrint fp,"  sizeof(UINT)       = ",sizeof(UINT)
            FPrint fp,"  sizeof(HDC)        = ",sizeof(HDC)
            FPrint fp,"  sizeof(DWORD32)    = ",sizeof(DWORD32)
            FPrint fp,"  sizeof(DWORD64)    = ",sizeof(DWORD64)
            FPrint fp,"  sizeof(ptrdiff_t)  = ",sizeof(ptrdiff_t)
           
            Raw As CBox Ptr pBox=NULL
            pBox = new CBox(2.0,3.0,4.0)
            If pBox Then
                SetWindowLongPtr(CBHNDL,0,(LONG_PTR)pBox)
                FPrint fp,"  pBox               = ",(LONG_PTR)pBox
                FPrint fp,"  OPAQUE             = ",OPAQUE
                FPrint fp,"  TRANSPARENT        = ",TRANSPARENT
                FPrint fp,"Leaving WM_CREATE Case!"
                Function = 0
            Else
                Function = -1   
            End If
        Case WM_PAINT
            Raw As CBox Ptr pBox = NULL
            Raw As HFONT hFont,hTmp
            Raw As PAINTSTRUCT ps
            Raw As HDC hDC
            Raw As TCHAR szBuffer[128]   
            Raw As Integer iBkMode
           
            FPrint fp,"\nEntering Case WM_PAINT!"
            hDC = BeginPaint(CBHNDL,&ps)
            iBkMode = SetBkMode(hDC,TRANSPARENT)
            FPrint fp,"  iBkMode =  (OPAQUE, Which Is Equal To 2, Was Just Taken Out, And TRANSPARENT, Equal To 1, Was Just Put In)",iBkMode
            hFont=CreateFont(-1*(18*GetDeviceCaps(hDC,LOGPIXELSY))/72,0,0,0,FW_HEAVY,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,DEFAULT_PITCH,_T("Courier New"))
            hTmp=(HFONT)SelectObject(hDC,hFont)
            pBox=(CBox*)GetWindowLongPtr(CBHNDL,0)
            _stprintf(szBuffer,_T("Box.GetLength() = %6.2f"),pBox->GetLength())
            TextOut(hDC,25,30,szBuffer,(int)_tcslen(szBuffer))
            _stprintf(szBuffer,_T("Box.GetWidth()  = %6.2f"),pBox->GetWidth())
            TextOut(hDC,25,60,szBuffer,(int)_tcslen(szBuffer))
            _stprintf(szBuffer,_T("Box.GetHeight() = %6.2f"),pBox->GetHeight())
            TextOut(hDC,25,90,szBuffer,(int)_tcslen(szBuffer))
            _stprintf(szBuffer,_T("Box.Volume()    = %6.2f"),pBox->Volume())
            TextOut(hDC,25,120,szBuffer,(int)_tcslen(szBuffer))
            SelectObject(hDC,hTmp)
            DeleteObject(hFont)
            iBkMode=SetBkMode(hDC,iBkMode) 
            FPrint fp,"  iBkMode = (Now TRANSPARENT, Which Is Equal To 1, Has Just Been Removed, And OPAQUE - The Default, Replaced.",iBkMode
            EndPaint(hWnd,&ps)
            FPrint fp,"Leaving Case WM_PAINT"
            Function = 0
        Case WM_DESTROY
            FPrint fp,"\nEntering WM_DESTROY Case!"
            Raw As CBox Ptr pBox=NULL
            pBox=(CBox*)GetWindowLongPtr(CBHNDL,0)
            FPrint fp,"  pBox = ",(LONG_PTR)pBox
            If pBox Then
                delete pBox
            End If
            PostQuitMessage(0)
            FPrint fp,"Leaving WM_DESTROY Case!"
            Close fp
            Function = 0       
    End Select
End Function
Title: Re: SetBkMode Function Question
Post by: Frederick J. Harris on December 31, 2012, 04:07:39 PM
That is rather interesting James, I have to admit.  The BC looks like an interesting combination of C like syntax with mostly Basic like syntax, with the emphases on basic syntax though.

The const keyword in C++ is really complicated to my feeble mind.  Its the kind of thing I have to keep referencing in various C++ books I have, because I keep forgetting the nitty gritty details myself.  But its use above in that C++ code is rather simple in that it just tells the compiler that the member functions don't alter the state of the object in any way, i.e., they provide read only access to the data members.  Of course, in that simple class I didn't even provide any 'Set' functions ('mutators' in high level OOP speak), but if I had they couldn't be defined as 'const' obviously, as their purpose would be to change properties.

I don't believe basic languages really have that concept at all.  I wish they did.  Unless I've missed it somewhere. 

You are way better than me at keeping up to date.  I've got to be pulled into the future kicking and screeming I guess.  I'm interested in your mention of the latest GCC compiler.  I did a search on that and I see there is a nice download for it but no IDE.  I could try that but I just checked the Code::Blocks site, and they are up to 10.11 I believe.  I'm still using 10.05 with a build date around May 2010.  I'm wondering if I uninstalled my 10.05 version and installed the new Code::Blocks 10.11 or whatever it is, if I'd get what you have?  Do you know anything about that James?
Title: Re: SetBkMode Function Question
Post by: Frederick J. Harris on December 31, 2012, 04:14:12 PM
Just found this on the Code::Blocks forum ...

This build of Code::Blocks is compiled using TDM-GCC 4.7.1 and wxWidgets 2.8.12.



Title: Re: SetBkMode Function Question
Post by: James C. Fuller on December 31, 2012, 06:28:03 PM
Fred,
  Check your evenlink email

James
Title: Re: SetBkMode Function Question
Post by: Frederick J. Harris on December 31, 2012, 09:09:46 PM
Hello James,

     Could you post here what you were going to send me, as I never got it?  That most likely isn't your fault, because I've been having trouble with my email for a very long time, at least since last May.  I simply don't get a lot of things sent to me, and I have no idea why.  They don't show up in spam folders either.  Its really hard to know when you haven't gotten something, and the only way you ever really know is in a case like this when somebody tells you they've sent you something in some other environment such as this.  I think its about time I go to my ISP about this.

Fred
Title: Re: SetBkMode Function Question
Post by: James C. Fuller on December 31, 2012, 09:47:01 PM
Fred,
  Get a GMail account :)

  I just checked out the latest code::blocks and the MinGW included I believe is 32bit only

I use RadAsm3 with bcx, bc9, PowerBasic, JWasm, Masm .....
I don't actually use it with MinGW because I write very little actual c/c++ code.
I use bc9 and then compile the translated c/c++ code with batch files.

I have several versions of MINGW but mostly I use  MinGWTDM64 (tdm64-gcc-4.7.1-3).
This is the download page:
http://tdm-gcc.tdragon.net/download

This is the info page:
http://tdm-gcc.tdragon.net/start

I've attached my batch files; one for gcc one for g++

They both expect the environment variable %MINGW% to point to your MinGW installation.

I have mine located at C:\MINGWTDM64. MINGW is set in RadAsm3 but you can set it anywhere (change the batch files to point to it is fine. SET MINGW=C:\MINGWTDM64

Parameters %1 -> filename no extension
           %2 -> -m32 or -m64
           %3 -> con gui or dll

If you have an rc file with the same name as the c/cpp file it will compile it and link it to the exe

Here is the link to my bc9 just in case you want to play.
http://basic-compiler.com/forum/index.php?topic=439.0

This is the link to an unmodified RadAsm3 with all the supported compilers, but last I tried the gcc one did not work correctly.

https://fbedit.svn.sourceforge.net/svnroot/fbedit/RadASM30/Release/RadASM.zip


James
Title: Re: SetBkMode Function Question
Post by: Frederick J. Harris on December 31, 2012, 10:39:15 PM
Thanks James!  Looks like I may have a New Years Day project! ;D

I downloaded the right mingw w64 file this morning (same as link you gave), but wasn't sure I understood everything OK.  In my haste somehow I missed that info page.  Thanks.

Might get gmail account.  This email thing has aggravated me to no end.  Got to deal with it.

I'd be pleased to get an x86 / x64 setup with Code::Blocks working, as that's my favorite C and C++ environment.  Will be in touch.  Thanks again

Fred