необходимо сделать вот такой калькулятор средствами win32 api

помогите ответить на вопрос при нажатии на button(посчитать) как узнать какая RadioButton отмечена?? if RadioButton1.checked then плюсуй else if RadioButton2.checked then минусуй итд... пытался получить отметку при нажатии, присваивал p № кнопки но при нажатии Button p стирался (p-не глобальная), при p-глобальной вылезала ошибка.
| Код | program LR2;
uses Windows, Messages, SysUtils;
const id_Button = 100; id_Edit = 101; id_Edit_2 = 102; id_RadioButton_1 =1; id_RadioButton_2 =2; id_RadioButton_3 =3; id_RadioButton_4 =4; bwidth = 100; bheight = 20; ewidth = 100; eheight = 20; rwidth = 50; rheight = 20; cListHeight = 100;
function PlainWinProc (hWnd: THandle; nMsg: UINT; wParam, lParam: Cardinal): Cardinal; export; stdcall; var Rect: TRect; s1, s2, s_c: array [0..127] of Char; Rbtn_check,i,n1, n2:integer; p: integer;
begin Result := 0; case nMsg of wm_Create: begin CreateWindowEx (0, 'button', '&Click here', ws_Child or ws_Visible or ws_Border or bs_PushButton, 0, 0, bwidth, bheight, hwnd, id_Button, hInstance, nil);
CreateWindowEx (0, 'Edit', '', ws_Child or ws_Visible or ws_Border or es_Number, 0, 0, ewidth, eheight, hwnd, id_Edit, hInstance, nil);
CreateWindowEx (0, 'Edit', '', ws_Child or ws_Visible or ws_Border or es_Number, 0, 0, ewidth, eheight, hwnd, id_Edit_2, hInstance, nil);
SetWindowText(GetDlgItem (hWnd, id_Edit),'0'); SetWindowText(GetDlgItem (hWnd, id_Edit_2),'0');
CreateWindowEx( 0, 'Button', '+', WS_CHILD or WS_VISIBLE or BS_RADIOBUTTON, 0, 0, rwidth, rheight, hWnd, id_RADIOBUTTON_1, hInstance, nil ); SendMessage(id_RADIOBUTTON_1, WM_SETFONT, GetStockObject( ANSI_VAR_FONT ), 0 );
CreateWindowEx( 0, 'Button', '-', WS_CHILD or WS_VISIBLE or BS_RADIOBUTTON, 0, 0, rwidth, rheight, hWnd, id_RADIOBUTTON_2, hInstance, nil ); SendMessage(id_RADIOBUTTON_2, WM_SETFONT, GetStockObject( ANSI_VAR_FONT ), 0 );
CreateWindowEx( 0, 'Button', '/', WS_CHILD or WS_VISIBLE or BS_RADIOBUTTON, 0, 0, rwidth, rheight, hWnd, id_RADIOBUTTON_3, hInstance, nil ); SendMessage(id_RADIOBUTTON_3, WM_SETFONT, GetStockObject( ANSI_VAR_FONT ), 0 );
CreateWindowEx( 0, 'Button', '*', WS_CHILD or WS_VISIBLE or BS_RADIOBUTTON, 0, 0, rwidth, rheight, hWnd, id_RADIOBUTTON_4, hInstance, nil ); SendMessage(id_RADIOBUTTON_4, WM_SETFONT, GetStockObject( ANSI_VAR_FONT ), 0 );
end; wm_Size: begin
GetClientRect (hWnd, Rect);
SetWindowPos ( GetDlgItem (hWnd, id_Button), 0, Rect.right - bwidth-20, Rect.Bottom - bheight - 10, 0, 0, swp_NoZOrder or swp_NoSize);
SetWindowPos ( GetDlgItem (hWnd, id_Edit), 0, Rect.Left + 10, Rect.Top + 10, 0, 0, swp_NoZOrder or swp_NoSize);
SetWindowPos ( GetDlgItem (hWnd, id_Edit_2), 0, Rect.Left + ewidth + 20, Rect.Top + 10, 0, 0, swp_NoZOrder or swp_NoSize);
SetWindowPos ( GetDlgItem (hWnd, id_RadioButton_1), 0, Rect.Left + 10, Rect.Top + eHeight+20, 0, 0, swp_NoZOrder or swp_NoSize);
SetWindowPos ( GetDlgItem (hWnd, id_RadioButton_2), 0, Rect.Left + 10, Rect.Top+eHeight+20+rheight+5, 0, 0, swp_NoZOrder or swp_NoSize);
SetWindowPos ( GetDlgItem (hWnd, id_RadioButton_3), 0, Rect.Left + 10, Rect.Top+eHeight+20+(rheight+5)*2, 0, 0, swp_NoZOrder or swp_NoSize);
SetWindowPos ( GetDlgItem (hWnd, id_RadioButton_4), 0, Rect.Left + 10, Rect.Top+eHeight+20+(rheight+5)*3, 0, 0, swp_NoZOrder or swp_NoSize);
end; wm_Command:
if (LoWord( wParam )>= id_RadioButton_1)and(LoWord( wParam )<= id_RadioButton_4) then begin CheckRadioButton( hWnd, id_RadioButton_1, id_RadioButton_4, LoWord( wParam ) );
//GetMem( pchar(p), 1); case LoWord( wParam )of 1:p:=1; 2:p:=2; 3:p:=3; 4:p:=4; end;
end else
if LoWord (wParam) = id_Button then if HiWord (wParam) = bn_Clicked then begin GetWindowText(GetDlgItem (hWnd, id_Edit), s1, GetWindowTextLength(GetDlgItem (hWnd, id_Edit))+1); GetWindowText(GetDlgItem (hWnd, id_Edit_2), s2, GetWindowTextLength(GetDlgItem (hWnd, id_Edit_2))+1);
MessageBox (hWnd, pchar(p), 'p=', MB_OK);
if p=1 then MessageBox (hWnd, PChar(Floattostr(StrToInt(s1)+StrToInt(s2))), 'Результат', MB_OK); if p=2 then MessageBox (hWnd, PChar(Floattostr(StrToInt(s1)-StrToInt(s2))), 'Результат', MB_OK); if p=3 then if StrToInt(s2) = 0 then MessageBox (hWnd, 'Деление на 0 запрещено', 'Ошибка', MB_OK) else MessageBox (hWnd, PChar(Floattostr(StrToInt(s1)/StrToInt(s2))), 'Результат', MB_OK); if p=4 then MessageBox (hWnd, PChar(Floattostr(StrToInt(s1)*StrToInt(s2))), 'Результат', MB_OK); //FreeMem( pchar(p), 1);
end;
wm_Destroy: PostQuitMessage (0); 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 := GetStockObject (white_Brush); WndClassEx.lpszMenuName := nil;
if RegisterClassEx (WndClassEx) = 0 then MessageBox (0, 'Invalid class registration', 'Plain API', MB_OK) else begin hWnd := CreateWindowEx ( WS_SIZEBOX, WndClassEx.lpszClassName, 'Пример', ws_OverlappedWindow, cw_UseDefault, cw_UseDefault, 240, 300, 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;
begin WinMain; end.
|
|