コードは正しいと思うのですが、アクセス違反が起こってしまいます。
コード: 全て選択
スレッド(&H250)でアクセス違反がありました(EPI=&H5AB77F36)。
ドラッグされているところは、
Callback.wbp の
コード: 全て選択
MainWnd_Create(ByVal (lParam As VoidPtr))
コード: 全て選択
MainWndProc=EventCall_MainWnd(hWnd,dwMsg,wParam,lParam)
一応コードを載せておきますので、参考にしてください。
(※注釈はありません!)
[ここをクリックすると内容が表示されます]
お願いします。コード: 全て選択
'-----------------------------------------------------------------------------
' イベント プロシージャ
'-----------------------------------------------------------------------------
' このファイルには、ウィンドウ [MainWnd] に関するイベントをコーディングします。
' ウィンドウ ハンドル: hMainWnd
' TODO: この位置にグローバルな変数、構造体、定数、関数を定義します。
Declare Function EndDocAPI Lib "gdi32" Alias "EndDoc" (ByVal hdc As Long) As Long
const ID_STATUS=71
dim hStatus as DWord
const ID_TOOLBAR=70
dim hToolbar as DWord
dim hImgList as DWord
sub SetTbButtonData(ByRef ptb as TBBUTTON,iBitmap as long,idCommand as long,fsState as Byte,fsStyle as Byte)
with ptb
.iBitmap=iBitmap
.idCommand=idCommand
.fsState=fsState
.fsStyle=fsStyle
.dwData=0
.iString=0
End With
End Sub
Sub PrintData(hDC as DWord)
dim buf[225] as Byte
dim rect as RECT
Dim Text As String
Text=ZeroString(GetWindowTextLength(GetDlgItem(hMainWnd,EditBox1)))
GetWindowText(GetDlgItem(hMainWnd,EditBox1),Text,GetWindowTextLength(GetDlgItem(hMainWnd,EditBox1))+1)
wsprintf(buf,Text)
DrawText(hDC,buf,-1,rect,DT_CALCRECT)
rect.left=100
rect.right=rect.left+rect.right
rect.top=100
rect.bottom=rect.top+rect.bottom
DrawText(hDC,buf,-1,rect,DT_LEFT)
End Sub
'-----------------------------------------------------------------------------
' ウィンドウメッセージを処理するためのコールバック関数
Function MainWndProc(hWnd As HWND, dwMsg As DWord, wParam As WPARAM, lParam As LPARAM) As DWord
' TODO: この位置にウィンドウメッセージを処理するためのコードを記述します。
' イベントプロシージャの呼び出しを行います。
MainWndProc=EventCall_MainWnd(hWnd,dwMsg,wParam,lParam)
End Function
'-----------------------------------------------------------------------------
' ここから下は、イベントプロシージャを記述するための領域になります。
Sub MainWnd_Destroy()
ImageList_Destroy(hImgList)
MemoPad_DestroyObjects()
PostQuitMessage(0)
End Sub
Sub MainWnd_Resize(SizeType As Long, cx As Integer, cy As Integer)
dim rc as RECT
dim nSH as long
dim nTH as long
GetWindowRect(hStatus,rc)
nSH=rc.bottom-rc.top
GetWindowRect(hToolbar,rc)
nTH=rc.bottom-rc.top
MoveWindow(GetDlgItem(hMainWnd,EditBox1),0,nTH,cx,cy-nSH-nTH,0)
SetFocus(GetDlgItem(hMainWnd,EditBox1))
SendMessage(hToolbar,WM_SIZE,cx,cy)
SendMessage(hStatus,WM_SIZE,cx,cy)
dim Statusbar[2] as long
Statusbar[0]=cx-350
Statusbar[1]=cx-200
Statusbar[2]=cx
SendMessage(hStatus,SB_SETPARTS,3,Statusbar)
dim buf[225] as Byte
wsprintf(buf,"ウィンドウ: %d×%d",cx,cy)
SendMessage(hStatus,SB_SETTEXT,1,buf)
MainWnd_EditBox1_Change()
End Sub
Sub MainWnd_IDM_NEW_MenuClick()
SetWindowText(GetDlgItem(hMainWnd,EditBox1),"")
MainWnd_EditBox1_Change()
End Sub
Sub MainWnd_IDM_OPEN_MenuClick()
dim ofn as OPENFILENAME
dim hEdit as long
dim hFile as long
dim buffer as BytePtr
dim dwFileSize as DWord
dim dwAccessByte as DWord
dim FileName[MAX_PATH-1] as Byte
FillMemory(VarPtr(ofn),Len(ofn),0)
ofn.lStructSize=Len(ofn)
ofn.hwndOwner=hMainWnd
ofn.lpstrFilter=Ex"テキスト文書(*.txt)\0*.txt\0メモ帳 専用ファイル(*.mef)\0*.mef\0すべてのファイル(*.*)\0*\0\0"
ofn.nFilterIndex=1
ofn.lpstrFile=FileName
ofn.nMaxFile=MAX_PATH
ofn.lpstrTitle="ファイルを開く"
ofn.Flags=OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST
ofn.lpstrDefExt="*"
if GetOpenFileName(ofn)=0 then exit sub
hFile=CreateFile(ofn.lpstrFile,GENERIC_READ,FILE_SHARE_READ or FILE_SHARE_WRITE,ByVal 0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0)
if hFile=INVALID_HANDLE_VALUE then
MessageBox(hMainWnd,"デバイスのオープンに失敗","メモ帳",MB_OK or MB_ICONEXCLAMATION)
exit sub
End If
dwFileSize=GetFileSize(hFile,0)
buffer=malloc(dwFileSize+1)
ReadFile(hFile,buffer,dwFileSize,VarPtr(dwAccessByte),ByVal 0)
buffer[dwAccessByte]=0
CloseHandle(hFile)
hEdit=GetDlgItem(hMainWnd,EditBox1)
SetWindowText(hEdit,buffer)
free(buffer)
SetFocus(hEdit)
MainWnd_EditBox1_Change()
End Sub
Sub MainWnd_IDM_SAVE_MenuClick()
dim ofn as OPENFILENAME
dim hEdit as long
dim hFile as long
dim buf as BytePtr
dim dwAccessByte as DWord
dim FileName[MAX_PATH] as Byte
dim length as DWord
FillMemory(VarPtr(ofn),Len(ofn),0)
ofn.lStructSize=Len(ofn)
ofn.hwndOwner=hMainWnd
ofn.lpstrFilter=Ex"テキスト文書(*.txt)\0*.txt\0メモ帳 専用ファイル(*.mef)\0*.mef\0すべてのファイル(*.*)\0*\0\0"
ofn.nFilterIndex=1
ofn.lpstrFile=FileName
ofn.nMaxFile=MAX_PATH
ofn.lpstrTitle="ファイルの保存"
ofn.Flags=OFN_FILEMUSTEXIST or OFN_HIDEREADONLY or OFN_PATHMUSTEXIST
ofn.lpstrDefExt="*"
if GetSaveFileName(ofn)=0 then exit sub
hEdit=GetDlgItem(hMainWnd,EditBox1)
length=GetWindowTextLength(hEdit)
buf=malloc(length+1)
GetWindowText(hEdit,buf,length+1)
hFile=CreateFile(ofn.lpstrFile,GENERIC_WRITE,0,ByVal 0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0)
if hFile=INVALID_HANDLE_VALUE then
MessageBox(hMainWnd,"デバイスのオープンに失敗","メモ帳",MB_OK or MB_ICONEXCLAMATION)
exit sub
End If
WriteFile(hFile,buf,length,VarPtr(dwAccessByte),ByVal 0)
CloseHandle(hFile)
free(buf)
End Sub
Sub MainWnd_IDM_EXIT_MenuClick()
SendMessage(hMainWnd,WM_CLOSE,0,0)
End Sub
Sub MainWnd_IDM_UNDO_MenuClick()
SendMessage(GetDlgItem(hMainWnd,EditBox1),WM_UNDO,0,0)
End Sub
Sub MainWnd_IDM_CUT_MenuClick()
SendMessage(GetDlgItem(hMainWnd,EditBox1),WM_CUT,0,0)
End Sub
Sub MainWnd_IDM_COPY_MenuClick()
SendMessage(GetDlgItem(hMainWnd,EditBox1),WM_COPY,0,0)
End Sub
Sub MainWnd_IDM_PASTE_MenuClick()
SendMessage(GetDlgItem(hMainWnd,EditBox1),WM_PASTE,0,0)
End Sub
Sub MainWnd_IDM_DELETE_MenuClick()
SendMessage(GetDlgItem(hMainWnd,EditBox1),WM_CLEAR,0,0)
End Sub
Sub MainWnd_IDM_ALLSELECT_MenuClick()
dim hEdit as long
dim length as long
hEdit=GetDlgItem(hMainWnd,EditBox1)
length=GetWindowTextLength(hEdit)
SendMessage(hEdit,EM_SETSEL,0,length)
End Sub
Sub MainWnd_IDM_ABOUT_MenuClick()
ShellAbout(hMainWnd,"メモ帳","M.S.",LoadIcon(GetModuleHandle(0),101))
End Sub
Sub MainWnd_IDM_PRINT_MenuClick()
dim pd as PRINTDLG
dim docinfo as DOCINFO
dim hDC as DWord
ZeroMemory(VarPtr(pd),Len(pd))
with pd
.lStructSize=66
.hwndOwner=hMainWnd
.Flags=PD_RETURNDC
End With
if PrintDlg(pd) then
hDC=pd.hDC
ZeroMemory(VarPtr(docinfo),Len(docinfo))
docinfo.cbSize=Len(docinfo)
docinfo.lpszDocName="text"
StartDoc(hDC,docinfo)
StartPage(hDC)
PrintData(hDC)
EndDoc(hDC)
DeleteDC(hDC)
End If
End Sub
Sub MainWnd_Create(ByRef CreateStruct As CREATESTRUCT)
dim ic as INITCOMMONCONTROLSEX
dim tb[18] as TBBUTTON
SetTbButtonData(tb[0],0,IDM_NEW,TBSTATE_ENABLED,TBSTYLE_BUTTON)
SetTbButtonData(tb[1],0,0,TBSTATE_ENABLED,TBSTYLE_SEP)
SetTbButtonData(tb[2],1,IDM_OPEN,TBSTATE_ENABLED,TBSTYLE_BUTTON)
SetTbButtonData(tb[3],2,IDM_SAVE,TBSTATE_ENABLED,TBSTYLE_BUTTON)
SetTbButtonData(tb[4],0,0,TBSTATE_ENABLED,TBSTYLE_SEP)
SetTbButtonData(tb[5],3,IDM_PRINT,TBSTATE_ENABLED,TBSTYLE_BUTTON)
SetTbButtonData(tb[6],0,0,TBSTATE_ENABLED,TBSTYLE_SEP)
SetTbButtonData(tb[7],4,IDM_CUT,TBSTATE_ENABLED,TBSTYLE_BUTTON)
SetTbButtonData(tb[8],5,IDM_COPY,TBSTATE_ENABLED,TBSTYLE_BUTTON)
SetTbButtonData(tb[9],6,IDM_PASTE,TBSTATE_ENABLED,TBSTYLE_BUTTON)
SetTbButtonData(tb[10],7,IDM_DELETE,TBSTATE_ENABLED,TBSTYLE_BUTTON)
SetTbButtonData(tb[11],0,0,TBSTATE_ENABLED,TBSTYLE_SEP)
SetTbButtonData(tb[12],8,IDM_UNDO,TBSTATE_ENABLED,TBSTYLE_BUTTON)
SetTbButtonData(tb[13],0,0,TBSTATE_ENABLED,TBSTYLE_SEP)
SetTbButtonData(tb[14],9,IDM_SM,TBSTATE_ENABLED,TBSTYLE_BUTTON)
SetTbButtonData(tb[15],0,0,TBSTATE_ENABLED,TBSTYLE_SEP)
SetTbButtonData(tb[16],10,IDM_ABOUT,TBSTATE_ENABLED,TBSTYLE_BUTTON)
SetTbButtonData(tb[17],0,0,TBSTATE_ENABLED,TBSTYLE_SEP)
SetTbButtonData(tb[18],11,IDM_EXIT,TBSTATE_ENABLED,TBSTYLE_BUTTON)
hToolbar=CreateToolbarEx(hMainWnd,WS_CHILD or WS_VISIBLE or TBSTYLE_TOOLTIPS,ID_TOOLBAR,12,GetModuleHandle(0),IDB_BITMAP1,tb,19,0,0,16,15,Len(tb[0]))
dim style as long
style=GetWindowLong(hToolbar,GWL_STYLE)
style=style or TBSTYLE_FLAT
SetWindowLong(hToolbar,GWL_STYLE,style)
hImgList=ImageList_LoadImage(GetModuleHandle(0),IDB_BITMAP2,16,0,RGB(192,192,192),IMAGE_BITMAP,LR_CREATEDIBSECTION)
SendMessage(hToolbar,TB_SETHOTIMAGELIST,0,hImgList)
ic.dwSize=Len(ic)
ic.dwICC=ICC_BAR_CLASSES
InitCommonControlsEx(ic)
hStatus=CreateStatusWindow(WS_CHILD or WS_VISIBLE or CCS_BOTTOM or SBARS_SIZEGRIP,NULL,hMainWnd,ID_STATUS)
dim buf[225] as long
dim temp[225] as long
lstrcpy(temp,"HH時 mm分 ss秒")
GetTimeFormat(LOCALE_USER_DEFAULT,NULL,ByVal 0,temp,buf,225)
SendMessage(hStatus,SB_SETTEXT,0,buf)
SetTimer(hMainWnd,0,1,NULL)
End Sub
Sub MainWnd_EditBox1_Change()
dim buf[225] as Byte
wsprintf(buf,"サイズ: %d バイト",GetWindowTextLength(GetDlgItem(hMainWnd,EditBox1)))
SendMessage(hStatus,SB_SETTEXT,2,buf)
End Sub
Sub MainWnd_Timer(TimerID As DWord)
dim buf[225] as long
dim temp[225] as long
lstrcpy(temp,"HH時 mm分 ss秒")
GetTimeFormat(LOCALE_USER_DEFAULT,NULL,ByVal 0,temp,buf,225)
SendMessage(hStatus,SB_SETTEXT,0,buf)
End Sub
Sub MainWnd_Notify(ByRef nmHdr As NMHDR)
dim ttt as *TOOLTIPTEXT
if nmHdr.code=TTN_NEEDTEXT then
ttt=VarPtr(nmHdr)
select case nmHdr.idFrom
case IDM_NEW
ttt->lpszText="新規作成"
case IDM_OPEN
ttt->lpszText="開く"
case IDM_SAVE
ttt->lpszText="保存"
case IDM_PRINT
ttt->lpszText="印刷"
case IDM_UNDO
ttt->lpszText="元に戻す"
case IDM_CUT
ttt->lpszText="切り取り"
case IDM_COPY
ttt->lpszText="コピー"
case IDM_PASTE
ttt->lpszText="貼り付け"
case IDM_DELETE
ttt->lpszText="削除"
case IDM_SM
ttt->lpszText="システム マネージャー"
case IDM_ABOUT
ttt->lpszText="バージョン情報"
case IDM_EXIT
ttt->lpszText="終了"
End Select
End If
End Sub
Sub MainWnd_IDM_SM_MenuClick()
Exec "SystemManager.exe"
End Sub