News:

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

String Arrays ?

Started by G`HOST, November 11, 2005, 06:41:10 PM

Previous topic - Next topic

G`HOST

Hi
   can you suggestme how to do the following in the proper way?
   OK what i am trying to do is.....

.ELSEIF uMsg==WM_KEYDOWN
                    mov edx,lParam   
                   invoke GetKeyNameText,edx,ADDR KeyBuffer,KEYSIZE

Now when i get the key text i want to compare it with four predefined keys lets say left,right,up and down and for each positive comparison i want to do a different thing.I tried lstrcmpi but that way i can compare it to only one string.
May be something to do with arrays.
So any help would be appreciated.Thank you

MichaelW

Assuming I correctly understand what you are trying to do, you could just compare wParam to VK_UP, VK_DOWN, VK_LEFT, and VK_RIGHT.

MSDN: WM_KEYDOWN Notification

The virtual key codes are defined in WINDOW.INC.
eschew obfuscation

Infro_X

As MichaelW said, compare wParam to VK_*, the reason for this is that it is much faster
VK_LEFT = 25h
VK_UP = 26h
VK_RIGHT = 27h
VK_DOWN = 28h

.ELSEIF uMsg==WM_KEYDOWN
  mov eax,wParam
  .IF (eax <= VK_DOWN) || (eax>=VK_LEFT)
    mov edx,eax
    invoke GetKeyNameText,edx,ADDR KeyBuffer,KEYSIZE
    .IF (eax<=VK_RIGHT)
      .IF (eax==VK_LEFT)
        ;LEFT CODE
      .ELSE
        ;RIGHT CODE
      .ENDIF
    .ELSEIF (eax==VK_DOWN)
      ;DOWN CODE
    .ELSE
      ;UPCODE
    .ENDIF
  .(elseif to process keys other than arrows, endif to end it)
.ELSEIF (other messages)

G`HOST

Hey thanx a lot.Problem solved. :U
I have started to like this forum and ppl here.Thanx again
But a question about string arrays. can we actually compare a given value/string with individual members of array or with the array as a whole and then know which member is equal to that value/string.

thomasantony

Hi,
   Use two arrays. One wit the strings like this

strings db 5,"Hello",4,BLah",0
myptrs dd DoHello,DoBlah,0

Compare each strings length andthen compare the strings(if lengths match). then take index of string with secon array to get address of the task to do for that string. For eg.

; if ebx has index (0 for hello, 1 for blah), esi points to myptrs
mov eax,[esi+ebx*4]
jmp eax

Hope you understood
Thomas :U
There are 10 types of people in the world. Those who understand binary and those who don't.


Programmer's Directory. Submit for free

G`HOST

Quote from: Infro_X on November 12, 2005, 05:37:36 PM
.ELSEIF uMsg==WM_KEYDOWN
  mov eax,wParam
  .IF (eax <= VK_DOWN) || (eax>=VK_LEFT)
    mov edx,eax
    invoke GetKeyNameText,edx,ADDR KeyBuffer,KEYSIZE
Shouldnt edx contain the value of "lParam" ??
From Win32.hlp......
Quote
The GetKeyNameText function retrieves a string that represents the name of a key.

int GetKeyNameText(

    LONG lParam,   // second parameter of keyboard message
    LPTSTR lpString,   // address of buffer for key name
    int nSize    // maximum length of key-name string length
   );

zooba

Quote from: G`HOST on November 13, 2005, 03:04:35 AM
Shouldnt edx contain the value of "lParam" ??

It does. Note the 'mov edx, eax' on the line above it ;)

BTW, I'd say you don't even need to call GetKeyNameText anymore:

mov eax, wParam
.if (eax == VK_UP)
  ; UP code
.elseif (eax == VK_DOWN)
  ; DOWN code
.elseif (eax == VK_LEFT)
  ; LEFT code
.elseif (eax == VK_RIGHT)
  ; RIGHT code
.else
  ; some other key
.endif

AeroASM

Quote from: zooba on November 14, 2005, 07:01:34 AM
It does. Note the 'mov edx, eax' on the line above it ;)

It doesn't. Note the "mov eax,wParam" two lines above that.

Quote from: G`HOST on November 12, 2005, 06:12:35 PM
But a question about string arrays. can we actually compare a given value/string with individual members of array or with the array as a whole and then know which member is equal to that value/string.

Yes. Define your strings, then use an array of pointers:

string1 db "first string",0
string2 db "second string",0
string3 db "third string",0

strarray dd offset string1,offset string2,offset string3


Now you compare your target string with each of the strings in the array and see if they match. Use lstrcmp.

G`HOST

hmmmmmmmmmmmmmmm     :red

Need to learn a lot about arrays and pointers.I will Get there .Soon.