Server Help

Trash Talk - Stupid Windows API

Cyan~Fire - Sat Apr 09, 2005 10:36 am
Post subject: Stupid Windows API
OK, I have to revamp a bit of WM_COMMAND-processing code I wrote for a new feature in a program I'm writing.

Now, it just so happened before that I didn't have to process a BN_CLICKED and a menu item click before, but now that I do, is it true that they both have a notification code of 0?!

MSDN Library wrote:
The high-order word specifies the notification code if the message is from a control. If the message is from an accelerator, this value is 1. If the message is from a menu, this value is zero.

winuser.h
Code: Show/Hide
/*
* User Button Notification Codes
*/
#define BN_CLICKED          0 //same as menu item click??
#define BN_PAINT            1 //same as accelerator message??
#define BN_HILITE           2
#define BN_UNHILITE         3
#define BN_DISABLE          4
#define BN_DOUBLECLICKED    5


If this is true, I guess I'm just going to have to handle both of them in the same case statement and just differentiate by ID? How messy.
Mr Ekted - Sat Apr 09, 2005 10:40 am
Post subject:
All commands should be handled by code AND id, otherwise you can confuse lots of messages. You can differentiate between menus, accelerators, and control notifications.
Cyan~Fire - Sat Apr 09, 2005 1:56 pm
Post subject:
Yeah, don't worry, I haven't been doing it just by code, I've been doing it by MAKELONG() with the full wParam. But sadly I can't do that now, since I'm processing the EN_SETFOCUS and EN_KILLFOCUS messages, and I somehow don't want to make a case for every single edit control I have.

What I find messy is simply this:
Code: Show/Hide
   switch (code)
   {
   case BN_CLICKED:   //and menuitem click!
   case CBN_SELCHANGE:   //and accelerator!
      switch (id)

I don't see why MS couldn't just allocate a range of numbers for each control. I mean, I really doubt that there are more than 65535 notifications, and the newer ones use WM_NOTIFY.

Anyway, thanks.
Mr Ekted - Sat Apr 09, 2005 2:44 pm
Post subject:
Yes I have often thought the same thing. In my command handler, I use if/else-if/else-if/else type statements. Doesn't have to be super efficient because commands are mostly at UI speed (ie user keys and clicks).

If you were ambitious, you could also combine code/id into a single value and switch on that.
Cyan~Fire - Sat Apr 09, 2005 3:53 pm
Post subject:
Ekted wrote:
If you were ambitious, you could also combine code/id into a single value and switch on that.

Yeah, that was what I was trying to say I had been doing above, but now I have many, many IDs for the same notification code, and I want to process them all the same.

(Are we the only Win32 programmers on this board?)
Mine GO BOOM - Sun Apr 10, 2005 1:41 am
Post subject:
Cyan~Fire wrote:
Are we the only Win32 programmers on this board?

No, just my UI skills are just crap. Take a look at 'pretty' the interface for my DeBuildlevel program was. I prefer to try and work on the background side of things, and leave the interface to someone else.

Of course, I've been working on trying to increase my UI skills, but have not had the time too much.
Solo Ace - Sun Apr 10, 2005 3:48 pm
Post subject:
Mine GO BOOM wrote:
No, just my UI skills are just crap.

Hah, if you call yours "crap" you haven't seen mine yet. sa_tongue.gif
Every time I try to get a nice GUI on a program I end up getting annoyed because things don't work how I want them to work or just, well, don't work at all. icon_sad.gif
I might start trying to skills ^ 2 again after this school year.
CypherJF - Sun Apr 10, 2005 5:14 pm
Post subject:
I didn't even know where to begin, most of the pages I lookup uses MFC or some variant of it.
Mr Ekted - Sun Apr 10, 2005 5:32 pm
Post subject:
MFC is like a virus. It took over Win32 API without improving it. It now dominates all searches for any real info.
Smong - Sun Apr 10, 2005 8:53 pm
Post subject:
I had a go at some GUI stuff last weekend. I had to port my code to c++ since that's what wxWidgets uses. It made the program 5 times bigger.
When I got round to installing the wx devpak in devcpp the barebones program int the project template is 1.8mb (statically linked I believe). The gtk libs were over 6mb themselves so wx is an improvement in a way.
Mr Ekted - Sun Apr 10, 2005 9:29 pm
Post subject:
My win32 apps (statically linked) are usually in the 20-60K area, unless they have a ton of resources in them.
Cyan~Fire - Sun Apr 10, 2005 11:00 pm
Post subject:
Eek. My program is 100K! It's dynamically linked, which by my understanding, should make it smaller? What's wrong?
Mr Ekted - Mon Apr 11, 2005 12:48 am
Post subject:
Straight win32? No other non-OS libs? No wrappers like MFC, etc? Large resources? Release mode compile?
CypherJF - Mon Apr 11, 2005 1:40 pm
Post subject:
Mr Ekted wrote:
MFC is like a virus. It took over Win32 API without improving it. It now dominates all searches for any real info.


Time to write your book now icon_wink.gif show us newb programmers how to do it right tongue.gif
Cyan~Fire - Mon Apr 11, 2005 5:46 pm
Post subject:
Well, I am using zlib.

Code: Show/Hide
## Makefile for AOK Trigger Studio by David Tombs

#Check for CFG macro

!IF "$(CFG)" == ""
!MESSAGE No configuration specified. Defaulting to Win32 Debug.
!MESSAGE
CFG=Win32 Debug
!ENDIF


#Release build
!IF  "$(CFG)" == "Win32 Release"

OUTDIR=.
INTDIR=.\Release

CPPFLAGS_OPT = -ML -O2
LINK32_FLAGS = /release /incremental:no

#Debug build
!ELSEIF  "$(CFG)" == "Win32 Debug"

OUTDIR=.\Debug
INTDIR=.\Debug

CPPFLAGS_DEBUG = -MLd -Gm -D "_DEBUG" -FAs -Fa"asm/" -Zi -Fd"$(INTDIR)\\"
LINK32_FLAGS = /debug /pdbtype:sept
RFLAGS_DEBUG = /D "_DEBUG"

!ELSE

!ERROR Invalid configuration "$(CFG)" specified.

!ENDIF

LINK_LIBS=zlib.lib user32.lib comdlg32.lib comctl32.lib advapi32.lib
CPPFLAGS = -c $(CPPFLAGS_DEBUG) $(CPPFLAGS_OPT) -YX -Fo"$(INTDIR)\\" -D WINVER=0x0400 -EHsc -W3
RFLAGS = /fo "$(INTDIR)\AOKTS.res" $(RFLAGS_DEBUG)

LINK_OBJS = \
   $(INTDIR)/aokts.obj \
   $(INTDIR)/datatypes.obj \
   $(INTDIR)/editors.obj \
   $(INTDIR)/scen.obj \
   $(INTDIR)/scen_const.obj \
   $(INTDIR)/trigedit.obj \
   $(INTDIR)/ecedit.obj \
   $(INTDIR)/utilui.obj \
   $(INTDIR)/zlibfile.obj \
   $(INTDIR)/unitedit.obj \
   $(INTDIR)/trigger.obj \
   $(INTDIR)/utilio.obj \
   $(INTDIR)/AOKTS.res

#Inference Rules

.cpp{$(INTDIR)}.obj:
   cl $(CPPFLAGS) $<

.rc{$(INTDIR)}.res:
   rc $(RFLAGS) $<

#Targets

build: $(OUTDIR)\aokts.exe
   @echo Build complete.

source: $(OUTDIR)\source.zip
   @echo Source zipped.

#Build targets

$(OUTDIR)\aokts.exe: $(LINK_OBJS)
   link.exe $(LINK32_FLAGS) /out:"$@" /pdb:"$(OUTDIR)\aokts.pdb" $(LINK_LIBS) $(LINK_OBJS)

$(LINK_OBJS):

#Source targets: yes, this is a stupid version of a batch file.

TEMPFILES=aokts.cpp datatypes.cpp editors.cpp scen.cpp scen_const.cpp trigedit.cpp utilui.cpp zlibfile.cpp ecedit.cpp unitedit.cpp

$(OUTDIR)\source.zip: *.cpp *.h aokts.rc src_notes.txt MAKEFILE res\aokts_big.bmp res\aokts.ico
   @"C:\Program Files\7-zip\7z" u $(OUTDIR)\source.zip $**

!INCLUDE makefile.dep

Mr Ekted - Mon Apr 11, 2005 5:58 pm
Post subject:
My static zlib.lib is 66K in release mode. It's a build I made with just the stuff I've used. For example, I don't use the file stuff. I have no idea how much bigger this lib makes the EXE though.
Cyan~Fire - Mon Apr 11, 2005 6:30 pm
Post subject:
The dynamic one with all the functions I'm using is 10.5K.
Mr Ekted - Mon Apr 11, 2005 6:55 pm
Post subject:
Dynamic means the EXE will use an external DLL.
Cyan~Fire - Mon Apr 11, 2005 7:52 pm
Post subject:
But it still needs a lib to link to, right? I looked in zlib.lib with a hex editor, and it seems it's just a bunch of function names and offsets.
Mr Ekted - Mon Apr 11, 2005 8:11 pm
Post subject:
A dynamic lib simply lists the exports that are in the DLL. This allows the linker to know that they exist, and to place the appropriate references in the EXE header so the loader knows to load zlib.dll and what functions to find/resolve.
Cyan~Fire - Mon Apr 11, 2005 8:45 pm
Post subject:
OK, that's what I thought. So... any clue what's going on? The source itself is 160K, if that's around the range you're looking for.
Mr Ekted - Mon Apr 11, 2005 9:39 pm
Post subject:
You use anything gay like STL?
Cyan~Fire - Tue Apr 12, 2005 3:55 pm
Post subject:
I don't use STL, but I use one template class that I wrote. I guess that does take up a bit of room, as it's used for 4 different classes, so 4 different copies.

But it's nowhere near STL which includes around 10 templates for one you use in your code.
Cyan~Fire - Mon Jun 20, 2005 9:05 pm
Post subject:
Off topic, but still Stupid Windows API.

Any way to catch a return sent to an edit control other than by subclassing? Of course, only common controls send NM_RETURN (not to mention WM_NOTIFY in general, which only makes command processing 50 times easier).
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group