WITH not Fixed

Started by jcfuller, February 26, 2025, 01:03:36 PM

Previous topic - Next topic

jcfuller

Kevin,
  We have an issue with your WITH fix.
James
Quote
Function CWindow_RegisterClass( szClassName As const char Ptr,hInstance As HINSTANCE,lpfnWndProc As WNDPROC) As ATOM
   Dim As ATOM wAtom
   Dim As WNDCLASSEXW wcexw
   static As Long nCount = 0

   static  As char m_wszClassName[256]
   If Len( szClassName) Then
      m_wszClassName = szClassName
   Else
      m_wszClassName = "BcxWindowClass"
      m_wszClassName = m_wszClassName & ":" + STR$(nCount)
   EndIf
   ' // Default handler
   If lpfnWndProc = NULL Then
      lpfnWndProc = (WNDPROC)&CWindow_WindowProc
   EndIf

   ' // Fill the WNDCLASSEXW structure
   With wcexw
      .cbSize        = SIZEOF(wcexw)
      .style         = CS_DBLCLKS BOR CS_HREDRAW BOR CS_VREDRAW
      .lpfnWndProc   = lpfnWndProc
      .cbClsExtra    = 0
      .cbWndExtra    = SIZEOF(HANDLE)
      .hInstance     = hInstance
      .hCursor       = LoadCursor(NULL, (LPCWSTR) IDC_ARROW)
      .hbrBackground = (HBRUSH) (COLOR_3DFACE + 1)
      .lpszMenuName  = NULL
      .lpszClassName = (LPCWSTR)&m_wszClassName
      .hIcon         = 0
      .hIconSm       = 0
      
   End With
   '' // Register the class
   wAtom = RegisterClassEx(&wcexw)
   '' // Increment the class counter
   IF wAtom THEN
      nCount = nCount + 1
   'Else
   '   zTrace(L"CRAP")
   EndIf
   '' // Return the atom
   
   Function = wAtom
End Function


Translation
Quote
// *************************************************
//            User's Subs and Functions
// *************************************************

ATOM CWindow_RegisterClass (const char* szClassName,HINSTANCE hInstance,WNDPROC lpfnWndProc)
{
  ATOM     wAtom= {0};
  WNDCLASSEXW  wcexw= {0};
  static long     nCount=0;
  static char     m_wszClassName[256];
  if((int)strlen(szClassName)){
      strcpy(m_wszClassName,szClassName);
    }
  else
    {
      strcpy(m_wszClassName,"BcxWindowClass");
      strcpy(m_wszClassName, join(3,m_wszClassName,":",str(nCount)));
    }
  if(lpfnWndProc==NULL ){
      lpfnWndProc=(WNDPROC)&CWindow_WindowProc;
    }
  wcexw.cbSize=sizeof();
  wcexw.style=CS_DBLCLKS|CS_HREDRAW|CS_VREDRAW;
  wcexw.lpfnWndProc=lpfnWndProc;
  wcexw.cbClsExtra=0;
  wcexw.cbWndExtra=sizeof(HANDLE);
  wcexw.hInstance=hInstance;
  wcexw.hCursor=LoadCursor(NULL,(LPCWSTR)IDC_ARROW);
  wcexw.hbrBackground=(HBRUSH)(COLOR_3DFACE+1);
  wcexw.lpszMenuName=NULL;
  wcexw.lpszClassName=(LPCWSTR)&m_wszClassName;
  wcexw.hIcon=0;
  wcexw.hIconSm=0;
  wAtom=RegisterClassEx(&wcexw);
  if(wAtom ){
      nCount+=1;
    }
  return wAtom;
}

BCX:      .cbSize        = SIZEOF(wcexw)
Translated to                 wcexw.cbSize=sizeof();

James

MrBcx

James,

In fairness to me, the Revision log does say:

Kevin Diggins  : Improved (fixed?) the translation of WITH / END WITH statements


My improvement limits the "search and replace" behavior per line to one instance of the governing WITH variable.

Your example has two instances, one implicit and one explicit:

  wcexw.cbSize        = SIZEOF(wcexw)


The easiest workaround for you is:

With wcexw
      .cbSize        = SIZEOF(WNDCLASSEXW)

MrBcx

BCX 8.2.6 will further refine the translation of WITH / END WITH, on top of the improvement
that I added in 8.2.5 and should correctly process any legitimate expression that we throw at it.

We should not have to monkey with workarounds, like in the previous message.