Upload sources of msgbox.obj library and use_mb example to SVN.

git-svn-id: svn://kolibrios.org@4327 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Yogev Ezra 2013-12-05 21:53:37 +00:00
parent cf448cafd3
commit 53829299a9
4 changed files with 871 additions and 0 deletions

View File

@ -0,0 +1,28 @@
msgbox версия 26.05.2009
*** О программе ***
Программа для вывода окна с сообщениями.
Лицензия свободная.
*** Возможности ***
Можно выводить сообщения с текстом, в которых до 8 кнопок
(указано в константе MB_MAX_BUT).
Вычисление координат кнопок и текста делается автоматически.
Управление кнопками (Влево, Вправо, Enter)
На каджую кнопку сообщения возможно назначить свою функцию.
*** Ограничения ***
При использовании msgbox-ов, нужно стараться избегать ситуаций,
когда несколько сообщений открыто одновременно. Потому что все окна
msgbox используют одни и те же указатели, и возможен конфликт.
*** Описание ***
Из библиотеки экспортируются 3 параметра:
mb_create - функция для создания потока с окном сообщения
mb_reinit - функция для (пере)вычисления размеров окна с сообщением
Обычно в большинстве случаев Вы будете пользоваться только функцией mb_create.
Функция mb_reinit будет нужна только в том случае, если Вы
захотите заменить готовое сообщение после его успешного запуска.
mb_setfunctions - назначение функций кнопкам. При нажатии на кнопку
сообщение закрывается, но если кнопке была назначена функция, то сперва будет
вызвана функция.

View File

@ -0,0 +1,349 @@
;Ž£à®¬­ ï ¡« £®¤ à­®áâì Maxxxx32, Diamond, Heavyiron
;¨ ¤à㣨¬ ¯à®£à ¬¬¨áâ ¬,   â ª¦¥
;’¥¯«®¢ã €«¥ªá¥î (<Lrz> www.lrz.land.ru)
use32
org 0x0
db 'MENUET01' ;¨¤¥­â¨ä. ¨á¯®«­ï¥¬®£® ä ©«  ¢á¥£¤  8 ¡ ©â
dd 0x1
dd start
dd i_end ; à §¬¥à ¯à¨«®¦¥­¨ï
dd mem
dd stacktop
dd 0x0 ;library_path
dd cur_dir_path
include 'macros.inc'
include 'load_lib.mac'
@use_library
align 4
start:
mov eax,40
mov ebx,0x25 ;¬ áª  ®¦¨¤ ¥¬ëå ᮡë⨩
mcall
sys_load_library msgbox_name, cur_dir_path, library_path, system_path, \
err_message_found_lib, head_f_l, msgbox_lib_import, err_message_import, head_f_i
red_win:
mcall 12,1
xor eax,eax
mov ebx,50*65536+200
mov ecx,30*65536+170
mov edx,0xffffd0
or edx,0x33000000
mov edi,hed
mcall
mov eax,8 ;ª­®¯ª 
mov ebx,10*65536+30
mov ecx,110*65536+20
mov edx,7
mov esi,0xffd040
mcall
mov ebx,10*65536+30
mov ecx,85*65536+20
mov edx,6
mcall
mov ebx,10*65536+30
mov ecx,60*65536+20
mov edx,5
mcall
mov ebx,10*65536+30
mov ecx,35*65536+20
mov edx,4
mcall
mov ebx,10*65536+30
mov ecx,10*65536+20
mov edx,3
mcall
mov eax,4 ;à¨á®¢ ­¨¥ ⥪áâ 
mov ebx,50*65536+115
mov ecx,0x4000d0
or ecx,0x80000000
mov edx,txt140
mcall
mov ebx,50*65536+90
mov edx,txt139
mcall
mov ebx,50*65536+65
mov edx,txt138
mcall
mov ebx,50*65536+40
mov edx,txt137
mcall
mov ebx,50*65536+15
mov edx,txt136
mcall
push eax ebx ecx edx esi
;line numbers
mov eax,47
mov esi,0xd00000
mov ebx,0x10000 ;format
; --- draw codes ---
xor ecx,ecx
mov cl,byte[msgbox_1]
mov dx,25
shl edx,16
mov dx,15
int 0x40
mov cl,byte[msgbox_2]
add dx,25
int 0x40
mov cl,byte[msgbox_3]
add dx,25
int 0x40
mov cl,byte[msgbox_4]
add dx,25
int 0x40
mov cl,byte[msgbox_5]
add dx,25
int 0x40
pop esi edx ecx ebx eax
call draw_square
mcall 12,2
still:
mov eax,10
mcall
cmp al,1 ;¨§¬. ¯®«®¦¥­¨¥ ®ª­ 
jz red_win
cmp al,3
jz button
jmp still
button:
mcall 17 ;¯®«ãç¨âì ª®¤ ­ ¦ â®© ª­®¯ª¨
cmp ah,3
jz but_1
cmp ah,4
jz but_2
cmp ah,5
jz but_3
cmp ah,6
jz but_4
cmp ah,7
jz but_5
cmp ah,1
jne still
.exit:
mcall -1 ;¢ë室 ¨§ ¯à®£à ¬¬ë
but_1:
push thread
push msgbox_1
call [mb_create]
jmp still
but_2:
push thread
push msgbox_2
call [mb_create]
;mov eax,5
;mov ebx,50
;int 0x40
push msgbox_2_funct
call [mb_setfunctions]
jmp still
but_3:
push thread
push msgbox_3
call [mb_create]
jmp still
but_4:
push thread
push msgbox_4
call [mb_create]
jmp still
but_5:
push thread
push msgbox_5
call [mb_create]
mcall 5,100 ;stop program
push msgbox_5_2
call [mb_reinit]
jmp still
txt136 db '¯à®á⮥',0
txt137 db '3 ª­®¯ª¨',0
txt138 db '3 áâப¨',0
txt139 db '¡®«ì讥',0
txt140 db 'mb_reinit',0
hed db '<27>ਬ¥à ¨á¯®«ì§®¢ ­¨ï MsgBox',0
;sc system_colors
;---------------------------------------------------------------------
msgbox_1:
dw 0
db 'MBox',0 ;+2 = +MB_TEXT_OFFSET
db '<27>ਬ¥à',0
db '‚¨¦ã',0 ;button1
db 0
msgbox_2:
dw 0
db 'MBox 3 but',0 ;+2 = +MB_TEXT_OFFSET
db '<27>ਬ¥à á 3-¬ï ª­®¯ª ¬¨',0
db '„ ',0 ;button1
db 'Žâ¬¥­ ',0 ;button2
db '<27>®¬®éì',0 ;button3
db 0
msgbox_2_funct:
dd 0
dd 0
dd fun_show_help
msgbox_3:
dw 0
db 'MBox 3 lines',0 ;+2 = +MB_TEXT_OFFSET
db '‘âப  1',13,'‘âப  2',13,'‘âப  3',0
db '2009 £.',0 ;button1
db 0
msgbox_4:
dw 0
db '‚¢¥¤¨â¥ ¤¥­ì',0 ;+2 = +MB_TEXT_OFFSET
db ' @@@@@@@@@@@@ @@@@@@@@',13
db ' @............@ @........@',13
db '@..............@ @..........@',13
db '@.......@@@.....@ @......@.....@',13
db '@.......@ @.....@@@@@@......@@......@',13
db '@......@ @.................@@.......@',13
db ' @....@ @.....@@......@@....@.......@',13
db ' @..@ @.........@.........@......@',13
db ' @@ @...................@@....@',13
db ' @.......@@@.......@ @..@',13
db ' @...............@ @@',13
db ' @...............@',13
db ' @.................@',13
db ' @...................@',13
db ' @.....................@',13
db ' @.......@@......@@......@ @@',13
db ' @......@....@..@....@.....@@..@',13
db ' @......@....@..@....@.........@',13
db ' @@@@@@@@@@@@@@@@@@@@@@@@@@@@@',0
db '<27>­',0
db '‚â',0
db '‘à',0
db '—â',0
db '<27>â',0
db '‘¡',0
db '‚®áªà¥á¥­¨¥',0
db 0
msgbox_5:
dw 0
db '‘®®¡é¥­¨¥',0 ;+2 = +MB_TEXT_OFFSET
db '‚믮«­ïî ¯à®æ¥áá ...',0
db 'Žáâ ­®¢¨âì',0
db '<27>à¥à¢ âì',0
db 0
msgbox_5_2:
dw 0
db '‘®®¡é¥­¨¥',0 ;+2 = +MB_TEXT_OFFSET
db '‚ᥠ§ ª®­ç¥­®',0
db '‡ ªàëâì ®ª­®',0
db 0
;--------------------------------------------------
align 4
msgbox_lib_import:
mb_create dd amb_create
mb_reinit dd amb_reinit
mb_setfunctions dd amb_setfunctions
dd 0,0
amb_create db 'mb_create',0
amb_reinit db 'mb_reinit',0
amb_setfunctions db 'mb_setfunctions',0
;--------------------------------------------------
system_path db '/sys/lib/'
msgbox_name db 'msgbox.obj',0
err_message_found_lib db 'Sorry I cannot load library msgbox.obj',0
head_f_i:
head_f_l db 'System error',0
err_message_import db 'Error on load import library msgbox.obj',0
;--------------------------------------------------
draw_square:
cmp byte[sh_help],0
je @f
push eax ebx ecx edx
mov eax,13 ;ðèñîâàíèå ïðÿìîóãîëüíèêà
mov ebx,105*65536+70
mov ecx,15*65536+50
mov edx,0x8080ff
int 0x40
mov eax,4 ;à¨á®¢ ­¨¥ ⥪áâ 
mov ebx,110*65536+25
mov ecx,0xffffff
mov edx,txt_help
mov esi,9
mcall
mov eax,47
mov esi,0xffff
mov ebx,0x10000 ;format
xor ecx,ecx
mov cl,byte[sh_help]
mov dx,150
shl edx,16
mov dx,40
int 0x40
pop edx ecx ebx eax
@@:
ret
fun_show_help:
inc byte[sh_help]
cmp byte[sh_help],10
jne @f
mov byte[sh_help],0
@@:
call draw_square
ret
sh_help db 0
txt_help db '<27>®¬®éì...'
i_end: ;ª®­¥æ ª®¤ 
rb 1024
thread:
rb 1024
stacktop:
cur_dir_path:
rb 4096
library_path:
rb 4096
file_info:
rb 40
mem:

View File

@ -0,0 +1,423 @@
format MS COFF
public EXPORTS
section '.flat' code readable align 16
include '../../../macros.inc'
purge mov
include 'strlen.inc'
MB_FIRST_BUT_ID equ 3 ;¨¤¥­â¨ä¨ª â®à 1-© ª­®¯ª¨ ­  á®®¡é¥­¨¨
MB_MAX_BUT equ 8 ;¬ ªá¨¬ «ì­®¥ ç¨á«® ª­®¯®ª ¢ á®®¡é¥­¨¨
MB_BUT_HEIGHT equ 20 ;¢ëá®â  ª­®¯ª¨ ­  á®®¡é¥­¨¨
CHAR_WIDTH equ 6 ;è¨à¨­  1-© ¡ãª¢ë ⥪áâ 
MB_BUT_OTY_1 equ 5 ;¢ëà⨪ «ì­ë©(¥) ®âáâã¯(ë) ¬¥¦¤ã: § £®«®¢ª®¬ ®ª­  ¨ ⥪á⮬, ⥪á⮬ ª­®¯ª ¬¨
;--- ®âáâã¯ë ­  ª­®¯ª å, 㪠§ ­­ë¥ ¢®¯à®á ¬¨: <-?->, ¡¥§ ãç¥â  ⥪áâ  ---
MB_BUT_OTX_1 equ 5 ;[<-?->Caption.....]
MB_BUT_OTX_2 equ 10 ;[<-?->Caption<-?->]
MB_BUT_OTX_3 equ 15 ;[<-?->Caption<-?->]<-?->
MB_TEXT_OFFSET equ 2 ;ᬥ饭¨¥, ¯® ª®â®à®¬ã ­ ç¨­ ¥âìáï ⥪áâ § £®«®¢ª  ®ª­ 
align 4
start:
mov eax,48
mov ebx,3
mov ecx,sc
mov edx,sizeof.system_colors
mcall
mov eax,40
mov ebx,0x27
mcall
;-- clear id pressed button ---
mov ebx,[mb_text]
mov al,byte[ebx]
add al,MB_FIRST_BUT_ID
dec al
mov byte[mb_key_foc],al
push [mb_text]
call MsgBoxReInit
align 4
red_win:
mov eax,12
mov ebx,1
mcall
xor eax,eax
mov bx,word[mb_left]
shl ebx,16
mov bx,word[mb_width]
mov cx,word[mb_top]
shl ecx,16
mov cx,word[mb_height]
mov edx,[sc.work]
or edx,0x33000000
mov edi,[mb_text]
add edi,MB_TEXT_OFFSET ;Caption
mcall
mcall 9,mb_procinfo,-1
mov eax,dword[mb_procinfo.client_box.width]
sub eax,[but_width]
shr eax,1
add eax,MB_BUT_OTX_1
mov [ot_left],eax
mov eax,4 ;à¨á®¢ ­¨¥ ⥪áâ 
mov bx,MB_BUT_OTX_1
shl ebx,16
mov bx,MB_BUT_OTY_1
mov ecx,[sc.work_text]
mov edx,[txtMsg]
@@:
mov esi,edx
call strlen
call linlen
cmp eax,0
je @f
mov esi,eax
push eax
mov eax,4
int 0x40
pop eax
add edx,eax
cmp byte[edx],0
je @f
inc edx
add ebx,10 ; move <--y-->
jmp @b
@@:
call MsgBoxDrawAllBut
mcall 12,2
align 4
still:
mov eax,10
mcall
cmp al,1 ;¨§¬. ¯®«®¦¥­¨¥ ®ª­ 
jz red_win
cmp al,2
jz key
cmp al,3
jz button
jmp still
align 4
key:
mcall 2
cmp ah,13
jne @f
mov ah,[mb_key_foc]
jmp close
@@:
cmp ah,176 ;Left
jne .no_left
cmp [mb_key_foc],MB_FIRST_BUT_ID
jg @f
mov al,[mb_key_max]
add [mb_key_foc],al
@@:
dec [mb_key_foc]
call MsgBoxDrawAllBut
.no_left:
cmp ah,179 ;Right
jne .no_right
mov al,[mb_key_max]
add al,MB_FIRST_BUT_ID
cmp [mb_key_foc],al
je .no_right
inc [mb_key_foc]
cmp [mb_key_foc],al
jl @f
mov [mb_key_foc],MB_FIRST_BUT_ID
@@:
call MsgBoxDrawAllBut
.no_right:
jmp still
align 4
button:
mcall 17 ;¯®«ãç¨âì ª®¤ ­ ¦ â®© ª­®¯ª¨
cmp ah,MB_FIRST_BUT_ID
jge close
cmp ah,1
jne still
;.exit:
mov ah,MB_FIRST_BUT_ID
dec ah
close:
sub ah,MB_FIRST_BUT_ID
inc ah
mov ebx,[mb_text]
mov byte[ebx],ah
;*** call msgbox functions ***
cmp ah,0
je @f
cmp dword[mb_funct],0
je @f
xor ebx,ebx
mov bl,ah
dec bl
shl bx,2 ;bx=bx*4
add ebx,dword[mb_funct]
cmp dword[ebx],0
je @f
call dword[ebx]
@@:
mcall -1 ;¢ë室 ¨§ ¯à®£à ¬¬ë
align 4
MsgBoxDrawAllBut:
mov ebx,[ot_left]
shl ebx,16
mov bx,word[ot_top]
add bx,MB_BUT_OTY_1
; Buttons ...
push edi
mov edi,txtBut
mov edx,[edi]
mov ecx,MB_FIRST_BUT_ID
@@:
;eax = len button caption text
mov esi,edx
call strlen
cmp eax,0
je @f
call MsgBoxDrawButton
inc ecx
add edi,4
cmp edi,endBut
jge @f
mov edx,[edi]
push bx
ror ebx,16
imul esi,CHAR_WIDTH
add esi,MB_BUT_OTX_3
add ebx,esi ; ...
ror ebx,16
pop bx
jmp @b
@@:
pop edi
ret
;input:
; ecx = button id
align 4
MsgBoxDrawButton:
push ecx
;button
push eax ebx edx
mov edx,ecx
imul eax,CHAR_WIDTH
add eax,MB_BUT_OTX_2
mov esi,[sc.work_button]
cmp cl,[mb_key_foc]
jne @f
mov esi,[sc.work_button_text]
@@:
mov cx,bx
sub cx,MB_BUT_OTY_1
shl ecx,16
mov cx,MB_BUT_HEIGHT
ror ebx,16
sub bx,MB_BUT_OTX_1
ror ebx,16
mov bx,ax
mov eax,8
int 0x40
pop edx ebx eax
;caption
mov ecx,[sc.work_button_text]
cmp esi,ecx
jne @f
mov ecx,[sc.work_button]
@@:
mov esi,eax
mov eax,4
int 0x40
pop ecx
ret
align 4
MsgBoxReInit:
push ebp
mov ebp,esp
m2m dword[mb_text],dword[ebp+8]
push eax ebx ecx edi esi
mov esi,[mb_text]
add esi,MB_TEXT_OFFSET
call strlen
inc esi ;add terminated zero
add esi,eax ;add len of caption
mov [txtMsg],esi
;--- go to first button text --- buttons 1...MB_MAX_BUT
mov ebx,txtBut
mov cx,MB_MAX_BUT
@@:
call strlen
add esi,eax ;add len of caption
inc esi ;add terminated zero
mov dword[ebx],esi
cmp byte[esi],0
je @f
add ebx,4
loop @b
@@:
;--- calc button top ---
mov eax,1
mov ebx,[txtMsg]
@@:
inc ebx
cmp byte[ebx],0
je @f
cmp byte[ebx],13
jne @b
inc eax
jmp @b
@@:
imul eax,10
add eax,2*MB_BUT_OTY_1
mov [ot_top],eax
;--- calc window height ---
add eax,MB_BUT_OTY_1
add eax,MB_BUT_HEIGHT
add ax,5 ;height of border
mov [mb_height],ax
mcall 48,4 ;skin height
add [mb_height],ax
;--- calc window top ---
mov eax,14
int 0x40
mov word[mb_top],ax
mov ax,word[mb_height]
sub word[mb_top],ax
shr word[mb_top],1
;---
shr eax,16
mov word[mb_left],ax
mov ax,word[mb_width]
sub word[mb_left],ax
shr word[mb_left],1
;--- calc button width ---
xor ebx,ebx
xor ecx,ecx
mov esi,[txtBut]
mov byte[mb_key_max],0
@@:
cmp byte[esi],0
je @f
inc ecx
call strlen
add esi,eax
inc esi
inc byte[mb_key_max]
add ebx,eax
jmp @b
@@:
imul ebx,CHAR_WIDTH
imul ecx,MB_BUT_OTX_3
add ebx,ecx
add ebx,MB_BUT_OTX_2
sub ebx,MB_BUT_OTX_3
mov [but_width],ebx
pop esi edi ecx ebx eax
pop ebp
ret 4
;input:
; [esp+8] = pointer to msgbox text
align 4
MsgBoxCreate:
push ebp
mov ebp,esp
m2m dword[mb_text],dword[ebp+8]
push eax ebx ecx edx
mov eax,51
mov ebx,1
mov ecx,start
mov edx,dword[ebp+12];thread
int 0x40
mov dword[mb_funct],0
pop edx ecx ebx eax
pop ebp
ret 8
;input:
; [esp+8] = pointer to msgbox functions pointers
align 4
MsgBoxSetFunctions:
push ebp
mov ebp,esp
m2m dword[mb_funct],dword[ebp+8]
pop ebp
ret 4
;--- data ---
txtMsg dd 0 ;㪠§ â¥«ì ­  ­ ç «® ⥪áâ  á®®¡é¥­¨ï
txtBut rd MB_MAX_BUT ;㪠§ â¥«ì ­  ­ ç «® ⥪áâ  ¯®¤¯¨á¥© ª­®¯®ª
endBut:
ot_left dd 0 ;®âáâ㯠᫥¢  (¤«ï à¨á®¢ ­¨ï ª­®¯®ª)
ot_top dd 0 ;®âáâ㯠ᢥàåã (¤«ï à¨á®¢ ­¨ï ª­®¯®ª)
but_width dd 0 ;è¨à¨­  ¢á¥å ª­®¯®ª + § §®àë ¬¥¦¤ã ­¨¬¨
;--- à §¬¥àë ­  íªà ­¥ ®ª­  á®®¡é¥­¨ï ---
mb_left dw 0
mb_width dw 300
mb_top dw 0
mb_height dw 50
mb_key_foc db MB_FIRST_BUT_ID ;ª­®¯ª  ¢ 䮪ãᥠ(á ãç¥â®¬ MB_FIRST_BUT_ID)
mb_key_max db 1 ;ç¨á«® ¢á¥å ª­®¯®ª á®®¡é¥­¨ï
;--------------------------------------------------
sc system_colors
mb_procinfo process_information ;㪠§ â¥«ì ­  áâàãªâãàã process_information த¨â¥«ì᪮£® ®ª­ 
mb_text dd 0 ;msgbox_1 ;㪠§ â¥«ì ¤ ­­ë¥ ¤«ï á®®¡é¥­¨ï (ª®â®àë ¯¥à¥¤ îâìáï ®ª­ã)
mb_funct dd 0 ;pointer to functions
;--------------------------------------------------
align 16
EXPORTS:
dd sz_mb_create, MsgBoxCreate
dd sz_mb_reinit, MsgBoxReInit
dd sz_mb_setfunctions, MsgBoxSetFunctions
dd 0,0
sz_mb_create db 'mb_create',0
sz_mb_reinit db 'mb_reinit',0
sz_mb_setfunctions db 'mb_setfunctions',0

View File

@ -0,0 +1,71 @@
; strlen function
;
; Copyright (c) 2003 Thomas Mathys
; killer@vantage.ch
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
;
;%ifndef _STRLEN_INC
;%define _STRLEN_INC
;********************************************************************
; returns the length of an asciiz string
; input : esi = pointer to string
; output : eax = string length
; destroys : nothing
;********************************************************************
strlen:
push ecx
push edi
pushfd
cld ; !
mov ecx,-1
mov edi,esi ; find terminating zero
xor al,al
repne scasb
mov eax,edi ; calculate string length
sub eax,esi
dec eax
popfd
pop edi
pop ecx
ret
; linlen function
;
; Copyright (c) 2009 Igor Afanasiev
linlen:
push ecx
push edi
pushfd
cld ; !
mov ecx,eax
inc ecx
mov edi,esi ; find terminating zero
mov al,13
repne scasb
mov eax,edi ; calculate string length
sub eax,esi
dec eax
popfd
pop edi
pop ecx
ret
;%endif