News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

FINDMSGSTRING Problem

Started by xandaz, January 04, 2021, 07:06:41 AM

Previous topic - Next topic

xandaz

    Hey... so i'm looking into putting text search on my app for mdichild windows and registered "FINDMSGSTRING but it doesn't appear on any window procudures of the app. why would that be? i've even tried to subclass the findtext dialog and still no sign of FINDMSGSTRING. Can someone gimme an example of its use please? Thanks

xandaz

   why does this not work?
__UNICODE__ equ TRUE
.586
.model flat,stdcall
option casemap:none

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD

include \masm32\include\masm32rt.inc
include \masm32\include\winclasses.asm

.const
MainWindowWidth equ 500
MainWindowHeight equ 400

.data
hInstance HINSTANCE ?
wcMain WNDCLASSEX <sizeof wcMain,CS_HREDRAW+CS_VREDRAW,offset WndProc,\
0,0,?,?,?,COLOR_WINDOW,0,offset MainWindowClass,?>
UCSTR MainWindowName,"Experience 1,2,3",0
UCSTR MainWindowClass,"MainWindowClass",0
hMainWindow HWND ?
frep FINDREPLACE <>
FINDMSGSTRING dd 0
UCSTR fmsgs,"FINDMSGSTRING",0
StringBuffer dw 80 dup(0)
hButton HWND ?
UCSTR ButtonName,"Find Text",0

.code
start:
mov hInstance,rv(GetModuleHandle,0)
invoke WinMain,hInstance,0,0,SW_SHOWNORMAL
invoke ExitProcess,eax

WinMain PROC hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD

local msg:MSG

push hInst
pop wcMain.hInstance
mov wcMain.hIcon,rv(LoadIcon,0,IDI_APPLICATION)
m2m wcMain.hIcon,wcMain.hIconSm
mov wcMain.hCursor,rv(LoadCursor,0,IDC_ARROW)
invoke RegisterClassEx,addr wcMain
mov eax,rv(GetSystemMetrics,SM_CYSCREEN)
shr eax,1
sub eax,MainWindowHeight/2
push eax
mov eax,rv(GetSystemMetrics,SM_CXSCREEN)
shr eax,1
sub eax,MainWindowWidth/2
pop ebx
mov hMainWindow,rv(CreateWindowEx,0,addr MainWindowClass,addr MainWindowName,WS_OVERLAPPEDWINDOW,eax,ebx,MainWindowWidth,MainWindowHeight,0,0,hInstance,0)
invoke ShowWindow,hMainWindow,CmdShow
invoke UpdateWindow,hMainWindow

msg_loop:
invoke GetMessage,addr msg,NULL,0,0
or eax,eax
jz end_msg_loop
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
jmp msg_loop
end_msg_loop:
mov eax,msg.wParam
ret

WinMain endp

WndProc PROC hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD

mov edx,uMsg
.if uMsg==WM_DESTROY
invoke PostQuitMessage,0
.elseif uMsg==WM_CREATE
mov edi,lParam
.if [edi.CREATESTRUCT.hWndParent]==0
invoke CreateWindowEx,0,addr WC_BUTTON,addr ButtonName,WS_VISIBLE+WS_CHILD+\
BS_PUSHBUTTON,0,0,200,32,hWnd,0,hInstance,0
mov hButton,eax
invoke RegisterWindowMessage,addr fmsgs
mov FINDMSGSTRING,eax

.endif
.elseif uMsg==WM_COMMAND
invoke RtlZeroMemory,addr StringBuffer,sizeof StringBuffer
mov frep.lStructSize,sizeof frep
push hWnd
pop frep.hwndOwner
push hInstance
pop frep.hInstance
mov frep.lpstrFindWhat,offset StringBuffer
mov frep.wFindWhatLen,80
mov frep.Flags,FR_DOWN+FR_MATCHCASE+FR_REPLACE
invoke FindText,addr frep

.elseif edx==FINDMSGSTRING
invoke MessageBox,hWnd,0,0,MB_OK
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.endif
xor eax,eax
ret

WndProc endp

end start

Thanks in advance

jj2007


Greenhorn

Hi xandaz

Read the manual:
QuoteYou must specify the FINDMSGSTRING constant in a call to the RegisterWindowMessage function to get the identifier for the message sent by the dialog box.


Delete these lines:
FINDMSGSTRING   dd      0
UCSTR      fmsgs,"FINDMSGSTRING",0


Insert something like this:
uFindReplaceMsg    DWORD    0    ; Store the return value of RegisterWindowMessage in this variable

Call RegisterWindowMessage like this:
invoke  RegisterWindowMessage, addr CStr(FINDMSGSTRING)
If FINDMSGSTRING is not defined in your windows header files:
invoke  RegisterWindowMessage, addr CStr("commdlg_FindReplace")

Read the next paragraph of the manual:
QuoteWhen you create the dialog box, use the hwndOwner member of the FINDREPLACE structure to identify the window to receive FINDMSGSTRING messages.
FINDMSGSTRING message

See example: Using Common Dialog Boxes - Finding Text

Kind regards
Greenhorn
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

   Thanks a lot. It worked like a charm. So it's "commdlg_FindReplace". Thanks a lot. Really guys.

xandaz

   Hi guys. I've been trying to get the FindText thing to work properlly but i'm having some issues. What would be the best way to srcoll the text selection into view. I've been trying EM_CHARFROMPOS and EM_SETSCROLLPOS but it doesn't work so welll. Isn't there a way to move line into the selected text automatically? Thanks in advance

xandaz

   Here is the code:
.if edx==FINDMSGSTRING
invoke SendMessage,hMdi,WM_MDIGETACTIVE,0,0
invoke GetWindowLong,eax,GWL_USERDATA
mov edi,eax
mov esi,lParam
test [esi.FINDREPLACE.Flags],FR_DIALOGTERM
jnz exit_1
invoke SendMessage,[edi.MdiStruct.hEdit],EM_HIDESELECTION,TRUE,0
invoke SendMessage,[edi.MdiStruct.hEdit],EM_EXSETSEL,0,addr crange
invoke SendMessage,[edi.MdiStruct.hEdit],EM_EXGETSEL,0,addr crange
push crange.cpMin
pop ft.chrg.cpMin
push crange.cpMax
pop ft.chrg.cpMax
mov lr,rv(SendMessage,[edi.MdiStruct.hEdit],EM_FINDTEXTEX,FR_DOWN,addr ft)
mov ft.chrg.cpMin,eax
.if lr>=0
inc lr
push lr
pop crange.cpMin
mov crange.cpMax,-1
exit_1:
invoke SendMessage,[edi.MdiStruct.hEdit],EM_POSFROMCHAR,addr pt,crange.cpMin
invoke SendMessage,[edi.MdiStruct.hEdit],EM_SETSCROLLPOS,0,addr pt
invoke SendMessage,[edi.MdiStruct.hEdit],EM_EXSETSEL,0,addr ft.chrgText
invoke SendMessage,[edi.MdiStruct.hEdit],EM_HIDESELECTION,FALSE,0
mov eax,TRUE
ret
.endif
mov eax,FALSE
ret

jj2007


xandaz

   Ok. I'll try that. Thanks. It worked. I thought i tried that but no. Thanks a lot JJ.

xandaz

    Hi guys. I'm having a hard time solving a little problem. invoke ClearMemory,addr FindReplace,sizeof FindReplace
push hWnd
pop FindReplace.hwndOwner
mov FindReplace.lStructSize,sizeof FINDREPLACE
push hInstance
pop FindReplace.hInstance
mov FindReplace.Flags,FR_DOWN or FR_FINDNEXT
mov FindReplace.lpstrFindWhat,offset FindString
mov FindReplace.lpstrReplaceWith,offset ReplaceString
invoke FindText,addr FindReplace

    Returns NULL but CommDlgExtendedError doesnt return any valid error code. 16385 tobe precise