News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Find position for a new box

Started by Magnum, December 12, 2012, 07:12:15 AM

Previous topic - Next topic

Magnum

I am going to add a 3rd box and would like to know if there is some tool or program that can tell me what position my cursor would be at.

Similar to what mspaint has.

It takes to long monkeying around with the values for horizontal position of window,etc.  :t
   

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

not sure what you mean by a "new box", Andy

GetCursorPos ?

Magnum

One of these. It will prompt for a string to be entered.

Andy

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

Roll your own, it's easy, even with Masm32 only...

include \masm32\MasmBasic\MasmBasic.inc        ; download
  Init
  push eax        ; create a 2-DWORD slot on stack
  push eax
  stack equ dword ptr [esp]
  .Repeat
        mov ecx, MouseY        ; could be GetCursorPos
        mov eax, MouseX
        .if eax!=stack || ecx!=stack[4]
                mov stack, eax
                mov stack[4], ecx
                deb 4, "MouseX", eax
                deb 4, "MouseY", ecx
        .endif
  .Until MouseK==2
  pop eax
  pop eax
  print "bye"
  invoke Sleep, 1000
  Exit
end start

dedndave

you can use EQUates to set the width of the buttons
and measure the dialog client width with GetClientRect
subtract the 3 buttons and divide by 4 - use that for the spacing
that way, whatever you make the dialog, they will be evenly spaced

MichaelW

Quote from: Magnum on December 12, 2012, 07:12:15 AM
I am going to add a 3rd box and would like to know if there is some tool or program that can tell me what position my cursor would be at.

Similar to what mspaint has.

It takes to long monkeying around with the values for horizontal position of window,etc.  :t

Does this "monkeying around" have to do with specifying coordinates and sizes in a dialog template that will result in some desired control placement and size in pixels?
Well Microsoft, here's another nice mess you've gotten us into.

Magnum

I have two buttons now and want to add a third.

I was going to use screen co-ordinates that I thought would be good for placing the 3rd box.

Probably next to the other two.

Andy

For later...

I know how to change the size of the window that the button are in, but I would like the window to center itself on the screen if that is possible.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

MichaelW

You didn't answer my question. In a dialog template positions and sizes are specified in dialog template units, see Dialog Box Measurements. If you prefer to work directly in pixel units, a straightforward method is to use an application window instead of a dialog, and create the parent window and the controls with CreateWindowEx.
Well Microsoft, here's another nice mess you've gotten us into.

dedndave

to get the screen size
    INVOKE  GetSystemMetrics,SM_CXSCREEN
    INVOKE  GetSystemMetrics,SM_CYSCREEN


let's say your window sizes are EQUates...
MAIN_WIDTH  EQU 400
MAIN_HEIGHT EQU 300


and your window position values are global variables
dwPosX dd ?
dwPosY dd ?


    INVOKE  GetSystemMetrics,SM_CXSCREEN
    sub     eax,MAIN_WIDTH
    sar     eax,1
    mov     dwPosX,eax
    INVOKE  GetSystemMetrics,SM_CYSCREEN
    sub     eax,MAIN_HEIGHT
    sar     eax,1
    mov     dwPosY,eax


now, when you create the window, you want X, Y, W, H...
dwPosX,dwPosY,MAIN_WIDTH,MAIN_HEIGHT
that will center the window on the screen

Magnum

Quote from: MichaelW on December 12, 2012, 12:46:09 PM
You didn't answer my question. In a dialog template positions and sizes are specified in dialog template units, see Dialog Box Measurements. If you prefer to work directly in pixel units, a straightforward method is to use an application window instead of a dialog, and create the parent window and the controls with CreateWindowEx.

I didn't understand what you were asking for.

My code uses MessageBox to prompt for the file name.

I will read up on Dialog Boxes.



invoke RegisterClassEx, addr wc ; register our window class

;invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,

;                                                                                             width  height 
invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW or WS_VISIBLE,3,3,  400,  280,NULL,NULL,hInstance,NULL ; Create the window
mov hwnd,eax

invoke ShowWindow, hwnd,CmdShow ; show our window
invoke UpdateWindow, hwnd

.WHILE TRUE ; The MessageLoop use of register assumed to ERROR <error FIXED Friday, December 07, 2012>

invoke GetMessage, ADDR msg,NULL,0,0

.BREAK .IF (!eax)

invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg

.ENDW

mov eax,msg.wParam
ret

WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL Fpointer

.IF uMsg==WM_CREATE

; Create 2 buttons and 2 editboxes

invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,ADDR WinName,WS_CHILD,30,15,210,20,hWnd,StringID,hInstance,NULL

; CreateWindowEx(
;
;     DWORD dwExStyle, // extended window style
;     LPCTSTR lpClassName, // pointer to registered class name
;     LPCTSTR lpWindowName, // pointer to window name
;     DWORD dwStyle, // window style
;     int x, // horizontal position of window
;     int y, // vertical position of window
;     int nWidth, // window width
;     int nHeight, // window height
;     HWND hWndParent, // handle to parent or owner window
;     HMENU hMenu, // handle to menu, or child-window identifier
;     HINSTANCE hInstance, // handle to application instance
;     LPVOID lpParam // pointer to window-creation data

mov hwndString,eax

;                                                                                Window where input is made              3rd number is width
invoke CreateWindowEx,WS_EX_CLIENTEDGE, ADDR EditClassName,NULL,WS_CHILD or WS_VISIBLE or WS_BORDER or ES_LEFT or ES_AUTOHSCROLL,30,40,310,20,hWnd,NStringID,hInstance,NULL

mov hwndNString,eax

invoke SetFocus, hwndString
                                ; open item
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonOpen,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,10,70,200,20,hWnd,ButtonOpenID,hInstance,NULL

mov hwndOpen,eax
                        ; repair window                                                                     ; horiz and vertical position
invoke CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonPatch,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,250,70,100,20,hWnd,ButtonPatchID,hInstance,NULL

mov hwndPatch,eax

.ELSEIF uMsg==WM_COMMAND

mov eax,wParam
mov edx,wParam
shr edx,16

.IF dx==BN_CLICKED

.IF ax==ButtonOpenID ; Open button clicked?

mov ofn.lStructSize,SIZEOF ofn
mov ofn.lpstrFile, OFFSET FilePath
mov ofn.lpstrFilter, OFFSET FilterString
mov ofn.nMaxFile,MAXSIZE
mov ofn.Flags, OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES or OFN_EXPLORER or OFN_HIDEREADONLY
mov ofn.lpstrTitle, OFFSET Caption

invoke GetOpenFileName, ADDR ofn

.IF eax == TRUE

; Open file to be repaired

invoke CreateFile, ofn.lpstrFile, GENERIC_READ OR GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL

.IF eax!=INVALID_HANDLE_VALUE

; Code does open the file properly, code looks good up to here

jmp next

; just a marker
place db  "Open Sesamee",0

next:

mov hFile, eax
Invoke GetFileSize, hFile, NULL

mov FSize, eax ; Save FileSize
Invoke GlobalAlloc, GMEM_FIXED, FSize
mov FPointer, eax

.IF eax == NULL ; If no pointer, error message

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoMem
push OFFSET Error

JMP MESSAGE

.ENDIF

Invoke ReadFile, hFile,FPointer,FSize, ADDR Numb, NULL

.ELSE ; error message if no valid handle

push MB_OK OR MB_ICONINFORMATION
push OFFSET NoFile
push OFFSET Error

jmp MESSAGE

.ENDIF

.ENDIF

.ELSEIF ax == ButtonPatchID ; See if Fix Button has been hit

Invoke GetDlgItemText,hWnd,StringID,ADDR StringBuf,MAXSTR ; Get first string
mov StrLenA, eax ; Save string length

Invoke Convert,ADDR StringBuf, ADDR OString ; Convert to bytes
;                         NString =    201             

Invoke GetDlgItemText,hWnd,NStringID,ADDR NStringBuf,MAXSTR ;Get 2nd string

.IF eax != StrLenA ; both strings equal?

push MB_OK OR MB_ICONINFORMATION ; If not, error message
push OFFSET Error
push OFFSET NotEqual
JMP MESSAGE

.ENDIF

Invoke Convert,ADDR NStringBuf, ADDR NString ; Convert to bytes

mov edi,FPointer ;move pointer to memory to edi
mov ecx,FSize ;move Filesize to ecx
mov esi,offset OString ;set ESI to the Opcode string we search
mov al, byte ptr [esi] ;move the first byte of the string to AL

SEARCH :

repnz scasb ;repeat until ECX=0 or AL equals the value of the byte [EDI], EDI is incremented by 1 every run

cmp ecx,0 ;If ECX=0, no matching string is found

jz NOT_FOUND

FOUND_A_MATCH :         ;found matching byte
push ecx                ;save registers
push edi
push esi
dec edi                 ;EDI-1 because REPZ added 1 byte to much
mov ecx,StrLen2         ;ECX = length of the string
repz cmpsb              ;repeat until the values in the memory o ;[EDI] and [ESI] are not equal, or ecx=0
cmp ecx,0               ;If ecx = 0, we have found the correct string

jz FIX

pop esi                 ;Restore registers for continuing search
pop edi
pop ecx
jmp SEARCH              ;go on with search

FIX :

pop esi
pop edi
pop ecx
dec edi ;EDI - 1
inc ecx ;ECX + 1
mov eax,FSize

sub eax,ecx ;compute the File Offset to repair FileSize - remaining bytes (ecx) = Offset to repair

Invoke SetFilePointer, hFile, eax, NULL, FILE_BEGIN

Invoke WriteFile, hFile,offset NString, StrLen2, ADDR Numb, NULL

mov eax, Numb
.IF eax == StrLen2 ; bytes written = Bytes to write ?

push MB_OK ; If so success-message
push OFFSET AppName
push OFFSET Done

JMP MESSAGE

.ELSE

push MB_OK OR MB_ICONINFORMATION ; If not, error message
push OFFSET Error
push OFFSET WrFile

.ENDIF

NOT_FOUND :

push MB_OK OR MB_ICONINFORMATION ; If no handle, error message
push OFFSET Error
push OFFSET NotFound

MESSAGE :

push NULL
Call MessageBox

.ENDIF

.ENDIF


.ELSEIF uMsg==WM_DESTROY ; Close program

invoke CloseHandle, hFile ; Release handle
invoke GlobalFree,Fpointer ; Release memory block
invoke ExitProcess,eax ; Exit
invoke PostQuitMessage,NULL

.ELSE

invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret

WndProc endp

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

what you want is GetOpenFileName

Hutch has a macro called OpenFileDlg that will make it easy for you
it is documented in masm32\help\hlhelp.chm

that macro calls the masm32.lib function OpenFileDialog if you don't like macros

Magnum

Already using it.


invoke GetOpenFileName, ADDR ofn

.IF eax == TRUE

; Open file to be repaired

invoke CreateFile, ofn.lpstrFile, GENERIC_READ OR GENERIC_WRITE, FILE_SHARE_READ OR FILE_SHARE_WRITE, NULL,OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL

.IF eax!=INVALID_HANDLE_VALUE

; Code does open the file properly, code looks good up to here

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Magnum

I just realized that I don't need any user input at all.

My code opens a file, search for a string and replaces it.

But I still want to finish this project that will need user input.

Andy

Andy

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave