The following is the complete code listing of a simple program with
a vertical scrollbar that was generated by version 4.0 of the Freeware
visual designer for multi-form SDK programs that I am just about to
release. This program is named Test1. It compiles fine in either
PbDll 5 or 6 but causes an invalid page fault when executed.
The guilty line of code is marked. It is just a plain old run of the
mill CreateWindowEx call which works fine in an identical program
generated by the old single form version. About the only thing I
can think of at the moment is that this program is using global
UDT's whereas the older one used individual variables. I have
been pulling what little hair I have left for a couple of days
now. Any ideas or tips would be greatly appreciated.
TIA.... Ed
------------------
a vertical scrollbar that was generated by version 4.0 of the Freeware
visual designer for multi-form SDK programs that I am just about to
release. This program is named Test1. It compiles fine in either
PbDll 5 or 6 but causes an invalid page fault when executed.
The guilty line of code is marked. It is just a plain old run of the
mill CreateWindowEx call which works fine in an identical program
generated by the old single form version. About the only thing I
can think of at the moment is that this program is using global
UDT's whereas the older one used individual variables. I have
been pulling what little hair I have left for a couple of days
now. Any ideas or tips would be greatly appreciated.
TIA.... Ed
Code:
' ** Eliminate unnecessary macros %NOANIMATE = 1 %NODRAGLIST = 1 %NOHEADER = 1 %NOIMAGELIST = 1 %NOLISTVIEW = 1 %NOTABCONTROL = 1 %NOTRACKBAR = 1 %NOTREEVIEW = 1 %NOUPDOWN = 1 %NOBUTTON = 1 %NOCOMBOEX = 1 %NOEDIT = 1 %NOCOMBO = 1 %NOLIST = 1 %NOREBAR = 1 %NOTOOLBAR = 1 %NOTOOLTIPS = 1 %NOSTATUSBAR = 1 '------------------------------------------------------------------------------ $COMPILE EXE $OPTION VERSION4 $INCLUDE "\PBDLL50\WINAPI\WIN32API.INC" GLOBAL hWndMain AS LONG, ghInstance AS LONG GLOBAL Am$, Vm$, svm$, crlf$, nll$, nlla AS ASCIIZ * 1 GLOBAL tempBuff AS ASCIIZ * 32000 GLOBAL hSaveCursor AS LONG, hCurrentCursor AS LONG GLOBAL hArrow AS LONG, hWait AS LONG GLOBAL cxChar AS LONG, cyChar AS LONG GLOBAL Loading AS LONG, tabbing AS LONG GLOBAL cfont() AS LOGFONT, hfont() AS LONG TYPE PRECT P1 AS POINTL P2 AS POINTL END TYPE TYPE MCTRL Typ AS LONG hWnd AS LONG ID AS LONG Style AS LONG ExStyle AS LONG TabStop AS LONG TabOrder AS LONG FontType AS LONG ForeColor AS LONG BackColor AS LONG hBrush AS LONG FormNo AS LONG nLeft AS LONG nRight AS LONG nTop AS LONG nBottom AS LONG Transparent AS LONG ImageType AS LONG hBmp AS LONG Number AS LONG MultiLine AS LONG nMax AS LONG ControlType AS ASCIIZ * 20 Caption AS ASCIIZ * 100 controlName AS ASCIIZ * 50 Index AS ASCIIZ * 5 Image AS ASCIIZ * 100 END TYPE GLOBAL wControl() AS MCTRL TYPE MFORM hWnd AS LONG hEditBrush AS LONG hFocusBrush AS LONG hPanelBrush AS LONG EditColor AS LONG TextFocusForeColor AS LONG TextForeColor AS LONG FocusBackColor AS LONG buttonTextFocusColor AS LONG hBack AS LONG hBackBack AS LONG panelColor AS LONG panelTextColor AS LONG hStatus AS LONG hToolbar AS LONG statusHeight AS LONG toolbarHeight AS LONG hVscroll AS LONG vscrollHeight AS LONG vscrollWidth AS LONG scrlPos AS LONG hHscroll AS LONG hscrollHeight AS LONG hscrollWidth AS LONG scrlPosH AS LONG formLength AS LONG formWidth AS LONG hBackBmp AS LONG LastTab AS LONG FirstControl AS LONG LastControl AS LONG END TYPE GLOBAL wForm() AS MFORM %ggf_Test1 = 0 TYPE THELP id AS LONG tip AS ASCIIZ * 100 END TYPE '------------------------------------------------------------------------------ Function MakeBrush(ByVal BrushColor As Long) As Long DIM lb As LOGBRUSH lb.lbStyle = %BS_SOLID lb.lbColor = BrushColor Function = CreateBrushIndirect(lb) End Function ' MakeBrush '------------------------------------------------------------------------------ Function MakeTiledBrush(ByVal hbmp As Long) As Long DIM lb As LOGBRUSH lb.lbStyle = %BS_PATTERN lb.lbHatch = hbmp Function = CreateBrushIndirect(lb) End Function ' MakeTiledBrush '------------------------------------------------------------------------------ SUB InitializeVariables() Am = Chr$(254): Vm = Chr$(253): svm = Chr$(252): nll = "": nlla = Chr$(0) crlf = Chr$(13) & Chr$(10) DIM wControl(0) DIM wForm(0) DIM cfont(0), hfont(0) hfont(0) = GetStockObject(%SYSTEM_FIXED_FONT) wForm(0).panelColor = 16777215 wForm(0).panelTextColor = 0 wForm(0).buttonTextFocusColor = 200 wForm(0).EditColor = 16777215 wForm(0).FocusBackColor = 65535 wForm(0).TextForeColor = 0 wForm(0).textFocusForeColor = 255 wForm(0).formWidth = 160 wForm(0).formLength = 250 wForm(0).FirstControl = 0 wForm(0).LastControl = -1 END SUB ' InitializeVariables '------------------------------------------------------------------------------ FUNCTION WinMain (BYVAL hInstance AS LONG, _ BYVAL hPrevInstance AS LONG, _ lpCmdLine AS ASCIIZ PTR, _ BYVAL iCmdShow AS LONG) AS LONG LOCAL Msg AS tagMsg LOCAL wndclass AS WndClassEx LOCAL hWnd AS LONG, hmainIcon AS LONG LOCAL rct AS RECT LOCAL szpgmname AS ASCIIZ * 20 szpgmname = "Test1" hmainIcon = LoadIcon(hInstance, "") If hmainIcon = 0 Then hmainIcon = LoadImage(0, "", %IMAGE_ICON, 0, 0, %LR_LOADFROMFILE) End if wndclass.cbSize = SIZEOF(WndClass) wndclass.style = %CS_HREDRAW OR %CS_VREDRAW wndclass.lpfnWndProc = CODEPTR(WndProc) wndclass.cbClsExtra = 0 wndclass.cbWndExtra = 0 wndclass.hInstance = hInstance wndclass.hIcon = hmainIcon wndclass.hCursor = LoadCursor(%NULL, BYVAL %IDC_ARROW) wndclass.hbrBackground = CreateSolidBrush(GetSysColor(%COLOR_MENU)) wndclass.lpszMenuName = %NULL wndclass.lpszClassName = VARPTR(szpgmname) wndclass.hIconSm = LoadIcon(hInstance, BYVAL %IDI_APPLICATION) RegisterClassEx wndclass ghInstance = hInstance InitializeVariables ' Create a window using the registered class hWndMain = CreateWindow(szpgmname, _ ' window class name "First Test project for new Designer", _ ' window caption %WS_OVERLAPPEDWINDOW, _ ' window style 64, _ ' initial x position 73, _ ' initial y position 454, _ ' initial x size 318, _ ' initial Y size %HWND_DESKTOP, _ ' parent window handle %NULL, _ ' window menu handle hInstance, _ ' program instance handle BYVAL %NULL) ' creation parameters 'InitCommonControls ShowWindow hWndMain, iCmdShow UpdateWindow hWndMain WHILE GetMessage(Msg, %NULL, 0, 0) TranslateMessage Msg DispatchMessage Msg WEND FUNCTION = msg.wParam END FUNCTION ' WinMain '------------------------------------------------------------------------------ FUNCTION WndProc (BYVAL hWnd AS LONG, BYVAL wMsg AS LONG, _ BYVAL wParam AS LONG, BYVAL lParam AS LONG) EXPORT AS LONG STATIC zText AS ASCIIZ * 255, WindowName AS ASCIIZ * 20 STATIC formNO AS LONG DIM crect AS RECT DIM hDC AS LONG, ctlType AS LONG DIM rct AS RECT DIM wclass AS WndClass DIM tm AS TEXTMETRIC SELECT CASE wMsg CASE %WM_SETFOCUS FUNCTION = 0 EXIT FUNCTION CASE %WM_CREATE formNo = 0 wForm(0).hStatus = 0 wForm(0).statusheight = 0 hDC = GetDC(hwnd) SelectObject hDC, GetStockObject(%SYSTEM_FIXED_FONT) GetTextMetrics hDC, tm cxChar = tm.tmAveCharWidth cyChar = tm.tmHeight + tm.tmExternalLeading hArrow = LoadCursor(0, BYVAL %IDC_ARROW) hWait = LoadCursor(0, BYVAL %IDC_WAIT) SetCursor hArrow wForm(formNo).hEditBrush = MakeBrush(wForm(formNo).EditColor) wForm(formNo).hFocusBrush = MakeBrush(wForm(formNo).FocusBackColor) wForm(formNo).hPanelBrush = MakeBrush(wForm(formNo).PanelColor) WindowName = "CustomPanel" wclass.style = %CS_DBLCLKS OR %CS_HREDRAW OR %CS_VREDRAW wclass.lpfnWndProc = CODEPTR(PanelProc) wclass.cbClsExtra = 0 wclass.cbWndExtra = 0 wclass.hInstance = ghInstance wclass.hIcon = 0 wclass.hCursor = LoadCursor( %NULL, BYVAL %IDC_ARROW ) wclass.hbrBackground = CreateSolidBrush(wForm(formNo).panelColor) wclass.lpszMenuName = 0 wclass.lpszClassName = VARPTR(WindowName) RegisterClass wclass ' ------------------THIS IS THE CULPRIT. THE NEXT CREATEWINDOWEX WORKS FINE IF THIS ONE IS COMMENTED OUT. wForm(formNo).hBackBack = CreateWindowEx(0, _ WindowName, "", _ %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPCHILDREN OR %SS_NOTIFY, _ 0, 0, _ 0, 0, hWnd, 10001 + 100 * formNo, ghinstance, ByVal %NULL) ' -------------------------------------------------------------------- wForm(formNo).hBack = CreateWindowEx(0, _ "CustomPanel", "", _ %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPCHILDREN OR %SS_NOTIFY, _ 0, 0, _ wForm(formNo).formWidth * cxChar, wForm(formNo).formLength * cyChar, _ wForm(formNo).hBackBack, _ 10000 + 100 * formNo, ghinstance, ByVal %NULL) wForm(formNo).hToolbar = 0 wForm(formNo).toolbarheight = 0 For i& = wForm(formNo).FirstControl To wForm(formNo).LastControl ctlType = wControl(i&).Typ wControl(i&).hwnd = CreateWindowEx(wControl(i&).ExStyle, wControl(i&).ControlType, wControl(i&).Caption, _ wControl(i&).Style, _ wControl(i&).nLeft, wControl(i&).nTop, _ wControl(i&).nRight - wControl(i&).nLeft, _ wControl(i&).nBottom - wControl(i&).nTop, _ wForm(formNo).hBack, wControl(i&).ID, ghinstance, BYVAL %NULL) wControl(i&).hBrush = MakeBrush(wControl(i&).BackColor) SendMessage wControl(i&).hwnd, %WM_SETFONT, hfont(wControl(i&).FontType), %TRUE Select Case ctlType End Select Next i& wForm(formNo).vscrollWidth = 2 * cxChar wForm(formNo).hVscroll = CreateWindowEx(0, "SCROLLBAR", "", _ %WS_CHILD OR %WS_VISIBLE OR %SBS_VERT, _ 0, _ 0, _ wForm(formNo).vscrollWidth, 0, hwnd, 10002 + 100 * formNo, ghinstance, BYVAL %NULL) wForm(formNo).hscrollWidth = 0 wForm(formNo).hscrollHeight = 0 wForm(formNo).hHscroll = 0 ReleaseDC hwnd, hDC Loading = %False FUNCTION = 0 EXIT FUNCTION CASE %WM_SIZE winx& = LOWRD(lparam) winy& = HIWRD(lparam) MoveWindow wForm(formNo).hBackBack, 0, wForm(formNo).ToolBarHeight&, winx& - wForm(formNo).vscrollWidth, winy& - wForm(formNo).ToolBarHeight& - wForm(formNo).statusHeight& - wForm(formNo).hscrollHeight, %True If wForm(formNo).hVscroll Then wForm(formNo).vscrollHeight = winy& - wForm(formNo).ToolBarHeight& - wForm(formNo).statusHeight& MoveWindow wForm(formNo).hVscroll, winx& - wForm(formNo).vscrollWidth, wForm(formNo).ToolBarHeight&, wForm(formNo).vscrollWidth, wForm(formNo).vscrollHeight, %TRUE SetScrollRange wForm(formNo).hVScroll, %SB_CTL, 0, wForm(formNo).formLength * cyChar - wForm(formNo).vscrollHeight, %FALSE End if FUNCTION = 0 EXIT FUNCTION CASE %WM_ERASEBKGND FUNCTION = 0 EXIT FUNCTION CASE %WM_VSCROLL SELECT CASE LOWRD(wParam) CASE %SB_PAGEDOWN wForm(formNo).scrlPos = wForm(formNo).scrlPos + 20 * cyChar - 1 CASE %SB_LINEDOWN wForm(formNo).scrlPos = wForm(formNo).scrlPos + cyChar CASE %SB_PAGEUP wForm(formNo).scrlPos = wForm(formNo).scrlPos - (20 * cyChar - 1) CASE %SB_LINEUP wForm(formNo).scrlPos = wForm(formNo).scrlPos - cyChar CASE %SB_THUMBPOSITION, %SB_THUMBTRACK wForm(formNo).scrlPos = HIWRD(wParam) END SELECT IF wForm(formNo).scrlPos > wForm(formNo).formLength * cyChar - wForm(formNo).vscrollHeight Then wForm(formNo).scrlPos = wForm(formNo).formLength * cyChar - wForm(formNo).vscrollHeight End if If wForm(formNo).ScrlPos < 0 Then wForm(formNo).scrlPos = 0 End if SetScrollPos wForm(formNo).hVScroll, %SB_CTL, wForm(formNo).scrlPos, %TRUE MoveWindow wForm(formNo).hBack, -wForm(formNo).scrlPosH, -wForm(formNo).scrlPos, wForm(formNo).formWidth * cxChar, wForm(formNo).formLength * cyChar, %TRUE FUNCTION = 0 EXIT FUNCTION CASE %WM_DESTROY ' WS_DESTROY logic for Controls ... For i& = wForm(formNo).FirstControl To wForm(formNo).LastControl Select Case wControl(i&).Typ End Select If wControl(i&).hBrush <> 0 Then DeleteObject wControl(i&).hBrush Next i& For i& = 1 To 100 If hfont(i&) = 0 Then Exit For DeleteObject hfont(i&) Next i& For i& = 0 to Ubound(wForm) DeleteObject wForm(i&).hEditBrush DeleteObject wForm(i&).hFocusBrush DeleteObject wForm(i&).hPanelBrush Next i& PostQuitMessage 0 FUNCTION = 0 EXIT FUNCTION END SELECT FUNCTION = DefWindowProc(hWnd, wMsg, wParam, lParam) END FUNCTION ' WndProc '------------------------------------------------------------------------------ FUNCTION PanelProc (BYVAL hwnd AS LONG, BYVAL message AS LONG, _ BYVAL wParam AS LONG, BYVAL lParam AS DWORD) EXPORT AS LONG ' hback, hgrid(), sline(), box() LOCAL ps AS PAINTSTRUCT LOCAL hdc AS LONG, formNo AS LONG, ID AS LONG, gridno AS LONG LOCAL r AS Rect, rct AS RECT LOCAL hbr AS LONG DIM hbrush as long, hbrushOld as long LOCAL hpen AS LONG LOCAL Bright AS LONG LOCAL Dark AS LONG LOCAL Black AS LONG LOCAL Grey AS LONG LOCAL hOldPen AS LONG LOCAL cx AS LONG, cy AS LONG LOCAL pdis AS DRAWITEMSTRUCT PTR LOCAL textBuff AS ASCIIZ * 100 ID = GetWindowLong( hwnd, %GWL_ID) formNo = wControl(ID).formNo SELECT CASE message CASE %WM_CREATE SetCursor hArrow FUNCTION = 0 EXIT FUNCTION CASE %WM_COMMAND SELECT CASE HIWRD(wParam) END SELECT END Select FUNCTION = DefWindowProc(hwnd, message, wParam, lParam) END FUNCTION ' PanelProc
Comment