Hi,
If you build this code (Windows), the text in the text box is centered. How do I set it to left align? The code that makes it centered is in the routine for WM_PAINT.
The text box is drawn in the second line of WM_CREATE.
.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\gdi32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\gdi32.lib
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
Tet proto :DWORD
RGB macro red,green,blue
xor eax,eax
mov ah,blue
shl eax,8
mov ah,green
mov al,red
endm
.DATA?
hInstance HINSTANCE ? ; Instance handle of our program
CommandLine LPSTR ?
; First button
hwndButton HWND ?
.CODE
ClassName db "WinClass",0 ; the name of our window class
AppName db "Window",0 ; the name of our window
OurText db "Win32 assembly is great and easy!",0
MBText db "You clicked the button!",0
ButtonClassName db "button",0
ButtonText db "Click Me!",0
TextBoxClassName db "edit",0
posx dword 200
posy dword 200
winw dword 250
winh dword 200
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_BACKGROUND+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,WS_OVERLAPPEDWINDOW,posx,posy,winw,winh,NULL,NULL,hInst,NULL
mov hwnd,eax
invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd
.WHILE TRUE
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 hdc:HDC
LOCAL ps:PAINTSTRUCT
LOCAL rect:RECT
.IF uMsg==WM_DESTROY ; if the user closes our window
invoke PostQuitMessage,NULL ; quit our application
.ELSEIF uMsg==WM_PAINT
invoke BeginPaint,hWnd, ADDR ps
mov hdc,eax
invoke GetClientRect,hWnd, ADDR rect
invoke DrawText, hdc,ADDR OurText,-1, ADDR rect,DT_SINGLELINE or DT_CENTER ;or DT_VCENTER ;
RGB 0,0,255
invoke SetBkColor,hdc,eax
invoke EndPaint,hWnd, ADDR ps
.ELSEIF uMsg==WM_LBUTTONDOWN ; user clicked anywhere on the form
invoke MessageBox,hWnd,ADDR OurText,ADDR AppName,MB_OK or MB_ICONINFORMATION
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx,NULL,ADDR ButtonClassName,ADDR ButtonText,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,55,70,140,25,hWnd,1,hInstance,NULL
invoke CreateWindowEx,NULL,ADDR TextBoxClassName,ADDR ButtonText,WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,55,100,140,25,hWnd,1,hInstance,NULL
mov hwndButton,eax
.ELSEIF uMsg==WM_COMMAND
mov eax,wParam
.IF ax==1
shr eax,16
.IF ax==BN_CLICKED
lea eax,Tet
push hWnd
call eax
.ENDIF
.ENDIF
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam ; Default message processing
ret
.ENDIF
xor eax,eax
ret
WndProc endp
Tet proc hWnd:HWND
invoke MessageBox,hWnd,ADDR MBText,ADDR AppName,MB_OK or MB_ICONINFORMATION
ret
Tet endp
end start
Substitute DT_LEFT for DT_CENTER.
Quote from: Astro on July 11, 2009, 05:01:42 PM
..... the text in the text box is centered..... The text box is drawn in the second line of WM_CREATE....
Hi Astro,
If I understood you correctly, just eliminate the BS_DEFPUSHBUTTON style in the second line and the text in the editbox will be left aligned.
Should be like :
invoke CreateWindowEx,NULL,ADDR TextBoxClassName,ADDR ButtonText,WS_CHILD or WS_VISIBLE,55,100,140,25,hWnd,1,hInstance,NUL
I usually handle all the control stuff (Static, Edittext, Groupbox etc.) in rsrc.rc file, partly because you can do some input filtering, formatting, text aligning and much more.
Btw, this is my first post, and no, I'm not am bot! Been lurking for a long time, learnt a lot. This forum is a great place with great knowledge! :U
Cheers.
Hi KhipuCoder,
That did it! Thanks!! :U
Hi KhipuCoder,
Welcome on board. :U
Quote from: hutch-- on July 12, 2009, 07:25:51 AM
Welcome on board. :U
G'day, mate!
Thank you for the welcome! (http://www.mysmiley.net/imgs/smile/animated/anim_37.gif)
KhipuCoder