News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

drawText and CreateFontIndirect problem

Started by ragdog, September 29, 2009, 08:44:16 AM

Previous topic - Next topic

ragdog

Hi

I have a problem with the CreateFontIndirect

Write i under Wm_Paint
invoke CreateFontIndirect, addr Courier_New
    mov hFont,eax

Destroy this my dialog
This works only under WM_INITDIALOG

.elseif uMsg==WM_PAINT
           invoke CreateFontIndirect, addr Courier_New
    mov hFont,eax
   invoke GetDlgItem,hWnd,1001
      mov hItem,eax
   invoke BeginPaint,hItem, ADDR ps
       mov hdc,eax

    invoke SelectObject, hdc,hFont ;select the font
    invoke GetClientRect,hItem, ADDR rect
    ;invoke SetTextColor, hdc,00FF8000h

    invoke SetBkMode, hdc, TRANSPARENT
    invoke DrawText, hdc,CTEXT("Masm32 DrawText Test"),-1, ADDR rect, DT_SINGLELINE or DT_CENTER or DT_VCENTER
    invoke EndPaint,hWnd, ADDR ps

Can me any tell me why?

regards,

six_L

regards

ragdog

Hi

I understand this not

hFont can a local or normal varibale this is not relevant this works same or not?

six_L

#3
the color of the font can't work adequatly.
.686p
.xmm
.model flat, stdcall  ;32 bit memory model
option casemap :none  ;case sensitive

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comdlg32.inc
include \masm32\include\Comctl32.inc
include \masm32\include\shell32.inc
include \masm32\include\advapi32.inc
include \masm32\include\gdi32.inc
include \masm32\include\shlwapi.inc
include \masm32\include\debug.inc
include \masm32\include\masm32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\comdlg32.lib
includelib \masm32\lib\Comctl32.lib
includelib \masm32\lib\shell32.lib
includelib \masm32\lib\advapi32.lib
includelib \masm32\lib\gdi32.lib
includelib \masm32\lib\shlwapi.lib
includelib \masm32\lib\debug.lib
includelib \masm32\lib\masm32.lib

include \masm32\Macros\macros.asm

.const
IDD_DIALOG equ 1000
IDC_PATH        equ 1003

.data
Textbuffer db "CTRL+Z: Exit.",0
stLogFont LOGFONT    <64,0,0,0,FW_NORMAL,\
0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS,\
CLIP_STROKE_PRECIS,DEFAULT_QUALITY,\
DEFAULT_PITCH or FF_SWISS,"Fixedsys">



.data?
hInstance dd ?
hStatic         dd ?
hWnd_main DD ?
hFont dd ?
ColorhFont dd ?


Wwd dd ?
Wht dd ?

.code

AdjustDialog proc hDlg:HWND
local rect:RECT
local hWnd:HWND

invoke GetParent, hDlg
mov hWnd, eax
invoke GetWindowRect, hWnd, addr rect
mov eax, rect.left
sub rect.right, eax
mov eax, rect.top
sub rect.bottom, eax
invoke ScreenToClient, hDlg, addr rect
invoke MoveWindow, hDlg, rect.left, rect.top, rect.right, rect.bottom, FALSE

ret

AdjustDialog endp

StcProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
Local ps:PAINTSTRUCT
LOCAL logbrush :LOGBRUSH
local rt:RECT

.if uMsg == WM_PAINT
invoke BeginPaint, hStatic,addr ps

invoke GetClientRect,hStatic,addr rt
invoke SetBkMode, ps.hdc, TRANSPARENT

mov logbrush.lbStyle,BS_HATCHED
mov eax,0FFC7C7H
mov logbrush.lbColor,eax
mov logbrush.lbHatch,HS_DIAGCROSS
invoke CreateBrushIndirect,addr logbrush

invoke SelectObject,ps.hdc,eax
invoke PatBlt,ps.hdc,rt.left,rt.top,rt.right,rt.bottom,PATCOPY
invoke SetTextColor,ps.hdc,ColorhFont

invoke SelectObject,ps.hdc,hFont

invoke DrawText,ps.hdc,addr Textbuffer,-1,addr rt,DT_VCENTER or DT_SINGLELINE or DT_CENTER

invoke EndPaint, hStatic, addr ps
xor eax,eax
ret
.endif
invoke GetWindowLong,hStatic,GWL_USERDATA
invoke CallWindowProc,eax,hWin,uMsg,wParam,lParam
ret
StcProc endp

cStatic proc hParent:DWORD,_x:DWORD,_y:DWORD,_w:DWORD,_h:DWORD,ID:DWORD

invoke CreateWindowEx,0,\
CTXT("Static"),NULL,050000001h,_x,_y,_w,_h,\
hParent,ID,hInstance,NULL
ret

cStatic endp

CreateLogicalFont proc
LOCAL cf:   CHOOSEFONT
LOCAL lf:   LOGFONT

mov   cf.lStructSize, SIZEOF(CHOOSEFONT)
mov   cf.hwndOwner, NULL
mov   cf.hDC, NULL
lea   eax, lf
mov   cf.lpLogFont, eax
mov   cf.iPointSize, 0
mov   cf.Flags, CF_SCREENFONTS or CF_EFFECTS

RGB   0, 0, 0                     
mov   cf.rgbColors, eax

mov   cf.lCustData, 0
mov   cf.lpfnHook, NULL
mov   cf.lpTemplateName, NULL
mov   cf.hInstance, NULL
mov   cf.lpszStyle, NULL
mov   cf.nFontType, SCREEN_FONTTYPE
mov   cf.nSizeMin, 0
mov   cf.nSizeMax, 0

invoke ChooseFont, ADDR cf
m2m ColorhFont,cf.rgbColors


invoke CreateFontIndirect, cf.lpLogFont

ret

CreateLogicalFont endp

DlgProc proc hWnd:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM

mov eax, uMsg
.if eax == WM_CREATE
invoke CreateLogicalFont;

;invoke  CreateFontIndirect,offset stLogFont
mov hFont, eax

invoke RegisterHotKey, hWnd, 8801, MOD_CONTROL, VK_Z

invoke cStatic,hWnd,0,0,627,403,1004
mov hStatic,eax

invoke AdjustDialog, eax
invoke SetWindowLong,hStatic,GWL_WNDPROC,offset StcProc
invoke SetWindowLong,hStatic,GWL_USERDATA,eax
.elseif eax == WM_HOTKEY   
mov eax, wParam
.if eax == 8801
invoke PostMessage,hWnd,WM_DESTROY,NULL,NULL
.endif
.elseif eax==WM_DESTROY
invoke DeleteObject, hFont
invoke PostQuitMessage,0
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret

DlgProc endp

TopXY proc wDim:DWORD, sDim:DWORD

shr sDim, 1     
shr wDim, 1     
mov eax, wDim   
sub sDim, eax   

mov eax, sDim
ret

TopXY endp

_WinMain proc uses esi edi edx ecx  hInst:DWORD, hPrevInst, CmdLine, CmdShow
        local wc:WNDCLASSEX
        LOCAL Msg:MSG
LOCAL Wtx:DWORD
LOCAL Wty:DWORD
       
xor     esi, esi           
        invoke  RtlZeroMemory,addr wc,sizeof wc
        invoke  LoadCursor,0,IDC_ARROW
        mov wc.hCursor,eax
        m2m wc.hInstance,hInst
        mov wc.cbSize,sizeof WNDCLASSEX
        mov wc.style,CS_HREDRAW or CS_VREDRAW
        mov wc.lpfnWndProc,offset DlgProc
        m2m wc.lpszClassName,CTXT("Test")

mov wc.hbrBackground,COLOR_WINDOW+1
       
invoke  RegisterClassEx,addr wc

invoke GetSystemMetrics,SM_CXSCREEN
mov Wwd, eax
invoke TopXY,Wwd,eax
mov Wtx, eax

invoke GetSystemMetrics,SM_CYSCREEN
mov Wht, eax
invoke TopXY,Wht,eax
mov Wty, eax

invoke  CreateWindowExA,esi,CTXT("Test"), CTXT("Test"),\
WS_POPUP,Wtx,Wty,Wwd,Wht,esi,esi,hInst,esi
mov     hWnd_main,eax

invoke SetWindowPos,hWnd_main,HWND_TOPMOST,0,0,Wwd,Wht,SWP_SHOWWINDOW
invoke  ShowWindow,hWnd_main,SW_SHOW
invoke  UpdateWindow,hWnd_main
       
.while TRUE                         
invoke  GetMessageA, addr Msg, esi, esi, esi
.break .if (!eax)
invoke  TranslateMessage, addr Msg                                             
invoke  DispatchMessageA, addr Msg                               
        .endw                                     
        mov eax, Msg.wParam
        ret

_WinMain endp
start:
invoke GetModuleHandle,NULL
mov hInstance,eax

invoke InitCommonControls
invoke GetCommandLine
invoke _WinMain, hInstance,NULL, eax, SW_SHOWDEFAULT
invoke ExitProcess,0

end start

regards

hotrod

six_L, why did you use these particular values for the window size? Thanks...
Quoteinvoke   cStatic,hWnd,0,0,627,403,1004