Solved

Window proc vs. Dialog proc?

Posted on 1997-10-27
14
1,400 Views
Last Modified: 2013-12-03

What is the difference between a window procedure and a dialog procedure?

I tried subclassing a dialog and it didn't work when I used DWL_DLGPROC but worked OK when I used GWL_WNDPROC.  Why?

MSVC help is confusing.  It says:
"Dialog boxes usually belong to a predefined, exclusive window class. Windows uses this window class and its corresponding window procedure for both modal and modeless dialog boxes. When the function is called, it creates the window for the dialog box, as well as the windows for the controls in the dialog box, then sends selected messages to the dialog box procedure. While the dialog box is visible, the predefined window procedure manages all messages, processing some messages and passing others to the dialog box procedure so that the procedure can carry out tasks. Applications do not have direct access to the predefined window class or window procedure, but they can use the dialog box template and dialog box procedure to modify the style and behavior of a dialog box."

Can you explain that one?
0
Comment
Question by:alexo
  • 7
  • 5
  • 2
14 Comments
 
LVL 3

Expert Comment

by:vinniew
ID: 1407929
The wndProc equivalent for a dialog box is done internally to speed it up and use less resources.  It's not that difficult to switch to using a wndProc, and you'll get the same result.


what are you subclassing, anyway?  Edit control?

Hasta,
v

0
 
LVL 11

Author Comment

by:alexo
ID: 1407930
I'm in my dense mode today.  Care to explain your answer?  I didn't get it.

I'm subclassing a dialog consisting of several controls.
I need to do it cause it belongs to another application.

0
 
LVL 3

Expert Comment

by:vinniew
ID: 1407931
Oh, so you're hooking a DlgProc, or trying to, anyway.  What are you trying to do to the dialog?

Hasta,

V

0
 
LVL 3

Expert Comment

by:vinniew
ID: 1407932
I meant, specifically, what are you trying to do to the dialog?

V

0
 
LVL 11

Author Comment

by:alexo
ID: 1407933
I added a button to it + some functionality.

however, let's get back to the question.

Subclassing via SetWindowLong(DWL_DLGPROC) failed but subclassing via SetWindowLong(GWL_WNDPROC) works.  Why?  Common sence says it should be the other way around.


0
 
LVL 3

Expert Comment

by:vinniew
ID: 1407934
If you notice, anything created by MFC, dialog box or not, compiles down to using wndProc. I would bet that the dialog box you're trying to screw with was created with MFC and not by straight C.

You can test this idea by using the listdlls.exe off www.ntinternals.com; if it's using MFCxxx.dll, it was created using MFC.

What do you think?

Hasta,
V

0
 
LVL 11

Author Comment

by:alexo
ID: 1407935
I'm not using MFC.  It's straight C and Win32 API.

0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 3

Expert Comment

by:vinniew
ID: 1407936
OK, you're not using MFC, but what about the dialog box?
I think that it was probably compiled with MFC if it isn't responding to dlgproc-specific hooks.

V

0
 
LVL 11

Author Comment

by:alexo
ID: 1407937
It was compiled with OWL.

0
 
LVL 11

Author Comment

by:alexo
ID: 1407938
Anybody?
0
 
LVL 11

Author Comment

by:alexo
ID: 1407939
Come on, 100 points are waiting...
0
 
LVL 1

Accepted Solution

by:
Tiutin earned 100 total points
ID: 1407940
The Platworm SDK Documentation says:

"...The SetWindowLong function creates the subclass by changing the window procedure associated with a particular window, causing Windows to call the new window procedure instead of the previous one. An application must pass any messages not processed by the new window procedure to the previous window procedure by calling CallWindowProc. This allows the application to create a chain of window procedures.

To subclass an instance of a window, call the SetWindowLong function and specify the handle of the window to subclass the GWL_WNDPROC flag and a pointer to the subclass procedure. SetWindowLong returns a pointer to the original window procedure; use this pointer to pass messages to the original procedure. The subclass window procedure must use the CallWindowProc function to call the original window procedure...".

I would add to the above your lines about special character of a dialog box - <<...While the dialog box is visible, the predefined window procedure manages all messages, processing some messages and passing others to the dialog box procedure so that the procedure can carry out tasks. Applications do not have direct access to the predefined window class or window procedure, but they can use the dialog box template and dialog box procedure to modify the style and behavior of a dialog box.>>
That's all. Is this an answer? Suppose you are looking for a more deep explanation.
0
 
LVL 11

Author Comment

by:alexo
ID: 1407941
Suppose I am :-)

This begins to make sence but I'd like some more details if possible.


0
 
LVL 1

Expert Comment

by:Tiutin
ID: 1407942
SDK Documentation says further:

"...When Windows starts, it registers a set of system global classes. The following table describes the system global classes:

Class            Description

Button            The class for a button.
ComboBox      The class for a combo box.
ComboLBox      The class for the list box contained in a combo box.
Edit            The class for an edit control.
ListBox            The class for a list box.
MDIClient      The class for an MDI client window.
Message            The class for a message-only window (Windows NT 5.0 and later).
ScrollBar      The class for a scroll bar.
Static            The class for a static control.
#32768            The class for a menu.
#32769            The class for the desktop window.
#32770            The class for a dialog box.
#32771            The class for the task switch window.
#32772            The class for icon titles (Windows NT only).

An application can subclass any window in the system;
however, when subclassing a window it does not own,
the application must ensure that the subclass procedure
does not destroy the original behavior of the window.
Because the application does not control the window,
it must not depend on information about the window
that the owner might change in the future.

An application should not use the extra window bytes or
the class bytes for a window without knowing exactly
what the bytes mean and how the original window procedure
uses them. Even so, the application should not use them
unless it owns the window.
If the application uses the extra window bytes of a window
that another application owns and the owner changes some
aspect of the extra bytes, the subclass procedure may fail.
For this reason, an application should not subclass a window
that belongs to a system global control class.
Windows owns the system global classes, and aspects of the
controls might change from one version of Windows to the next.
If the application must subclass a window that belongs to a
system global class, the developer may need to update the
application when a new version of Windows is released...".

I guess this is a reason why dialog box subclassing may fail.
Regards.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now