flat assembler
Message board for the users of flat assembler.

Index > Windows > cursor and center screen

Author
Thread Post new topic Reply to topic
sina



Joined: 18 Aug 2003
Posts: 132
Location: istanbul turkey
sina
i am trying to learn win32asm by trying the things i have seen on the net or elsewhere, in this code i have 2 problems
1) i want to change the cursor to a file called 1.cur but i cant
2)i have tried to port the code that masm examples use to center the window in the screen but it does not work too
i think i need some help here...

format PE GUI 4.0
entry start

include '%include%\win32a.inc'

section '.data' data readable writeable

_title db 'Win32 program template',0
_class db 'FASMWIN32',0
_messageboxcaption1 db 'example!',0
_example1 db 'bye bye!',0

mainhwnd dd ?
hinstance dd ?

;w_width dd 192 ;these are the old values i have used to create my window before i tried the masm center code
;w_height dd 192
;w_top dd 128
;w_left dd 128

Wtx dd ?
Wty dd ?
Wwd dd ?
Wht dd ?

msg MSG
wc WNDCLASS
w_cursor1 FILE 'c:\fasmw\template\1.cur'

section '.code' code readable executable

start:

;main window begin
invoke GetModuleHandle,0
mov [hinstance],eax
invoke LoadIcon,eax,17
mov [wc.hIcon],eax
;invoke LoadIcon,0,IDI_APPLICATION
;mov [wc.hIcon],eax
;invoke LoadCursor,0,IDC_ARROW
invoke LoadCursorFromFile,w_cursor1
mov [wc.hCursor],eax
mov [wc.style],0
mov [wc.lpfnWndProc],WindowProc
mov [wc.cbClsExtra],0
mov [wc.cbWndExtra],0
mov eax,[hinstance]
mov [wc.hInstance],eax
mov [wc.hbrBackground],COLOR_BTNFACE+1
mov [wc.lpszMenuName],0
mov [wc.lpszClassName],_class
;invoke LoadCursorFromFile,w_cursor1
;invoke SetCursor,eax

mov [Wwd], 500
mov [Wht], 350

invoke GetSystemMetrics,SM_CXSCREEN ; copy paste from masm example
stdcall TopXY,Wwd,eax
mov [Wtx], eax

invoke GetSystemMetrics,SM_CYSCREEN
stdcall TopXY,Wht,eax
mov [Wty], eax

invoke RegisterClass,wc
invoke CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,[Wtx],[Wty],[Wwd],[Wht],NULL,NULL,[hinstance],NULL
mov [mainhwnd],eax
;main window end


msg_loop:
invoke GetMessage,msg,NULL,0,0
or eax,eax
jz end_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop

end_loop:
invoke ExitProcess,[msg.wParam]

proc WindowProc, hwnd,wmsg,wparam,lparam
enter
push ebx esi edi
cmp [wmsg],WM_DESTROY
je wmdestroy
cmp [wmsg],WM_NCHITTEST
je wmnchittest

wmnchittest:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
cmp eax,1
jnz @F
inc eax
@@:
jmp finish

wmdestroy:
stdcall msgbox,_example1
invoke PostQuitMessage,0
xor eax,eax
finish:
pop edi esi ebx
return

proc msgbox,string
enter
mov eax, [string]
invoke MessageBox,HWND_DESKTOP,eax,_messageboxcaption1,MB_OK;+MB_ICONASTERISK
return

proc TopXY,wDim,sDim ;copy paste from masm example
enter
shr [sDim],1 ; divide screen dimension by 2
shr [wDim],1 ; divide window dimension by 2
mov eax,[wDim] ; copy window dimension into eax
sub [sDim],eax ; sub half win dimension from half screen dimension
mov eax,[sDim] ; in the masm example they have used "return sDim" so i have added this line to return sDim in eax
return


section '.idata' import data readable writeable

library kernel,'KERNEL32.DLL',\
user,'USER32.DLL'

import kernel,\
GetModuleHandle,'GetModuleHandleA',\
ExitProcess,'ExitProcess'

import user,\
RegisterClass,'RegisterClassA',\
CreateWindowEx,'CreateWindowExA',\
DefWindowProc,'DefWindowProcA',\
GetMessage,'GetMessageA',\
MessageBox,'MessageBoxA',\
TranslateMessage,'TranslateMessage',\
DispatchMessage,'DispatchMessageA',\
LoadCursor,'LoadCursorA',\
SetCursor,'SetCursor',\
GetSystemMetrics,'GetSystemMetrics',\
LoadCursorFromFile,'LoadCursorFromFileA',\
LoadIcon,'LoadIconA',\
PostQuitMessage,'PostQuitMessage'

section '.rsrc' resource data readable

; resource directory

directory RT_ICON,icons,\
RT_GROUP_ICON,group_icons

; resource subdirectories

resource icons,\
1,LANG_NEUTRAL,icon_data

resource group_icons,\
17,LANG_NEUTRAL,main_icon

icon main_icon,icon_data,"1.ico"
Post 20 Oct 2003, 20:26
View user's profile Send private message ICQ Number Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
1) you should declare filename of your cursor not via FILE directive, but you should declare normal string, ie:
Code:
 w_cursor1 db 'c:\fasmw\template\1.cur', 0     

2)code
Code:
 invoke GetSystemMetrics,SM_CXSCREEN ; copy paste from masm example
stdcall TopXY,Wwd,eax
mov [Wtx], eax
invoke GetSystemMetrics,SM_CYSCREEN
stdcall TopXY,Wht,eax
mov [Wty], eax    

should be
Code:
 invoke GetSystemMetrics,SM_CXSCREEN ; copy paste from masm example
stdcall TopXY,[Wwd],eax
mov [Wtx], eax
invoke GetSystemMetrics,SM_CYSCREEN
stdcall TopXY,[Wht],eax
mov [Wty], eax    

regards
Post 20 Oct 2003, 21:18
View user's profile Send private message Visit poster's website Reply with quote
sina



Joined: 18 Aug 2003
Posts: 132
Location: istanbul turkey
sina
ok center screen code works as you helped
but the cursor does not work although i have changed it to the string
and in the win32 sdk i have found that it says

"If your application must set the cursor while it is in a window, make sure the class cursor for the specified window's class is set to NULL. If the class cursor is not NULL, the system restores the class cursor each time the mouse is moved."

is it something to do with this?
in the code i have written
invoke LoadCursor,0,NULL
mov [wc.hCursor],eax
to make in null but its not working
and the cursor i am trying to apply is the original windows cursor found in the cursors folder of xp
anyway thanks for your help Smile
Post 21 Oct 2003, 12:52
View user's profile Send private message ICQ Number Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
The problem was with your WindowProc. It should directly return a value that DefWindowProc returns (when DefWindowProc is called).
Try this:
Code:
proc WindowProc, hwnd,wmsg,wparam,lparam
enter
push ebx esi edi
cmp [wmsg],WM_DESTROY
je wmdestroy
cmp [wmsg],WM_NCHITTEST
je wmnchittest

wmnchittest:                                          
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]    ;  go directly to the finish:)
jmp finish

wmdestroy:
stdcall msgbox,_example1
invoke PostQuitMessage,0
xor eax,eax
finish:
pop edi esi ebx
return     


oh, in future, can you use indents? They make your programs more readable. See some FASMW examples - they show how your progam should look like Very Happy

regards
Post 21 Oct 2003, 15:43
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.