С главной формы по нажатию Button создается явно окно средствами WinApi (форма загружается из длл) код длл:
| Код | library mydpr;
uses SysUtils, Classes, Windows, Messages;
const id_close=1; id_edit_1 = 100; id_button_1 = 104; bwidth = 100; bheight = 20; ewidth = 100; eheight = 20; cwidth = 170; cheight = 20; cListHeight = 100; var
ok:boolean;
{$R *.res}
function runMe(n:integer):boolean; var i:integer; begin result:=true; if (n<=0)or(n=2) then result:=false; if n>=3 then for i:=2 to (n-1) do begin if round(n/i)-(n/i)=0 then result:=false; end; end;
function PlainWinProc (hWnd: THandle; nMsg: UINT; wParam, lParam: Cardinal): Cardinal; export; stdcall; var Rect: TRect; s1: array [0..127] of Char; hCloseBtn,n1, n2,b,n:integer; str:string; i:integer;
begin Result := 0; case nMsg of wm_Create: begin CreateWindowEx (0, 'edit', '', ws_Child or ws_Visible or ws_Border or es_Number, 0, 0, cwidth, cheight, hwnd, id_Edit_1, hInstance, nil);
CreateWindowEx (0, 'button', 'Запомнить', ws_Child or ws_Visible or ws_Border or bs_PushButton, 0, 0, bwidth, bheight, hwnd, id_Button_1, hInstance, nil);
end; wm_Size: begin
GetClientRect (hWnd, Rect);
SetWindowPos ( GetDlgItem (hWnd, id_Edit_1), 0, Rect.left + 10, Rect.top + 10, 0, 0, swp_NoZOrder or swp_NoSize);
GetClientRect (hWnd, Rect);
SetWindowPos ( GetDlgItem (hWnd, id_Button_1), 0, Rect.right - bwidth-10, Rect.Bottom - bheight - 15, 0, 0, swp_NoZOrder or swp_NoSize);
end;
wm_Command:
if LoWord (wParam) = id_Button_1 then if HiWord (wParam) = bn_Clicked then begin GetWindowText(GetDlgItem (hWnd, id_edit_1), s1, GetWindowTextLength(GetDlgItem (hWnd, id_edit_1))+1); n:=strtoint(s1); ok:=runMe(n); EndDialog(hWnd, 0); end; WM_CLOSE: DestroyWindow(hWnd); wm_Destroy: begin PostQuitMessage (0); Result := 0; Exit; end else Result := DefWindowProc (hWnd, nMsg, wParam, lParam); end;
end;
procedure winmain; var hWnd: THandle; Msg: TMsg; WndClassEx: TWndClassEx; begin
WndClassEx.cbSize := sizeOf (TWndClassEx); WndClassEx.lpszClassName := 'PlainWindow'; WndClassEx.style := cs_VRedraw or cs_HRedraw; WndClassEx.hInstance := HInstance; WndClassEx.lpfnWndProc := @PlainWinProc; WndClassEx.cbClsExtra := 0; WndClassEx.cbWndExtra := 0; WndClassEx.hIcon := LoadIcon (hInstance, MakeIntResource ('MAINICON')); WndClassEx.hIconSm := LoadIcon (hInstance, MakeIntResource ('MAINICON')); WndClassEx.hCursor := LoadCursor (0, idc_Arrow);; wndclassex.hbrbackground:=Color_BtnFace+13; WndClassEx.lpszMenuName := nil;
if RegisterClassEx (WndClassEx) = 0 then begin MessageBox (0, 'Invalid class registration','Plain API', MB_OK); end else begin MessageBox (0, 'CreateWindowEx','Plain API', MB_OK); hWnd := CreateWindowEx ( WS_SIZEBOX, WndClassEx.lpszClassName, '', ws_OverlappedWindow, cw_UseDefault, cw_UseDefault, 205, 130, 0, 0, HInstance, nil); if hWnd = 0 then MessageBox (0, 'Window not created', 'Plain API', MB_OK) else begin ShowWindow (hWnd, sw_ShowNormal); while GetMessage (Msg, 0, 0, 0) do begin TranslateMessage (Msg); DispatchMessage (Msg); end; end; end; end;
Function R:boolean; begin result:=ok; end; Exports R,winmain; begin end.
|
при вовторном нажатии на Button с гл. формы появляется сообщение "Invalid class registration" т.е. RegisterClassEx (WndClassEx) = 0, как можно при закрытии формы удалить этот класс регистрации? если закоментить
| Код | if RegisterClassEx (WndClassEx) = 0 then begin MessageBox (0, 'Invalid class registration','Plain API', MB_OK); end else
|
то появляется собщение "Window not created"
Помогите разобраться!! |