| | |
Small Visual C++ doubt.
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Aug 2009
Posts: 7
Reputation:
Solved Threads: 0
In visual c++, what is the difference between these three:
WindowClass.style = CS_HREDRAW | CS_VREDRAW; //Found in winmain()
UpdateWindow(hWnd); // Also found in winmain()
WM_PAINT //It is a switch case in funtion winproc()
I unerstand that all three of them does something like to draw/redraw the client window/window. But can someone elaborate abit about these three in simple and their difference in simple terms.
Thank you.
WindowClass.style = CS_HREDRAW | CS_VREDRAW; //Found in winmain()
UpdateWindow(hWnd); // Also found in winmain()
WM_PAINT //It is a switch case in funtion winproc()
I unerstand that all three of them does something like to draw/redraw the client window/window. But can someone elaborate abit about these three in simple and their difference in simple terms.
Thank you.
•
•
Join Date: Aug 2008
Posts: 83
Reputation:
Solved Threads: 18
C++ Syntax (Toggle Plain Text)
WindowClass.style = CS_HREDRAW | CS_VREDRAW
C++ Syntax (Toggle Plain Text)
UpdateWindow()
C++ Syntax (Toggle Plain Text)
WM_PAINT
•
•
Join Date: Jul 2008
Posts: 134
Reputation:
Solved Threads: 14
These three items you mention refer to three distinct stages in the creation of a window using the low level Windows Api (the best way to program Windows in my opinion).
Before you can create a window you fill out all the fields of a WNDCLASSEX structure. This...
WindowClass.style = CS_HREDRAW | CS_VREDRAW;
pertains to the setting of one of the many fields (10 or so). It tells the operating system that when a window of the class szClassName is instantiated, and any change occurs to the window, the whole window should be redrawn (Windows will send a WM_PAINT message).
Note that the filling out of all the fields of a WNDCLASSEX structure is done before any windows of the class specified by the sz.ClassName field can be created/instantiated. In that sence, it represents the 1st step.
Once all the fields of the WNDCLASS striucture are filled out, one uses the RegisterClassEx() Api function to register the class with windows. the .szClassName field is of critical importance here. Let me digress for a moment.
Lets say I want to create an edit control (text box) with somewhat different characteristics than the standard/stock text box included with Windows. If I want to do that I create my own Window Class and fill out a WNDCLASSEX structure and specify the name of my new class/control through the .szClassName field. Lets say I call mine "MyEdit" . This would distinguish my edit control class from Windows own "edit" control class. Naturally, I'd have to fill in all the other fields too. And I'd have to RegisterClassEx() it too. At that point Windows would know about the general characteristics of a class known as "MyEdit".
At that point I could use the CreateWindowEx() function to create an actual instance of my "MyEdit" class with the specific characteristics I provide in the various parameters of the CreateWindowEx() call. For example, I might want my specific instance of the "MyEdit" class to be located at 75,90, in terms of x,y coordinates on the desktop, and I might want it to be a window 200 pixels wide and 225 pixels deep.
After the CreateWindowEx() call Windows will know what function to call when it wishes to provide information it has gleaned about your window because in filling out the fields of the WNDCLASSEX structure you would have provided Windows with the address of the Window Procedure to call in the lpWndProc field. If, immediately after your CreateWindowEx() call, you place a ShowWindow() call with the SW_SHOWNORMAL flag set, the window will probably become visible on your screen even without an UpdateWindow() call. However, the UpdateWindow() call forces a WM_PAINT message to be sent to the window's WndProc() function, and that message should cause a repainting of the window.
Hey! I'm not as good at explaining this as Charles Petzold! If you wish to persist at low level Api coding for Windows you absolutely need to get Petzold's Windows 95 or 98 book. They can be cheaply gotten used for a buck or two.
Having said that I do have tutorials on this subject at Jose Roca's forum for PowerBASIC programmers set up at...
http://www.jose.it-berater.org/smffo...hp?board=285.0
PowerBASIC might be something you would be interested in. I use different languages, but with Windows I invariably use the Windows Api. I commend you for attempting this. Stick with it.
Before you can create a window you fill out all the fields of a WNDCLASSEX structure. This...
WindowClass.style = CS_HREDRAW | CS_VREDRAW;
pertains to the setting of one of the many fields (10 or so). It tells the operating system that when a window of the class szClassName is instantiated, and any change occurs to the window, the whole window should be redrawn (Windows will send a WM_PAINT message).
Note that the filling out of all the fields of a WNDCLASSEX structure is done before any windows of the class specified by the sz.ClassName field can be created/instantiated. In that sence, it represents the 1st step.
Once all the fields of the WNDCLASS striucture are filled out, one uses the RegisterClassEx() Api function to register the class with windows. the .szClassName field is of critical importance here. Let me digress for a moment.
Lets say I want to create an edit control (text box) with somewhat different characteristics than the standard/stock text box included with Windows. If I want to do that I create my own Window Class and fill out a WNDCLASSEX structure and specify the name of my new class/control through the .szClassName field. Lets say I call mine "MyEdit" . This would distinguish my edit control class from Windows own "edit" control class. Naturally, I'd have to fill in all the other fields too. And I'd have to RegisterClassEx() it too. At that point Windows would know about the general characteristics of a class known as "MyEdit".
At that point I could use the CreateWindowEx() function to create an actual instance of my "MyEdit" class with the specific characteristics I provide in the various parameters of the CreateWindowEx() call. For example, I might want my specific instance of the "MyEdit" class to be located at 75,90, in terms of x,y coordinates on the desktop, and I might want it to be a window 200 pixels wide and 225 pixels deep.
After the CreateWindowEx() call Windows will know what function to call when it wishes to provide information it has gleaned about your window because in filling out the fields of the WNDCLASSEX structure you would have provided Windows with the address of the Window Procedure to call in the lpWndProc field. If, immediately after your CreateWindowEx() call, you place a ShowWindow() call with the SW_SHOWNORMAL flag set, the window will probably become visible on your screen even without an UpdateWindow() call. However, the UpdateWindow() call forces a WM_PAINT message to be sent to the window's WndProc() function, and that message should cause a repainting of the window.
Hey! I'm not as good at explaining this as Charles Petzold! If you wish to persist at low level Api coding for Windows you absolutely need to get Petzold's Windows 95 or 98 book. They can be cheaply gotten used for a buck or two.
Having said that I do have tutorials on this subject at Jose Roca's forum for PowerBASIC programmers set up at...
http://www.jose.it-berater.org/smffo...hp?board=285.0
PowerBASIC might be something you would be interested in. I use different languages, but with Windows I invariably use the Windows Api. I commend you for attempting this. Stick with it.
Last edited by Frederick2; Aug 5th, 2009 at 11:58 pm.
•
•
Join Date: Aug 2009
Posts: 7
Reputation:
Solved Threads: 0
Alright, so the first sends a request for the windows to be repainted whenever the width/height is edited by the user.
So, when this is there then what is the use of the second one(i.e update() ).
Aren't these both doing doing the samething? (i.e sending reapaint request whenever width/height is changing)
So, when this is there then what is the use of the second one(i.e update() ).
Aren't these both doing doing the samething? (i.e sending reapaint request whenever width/height is changing)
•
•
Join Date: Jul 2008
Posts: 134
Reputation:
Solved Threads: 14
•
•
•
•
Alright, so the first sends a request for the windows to be repainted whenever the width/height is edited by the user.
In contrast, an UpdateWindow() call can be made countless times during the execution of a running program. You need to grasp the concept of update regions possibly to fully understand this. A window can accumulate invalid regions without Windows automatically repainting it. To force an immediate WM_PAINT UpdateWindow can be used.
As I mentioned, you need to study a real solid three dimensional book with weight & mass to grasp all this.
•
•
Join Date: Aug 2008
Posts: 83
Reputation:
Solved Threads: 18
Sort of, the first one simply tells the system to request a repaint given those conditions. The
UpdateWindow(hWnd); function on the other hand, allows you to request an update when you need one. If you make some changes to the window, where you don't change the size, then you will need to request a repaint yourself. •
•
Join Date: Jul 2008
Posts: 134
Reputation:
Solved Threads: 14
•
•
•
•
Sort of, the first one simply tells the system to request a repaint given those conditions. The UpdateWindow(hWnd); function on the other hand, allows you to request an update when you need one. If you make some changes to the window, where you don't change the size, then you will need to request a repaint yourself.
I have Ivor Horton's VC++ 6 (around 2000 or so) "Beginning C++ 6" book. In that edition anyway there was one chapter devoted to Sdk style Windows programming. The rest of the book was all MFC.
If your only interest is to become acquainted with Sdk style coding for Windows then quickly move on to MFC or .NET (various class frameworks), then Ivor's book would be enough. However, if you wish to really delve deeper into programming Windows with the raw Api, then you need to acquire Charles Petzold's "Programming Windows" book.
Last edited by Frederick2; Aug 6th, 2009 at 11:22 am.
![]() |
Similar Threads
- tic-tac-toe! (Java)
- Database - CPanel (Database Design)
- TORONTO, CANADA: Exciting startup seeking Visual / Interaction Designer (Web Development Job Offers)
- Large Icon ListView like with Text area (Visual Basic 4 / 5 / 6)
- Dilettante Alert (Community Introductions)
- Creating an OS in visual basic 6.0 (Visual Basic 4 / 5 / 6)
- Doubts about constructor (C++)
- Help on dedicated network drive please. (Networking Hardware Configuration)
- The Move.....Visual Basic 6, Visual Basic .NET ? (VB.NET)
Other Threads in the C++ Forum
- Previous Thread: SQL with C++
- Next Thread: Which Library to use Insert + Erase
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





