flat assembler
Message board for the users of flat assembler.

Index > Windows > [SOLVED] HIWORD and LOWORD

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
frech



Joined: 10 Mar 2009
Posts: 31
frech
Hi. Trying to learn asm and winapi, I'm writing a simple ide (not yet for fasm, but for Inform Wink ). I use a "normal" edit control (for now; in the future... who knows), and thanks to you all I managed to create the code to load and save the text, even if I don't understand all of the code.
Now I'm facing a little problem regarding the function to create a new file. I want to implement a simple way to make this check: if the user has modified the edit control's content AND not saved the file, ask before erasing the content of the control itself. Of course, this would be the same routine for quitting the program without saving, in the future.
I know I can
Code:
mov [notsaved],1    

or something like that, but how can I perform this check?
I know I have to check the HiWord and the LoWord of wparam in order to see if the control IDC_EDIT has been modified and if the message is EN_CHANGE... but it doesn't work.
Here's the code I wrote after googling a lot looking for an answer:
Code:
          mov eax, [wparam]
          .if ax,e,IDC_EDIT
            shr eax,16
            .if ax,e,EN_CHANGE
                invoke SendMessage,[hEdit],WM_SETTEXT,0,0
            .endif
          .endif
    

Where do I make a mistake?
Thanks in advance to anybody who can help.


Last edited by frech on 17 Mar 2009, 09:05; edited 1 time in total
Post 16 Mar 2009, 08:59
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
What comes after the last .endif? Do you use the value in eax again or do you reload it from [wparam] again?

What is "invoke SendMessage,[hEdit],WM_SETTEXT,0,0" going to do? It will erase the edit space. Is that what you want to do every time the user tries to make a change?
Post 16 Mar 2009, 11:38
View user's profile Send private message Visit poster's website Reply with quote
frech



Joined: 10 Mar 2009
Posts: 31
frech
After the last .endif there's just a jmp to the end of the examination of WM_COMMAND, that's why I did not write it. The above code, of course, should be executed only in cases such as: does the user want to quit without saving? If the text has changed and variable "saved" is not set, the user will be prompted. Of course this code is going to be execute if and only if the user choses the menu option NEW or QUIT (and also OPEN, as the program will be SDI), and of course there must be a check on that "saved" variable, I don't want the edit control to erase itself on each key pression... Wink
My problem is just to get the value of hiword(wparam) and loword(wparam). This will be useful also for other WinAPI message, of course.
Post 16 Mar 2009, 13:15
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
So what is not working exactly?

After the second ".if" I would expect you want to put "mov [notsaved],1" instead of what you have there. Then when you get the "close" message you can check the notsaved variable and decide what to do from that.
Post 16 Mar 2009, 13:19
View user's profile Send private message Visit poster's website Reply with quote
frech



Joined: 10 Mar 2009
Posts: 31
frech
Hi revolution. I tried also that solution, but no way: the .if condition (don't know if the first or the second) is not met, so the code after the last .endif is run in all cases. Maybe I'm wrong in how to get hiword or loword?
I attach the source. Before throwing it into the trashcan (or /dev/null) please remember that I'm still beginning both asm and WinAPI... I will optimize it and give it a better look once I get it working. The source is far from complete, I'm just working on the gui and the main commands for now, that's why you won't find find/replace and other things...
Thanks.


Description:
Download
Filename: ISIDE.zip
Filesize: 3.67 KB
Downloaded: 41 Time(s)

Post 16 Mar 2009, 13:43
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
frech wrote:
... so the code after the last .endif is run in all cases.
Oh, is this the problem? If so, then you need to put code inside the .if/.endif structure to jmp to somewhere else that skip following tests. Usually something like "jmp .processed" or similar.
Code:
          mov eax, [wparam]
          .if ax,e,IDC_EDIT
            shr eax,16
            .if ax,e,EN_CHANGE
                mov [notsaved],1
                jmp .somewhereElse ;<--- add this.
            .endif
          .endif    
Post 16 Mar 2009, 14:09
View user's profile Send private message Visit poster's website Reply with quote
frech



Joined: 10 Mar 2009
Posts: 31
frech
Hi. Try and substitute in my code the content of ..creanuovo: with the following lines:
Code:
      ..creanuovo:
          mov eax, [wparam]
          .if ax,e,IDC_EDIT
            shr eax,16
            .if ax,e,EN_CHANGE
                invoke SendMessage,[hEdit],WM_SETTEXT,0,0
            .endif
          .endif
          jmp   ..wmCOMMAND_COMMAND_EXIT_POINT    

You will see that SendMessage will not be executed. So the problem must be in getting hiword(wparam) and loword(wparam).
Post 16 Mar 2009, 14:22
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
I'm still not sure what is wrong or what you are trying to achieve? Can you please explain in more detail what exactly is not working the way you expect.

There seem to be conflicting goals, one is to save the user edit space before quitting and the other is to erase the user edit space when the users changes something.
Post 16 Mar 2009, 15:00
View user's profile Send private message Visit poster's website Reply with quote
frech



Joined: 10 Mar 2009
Posts: 31
frech
I need to implement a way to check for the file being saved on disk
- when the user wants to quit the program
- when the user wants to open another file
- when the user wants to create a new file
I learnt from google that in order to do that I need to check if the edit control has been modified, and that to do it I need to check the value of the hiword and the loword of the wparam message, set a variable to a certain value according to those hiword/loword and check the value of that variable when the user chooses one of the above mentioned options.
The problem is that I can't get those values, so I can't perform any check.
Post 16 Mar 2009, 15:14
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2913
Location: [RSP+8*5]
bitRAKE
if the values are unsigned:

movzx eax,word[wparm] ; LOWORD
movzx ecx,word[2+wparm] ; HIWORD

or with older processors:

mov eax,[wparm]
mov ecx,eax
and eax,$FFFF ; LOWORD
shr ecx,16 ; HIWORD

if the values are signed:

movsx eax,word[wparm] ; LOWORD
movsx ecx,word[2+wparm] ; HIWORD

or with older processors:

mov eax,[wparm]
mov ecx,eax
shl eax,16
sar ecx,16 ; HIWORD
sar eax,16 ; LOWORD
Post 16 Mar 2009, 17:20
View user's profile Send private message Visit poster's website Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1137
Location: Russian Federation
comrade
bitRAKE wrote:
or with older processors:

mov eax,[wparm]
mov ecx,eax
and eax,$FFFF ; LOWORD
shr ecx,16 ; HIWORD


Those would be some very old processors Razz

Though we didn't have a discussion recently about some newer VIAs or some other embedded x86 clones not supporting cmov?

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 16 Mar 2009, 17:26
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2913
Location: [RSP+8*5]
bitRAKE
I guess the odds of someone both using a 286,
and running Windows on it are quite low. Laughing

_________________
¯\(°_o)/¯ unlicense.org


Last edited by bitRAKE on 17 Mar 2009, 05:28; edited 1 time in total
Post 16 Mar 2009, 17:30
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
bitRAKE wrote:
I guess the odds of someone both using a 286,
and running Windows on it are quite low. Laughing

I guess the odds of someone running Win32 on 286 machine are like... zero? Wink
Post 16 Mar 2009, 17:34
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo
comrade wrote:
bitRAKE wrote:
or with older processors:

mov eax,[wparm]
mov ecx,eax
and eax,$FFFF ; LOWORD
shr ecx,16 ; HIWORD


Those would be some very old processors Razz


I assume he means for speed, e.g. original Pentiums (not PPro/PII), which supposedly run MOV[SZ]X slower than otherwise.

Quote:

Though we didn't have a discussion recently about some newer VIAs or some other embedded x86 clones not supporting cmov?


Some so-called older 686s of VIA didn't support CMOV (which caused Ubuntu and/or Debian to only tune for "486"). Even some early PPros may not either (although GCC has always, possibly erroneously, assumed -march=ppro or =i686 means CMOV.. is supported.)

Quote:

Quote:

I guess the odds of someone both using a 286,
and running Windows on it are quite low. Laughing


I guess the odds of someone running Win32 on 286 machine are like... zero? Wink


Win95 needs a 386. WinXP needs a 586 (in reality, even newer). IIRC, the last Windows to support a 286 was Win 3.1 "standard mode" (not WfW 3.11).
Post 17 Mar 2009, 03:38
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
Tomasz Grysztar wrote:
bitRAKE wrote:
I guess the odds of someone both using a 286, and running Windows on it are quite low. Laughing

I guess the odds of someone running Win32 on 286 machine are like... zero? Wink
Not zero, but not high.

Ever heard of an emulator? I think with old Win3.1 and the Win32S extension one could find an old 286 machine with lots of ram/hdd and emulate. Although it would probably run like a snail into a gale force head wind.

I have emulated 64bit on my 32bit machine so it's not like it is impossible.
Post 17 Mar 2009, 04:43
View user's profile Send private message Visit poster's website Reply with quote
frech



Joined: 10 Mar 2009
Posts: 31
frech
bitRAKE wrote:
if the values are unsigned:

movzx eax,word[wparm] ; LOWORD
movzx ecx,word[2+wparm] ; HIWORD

or with older processors:

mov eax,[wparm]
mov ecx,eax
and eax,$FFFF ; LOWORD
shr ecx,16 ; HIWORD

if the values are signed:

movsx eax,word[wparm] ; LOWORD
movsx ecx,word[2+wparm] ; HIWORD

or with older processors:

mov eax,[wparm]
mov ecx,eax
shl eax,16
sar ecx,16 ; HIWORD
sar eax,16 ; LOWORD

Sorry, I can't understand very well... yet. Would You be so kind to quote the entire code snippet for this kind of operation? Just to try, in the code I submitted I've tried to change the ..creanuovo routine this way:
Code:
..creanuovo:
          mov eax, [wparam]
          movzx ecx,word[2+wparam]
          .if cx,e,IDC_EDIT
            movzx eax,word[wparam]
            .if ax,e,EN_CHANGE
                invoke SendMessage,[hEdit],WM_SETTEXT,0,0
            .endif
          .endif
          jmp   ..wmCOMMAND_COMMAND_EXIT_POINT    

without setting any variable, just to test. No way. Of course I've mistaken...
Post 17 Mar 2009, 07:27
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
frech: Why do you have this line "invoke SendMessage,[hEdit],WM_SETTEXT,0,0"? That does not make sense. I think that will also cause a EN_CHANGE message to be sent, so you might end up with a second way around the loop doing things twice. I'm not sure how the edit box works internally, but I don't think it is a good idea to put that line in.

May I suggest instead that you put a message box and pop up a window for you to see when something is triggered. It may enlighten your way to see what is happening inside the loop.
Post 17 Mar 2009, 08:00
View user's profile Send private message Visit poster's website Reply with quote
frech



Joined: 10 Mar 2009
Posts: 31
frech
Yeah, I put that line just to cause a reaction in case I can get the HIWORD and the LOWORD correctly. When I find that it works, I'll know I get the correct way to read those HIWORD and LOWORD. I tried using MessageBox instead, but I got the same result. That's why I think I have mistaken something and I can't get those parameters.
Post 17 Mar 2009, 08:13
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7721
Location: Kraków, Poland
Tomasz Grysztar
revolution wrote:
Ever heard of an emulator? I think with old Win3.1 and the Win32S extension one could find an old 286 machine with lots of ram/hdd and emulate. Although it would probably run like a snail into a gale force head wind.

But then the emulator would emulate MOVZX/MOVSX aswell, so I think it's not related to the problem metioned here. Smile
Post 17 Mar 2009, 08:36
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
Okay I just downloaded your code to see what you have done.

Code:
        cmp     [wparam],IDM_NEW
        je      ..controlla

...

      ..controlla:
          ; FIXME: metti controllo: c'è già un file modificato o no?
          mov eax, [wparam]
          .if ax,e,IDC_EDIT
            shr eax,16
            .if ax,e,EN_CHANGE
                mov     [NotSaved],1
            .endif
          .endif
          cmp   [NotSaved],1
          je    ..creanuovo
          jmp   ..wmCOMMAND_COMMAND_EXIT_POINT    
You can't do it like that. When the jmp to ..controlla is made the wparam value is IDM_NEW, so it will never be the EN_CHANGE value.


Win32 docs wrote:
WM_COMMAND
wNotifyCode = HIWORD(wParam); // notification code
wID = LOWORD(wParam); // item, control, or accelerator identifier
hwndCtl = (HWND) lParam; // handle of control


You should only check the high word of wparam in the .wmcommand section.
Code:
  .wmcommand:
        cmp     word[wparam],IDM_NEW
        je      ..somewhereElse
        cmp     word[wparam+2],EN_CHANGE
        je      ..controlla

...

      ..controlla:
          mov ax, word[wparam+0]
          .if ax,e,IDC_EDIT
                mov     [NotSaved],1
          .endif
          jmp   ..wmCOMMAND_COMMAND_EXIT_POINT    
Post 17 Mar 2009, 08:56
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.