hi, trying to get to grips with comboboxes..
i created a combobox on my window during wm_create message, and also tried to "invoke SendMessage,hCombo,CB_ADDSTRING,0,ADDR string" below that.
now, the combo box shows; but nothing is added in the lists..:confused: any idea?
here is my code snippet:
.IF uMsg==WM_CREATE


invoke CreateWindowEx,WS_EX_LEFT or WS_EX_LTRREADING or WS_EX_RIGHTSCROLLBAR,\
ADDR cmbBox,0,CBS_HASSTRINGS or CBS_DROPDOWN or CBS_SIMPLE or WS_CHILD or WS_OVERLAPPED or WS_VISIBLE\
,10,10,180,25,hWnd,NULL,hInstance,NULL

mov hCombo,eax

invoke SendMessage,hCombo,CB_SETITEMDATA,0,ADDR string1
invoke SendMessage,hCombo,CB_ADDSTRING,0,ADDR string2
invoke SendMessage,hCombo,CB_ADDSTRING,0,ADDR string3
Posted on 2003-07-31 15:42:30 by wilson
Make your combobox large enough to display the information. A hieght of 25 pixels is not enough to display a line of text when you subtract the height of the edit box and it's border (25 - 10 - 3 - 3 = 9 pixels), try a value of 300 instead...
invoke CreateWindowEx,WS_EX_LEFT or WS_EX_LTRREADING or WS_EX_RIGHTSCROLLBAR,

ADDR cmbBox,0,CBS_HASSTRINGS or CBS_DROPDOWN or CBS_SIMPLE or WS_CHILD or WS_OVERLAPPED or WS_VISIBLE,
10,10,180,[color=red][b]300[/b][/color],hWnd,NULL,hInstance,NULL


Also if the line ends in a comma no continuation character is required.
Posted on 2003-07-31 17:22:36 by donkey
thanks donkey, working now:)

is it possible to list the lines from a text file, or would i need to do OpenFile then load them from memory?
Posted on 2003-07-31 17:39:25 by wilson
Well, there is no way to do that with an API command or message. You will have to read the text file in and parse the eol's yourself by looking for CRLF, then when you have a full line add that to the combo box... This should do it for ya :
[b];Open the file and pass the handle to this procedure.[/b]


ReadTextFile Proc hFile:DWORD
LOCAL fSize :DWORD
LOCAL nBytes :DWORD
LOCAL byteBuffer[4] :BYTE
LOCAL pBuffer :DWORD

invoke GetFileSize,hFile,NULL
mov fSize,eax
lea eax,TBUFFER
mov pBuffer,eax
mov eax,0
.While eax <= fSize
; read a line from the file
mov ecx,0
; Keep reading until a CR is encountered
.WHILE al != 0DH
push ecx
invoke ReadFile,hFile,ADDR byteBuffer,1,ADDR nBytes,NULL
.IF nBytes == 0
.BREAK
.endif
pop ecx
lea edx,byteBuffer
mov al,[edx]
mov edx,pBuffer
mov [edx+ecx],al
inc ecx
.ENDW
; set the buffer pointer to overwrite 0DH
dec ecx
; Null terminate the string
mov [edx+ecx],BYTE PTR 0
;
invoke SendMessage,hCombo,CB_ADDSTRING,0,pBuffer
;
; move the file pointer to the start of the next line
invoke SetFilePointer,hFile,1,0,FILE_CURRENT
.ENDW
; Close the file when your done
invoke CloseHandle,hFile
ret
ReadTextFile endp
Posted on 2003-07-31 18:20:08 by donkey
hhm,
first thing this morning, i put your ReatTextFile process into my combobox app and it worked fine (the file was just a list of "one","two","three")
then i changed the file to something with a bit more meat and again it worked, untill i made the combobox wider/higher.. then it would crash at startup..

now i tried to put it back to how it was, and it wont work at all (even with original of this morning:( )..
line causing crash is:
mov ,BYTE PTR 0

thanks for the code, it was working a treat :confused:
Posted on 2003-08-01 05:33:17 by wilson
Just as an aside, rather than repeatedly invoking readfile to read a byte from the file you could map the entire file into your processes memory space and then simply read the bytes in the file by incrementing the pointer returned by MapViewOfFile. This should run a little quicker. For instance:

include windows.inc

cr equ 0Dh
Lf equ 0Ah

.data
; filename is the full path and filename of the file to open
filename byte "C:\myFiles\......\myFile.txt",0
.....
.data?
lineBuffer byte dup 100h (?)
handle dword ?
filesize dword ?
hMapfile dword ?
pMapFile dword ?


.code
....

;---------------------------------------------------------------
; Open the file
;---------------------------------------------------------------

invoke CreateFile, offset filename, GENERIC_READ, FILE_SHARE_READ, 0,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0

cmp eax, INVALID_HANDLE_VALUE
je fileOpenError

; Save the handle returned from CreateFile
mov handle, eax


;---------------------------------------------------------------
; Get the file size (in bytes)
;---------------------------------------------------------------

invoke GetFileSize, handle, 0
cmp eax, INVALID_FILE_SIZE
je fileSizeError

cmp eax, 0
je zeroFileSizeError

; Save the filesize
mov filesize, eax


;---------------------------------------------------------------
; Map the file into this process's memory space
;---------------------------------------------------------------

invoke CreateFileMapping, handle, 0, PAGE_READONLY, 0, 0, 0
cmp eax, 0
je createFileMapError

; Save the file mapping handle
mov hMapfile, eax

invoke MapViewOfFile, hMapfile, FILE_MAP_READ, 0, 0, 0
cmp eax, 0
je mapFileError

; Save the pointer to the mapped file
mov pMapFile, eax

.....

;---------------------------------------------------------------
; Read the bytes
;---------------------------------------------------------------

mov esi, pMapFile
lea edi, lineBuffer
mov ecx, filesize

WhileLoop:
; While (ecx != 0)
mov dl, byte ptr ; move a byte
cmp dl, cr
je doWhateverComesNext
mov byte ptr , dl
dec ecx
or ecx, ecx
jnz WhileLoop

.....

;---------------------------------------------------------------
; Cleanup
;---------------------------------------------------------------

invoke UnmapViewOfFile, pMapFile
invoke CloseHandle, hMapfile
mov hMapfile, 0
invoke CloseHandle, handle
mov handle, 0


Hope this helps out a bit
Posted on 2003-08-01 06:49:54 by andrew_k
Yup, if your doing big files it's best to use a memory mapped file. The sniplet was from a project that read a file with no more than 2 or 3 hundred bytes and I didn't see a practical reason to memory map it. I had just assumed that your files would be small as you are adding them to a combo box.

For the size problem, I have no idea what could be wrong, it might be a buffer thing make sure TBUFFER is large enough to hold the string. I have found that XP is very picky about buffer sizes and will occasionally gpf where 2K and 9x will not. If not maybe try to send a CB_INITSTORAGE message with the number of bytes in the file before you start adding the items, could be that there is not enough storage in the combobox.
Posted on 2003-08-01 12:48:15 by donkey