flat assembler
Message board for the users of flat assembler.

Index > Windows > SetWindowLong & WM_CHAR

Author
Thread Post new topic Reply to topic
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 22 Jun 2007, 17:09
Hello,

I have two problems:

1. I'm having some trouble with the SetWindowLong API.

Code:
invoke CreateWindowEx,0,'BUTTON','Caption',WS_CHILD+WS_VISIBLE+WS_TABSTOP+BS_AUTOCHECKBOX+BS_FLAT,10,66,100,22,[hwnd],OvrWrtChckBoxID,[wc.hInstance],0
mov [hOvrWrtChckBox],eax
...
invoke SetWindowLong,[hOvrWrtChckBox],GWL_STYLE,WS_CHILD+WS_VISIBLE+WS_TABSTOP+BS_AUTOCHECKBOX
    

The auto-check box is not updated until I click it. The return value is non-zero as it should be.

Code:
invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW,'EDIT',0,WS_CHILD+WS_VISIBLE+WS_BORDER+ES_LEFT+ES_AUTOHSCROLL+ES_AUTOVSCROLL+WS_TABSTOP,10,38,200,22,[hwnd],KeyEditID,[wc.hInstance],0
mov [hKeyEdit],eax
...
invoke SetWindowLong,[hKeyEdit],GWL_STYLE,WS_CHILD+WS_VISIBLE+WS_BORDER+ES_LEFT+ES_AUTOHSCROLL+ES_AUTOVSCROLL+WS_TABSTOP+ES_PASSWORD
    

With the editbox, it's even worse. Some parts of the window lose focus and cannot be controled anymore, the program's system menu (Minimize, Maximize, Close, ...) disappears.

Isn't this API supposed to be used like that? Am I missing something?


2. I'm trying to count how many times the user types characters in an edit box. But the WM_CHAR message seems to be firing up only when keys are pressed OUTSIDE the edit box, which is not really useful.
What's the problem?


Thanks for your replies.
Post 22 Jun 2007, 17:09
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 22 Jun 2007, 17:17
As I see all you are doing is creating the windows (edits, auto-checks, etc) and then setting the style with SetWindowLong with almost the same style that you used with CreateWindowEx. If you want to trap the messages you have to change the window procedure of the window, not its style.

Here you have a full example http://win32assembly.online.fr/tut20.html
Post 22 Jun 2007, 17:17
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 22 Jun 2007, 18:54
Hello,

my program does more than this. This is just an excerpt, hence the "...".
And I'm not trying to trap messages at all. It's in my second problem that I'm trying to trap key presses in a specific edit box.

In the first problem, I'm only trying to modify the controls styles. I must reuse the same styles and add the newer ones because the old styles get overwritten when using SetWindowLong, AFAIK.

These are two separate problems. As I said:
Quote:
I have two problems
Post 22 Jun 2007, 18:54
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 22 Jun 2007, 19:11
Quote:

And I'm not trying to trap messages at all. It's in my second problem that I'm trying to trap key presses in a specific edit box.

How do you propose to get the key presses without getting the window messages? If you look at the example you will found exactly what you want (except that the new handler forbids non hex keys while you just want to get the keys).

Sorry for the misunderstanding, I don't know why your first problem doesn't work. Try with UpdateWindow passing as paramenter the hwnd of the control but I bet it will fix only the checkbox, no the editbox problem.

PS: Instead of changing the Editbox style try with EM_SETPASSWORDCHAR that seems it will do what you need.
Post 22 Jun 2007, 19:11
View user's profile Send private message Reply with quote
handyman



Joined: 04 Jun 2007
Posts: 40
Location: USA - KS
handyman 23 Jun 2007, 05:40
Some thoughts here:

for problem 1 autocheckbox: You may want to check out the 'CheckDlgButton' function and associated functions listed in the Win32 programmer's reference.

for problem 2: According to definition WM_CHAR is only sent to the window that has the current keyboard focus. So, does the edit window have the current keyboard focus?
Post 23 Jun 2007, 05:40
View user's profile Send private message Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 23 Jun 2007, 06:28
LocoDelAssembly,
Quote:
How do you propose to get the key presses without getting the window messages? If you look at the example you will found exactly what you want (except that the new handler forbids non hex keys while you just want to get the keys).

Yes, I read it. Thank you. Iczelion's tutorials are always the best.
The "I'm not trying to trap messages at all" was for my first problem actually. Of course I'll have to read Window's messages, you're right. So I'm sorry too for any confusion.

Quote:
Try with UpdateWindow passing as paramenter the hwnd of the control but I bet it will fix only the checkbox, no the editbox problem.

It didn't work with neither of them.

Quote:
PS: Instead of changing the Editbox style try with EM_SETPASSWORDCHAR that seems it will do what you need.

It didn't work either. What's even more incredible is that I tried creating the editbox using the ES_PASSWORD style and it showed the asterisks, but when I used EM_SETPASSWORDCHAR with no parameter it didn't reset to normal:
Code:
invoke SendMessage,[hKeyEdit],EM_SETPASSWORDCHAR,0,0    



handyman,
Quote:
According to definition WM_CHAR is only sent to the window that has the current keyboard focus.

It is set with SetFocus if that's what you're asking.
Anyway, that problem should be resolved with the code LocoDelAssembly linked to.
Post 23 Jun 2007, 06:28
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 23 Jun 2007, 07:20
Quote:
It didn't work with neither of them.


Dosn't surprise me. One thing i've learned when messing around with things is that you should never trust WM_PAINT. Though, i'm sure some one will beg to differ, my personal experience is that it's a little unpredictable. Same with WM_MOUSEMOVE. I tried once to check if my mouse moved or not, and i found out that even when my mouse isn't moving, for some reson it sends the message anyway.

Another thing that i noticed is that you're doing things with +. I've seen alot of people do that and i've found that if you do that you can present the problem i'll illistrate below.

FLAG1 = 1
FLAG2 = 2

FLAG1+FLAG2=3 (Works as you want.)
FLAG1+FLAG1=FLAG2 (UH OH)

FLAG1 or FLAG2 = 3 (Works as you want.)

FLAG1 or FLAG1 = 1 (What you want)

I don't know what the constants are, but you could have a few things going haywire there because some of your flags (maybe even ones already attributed to the window) may have binary values that colide, making them a hire number.

EDIT: I've seen this kind of thing alot. And i've found it to be one of the biggest problems to some one who accidentally puts the same flag twice, because everything but that extra flag works. Chances are, doing this will give you the problem sooner or later, but in many situations, you're noticing you already have that style in the window and don't want to add it so doing this will be just like oring them together, but if you don't or them, a situation like this could occure.
Post 23 Jun 2007, 07:20
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 23 Jun 2007, 09:27
Correction: sending the EM_SETPASSWORDCHAR message works perfectly. I was just doing the most stupid mistake after creating the editbox:
Code:
invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW,'EDIT',0,WS_CHILD+WS_VISIBLE+WS_BORDER+ES_LEFT+ES_AUTOHSCROLL+ES_AUTOVSCROLL+WS_TABSTOP,10,38,200,22,[hwnd],KeyEditID,[wc.hInstance],0
invoke SetFocus,eax
mov [hKeyEdit],eax
    

No wonder I had hard time using this "handle".

One more thing, the changes only take place when I click on the editbox, so I had to add a second SetFocus right after sending the EM_SETPASSWORDCHAR message. Is that normal?
Post 23 Jun 2007, 09:27
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 23 Jun 2007, 09:36
I never messed with it much, but it wouldn't surprise me. I've seen lots of programs having to resort to such patchwork before. The reson could be the fact that when a window (not neccessarily children) goes out of focus, it's because another window comes ontop of it. Usually those windows don't update much, so windows probably has it in implimentation that windows out of focus don't get messages immediately or at all. It might set the priority low and it's sending initialization messages (WM_SIZE, WM_PAINT, etc) to it before your message, and if it's priority's lower, it might be slowly sending each message. For that reason, i (this is purely preferencial and probably less efficient than patchwork, but i just can't stand patching) would either use sub-classing or super-classing for password input if i needed it from the start, but if i was going to use password input, i'd probably just send the message cause it'll come into focus when the user clicks the box to put input in it.
Post 23 Jun 2007, 09:36
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
ManOfSteel



Joined: 02 Feb 2005
Posts: 1154
ManOfSteel 23 Jun 2007, 12:54
kohlrak,
In general you only use a few flags at a time. It should be quite easy to notice that you retyped the same flag twice and see inconsistencies between what you wrote and what is displayed.
But you're right it's a more proper habit to use "or" instead of "+".
Post 23 Jun 2007, 12:54
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak 23 Jun 2007, 13:19
Quite easy, but so is noticing you're using the wrong handle. Accidents happen. I'm not going to be one of them. XD
Post 23 Jun 2007, 13:19
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.