சனி, 20 பிப்ரவரி, 2010

C- QUESTIONS

1. What does static variable mean?
2. What is a pointer?
3. What is a structure?
4. What are the differences between structures and arrays?
5. In header files whether functions are declared or defined?
6. What are the differences between malloc() and calloc()?
7. What are macros? what are its advantages and disadvantages?
8. Difference between pass by reference and pass by value?
9. What is static identifier?
10. Where are the auto variables stored?
11. Where does global, static, local, register variables, free memory and C Program instructions get stored?
12. Difference between arrays and linked list?
13. What are enumerations?
14. Describe about storage allocation and scope of global, extern, static, local and register variables?
15. What are register variables? What are the advantage of using register variables?
16. What is the use of typedef?
17. Can we specify variable field width in a scanf() format string? If possible how?
18. Out of fgets() and gets() which function is safe to use and why?
19. Difference between strdup and strcpy?
20. What is recursion?
21. Differentiate between a for loop and a while loop? What are it uses?
22. What are the different storage classes in C?
23. Write down the equivalent pointer expression for referring the same element a[i][j][k][l]?
24. What is difference between Structure and Unions?
25. What the advantages of using Unions?
26. What are the advantages of using pointers in a program?
27. What is the difference between Strings and Arrays?
28. In a header file whether functions are declared or defined?
29. What is a far pointer? where we use it?
30. How will you declare an array of three function pointers where each function receives two ints and returns a float?
31. what is a NULL Pointer? Whether it is same as an uninitialized pointer?
32. What is a NULL Macro? What is the difference between a NULL Pointer and a NULL Macro?
33. What does the error 'Null Pointer Assignment' mean and what causes this error?
34. What is near, far and huge pointers? How many bytes are occupied by them?
35. How would you obtain segment and offset addresses from a far address of a memory location?
36. Are the expressions arr and &arr same for an array of integers?
37. Does mentioning the array name gives the base address in all the contexts?
38. Explain one method to process an entire string as one unit?
39. What is the similarity between a Structure, Union and enumeration?
40. Can a Structure contain a Pointer to itself?
41. How can we check whether the contents of two structure variables are same or not?
42. How are Structure passing and returning implemented by the complier?
43. How can we read/write Structures from/to data files?
44. What is the difference between an enumeration and a set of pre-processor # defines?
45. what do the 'c' and 'v' in argc and argv stand for?
46. Are the variables argc and argv are local to main?
47. What is the maximum combined length of command line arguments including the space between adjacent arguments?
48. If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?
49. Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?
50. What are bit fields? What is the use of bit fields in a Structure declaration?
51. To which numbering system can the binary number 1101100100111100 be easily converted to?
52. Which bit wise operator is suitable for checking whether a particular bit is on or off?
53. Which bit wise operator is suitable for turning off a particular bit in a number?
54. Which bit wise operator is suitable for putting on a particular bit in a number?
55. Which bit wise operator is suitable for checking whether a particular bit is on or off?
56. which one is equivalent to multiplying by 2:Left shifting a number by 1 or Left shifting an unsigned int or char by 1?
57. Write a program to compare two strings without using the strcmp() function.
58. Write a program to concatenate two strings.
59. Write a program to interchange 2 variables without using the third one.
60. Write programs for String Reversal & Palindrome check
61. Write a program to find the Factorial of a number
62. Write a program to generate the Fibinocci Series
63. Write a program which employs Recursion
64. Write a program which uses Command Line Arguments
65. Write a program which uses functions like strcmp(), strcpy()? etc
66. What are the advantages of using typedef in a program?
67. How would you dynamically allocate a one-dimensional and two-dimensional array of integers?
68. How can you increase the size of a dynamically allocated array?
69. How can you increase the size of a statically allocated array?
70. When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
71. Which function should be used to free the memory allocated by calloc()?
72. How much maximum can you allocate in a single call to malloc()?
73. Can you dynamically allocate arrays in expanded memory?
74. What is object file? How can you access object file?
75. Which header file should you include if you are to develop a function which can accept variable number of arguments?
76. Can you write a function similar to printf()?
77. How can a called function determine the number of arguments that have been passed to it?
78. Can there be at least some solution to determine the number of arguments passed to a variable argument list function?
79. How do you declare the following:
o An array of three pointers to chars
o An array of three char pointers
o A pointer to array of three chars
o A pointer to function which receives an int pointer and returns a float pointer
o A pointer to a function which receives nothing and returns nothing
80. What do the functions atoi(), itoa() and gcvt() do?
81. Does there exist any other function which can be used to convert an integer or a float to a string?
82. How would you use qsort() function to sort an array of structures?
83. How would you use qsort() function to sort the name stored in an array of pointers to string?
84. How would you use bsearch() function to search a name stored in array of pointers to string?
85. How would you use the functions sin(), pow(), sqrt()?
86. How would you use the functions memcpy(), memset(), memmove()?
87. How would you use the functions fseek(), freed(), fwrite() and ftell()?
88. How would you obtain the current time and difference between two times?
89. How would you use the functions randomize() and random()?
90. How would you implement a substr() function that extracts a sub string from a given string?
91. What is the difference between the functions rand(), random(), srand() and randomize()?
92. What is the difference between the functions memmove() and memcpy()?
93. How do you print a string on the printer?
94. Can you use the function fprintf() to display the output on the screen?

C++- QUESTIONS

C++- Questions

  1. What is a class?
  2. What is an object?
  3. What is the difference between an object and a class?
  4. What is the difference between class and structure?
  5. What is public, protected, private?
  6. What are virtual functions?
  7. What is friend function?
  8. What is a scope resolution operator?
  9. What do you mean by inheritance?
  10. What is abstraction?
  11. What is polymorphism? Explain with an example.
  12. What is encapsulation?
  13. What do you mean by binding of data and functions?
  14. What is function overloading and operator overloading?
  15. What is virtual class and friend class?
  16. What do you mean by inline function?
  17. What do you mean by public, private, protected and friendly?
  18. When is an object created and what is its lifetime?
  19. What do you mean by multiple inheritance and multilevel inheritance? Differentiate between them.
  20. Difference between realloc() and free?
  21. What is a template?
  22. What are the main differences between procedure oriented languages and object oriented languages?
  23. What is R T T I ?
  24. What are generic functions and generic classes?
  25. What is namespace?
  26. What is the difference between pass by reference and pass by value?
  27. Why do we use virtual functions?
  28. What do you mean by pure virtual functions?
  29. What are virtual classes?
  30. Does c++ support multilevel and multiple inheritance?
  31. What are the advantages of inheritance?
  32. When is a memory allocated to a class?
  33. What is the difference between declaration and definition?
  34. What is virtual constructors/destructors?
  35. In c++ there is only virtual destructors, no constructors. Why?
  36. What is late bound function call and early bound function call? Differentiate.
  37. How is exception handling carried out in c++?
  38. When will a constructor executed?
  39. What is Dynamic Polymorphism?
Write a macro for swapping integers.

What are the basic functions of an operating system?

  1. What are the basic functions of an operating system?
  2. Explain briefly about, processor, assembler, compiler, loader, linker and the functions executed by them.
  3. What are the difference phases of software development? Explain briefly?
  4. Differentiate between RAM and ROM?
  5. What is DRAM? In which form does it store data?
  6. What is cache memory?
  7. What is hard disk and what is its purpose?
  8. Differentiate between Complier and Interpreter?
  9. What are the different tasks of Lexical analysis?
  10. What are the different functions of Syntax phase, Sheduler?
  11. What are the main difference between Micro-Controller and Micro- Processor?
  12. Describe different job scheduling in operating systems.
  13. What is a Real-Time System ?
  14. What is the difference between Hard and Soft real-time systems ?
  15. What is a mission critical system ?
  16. What is the important aspect of a real-time system ?
  17. If two processes which shares same system memory and system clock in a distributed system, What is it called?
  18. What is the state of the processor, when a process is waiting for some event to occur?
  19. What do you mean by deadlock?
  20. Explain the difference between microkernel and macro kernel.
  21. Give an example of microkernel.
  22. When would you choose bottom up methodology?
  23. When would you choose top down methodology?
  24. Write a small dc shell script to find number of FF in the design.
  25. Why paging is used ?
  26. Which is the best page replacement algorithm and Why? How much time is spent usually in each phases and why?
  27. Difference between Primary storage and secondary storage?
  28. What is multi tasking, multi programming, multi threading?
  29. Difference between multi threading and multi tasking?
  30. What is software life cycle?
  31. Demand paging, page faults, replacement algorithms, thrashing, etc.
  32. Explain about paged segmentation and segment paging
  33. While running DOS on a PC, which command would be used to duplicate the entire diskette?

Windows Questions.

  1. Explain the windows Architecture
  2. What is Create Window API?
  3. What is the use of Create Window API?
  4. What is the use of Get Message?
  5. What is the use of Translate Message?
  6. What is the use of Dispatch Message?
  7. What is paint structure?
  8. What is Device context?
  9. What is Get DC and Release DC
  10. What is Window Procedure?
  11. What is Window class?

Microsoft Windows programming interview questions

Windows interview questions
1. Which controls can not be placed in MDI ?
2. List out controls which does not have events
3. Which property of textbox cannot be changed at runtime. What is the max size of textbox?
4. How many system controls are available
5. ___,_____ and ____ container objects.
6. strech___ Property is to compress a image in image control.
7. ___,___ and __ are difference between image and picture controls.
8. Is it possible to set a shortcut key for label.
9. What is the default property of data control?
10. ___,__,___ are the type of combo box?
11. __ no of controls in form.
12. OLE is used for _______
13. What is the need of tabindex property is label control.
14. ___ is the control used to call a windows application.
15. Clear property is available in ____,___ control.
16. ___ Property is used to count no. of items in a combobox.
17. ___ is a property to resize a label control according to your caption.
18. Which controls have refresh method.
19. ___ property is used to change to ___ value to access a identity column in datacontrols.
20. _____ is the property to ___,____,____ are valid for recordsource property of dat control.
21. To find the current record position in data control.
22. Timer control contains ________ no. of events.
23. ____ property is used to lock a textbox to enter data.
24. What is the need of z-order method?
25. ____ is the difference between Listindex and Tab index.
26. ____ property of menu cannot be set at run time.
27. Can you create a tabletype of recordset in Jet - connected ODBC dbengine.
28. Difference between listbox and combo box.
29. What are the new events in textbox that has been included in VB
30. 0
31. Can you create a Updatecascade, Deletecascade relation in Ms- Access? If no, give on eample.
32. _____ collection in recordset used to assign a value from textbox to table columns without making abinding in datacontrol.
33. ____ argument can be used to make a menu item into bold.
34. What is the difference between Msgbox Statement and MsgboxQ function?
35. What is.the difference between queryunload and unload in form?
36. ___,___ arguments will be used to run a executable program in shell function
37. ___ property used to add a menus at runtime.
38. What is the difference between modal and module-less window?
39. ___ VB constant make the menu item in centre.
40. ___ method used to move a recordset pointer in nth position in DAG.
41. To validate a range of values for a property whenever the property values changes,which type of property procedure you use?
42. What are 3 main differences between flexgrid control and dbgrid control?
43. What is the difference between change event in normal combobox and dbcombobox?
44. To populate a single column value which dbcontrols you to use?
45. What is ODBC?
46. Parts of ODBC?
47. What is DSN?
48. What is DAO?
49. Types of cursors in DAO?
50. Types of LockEdits in DAO? 51 .Types of Recordsets.
51. Difference between Tabletype and Snapshot?
52. Draw Sequence Modal of DAO? Explain.
53. Difference between Dynaset and Snapshot?
54. Difference between Recordset and Querydef?
55. What is the use of Tabledef?
56. Default cursor Type and LockEdit type in DAO?
57. What is the default workspace?
58. 1s it posible to Create Tables Through Querydef?
59. It is possible to access Text (x.txt) files? Explain.
60. What is ODBC Direct and Microsoft Jet Database Engine ?
61. Is it possible to Manipulate data through flexgrid? Explain.
62. Types of DBCombo boxes
63. What do you mean by Databound Controls? Explain.
64. What is RDO?
65. Types of cursors in RDO.
66. Types of LockEdits in RDO.
67. Types of LockEdits in RDO.
68. Types of Resultsets.
69. Difference between Recordset and Resultsets.
70. Explain Default cursor Type and LockEdits type in RDO
71. Draw Sequence Modal of RDO? Explain.
72. What is meant by Establish Connection in RDO?
73. Is it possible to Access BackEnd procedures? Explain.
74. What is OLE? Explain.
75. What is DDE?
76. Difference between Linked Object and Embedded Object?
77. Explain OLE Drag and Drop.
78. Difference between DDE and OLE.
79. What is the difference between Object and Class?
80. Give brief description about class?
81. Does VB support object-oriented concepts? Explain..
82. Difference between Class Module and Standard Module?
83. Explain Get, Let, Set Properties.
84. Difference Types of Procedures in VB?
85. What is the use of NEW Keyword? Explain.
86. What is constructors and distructors.
87. Types of Modal windows in VB.
88. What is ActiveX? Explain.
89. Types of ActiveX Components in VB?
90. Difference between ActiveX Control and Standard Control.
91. Difference between ActiveX Exe and Dll.
92. What is instantiating?
93. Advantage of ActiveX Dll over Active Exe.
94. Difference Types of Instancing Property in ActiveX Dll and Exe.
95. What is ActiveX Dll and ActiveX Exe?
96. Write the steps in Creating ActiveX Dll and Active Exe?
97. Explain the differences between ActiveX Dll and ActiveX Exe?
98. How would you use ActiveX Dll and ActiveX Exe in your application?
99. How would you access objects created in ActiveX Exe and ActiveX D1T
100. What is the use of ActiveX Documents?
101. What is ActiveX Document?
102. What is the use of Visual Basic Document file?
103. What is hyperlink?
104. How would you create Visual basic Document file?
105. What is Internet Explorer and its uses?
106. How would you navigate between one document to another document in Internet Explorer ?
107. How would you run your ActiveX Document Dll?
108. How would you view html code in Active Server Pages?
109. How would you cre.ate your application in DHTML?
110. What is ActiveX Control?
111. Write the Steps in Creating an ActiveX Control?
112. How would you attach an ActiveX control in Your Application?
113. How would you create properties in ActiveX Control?
114. What is the-use of property page Wizard in ActiveX Control?
115. How would you add elements in TreevieW Control.
116. What are the types of line styles available in Treeview Control?
117. What is the use of Imagelist Controls
118. How would you attach pictures in Treeview Control?
119. What are the uses of List View Control?
120. Explain the types of Views in Listview Control.
121. How would you attach pictures in column headers of List View Control?
122. How would you add column headers in listview control?
123. How would you add elements and pictures to listitems in listview control?
124. How would you activate animation control?
125. What is the use of progress Bar Control?
126. How would you find out the value property in Slider Bar Control?
127. What is the use of Data Form Wizard?
128. How would you map properties to controls by using ActiveX Control Interface Wizard?
129. How would you convert a form into document?
130. How would you Create a Query Builder and Explain its uses
131. How would you create properties by using class Builder Wizard?
132. HTML stands for What? Use of HTML ?
133. Whether HTML supports multimedia: and document links?
134. DHTML Is used for what?
135. What do you mean by HTTP?
136. What is the use of Hyperlink control for DHTML applications?
137. How can you Navigate from the DHTML application to another DHTML application? .
138. What are the Internet tools available in VB
139. 0?
140. Explain the usage of Web Browser Control?
141. What do you mean by ADO?
142. What is the difference Between ADO and other data access objects0
143. What is OLEDB?
144. What are the important components of OLEDB?
145. Through which protocol OLEDB components are interfaced?
146. It possible to call OLEDB’s Features directly in VB without using any control?
147. What type of databases you can access through AD I Data Access Object?
148. How many objects resides in ADO ?
.
149. What is the use of Connection object?
150. What is the use of command Object?
151. Record set object consists of what?
152. What is the use of parameters collection?
153. Which type of object requires this object?
154. Is it possible to call backend procedures with ADO control?
155. Is there any Edit method in ADO Data Access method?
156. How can you check whether a record is valid record or Invalid record using ADO control or Object?
157. What do you mean by provider?
158. What type of record sets are available in ADO?
159. Is it possible to call oracle database through ADO control or Object?
160. How many File System Controls are there ? Explain.
161. How can you filter out specific type of file using file system controls?
162. How can you get selected file from file system Control?
163. How many ways we can access file using VB?
164. Which method is preferred to save data like database to the disk?
165. How to get free file location in memory?
166. How to find size of the file. Which method or function is used to occomplish this?
167. Using which type we can access file line by line?
168. Which method is used to write context Into file?
169. How can you read content from file?
170. Binary Access-method is used to access file in which manner?
171. How can you check Beginning and End of the file?
172. What is the use of Scalewidth and ScaleHeight Proeperty?
173. What is the use of Active Control Property?
174. How can you save and Get data from Clipboard/
175. What are the types of Error?
176. In which areas the Error occurs?
177. What are the tools available for Debug in VB?
178. What is the use of Immediate, Local Window?
179. What is the use of debug Window?
180. How can you Implement windows functionality in VB?
181. How many types of API functions are available in VB?
182. How can you Add API functions to your Application?
183. How to get Cursor position using API?
184. Is it possible to change menu runtime using API? If yes? Specify the function names.
185. What are the types of API Types.
186. Scope of API’s can be of types, what are they? Why API functions are Required?

Windows programming interview questions

Windows, C++ interview questions
1. What are kernel objects? - - Several types of kernel objects, such as access token objects, event objects, file objects, file-mapping objects, I/O completion port objects, job objects, mailslot objects, mutex objects, pipe objects, process objects, semaphore objects, thread objects, and waitable timer objects.
2. What is a kernel object? - Each kernel object is simply a memory block allocated by the kernel and is accessible only by the kernel. This memory block is a data structure whose members maintain information about the object. Some members (security descriptor, usage count, and so on) are the same across all object types, but most are specific to a particular object type. For example, a process object has a process ID, a base priority, and an exit code, whereas a file object has a byte offset, a sharing mode, and an open mode.
3. User can access these kernel objects structures? - Kernel object data structures are accessible only by the kernel
4. If we cannot alter these Kernel Object structures directly, how do our applications manipulate these kernel objects? - The answer is that Windows offers a set of functions that manipulate these structures in well-defined ways. These kernel objects are always accessible via these functions. When you call a function that creates a kernel object, the function returns a handle that identifies the object.
5. How owns the Kernel Object? - Kernel objects are owned by the kernel, not by a process
6. How does the kernel object outlive the process that created it? - If your process calls a function that creates a kernel object and then your process terminates, the kernel object is not necessarily destroyed. Under most circumstances, the object will be destroyed; but if another process is using the kernel object your process created, the kernel knows not to destroy the object until the other process has stopped using it
7. Which is the data member common to all the kernel object and what is the use of it? -
The usage count is one of the data members common to all kernel object types
8. How to identify the difference between the kernel object and user object? -
The easiest way to determine whether an object is a kernel object is to examine the function that creates the object. Almost all functions that create kernel objects have a parameter that allows you to specify security attribute information.
9. What is the purpose of Process Handle Table? -
When a process is initialized, the system allocates a handle table for it. This handle table is used only for kernel objects, not for User objects or GDI objects. When a process first initializes, its handle table is empty. Then when a thread in the process calls a function that creates a kernel object, such as CreateFileMapping , the kernel allocates a block of memory for the object and initializes it; the kernel then scans the process’s handle table for an empty entry
10. Name few functions that create Kernel Objects? - HANDLE CreateThread(…),HANDLE CreateFile(..),HANDLE CreateFileMapping(..)HANDLE CreateSemaphore(..)etcAll functions that create kernel objects return process-relative handles that can be used successfully by any and all threads that are running in the same process.
11. What is handle? - Handle value is actually the index into the process’s handle table that identifies where the kernel object’s information is stored.
12. How the handle helps in manipulating the kernel objects? - Whenever you call a function that accepts a kernel object handle as an argument, you pass the value returned by one of the Create* functions. Internally, the function looks in your process’s handle table to get the address of the kernel object you want to manipulate and then manipulates the object’s data structure in a well-defined fashion.
13. What happens when the CloseHandle(handle) is called? - This function first checks the calling process’s handle table to ensure that the index (handle) passed to it identifies an object that the process does in fact have access to. If the index is valid, the system gets the address of the kernel object’s data structure and decrements the usage count member in the structure; if the count is zero, the kernel destroys the kernel object from memory.
14. You forget to call CloseHandle - will there be a memory leak? - Well, yes and no. It is possible for a process to leak resources (such as kernel objects) while the process runs. However, when the process terminates, the operating system ensures that any and all resources used by the process are freed—this is guaranteed. For kernel objects, the system performs the following actions: When your process terminates, the system automatically scans the process’s handle table. If the table has any valid entries (objects that you didn’t close before terminating), the system closes these object handles for you. If the usage count of any of these objects goes to zero, the kernel destroys the object.
15. What is the need of process relative handles? - The most important reason was robustness. If kernel object handles were system-wide values, one process could easily obtain the handle to an object that another process was using and wreak havoc on that process. Another reason for process-relative handles is security. Kernel objects are protected with security, and a process must request permission to manipulate an object before attempting to manipulate it. The creator of the object can prevent an unauthorized user from touching the object simply by denying access to it
16. How the handles are handled in the child process? - The operating system creates the new child process but does not allow the child process to begin executing its code right away. Of course, the system creates a new, empty process handle table for the child process—just as it would for any new process. But because you passed TRUE to CreateProcess’s bInheritHandles parameter, the system does one more thing: it walks the parent process’s handle table, and for each entry it finds that contains a valid inheritable handle, the system copies the entry exactly into the child process’s handle table. The entry is copied to the exact same position in the child process’s handle table as in the parent’s handle table.
17. Why the entries in the parent process table and child table are same? - It means that the handle value that identifies a kernel object is identical in both the parent and the child processes.
18. What about the usage count in the parent child process tables? - The system increments the usage count of the kernel object because two processes are now using the object. For the kernel object to be destroyed, both the parent process and the child process must either call CloseHandle on the object or terminate.
19. What are Named Objects? - Method available for sharing kernel objects across process boundaries is to name the objects. Below are the kernel named objects 1) mutex, 2) Events, 3) semaphore, 4) waitableTimers, 5)file mapping, 6)job object. There are APIs to create these objects with last parameter as the object name.
20. What do you mean by unnamed object? - When you are creating the kernel objects with the help of API’s like CreateMutex(, , , ,pzname). And the Pzname parameter is NULL , you are indicating to the system that you want to create an unnamed (anonymous) kernel object. When you create an unnamed object, you can share the object across processes by using either inheritance or DuplicateHandle
21. What is DuplicateHandle (API)? - Takes an entry in one process’s handle table and makes a copy of the entry into another process’s handle table
22. What is a thread? - A thread describes a path of execution within a process. Every time a process is initialized, the system creates a primary thread. This thread begins executing with the C/C++ run-time library’s startup code, which in turn calls your entry-point function ( main , Wmain , WinMain , or WWinMain ) and continues executing until the entry-point function returns and the C/C++ run-time library’s startup code calls ExitProcess
23. What is the limit on per process for creating a thread? - The number of threads a process can create is limited by the available virtual memory and depends on the default stack size
24. What is Synchronization Objects? - Synchronization object s are use to co-ordinate the execution of multiple threads.
25. Which kernel objects are use for Thread Synchronization on different processes? - Event, Mutex, Semaphore
26. What is Event Object and why it is used? - Event is the thread synchronization object to set signaled state or non-signaled state.
27. What is signaled and non signaled state? - An event is in signaled state means that it has the capacity to release the threads waiting for this event to be signaled. An event is in non signaled state means that it will not release any thread that is waiting for this particular event.example in our project: when user clicks the image application icon double simultaneously. Two image application windows were created. so PAIG created an event and set it to non-signaled state. Then the image application will reset the event to signaled state, after this all the threads are released.
28. APIs for creating event and set and reset the events - CreateEvent-to create the event OpenEvent – to open already created event SetEvent – to set the event signaled stateRestEvent - To set the Event To non-Signaled State
29. What is Mutex Object and why it is used? - A mutex object is a synchronization object whose state is set to signaled when it is not owned by any thread, and non-signaled when it is owned. For example, to prevent two threads from writing to shared memory at the same time, each thread waits for ownership of a mutex object before executing the code that accesses the memory. After writing to the shared memory, the thread releases the mutex object.
30. How do I create a Mutex? - A thread uses the CreateMutex function to create a mutex object. The creating thread can request immediate ownership of the mutex object and can also specify a name for the mutex object
31. How do other threads own the mutex? - Threads in other processes can open a handle to an existing named mutex object by specifying its name in a call to theOpenMutex - function. Any thread with a handle to a mutex object can use one of the wait functions to request ownership of the mutex object. If the mutex object is owned by another thread, the wait function blocks the requesting thread until the owning thread releases the mutex object using theReleaseMutex - function.
32. What is semaphores and why it is used? - A semaphore object is a synchronization object that maintains a count between zero and a specified maximum value. The count is decremented each time a thread completes a wait for the semaphore object and incremented each time a thread releases the semaphore. When the count reaches zero, no more threads can successfully wait for the semaphore object state to become signaled. The state of a semaphore is set to signaled when its count is greater than zero, and non-signaled when its count is zero. The semaphore object is useful in controlling a shared resource that can support a limited number of users. It acts as a gate that limits the number of threads sharing the resource to a specified maximum number. For example, an application might place a limit on the number of windows that it creates. It uses a semaphore with a maximum count equal to the window limit, decrementing the count whenever a window is created and incrementing it whenever a window is closed. The application specifies the semaphore object in call to one of the wait functions before each window is created. When the count is zero - indicating that the window limit has been reached - the wait function blocks execution of the window-creation code.

What Is CMutex ?

What Is CMutex ?

An object of class CMutex represents a “mutex” — a synchronization object that allows one thread mutually exclusive access to a resource. Mutexes are useful when only one thread at a time can be allowed to modify data or some other controlled resource. For example, adding nodes to a linked list is a process that should only be allowed by one thread at a time. By using a CMutex object to control the linked list, only one thread at a time can gain access to the list.

To use a CMutex object, construct the CMutex object when it is needed. Specify the name of the mutex you wish to wait on, and that your application should initially own it. You can then access the mutex when the constructor returns. Call CSyncObject::Unlock when you are done accessing the controlled resource.

What is the difference between ASSERT and VERIFY?

The main difference between ASSERT and VERIFY is when you compile the release build of the program.

ASSERT will not be present in the release build version of the executables/dlls, and its expression that would have been evaluated will be deleted.

VERIFY will be present in the release build version of the executables/dlls but its expression that would have been evaluated will be left intact


what is the use of AFX_MANAGE_STATE ?

By default, MFC uses the resource handle of the main application to load the resource template. If you have an exported function in a DLL, such as one that launches a dialog box in the DLL, this template is actually stored in the DLL module. You need to switch the module state for the correct handle to be used. You can do this by adding the following code to the beginning of the function:
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
This swaps the current module state with the state returned from AfxGetStaticModuleState until the end of the current scope.

If all your resources lies in the single DLL you can even change the default handle to the DLL handle with the help of AfxSetResourceHandle function.

VC++ tips:

VC++ tips:


1) Explain COM?
1. How do I get the main window Handle?

AfxGetMainWnd() API returns the main wnd handle for you. You can get whatever you want on the main window. Here I give some piece of code

AfxGetMainWnd()->GetDlgItemText(IDC_EDIT_TEST1, str);
SetDlgItemText(IDC_EDIT_TEST1, str);


2.Can I have same ID for the control in different dialog?

Sure. There is no problem when you are assigning same ID for the controls in different dialog. But in the same dialog, we can’t able to create two controls with the same ID.
For example, if u has two dialogs with one edit control for each, then you will enter same ID as IDC_EDIT_TEST1 for the two edit controls. Surprisingly, it will work so nice. Reason for this is each control is coupled with theirs own window.


3. How do I convert CString to WCHAR?
Steps here,
WCHAR wFile = new WCHAR[MAX_PATH];
mbstowcs(wFile, string.GetBuffer(), string.GetLength() + 1);

now the wfile has the string in wchar format.

4. How can I draw image using OpenCV in a simple way?

Easiest way to draw an image on the DC is OpenCV with GDI+. GDI+ reduces our task to copy the image data from Iplimage. Here some code for ur reference.

CString sFileName("");
int iWidth, iHeight;
CRect rect;
IplImage *SU_Image = 0;
iWidth = iHeight = 0;
char m_chBmpBuf[2048];

M_StPict.GetClientRect(&rect);
iWidth = rect.Width(); iHeight = rect.Height();

IplImage *img=cvLoadImage(sFileName.GetBuffer(sFileName.GetLength()),3);

if(!img) return;

SU_Image = cvCreateImage(cvSize(iWidth,iHeight),8,3);
cvResize(img, SU_Image);

Bitmap bmp(iWidth,iHeight,iWidth*3, PixelFormat24bppRGB, (BYTE*)SU_Image->imageData);

Graphics gr(M_StPict.GetDC()->m_hDC);
gr.DrawImage(&bmp, 0, 0, iWidth, iHeight);

cvReleaseImage(&SU_Image);
cvReleaseImage(&img);


5. What is the difference between public, private, and protected?
• A member (either data member or member function) declared in a private section of a class can only be accessed by member functions and friends of that class
• A member (either data member or member function) declared in a protected section of a class can only be accessed by member functions and friends of that class, and by member functions and friends of derived classes
• A member (either data member or member function) declared in a public section of a class can be accessed by anyone
6. What is Copy Constructor?
CPoint pt(1,2);
CPoint pt1( pt ); //copy constructor
CPoint pt2 = pt1; //copy constructor

In the copy constructor, the compiler creates a new object pt2 and copies the data from pt1 member-by-member, into pt2.

7. Not possible this kind of inclusion.

If I have two file namely A & B. The A file includes the B file and B file includes A file. Then some error will occur due to this.


8. What is Smart Pointer?

Smart pointers are objects which store pointers to dynamically allocated (heap) objects. They behave much like built-in C++ pointers except that they automatically delete the object pointed to at the appropriate time. Smart pointers are particularly useful in the face of exceptions as they ensure proper destruction of dynamically allocated objects. They can also be used to keep track of dynamically allocated objects shared by multiple owners.
Conceptually, smart pointers are seen as owning the object pointed to, and thus responsible for deletion of the object when it is no longer needed.
9. Give me some messages when I press some controls in a dialog?

WM_CLOSE WM_DESTROY WM_SYSCOMMAND


10. Before to use pointer variable (anything), you have to make sure about to initialize them. Otherwise you will face some unhandled exception.

Using calloc function to create dynamic memory allocation. It will allocate memory as well as initialize them also.

int *iSamp = (int*) calloc(6, sizeof(int));

If you are using malloc function, then you will initialize them before to use.

int *iSamp = (int*) malloc(6);
zeromemory( iSamp, 6); (or)
FillMemory( iSamp, 6, 0);

11. How to avoid multiple instance of the same process?

In SDK, it is very simple. Before to create instance, check the HINSTANCE hPrevInstance in the winmain function. If it is false or null, then no one instance is there. Otherwise instance of the same process is on the screen.

int winmain(HINSTANCE hInstnce,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
if(hPrevInstance)
{
AfxMessageBox(“Another instance is running.”);
Return 0;
}
.
.
.
}

In MFC, we can use kernel object to handle this problem. Here I am using mutex to handle this one.

BOOL CModelessDialogApp::InitInstance()
{

HANDLE hMutex = ::CreateMutex(NULL,FALSE,“nat”); if(::GetLastError() == ERROR_ALREADY_EXISTS){
AfxMessageBox("Another Instance is already running.");
return FALSE;}
.
.
.
}

After that u have to close the handle in the exit instance then only the mutex object will be released.

int CModelessDialogApp::ExitInstance()
{
if(!::CloseHandle(hMutex))
AfxMessageBox("Handle is not closed");
return CWinApp::ExitInstance();
}



11. Tell me all the data types size in VC++?

int : 4 bytes
char : 1 byte
float : 4 bytes
double : 4 bytes
long : 4 bytes
short : 2 bytes
BOOL : 4 bytes
bool : 1 byte

12. Tell me about Structure Padding?

Structure Padding is nothing but add some extra padding bytes to make even storage space the structure storage space.

To reduce the padding bytes, you can group the
same data types together. Let me explain with one example.

struct name
{
int a;
char c;
int b;
char d;
};

if you get the size of this structure, then it will give 16 bytes. Before to calculate the size of the structure, first it will find the maximum size data type. After that it will allocate the memory based on the maximum size. It looks like
i0 i1 i2 i3

c0 padding bytes

i0 i1 i2 i3

c0 padding bytes

So only it will take 16 bytes long. If you want to reduce the size of the structure, you will group them with same data type. Now we can write the same structure like this,


struct name
{
int a;
int b;
char c;
char d;
};

Now we check its size, it will return 12. Let me explain, how it is possible. Only two padding bytes is enough to complete the structure memory space as even.

i0 i1 i2 i3

i0 i1 i2 i3

c0 c1 pad_bytes // 2 bytes enough


13. What stands for Afx?

Afx – Application Framework(X)

14. Describe Static member function?

Static data types can be accessed without instantiation of the class in C++. This is applicable for static functions also.
The differences between a static member function and non-static member functions are as follows.
• A static member function can access only static member data, static member functions and data and functions outside the class. A non-static member function can access all of the above including the static data member.
• A static member function can be called, even when a class is not instantiated, a non-static member function can be called only after instantiating the class as an object.
• A static member function cannot be declared virtual, whereas a non-static member functions can be declared as virtual
• A static member function cannot have access to the 'this' pointer of the class.
The static member functions are not used very frequently in programs. But nevertheless, they become useful whenever we need to have functions which are accessible even when the class is not instantiated.


15. Explain inline function?

When a function is declared inline, the function is expanded at the calling block. The function is not treated as a separate unit like other normal functions.
But a compiler is free to decide, if a function qualifies to be an inline function. If the inline function is found to have larger chunk of code, it will not be treated as an inline function, but as like other normal functions.
Inline functions are treated like macro definitions by the C++ compiler. They are declared with the keyword inline as follows.

//Declaration for C++ Tutorial inline sample:
int add(int x,int y);

//Definition for C++ Tutorial inline sample:
inline int add(int x,int y)
{
return x+y;
}
In fact, the keyword inline is not necessary. If the function is defined with its body directly and the function has a smaller block of code, it will be automatically treated as inline by the compiler.
As implied, inline functions are meant to be used if there is a need to repetitively execute a small block of code, which is smaller. When such functions are treated inline, it might result in a significant performance difference.

16. Shallow Copy and Deep Copy?


17. Thread Synchronization object difference?


18. C++ Virtual function:
Properties:
C++ virtual function is,
• A member function of a class
• Declared with virtual keyword
• Usually has a different functionality in the derived class
• A function call is resolved at run-time
The difference between a non-virtual c++ member function and a virtual member function is, the non-virtual member functions are resolved at compile time. This mechanism is called static binding. Where as the c++ virtual member functions are resolved during run-time. This mechanism is known as dynamic binding.
Call Mechanism
Whenever a program has a C++ virtual function declared, a v-table is constructed for the class. The v-table consists of addresses to the virtual functions for classes and pointers to the functions from each of the objects of the derived class. Whenever there is a function call made to the c++ virtual function, the v-table is used to resolve to the function address. This is how the Dynamic binding happens during a virtual function call.




19. Difference between C Structure and C++ Structure?

• structure declaration:

In C : strut Car Maruti;

In C++ : Car Maruti;

• Structure method:

In C : does not possible

In C++ : possible as like class

Struct car
{
int a;
int fn_Test()
{
cout<};
};

or

Struct car
{
int a;
int fn_Test();
}

int car::fn_Test()
{
cout<}

• Structure Inheritance:

In C, No structure inheritance possible
In C++, structure inheritance is possible

Struct A
{
int a;
int b;
};
struct B
{
int c;
int d;
};

struct C : public A, public B
{
int fn_print()
{
cout<};
}


20. Describe structure in C++?

Structure in C++ is functionally equivalent to class. The following are possible in structure also.

1. it can have member function
struct A
{
int a;
void fn_Nat()
{
cout<<”hai”<};
};

2. structure can have characteristics of another structure. i.e., inheritance is possible
struct B : public A
{
int b;
void fn_print()
{
cout<};
};

3. all of its member are public.

4. we cant give any access specifier in it(public, private, and protected).

5. No polymorphism in structure. (i.e., Overloading, overriding)

6. we can inherit struct to a class.
struct A
{
int a;
int b;
};
class B : public A
{
int fn_print()
{
cout<};
};

21. what is aggregate data type?
An aggregate type is an array, class, or structure type which:
• Has no constructors
• Has no nonpublic members
• Has no base classes
• Has no virtual functions
Initializers for aggregates can be specified as a comma-separated list of values enclosed in curly braces. For example, this code declares an int array of 10 and initializes it:
int rgiArray[10] = { 9, 8, 4, 6, 5, 6, 3, 5, 6, 11 };

22. About Union?

Union is just like a structure. But it can have one value at a time. Real time example of union is socket address.

union aa
{
int a;
char b;
float c;
};
The size of the union is the largest member type size. So here, its size is 4. Totally 4 bytes alone is allocated for this union. If you are assigning a to 65, then access the char b, it will give the charecter A, because ascii value of A is 65.

aa test;
test.a = 65;
cout< // value of A is 65).


23. Differences between Modifier and accessor?








24. Size of the class ?

• The size of classes depends on class member variable. and vptr (if there is virtual functions).

• No of member functions (Non Virtual)doesn't affect size of class

• Empty class has 1 byte size

• If you get the size of the class member function, it will return the size of its return type

Class b
{
int fn_nat()
{
return 0;
}
};
int main(void)
{
b bb;
cout<
}
• http://codeguru.earthweb.com/forum/printthread.php?t=377183


Size of a class

What all factors determine the size of a class? Its like i created a simple class named CParent.............

class CParent
{
public:
int faint()
{
int val,nal;
return 0;
}
};

and in main function when i wanted to see the size of this class as well as its member function (faint)..........

void main()
{
CParent ptr;

cout << sizeof(ptr) << endl << sizeof (ptr.faint()) << endl;
}

It simply displayed 1 and 4. Since faint was a member function of ******* type and 2 variables reside inside that function then howcome the size of the class was still 1?

Similarly when when I used virtual keyword for that member function faint.........

class CParent
{
public:
virtual int faint()
{
int val,nal;
return 0;
}
};

then the size of the class increased from 1 to 4 what is the concept behind this? When the class size if independent of its member functions then howcome a virtual function increased the size of the class?

anantwakode 02-24-2006 06:58 AM

Re: Size of a class

Hi,

Actually Class size should be zero But ..as two different objects of same class must have different memory location ..

therefore empty classes have size 1 .

The size of classes depends on class member variable. and vptr (if there is virtual functions).

No of member functions (Non Virtual)doesn't affect size of class.

sizeof (ptr.faint()) = 4 because function ptr requires 4 bytes.

-Anant

maverick786us 02-24-2006 07:04 AM

Re: Size of a class

I know it requires 4 bites but what is the concept behind it? How do virtual functions occupy 4 bytes and how do they affect the size of class why not non virtual functions? They too occupy some space in memory?

treuss 02-24-2006 07:08 AM

Re: Size of a class

Actually the size of your class is zero. Your class does not contain any member variables, so any object of your class will not take any memory. That's the theory. In practice, objects of size zero would bring all kind of complications (e.g. a zero size object could not have a memory address), so it is put to minimum size 1.

sizeof(ptr.faint()) makes a call to ptr.faint(), which returns an int, and gives sizeof that int.

If you add a virtual function to your class, each object of your class will have a hidden pointer to a virtual function table. The table is used to resolve calls to virtual functions at runtime. Therefore the class has now the size of that pointer.

treuss 02-24-2006 07:13 AM

Re: Size of a class

Quote:
Originally Posted by maverick786us
I know it requires 4 bites but what is the concept behind it? How do virtual functions occupy 4 bytes and how do they affect the size of class why not non virtual functions? They too occupy some space in memory?
sizeof(some class) always gives you the size of one object of that class. In that sense, functions do not take memory, because the code for a function is used by all objects. There is no way to calculate the size of the code a function will take, if that is what you are after. Memory for local variables within a function will only be allocated on the stack if the function is called. Thus they also do not affect what the sizeof operator returns.

Vedam Shashank 02-24-2006 07:25 AM

Re: Size of a class

Member functions do not add count to the size of an object of a class.

I doubt that u can determine the size of an object of a class by just looking at it.

For more see..
C++ Structure: Why returns 'sizeof()' a bigger size than the members actually need?


As for size of a function, i am not sure if u can apply sizeof to determine that.

Vedam Shashank 02-24-2006 07:29 AM

Re: Size of a class

From the standards...
Quote:
5.3.3 Sizeof [expr.sizeof]
1 The sizeof operator yields the number of bytes in the object representation of its operand. The operand
is either an expression, which is not evaluated, or a parenthesized typeid.
The sizeof operator shall not
be applied to an expression that has function or incomplete type, or to an enumeration type before all its
enumerators have been declared, or to the parenthesized name of such types, or to an lvalue that designates
a bitfield.
sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1; the
result of sizeof applied to any other fundamental type (3.9.1) is implementationdefined.
[Note: in particular,
sizeof(bool) and sizeof(wchar_t) are implementationdefined.
69) ] [Note: See 1.7 for
the definition of byte and 3.9 for the definition of object representation. ]


Graham 02-24-2006 08:30 AM

Re: Size of a class

Just to complete the picture: if a class has no data members or virtual functions, sizeof must report its size as at least 1 (as has been pointed out) - however it is allowed to have zero size if it is used as a base class. So, if B is an empty class, and D (derived from B) contains an int, then sizeof(B) == 1, but sizeof(D) == sizeof(int) (not sizeof(int) + 1). (All numbers are illustrative...)

sunnypalsingh 02-24-2006 09:13 AM

Re: Size of a class

sizeof class also depends on the order in which you lay out members in the class.

RoboTact 02-24-2006 09:33 AM

Re: Size of a class

And there are about no applications of sizeof() in C++.

Vedam Shashank 02-24-2006 10:09 AM

Re: Size of a class

Quote:
Originally Posted by RoboTact
And there are about no applications of sizeof() in C++.


Like u said practically there are no uses of sizeof(...), why was it ever there. Of what use was it earlier???

RoboTact 02-24-2006 10:13 AM

Re: Size of a class

Why, you can save structures in binary files (which you shouldn't do anyway) and get sizes of arrays.

SuperKoko 02-24-2006 10:30 AM

Re: Size of a class

sizeof was much used by C programs which were allocating memory through malloc, because they needed to know the size of the allocated block.

sizeof is still useful in C++, to provide low level memory management.
It is probably used in STL.
For example, a specialization for std::copy may be provided for builtin types pointers.
In that case, the number of elements is multiplied by sizeof(BuiltinType) and passed to memcpy.

To get an idea of sizeof uses, you can search it in your headers/modules of your compiler standard library and STL.

sunnypalsingh 06-01-2006 10:43 AM

Re: Size of a class

Quote:
Originally Posted by Graham
Just to complete the picture: if a class has no data members or virtual functions, sizeof must report its size as at least 1 (as has been pointed out) - however it is allowed to have zero size if it is used as a base class. So, if B is an empty class, and D (derived from B) contains an int, then sizeof(B) == 1, but sizeof(D) == sizeof(int) (not sizeof(int) + 1). (All numbers are illustrative...)


Sorry I am picking up an old thread.

But how can a size be 0?? Plz explain.

SuperKoko 06-01-2006 10:53 AM

Re: Size of a class

Quote:
Originally Posted by sunnypalsingh
But how can a size be 0?? Plz explain.

It means that adding such empty base class doesn't change the size of the derived class:
Code:

class Base1 {};
class Base2 {};
class Base3 {};
class Base4 {};

struct Derived:Base1,Base2,Base3,Base4 {
char c[2];
};

This Derived class may have a size of 2 on some compilers.
Which is smaller than the sum of the sizes of the base classes.




How to map the class with dialog? What are the steps to be followed?

1. The class must derive from the CDialog class.

2. In the class definition file, at the constructor prototype, you have to give the Dialog ID to the CDialog constructor like below

CMyDialog::CMyDialog() : CDialog(IDD_DIALOG1, NULL)
{
}

3. If you want to add event handler function , then you will follow this instructions. Otherwise you will get error.

DECLARE_MESSAGE_MAP() macro should be placed the class declaration gets closed.

BEGIN_MESSAGE_MAP(your class, base class)
//add your message mapping here
ON_CONTROL(WM_COMMAND, BN_CLICKED, IDOK, OnOK)
END_MESSAGE_MAP()

These statements must be inserted into your class
definition file for mapping the messages with its event handler function.

4. It may be have the following function

OnInitDialog() – this is the next function to be
executed after its class
constructed.

DoDataExchange() – If you have some controls on the
dialog and needed to take a
variable for that controls, then
you will add this function.

The below class will explain all the details what mentioned in the above instruction.

Class Declaration

#pragma once

class CMyDialogDlg : public CDialog
{

public:
CMyDialogDlg();
virtual ~CMyDialogDlg(void);

protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support

public:
virtual BOOL OnInitDialog();
afx_msg void OnOK();
afx_msg void OnCancel();

DECLARE_MESSAGE_MAP()
};



Class Definition :

#include "StdAfx.h"
#include "CDialogTest.h" //application class
#include "mydialogdlg.h" //your own class


CMyDialogDlg::CMyDialogDlg()
: CDialog(IDD_DIALOG_NEW, NULL)
{

}

CMyDialogDlg::~CMyDialogDlg(void)
{
}

void CMyDialogDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}

BOOL CMyDialogDlg::OnInitDialog()
{
return TRUE;
}

BEGIN_MESSAGE_MAP(CMyDialogDlg, CDialog)
ON_CONTROL(BN_CLICKED, IDOK, ONOK)
ON_CONTROL(BN_CLICKED, IDCANCEL, OnCancel)
END_MESSAGE_MAP()

void CMyDialogDlg::OnOK()
{
AfxMessageBox("hai");
CDialog::OnOK();
}

void CMyDialogDlg::OnCancel()
{
CDialog::OnCancel();
}


























Some Useful Sites:


www.codeguru.com
www.codeproject.com
www.codersource.com

http://www.icce.rug.nl/documents/cplusplus/
www.w3school.com


http://www.functionx.com/visualc/
http://www.microsoft.com/msj/1098/vc6/vc6.aspx
http://www.samspublishing.com/library/content.asp?b=Visual_C_PlusPlus&seqNum=62&rl=1
http://www.codepedia.com/1/Cpp
http://www.go4expert.com/forums/forumdisplay.php?f=60
http://www.cplusplus.com/doc/tutorial/templates.html

http://www.informit.com/guides/content.asp?g=cplusplus&seqNum=169&rl=1

http://www.devarticles.com/c/b/Cplusplus/

How can I handle dynamic menus in MFC?

  1. I put a RichEdit control on my MFC Dialog-based app and the program won't run anymore. What do I do?
  2. How do I prevent a the user from starting a second instance of my app?
  3. How can I handle dynamic menus in MFC?
  4. How do I prevent my application showing a button on the taskbar?
  5. How do I display a bitmap on a button?
  6. Why don't I get a WM_CONTEXTMENU message when I right click in a Tree Control?
  7. How do I change the font of a dialog control?
  8. How can I update my menu in a dialog? I tried adding a ON_COMMAND_UPDATE handler but it never gets called!
  9. How can I convert a CString variable to char* or LPTSTR?
  10. How can I make my Edit Controls created at runtime look 3D?
  11. Why do I get an assertion in MFC when my thread calls a function in the main thread?
  12. How do I send/post a message to the main thread from another thread?
  13. How can I set the title of a property page in Wizard mode?
  14. How can I remove the X (close) button on a floating toolbar?
  15. How can I handle the arrow keys on a custom control on a dialog or CFormView?
  16. Is there a way to find out, from a controlbar, on which side of the parent frame it is docked?
  17. How can I make the ENTER key act like the TAB key on a dialog?
  18. How can I get keyboard shortcuts like TAB to work on a modeless dialog on an MFC control?

VC++ or C++?

  1. Can I use VC++ when MFC is not allowed?
  2. Yes, you can use VC++. VC++ is a development environment, while MFC is a library for developing GUI applications.
  3. What should I use: VC++ or C++?
  4. On the Windows platform, VC++ is a development environment (editor, compiler, debugger) that allows for application development using C as well as C++. All features available in the C++ standard are supported by VC++.
  5. How can I use VC++ when I do not know Windows SDK (Win32 SDK) programming?
  6. VC++ is a development environment (editor, compiler, debugger). CNumbered Listonsole-based, text applications can be developed easily with VC++.
  7. What is curses?
  8. Curses is a library for screen manipulation. The library allows for text mode applications only. It is available on the Unix and Linux platforms. It is available on the windows platform as well, but only with the GNU C++ distribution.
  9. How do I use files for data storage in the project?
  10. To be discussed in class.
  11. Can I use a database / Can I use database connectivity?
  12. No. Database connectivity of any sort is not allowed. To save to disk and read from disk, use simple file I/O.
  13. Can I use MFC?
  14. No. Usage of MFC is not allowed.
  15. What is STL?
  16. STL is a library of common containers and functions written using templates. It is quite an extensive library that should be used wherever possible in the project.
  17. Can I use STL?
  18. Yes. You are encouraged to used STL. Do not spend time writing containers and stacks and sorting routines. use STL and spend more time on the application logic.
  19. Is inheritance a must in the project?
  20. No. Inheritance is not a must. Presence of inheritance depends on the project. You might not be having a single derived class and still it may not be a bad mark on the project.
  21. How big should the project be?
  22. To be discussed in class.
  23. How many classes should be present in the project?
  24. Though the number of classes in the project depends completely on the scope of the project, as a simple markup (for measurement), we follow: 3 to 5 classes per project group person.
  25. But I do not have a GUI!
  26. The main focus of the project should be the classes and their functionality. A jazzy GUI, but not enough functionality, will not fetch you the required marks. Good functionality, with a functional user interface is surely be a better option.
  27. Can I use some classes from MFC?
  28. NO. Usage of MFC in any form - part or whole - is not allowed.
  29. Can I use standard libraries/free libraries?
  30. Yes. But only if you are building an application on top of such a library. Such libraries should not be used to substitute some of the classes you are supposed to be developing as part of the project.
  31. Which compilers are available on the Windows platform?
  32. VC++ and GNU C++.
  33. Which compilers are available on the Unix platform?
  34. There are two choices. The first choice is the native C++ compiler of the environment. The second choice is to use GNU C++ installed on the platform.
  35. Which compilers are available on the Linux platform?
  36. GNU C++ is the native C++ compiler provided with the environment.
  37. How can I use VC++ if I do not use the Win32 SDK?
  38. It is not necessary to useWin32 SDK when using VC++. VC++ is a development environment (editor, compiler, debugger) that allows development of text based applications, windows applications.
  39. Which notation is to be used for the class diagram?
  40. UML only.
  41. Can I use CRC?
  42. No. Use UML notation only.
  43. Can I use OMT?
  44. No. Use UML notation only.
  45. Which part of UML do I refer?
  46. Refer to the "class diagram" part from the appropriate UML references.
  47. Can I use Borland C++ or T
  48. urbo C++?
  49. No. Usage of Borland C++ as well as Turbo C++ is not allowed.
  50. Can I select a project not given in the list?
  51. Yes. In fact, you are encouraged to select a project outside the list. In such a case, use the outlines as a reference to get decide the scope of the project. most importantly, projects not specified in the list have to be approved by local faculty.
  52. How do I decide the scope of the project?
  53. You can refer to the project outlines while deciding the scope of your project.
  54. What is the minimum NCST expects from a project?
  55. To be discussed in class.
  56. What are the expectations from the project?
  57. Expectations from the project are a decent class diagram, good understanding of OO and UML concepts, as well as a running demo.
  58. Can I have design that is more than the code?
  59. Yes. Design is done first. Code is developed according to the design. How can there be code if it has not been designed earlier? Having code but not design means you have created the design from the code, which is a very bad idea.
  60. Can I have more design classes that the implementation at evaluation time?
  61. At the time of evaluation, there is a possibility that the design you have is more than the code implemented. In such a case, do not edit the design diagram to match the implemented code. Let the design model be unchanged. At the time of evaluation, make a distinction between the features implemented versus the features not implemented.
  62. How do I compare code and design?
  63. Your code should be a direct reflection of the design. Design and code have to match.
  64. What is the conceptual diagram?
  65. A conceptual class diagram is a class diagram that does not contain any platform and language specific details. It is a logical diagram. For example, if you wish to represent a collection, putting a "linked list" class in the conceptual diagram is a bad idea. The conceptual diagram should instead mention "pool" or "collection", without talking about implementation specific details. Decisions such as "linked list" or "tree" should reflect in the implementation diagram.
  66. What is the implementation model?
  67. An implementation class diargam is a conceptual diagram plus platform and language specific considerations. An implementation diagram uses the conceptual diagram as its basis.
  68. How can I code in C++ if I do not know C?
  69. The C programming language is a full subset of the C++ programming language. Though the programming paradigms are different for the languages (C advocates procedural programming paradigm while C++ advocates object-oriented programming paradigm), basic programming language constructs are similar.
  70. But we have not done a project in C?
  71. The C programming language is a complete subset of C++. Hence, you do not really need to do a project in C before attempting a project in C++.

What are the advantages of using Doc/View or SDI over DialogBox

What are the advantages of using Doc/View or SDI over DialogBox
1
220



what do you mean by psychic window? Patni
0
8



What is the difference between Extension DLL and Regular DLL? GE
1
1622



how to create SDK based ATL ? how to create SDK based COM? TCS
0
26



what is message loop how mfc does it internally?
2
1429



what is the component of CLR ? AZTEC
2
1669



Do COM keep track of all the object references(Accounting)? Microsoft
2
1454



Define and explain COM? Microsoft
2
1277



Tell us something about MFC? Microsoft
3
2878



What are the two types of events generated by ActiveX controls?
1
846



What is an ActiveX interface?
1
678



What are some differences between a form view and a dialog box? Manipal-Ecommerce
1
1013



What is the difference between serialization and deserialization? MBT
1
1181



What is persistence?
2
938



Which CPrintInfo member variable must be set for multiple page printouts?



what is oops 33


Explain transaction atomicity? 9


What Is FrontPage? 9


Which steps are required to add a column to a list view? 10


What's the Use of OLE Hyperlinking? 5


What is a transparent image? 7


How does a DCOM component know where to instantiate itself? 7


How to Implement static object hierarchies in ATL ? 7


What Is InfoViewer? 7


What changes does a control need to run in an MFC 4.2b container? 22


What is a glyph? 6


In which Way invoke context-sensitive help inside the editor? 8


How do you define a function in vc++? 7


What is the purpose of declaring a variable as unsigned? 7


Does ATL require an application server to operate? 7


What is the file extension used for C++ class implementation files? 6


What property is used to indicate that the up-down control is associated with a buddy control? 4


How to declare more than one variable on a single line? 5


What four types of properties are supported by an ActiveX control? 7


Will ATL create all of the topological relationships within the topology layer?

http://www.shredskerala.org/index.html

http://www.linkedin.com/profile?goback=%2Econ&viewConns=&key=17744669&jsstate=.conbro_0_*51_false_*2_0


http://www.freshersworld.com/
http://www.firstsalary.com
http://www.careerenclave.com/
http://www.shredskerala.org/index.html
http://www.ChetanaS.com
http://www.ChetanaSinterview.com
http://www.vyomworld.com/placementpapers
http://www.go4campus.com/mepz.asp
http://www.geocities.com/careeraid2003/company.html
http://www.aucse.com/Question%20Bank.htm
http://groups.yahoo.com/group/nestjobs/files/
http://jminds.hollosite.com/placement/index.php
http://www.koolkampus.com/campuspapers.php
http://www.jobshive.ne1.net/
http://www.naukri4u.co.nr/
http://www.geekinterview.com/
http://www.sqa-forum.com
http://www.Freshers.in

OPERATING SYSTEM

1. What is MUTEX ?
2. What isthe difference between a 'thread' and a 'process'?
3. What is INODE?
4. Explain the working of Virtual Memory.
5. How does Windows NT supports Multitasking?
6. Explain the Unix Kernel.
7. What is Concurrency? Expain with example Deadlock and Starvation.
8. What are your solution strategies for "Dining Philosophers Problem" ?
9. Explain Memory Partitioning, Paging, Segmentation.
10. Explain Scheduling.
11. Operating System Security.
12. What is Semaphore?
13. Explain the following file systems : NTFS, Macintosh(HPFS), FAT .
14. What are the different process states?
15. What is Marshalling?
16. Define and explain COM?
17. What is Marshalling?
18. Difference - Loading and Linking ?
19. What are the basic functions of an operating system?
20. Explain briefly about, processor, assembler, compiler, loader, linker and the functions executed by them.
21. What are the difference phases of software development? Explain briefly?
22. Differentiate between RAM and ROM?
23. What is DRAM? In which form does it store data?
24. What is cache memory?
25. What is hard disk and what is its purpose?
26. Differentiate between Complier and Interpreter?
27. What are the different tasks of Lexical analysis?
28. What are the different functions of Syntax phase, Sheduler?
29. What are the main difference between Micro-Controller and Micro- Processor?
30. Describe different job scheduling in operating systems.
31. What is a Real-Time System ?
32. What is the difference between Hard and Soft real-time systems ?
33. What is a mission critical system ?
34. What is the important aspect of a real-time system ?
35. If two processes which shares same system memory and system clock in a distributed system, What is it called?
36. What is the state of the processor, when a process is waiting for some event to occur?
37. What do you mean by deadlock?
38. Explain the difference between microkernel and macro kernel.
39. Give an example of microkernel.
40. When would you choose bottom up methodology?
41. When would you choose top down methodology?
42. Write a small dc shell script to find number of FF in the design.
43. Why paging is used ?
44. Which is the best page replacement algorithm and Why? How much time is spent usually in each phases and why?
45. Difference between Primary storage and secondary storage?
46. What is multi tasking, multi programming, multi threading?
47. Difference between multi threading and multi tasking?
48. What is software life cycle?
49. Demand paging, page faults, replacement algorithms, thrashing, etc.
50. Explain about paged segmentation and segment paging ?
51. While running DOS on a PC, which command would be used to duplicate the entire diskette?

MFC

MFC 1.0 introduced these classes:

General:
CObject
CWinApp
CMenu
CArchive
CDumpContext
CRuntimeClass
CMemoryState
CFileStatus
CString
CTime
CTimeSpan
CPoint
CRect
CSize

Exceptions:
CException
CMemoryException
CNotSupportedException
CArchiveException
CFileException
CResourceException

File Services:
CFile
CStdioFile
CMemFile

Collections:
CByteArray
CWordArray
CDWordArray
CPtrArray
CObArray
CStringArray
CPtrList
CObList
CStringList
CMapWordToPtr
CMapWordToOb
CMapPtrToWord
CMapPtrToPtr
CMapStringToPtr
CMapStringToOb
CMapStringToString

Graphics:
CDC
CClientDC
CWindowDC
CPaintDC
CMetaFileDC
CGdiObject
CPen
CBrush
CFont
CBitmap
CPalette
CRgn

Windows Support:
CWnd
CFrameWnd
CMDIChildWnd
CMDIFrameWnd
CDialog
CModalDialog
CStatic
CButton
CEdit
CListBox
CComboBox
CScrollBar

---------------------------------------------------------------------------

3.4. MFC 2.0
=============
MFC 2.0 was a 16-bit release that shipped with Visual C++ 1.0. It
added the Document/View framework on top of MFC 1.0 and also added OLE
1.0 classes, message maps and common dialog classes. This was a
16-bit release released on 02/93

MFC 2.0 introduced these classes:

General:
CCreateContext
CPrintInfo
CDataExchange
CCmdUI

Exceptions:
CFileException
COleException

Dialogs:
[Note CModalDialog was nuked and functionality moved to CDialog, you
can still see a #define CModalDialog CDialog in the header files]
CDialog [not introduced here, but revamped to be a base for common dlgs]
CFileDialog
CColorDialog
CFontDialog
CPrintDialog
CFindReplaceDialog

Windows Support:
[Just new derivatives of CButton/CEdit and VBX class.]
CButton
CBitmapButton
CEdit
CHEdit
CBEdit
CVBControl

Document Architecture:
CCmdTarget
CWinApp [Moved in hierarchy, use to be derived from CObject]
CDocTemplate
CSingleDocTemplate
CMultiDocTemplate
CDocument
COleDocument
COleClientDoc
COleServerDoc

Views:
CView
CScrollView
CFormView
CEditView

Control Bars:
CControlBar
CToolBar
CStatusBar
CDialogBar
CSplitterWnd

OLE 1.0 Classes:
COleServer
COleTemplateServer
CDocItem
COleClientItem
COleServerItem

---------------------------------------------------------------------------

3.5. MFC 2.1
=============
MFC 2.1 shipped with Visual C++ 1.1 for NT, it was basically a Win32
port of MFC 2.0. It was a 32-bit release that was released on
08/93.

MFC 2.1 did not introduce any new classes.

---------------------------------------------------------------------------

3.6. MFC 2.5
=============
MFC 2.5 shipped with Visual C++ 1.5. It introduced the OLE 2 and ODBC
classes. It was the last 'official' 16-bit release.

Released in 12/93

MFC 2.5 introduced these classes:

General: [OLE and DB related]
CFieldExchange
COleDataObject
COleDispatchDriver
CRectTracker

Exceptions: [OLE and DB exceptions]
COleException
COleDispatchException
CDBException

Files: [New OLE File support]
CFile
COleStreamfile

Dialogs: [New OLE Dialogs]
CDialog
COleDialog
COleInsertdialog
COleChangeIconDialog
COlePasteSpecialDialog
COleConvertDialog
COleBusyDialog
COleLinksDialog
COleUpdateDialog

Windows Support: [Some OLE additions]
CFrameWnd
COleIPFrameWnd
CControlBar
COleResizeBar

Document Architecture: [Significant classes added for OLE here.]
CCmdTarget
COleObjectFactory
COleTemplateServer
COleDataSource
COleDropSource
COleDropTarget
COleMessageFilter
CDocument
COleDocument
COleLinkingDoc
COleServerDoc
CDocItem
COleClientItem
COleServerItem

Views: [New view for DB support]
CView
CScrollView
CFormView
CRecordView

ODBC/Database Classes:
CDatabase
CRecordSet
CLongBinary

...........................................................................

3.6.1. MFC 2.51
----------------
A point release to 2.5 (16-bit) that was a bug fix release. Shipped
with MSVC 2.0 in 9/94 with MFC 3.0 (32-bit).

...........................................................................

3.6.2. MFC 2.52
----------------
A point release to 2.5 (16-bit) that added some of the MFC 3.0
features such as property sheets, Winsock and MAPI support.
Shipped with MSVC 2.1 in 1/95 with MFC 3.1 (32-bit).

NOTE: This is only available via the MSVC Subscription.

Classes added in 2.52:
CSocket
CAsyncSocket
CSocketFile
CPropertyPage
CPropertySheet

MAPI:
[Note that MAPI support was added to CDocument, no new classes]
CDocument::OnFileSendMail
CDocument::OnUpdateFileSendMail
COleDocument::OnFileSendMail

...........................................................................

3.6.3. MFC 2.52b
----------------
[Excerpt from the 2.52b rel notes]
Visual C++ 1.52b includes the industry-standard Microsoft
Foundation Class Library (MFC) version 2.52b. Besides classes for OLE
and database, this version includes classes for OLE control
development.

Bugs Fixed in Visual C++ 1.52b

Visual C++ 1.52b fixes a number of bugs from Visual C++ 1.5. Of
particular interest to most developers are the following bug fixes:

MFC 2.52b

Error L2025 occurred on CWnd::DoDataExchange.
This bug has been corrected. See Microsoft Knowledge Base article
Q120152 for more information.

CArchive::ReadObject sometimes caused an assertion in a CPtrArray
object because CPtrArray can hold a maximum object size of 16K in a
large memory model application. CArchive did not take the memory model
into account; since CArchive enforced a 32K limit, objects of 32K
could be written but an assertion was generated if CArchive read in
more than 16K.
This bug has been corrected.

There was a memory leak in 16-bit AUX_DATA.

The three pens used in the class CPropertySheet were leaking. See
Microsoft Knowledge Base article Q128604 for more information.

The CArchive buffer pointer could wrap around the end of a segment unintentionally.
This bug has been corrected.

If AfxSockInit failed, applications sometimes produced a General
Protection Fault.
This bug has been corrected. See Microsoft Knowledge Base article
Q130653 for more information.

The MAPISendMail dialog did not stay modal.
This bug has been corrected.

Source file DLGPROP.CPP had non-near data. This could prevent
applications from being able to run multi-instance.
This bug has been corrected.

---------------------------------------------------------------------------

3.7. MFC 3.0
=============
MFC 3.0 shipped with Visual C++ 2.0 in 9/94. It introduced docking
toolbars, property sheets and template based collection classes. This
was the first release in the MSVC subscription, it was a 32-bit release.

Classes added in MFC 3.0:

Tabbed Dialog Support:
CWnd
CPropertySheet
CDialog
CPropertyPage

---------------------------------------------------------------------------

3.8. MFC 3.1
=============
MFC 3.1 shipped with Visual C++ 2.1 in 1/95. It introduced MAPI,
WinSock and Windows Common Controls. The MFC toolbar, status bar,
etc.. still live in MFC. This is the latest release out. It is a
32-bit release.

NOTE: Only available via MSVC subscription.

Classes added in MFC 3.1:

MAPI:
[Note that MAPI support was added to CDocument, no new classes]
CDocument::OnFileSendMail
CDocument::OnUpdateFileSendMail
COleDocument::OnFileSendMail

Windows Common Controls Classes: [All of these are CWnd derived]
CAnimateCtrl
CHeaderCtrl
CHotkeyCtrl
CImageList
CListCtrl
CProgressCtrl
CSliderCtrl
CSpinButtonCtrl
CStatusBarCtrl
CTabCtrl
CToolBarCtrl
CToolTipCtrl
CTreeCtrl

WinSock Support:
CAsyncSocket
CSocket

---------------------------------------------------------------------------
3.9. MFC 3.2
=============
MFC 3.2 shipped with Visual C++ 2.2 via the subscription in
mid/late July. It is a 32-bit release. Includes a 2.52b 16-bit
release update.

[here's an excerpt from the release notes]

Support for Windows Common Controls in USRDLLs. In order to use the
MFC Windows Common Control classes you must link in the appropriate
static libraries, as shown in the following table:

Library Target
DAFXCC.LIB Release version
DAFXCCD.LIB Debug version
DAFXCCU.LIB Release Unicode version
DAFXCCUD.LIB Debug Unicode version

Updated MFC Common Control classes that work with those controls
that have been recently released in Windows NT 3.51 and those that
will be available in Windows 95 and a future version of Win32s.

Improved common control documentation that is more complete and
reflects changes since the first implementation.

New MFC sample applications
---------------------------
NOTEPAD + Notepad+ is an enhanced version of Notepad. The
enhancements are mainly from questions our customers
have been asking.

SAVER Saver is a screen saver written using MFC. It
"morphs" the text "MFC" to the text "C++".

OLEVIEW The OLEVIEW sample is very similar to the OLE2VIEW.EXE
applet provided in \MSVC20\BIN. The sample illustrates
how to implement OLE Object viewers through custom OLE
interfaces. These custom interfaces are implemented in
IVIEWERS.DLL

BATCH BATCH is an MDI application that lets you compress
different AVI (Audio Video Interleaved) files in
different ways.

WORDPAD WORDPAD illustrates use of the CRichEditCtrl and
CRichEditView classes, which encapsulate the new Rich
Edit common control.


These samples are located in the SAMPLES\MFC directory of your
Visual C++ installation.

Updated Win32 SDK components
----------------------------
With the release of Windows NT 3.51 and the upcoming release of
Windows 95, the Win32 SDK has been updated to support both of these
operating systems. Changes include new header files, new import
libraries, and additional documentation. Visual C++ 2.2 includes the
latest header files, import libraries and Win32 API documentation to
support writing Windows NT- and Windows 95-compatible applications.

---------------------------------------------------------------------------

3.10. MFC 4.0
==============
Rumor has it that MFC 4.0 will be part of MSVC 4.0 (they are finally
going to get the numbers in synch) to ship shortly after Windows 95
ships (9/95). The MFC status bar, toolbars, property dialog and
other UI classes will be rewritten to use the Windows 95 common
controls. There will be other Windows 95 enhancements as well and much
better OLE control support too! Just heard that there will be some
new database classes based on the Jet Engine and
something called message reflection, so you can stop messages from
bouncing up to parents if you want to grab them all.

Classes added in MFC 4.0:
CSynchronize
CMutex
CEvent
CMultiLock
CShellNew - Windows 95

**NOTE: This has not been released yet, MFC 3.2/MSVC 2.2 is the latest
release with MFC 4.0/VC++ 4.0 due out in September.

---------------------------------------------------------------------------

3.11. Table of MFC releases
============================
** Hint, MFC releases are always MSVC release - 1. This is because MFC
1.0 came out with MS C 7.

MFC Rel MSVC Release 16 or 32 bit Notes
---------------------------------------------------------------------------
1.0 16 Just thin Windows coverage
2.0 1.0 16 Document/Views added
2.1 1.1 for NT 32 First 32-bit release for NT
2.5 1.5 16 OLE/ODBC, last 16-bit release
2.51 2.0 16 Bug fixes.
2.52 2.1 16 Adds prop sheets to 2.5
2.52b 2.2 16 Shipped in July '95, bug fixes
3.0 2.0 32 Property sheets, dock toolbars
3.1 2.1 32 Winsock/MAPI, Win commcntrls
3.2 2.2 32 Shipped in July '95, more commcntrls
4.0 4.0 32 Not out yet, Win 95, OLE Control container

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

4. Generic Class Questions
=========================

4.1. CException - Exceptions and exception handling.
----------------------------------------------------

4.1.1. How do I throw a CUserException derived exception?
----------------------------------------------------------
When I try to catch a derived exception I get the following error:
error C2039: 'classCMyException' : is not a member of
'CMyException' 'classCMyException' : undeclared identifier
'IsKindOf' : cannot convert parameter 1 from 'int*' to 'const
struct CRuntimeClass*'

You need to make your CMyException class dynamically creatable
using the DECLARE_DYNAMIC() and IMPLEMENT_DYNAMIC() macros. The
CATCH macro expects to be able to access run-time information about
the thrown class.
-blaszczak@bix.com, Mike B, 6/5/95, comp.os.ms-windows.programmer.misc

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

5. GDI Class Questions
======================

5.1. CDC
========

5.1.1. How do I create a CDC from a HDC?
----------------------------------------
Sometimes the Windows API will just give you a handle to a DC and
you might want to create a CDC from that. On example is
owner-drawn lists, combos and buttons. You will receive a draw
item message with a hDC. Here's some code to turn that hdc into
the more familiar CDC.

void MyODList::DrawItem(LPDRAWITEMSTRUCT lpDrawItem)
{

CDC myDC;
myDC.Attach(lpDrawItem->hDC);

//Do more stuff here

//If you don't detach, it will get deleted and windows will
//not be happy if you delete it's dc..

myDC.Detach();
}
You can use this technique for any of the other MFC class/ Windows
handle pairs too.

Another approach is to call the CDC FromHandle method:

CDC * pDC = CDC:FromHandle(lpDrawItem->hDC);

It's not clear which is 'better', FromHandle is less error prone
because you do not have to remember to 'detach'.
-jmccabe@portage1.portup.com (Jim McCabe) 6/5/95

---------------------------------------------------------------------------

5.2. CBitmap
============

5.2.1. How do I read a 256 color bitmap file from disk?
------------------------------------------------------

Currently, MFC does not contain direct support for reading and
displaying DIBs or BMPs. However, there are a number of sample
applications that illustrate just how to do this.

The first sample is the MFC sample application DIBLOOK. The
MULTDOCS sample uses the same source code provided by DIBLOOK to read
and display DIBs and BMPs.

Two other examples provided with Visual C++ are the SDK samples
DIBVIEW and SHOWDIB.
- Question posted on comp.lang.c++, 6/5/95, found this in MS FAQ, 6/25/95

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


6. Window, Control, and Dialogs Class Questions
===============================================

6.1. Windows
============

6.1.1. How can I use a custom icon for a window?
-------------------------------------------------
The Microsoft Foundation Class Library stores icons for the main
frame window and the MDI frame window as resources. The icon with
resource ID AFX_IDI_STD_MDIFRAME is the icon for the MDI frame
window, and the icon with resource ID AFX_IDI_STD_FRAME is the icon
for the main frame window. To replace these icons in your
application, add an icon to your resources file with the
appropriate ID.

The application specifies the icon for a view in an MDI child
window when it creates the template. The application uses the icon
with the specified resource ID when the user minimizes the MDI
child window that contains the corresponding view.

This technique allows you to specify one icon for the application
to associate with these windows. Windows also supports dynamically
painting a minimized window. To do this with MFC, use
AfxRegisterWndClass() to register a window class with a NULL icon
handle. Override the PreCreateWindow() function in the window class
for the dynamically painted icon and copy the name returned by
AfxRegisterWndClass() into the lpszClassName member of the
CREATESTRUCT. This creates the window using the class that has a
NULL icon. When the user minimizes this window, the icon receives
WM_PAINT messages that it can process to display information
appropriately. To do so, override the OnPaint() message handler and
call the IsIconic() function to see if the window is minimized. If
so, create a CPaintDC object and use it to draw on the icon. If the
window is not minimized, call the base class version of OnPaint()
to update the window normally.
-MSVC Knowledge Base 6/4/94

...........................................................................

6.1.2. How do I change the styles for a window that's created by MFC?
---------------------------------------------------------------------
To change the default window attributes used by a framework
application created in AppWizard, override the window's
PreCreateWindow() virtual member function. PreCreateWindow()
allows an application to access the creation process normally
processed internally by the CDocTemplate class. The framework
calls PreCreateWindow() just prior to creating the window. By
modifying the CREATESTRUCT structure parameter to
PreCreateWindow(), your application can change the attributes
used to create the window.

The CTRLBARS sample application, provided with the Microsoft
Foundation Class Library version 2.0, demonstrates this
technique to change window attributes. Note that depending on
what your application changes in PreCreateWindow(), it may be
necessary to call the base class implementation.

For more information, see MSVC knowledge base article Q99847.
-MSVC Knowledge Base 6/7/95

............................................................................

6.1.3. How do I get the minimal size of a window using MFC?
------------------------------------------------------------
Write a handler for WM_GETMINMAXINFO.
-blaszczak@BIX.com, Mike Blaszczak, 6/12/95 via programmer.misc

............................................................................

6.1.4. How do I change a Window's title?
-----------------------------------------
AfxGetApp()->m_pMainWnd->SetWindowText("My Window Title");
-or-
AfxGetMainWnd()->SetWindowText ( "My Own Title" ) ;
-aj536@freenet.toronto.on.ca, mfc-l, 7/9/95

............................................................................

6.1.5. How do I get rid of 'Untitled' in my main window caption?
-----------------------------------------------------------------
Override the PreCreateWindow function in your MainFrame class and
do the following in it..
cs.style &= ~FWS_ADDTOTITLE ;

You can also set the initial window position (cs.x, cs.y, cs.cx,
cs.cy) this way and change your class (cs.lpszClass) this way!

Remember to call CFrameWnd::PreCreateWindow at the end...
-netninja@svpal.org, programmer.misc, 7/29/95

............................................................................

6.1.6. How do I maximize my MDI child?
---------------------------------------

void CMainFrame::ActivateFrame(int nCmdShow)
{
if (!m_bActivated) {
m_bActivated = TRUE;
nCmdShow = SW_SHOWMAXIMIZED;
}
CFrameWnd::ActivateFrame(nCmdShow);
}

where m_bActivated is a member variable of your frame object.
-duane@anasazi.com, programmer.win32, 8/3/95

............................................................................

6.1.7. Why does focus go nutso with a CSplitterWnd?
----------------------------------------------------
<<< Whenever I move the splitter bar, the I-beam cursor in my edit
control goes away. I have to click again in the edit control to get
back the cursor.>>>

The following Knowledge Base Article (GO MSKB on CIS) explains the
focus problem associated with splitter windows and a couple of
work-arounds to the problem. This may be of help to you.

ID: Q108434
FIX: CSplitterWnd Class Does Not Handle All Focus Cases

-Ramesh, NetQuest., MSMFC, 8/3/95

----------------------------------------------------------------------------

6.2. Controls
=============

6.2.1. How do I get a CControl from a Dialog Template?
-------------------------------------------------------
You can get a pointer to a control from a already created dialog
control by doing a simple typecast of the results from GetDlgItem.
Here's an example that creates a CButton from a checkbox with ID
IDC_CHECK1.

void my_function(CDialog * pDialog)
{

CButton * pButton = (CButton *)pDialog->GetDlgItem(IDC_CHECK1);

ASSERT(pButton != NULL);
pButton->SetCheck(m_bShowState);
}

Note that it's always safer to check for the validity of the
results from GetDlgItem.
-scot_wingo@msn.com, 6/1/95

............................................................................

6.2.2. How do I subclass a control using MFC?
----------------------------------------------
Read the documentation on SubClassDlgItem. Here's an example of
how to call it:

BOOL CMyDialog::OnInitDialog()
{
//Do your subclassing first.
m_MyControl.SubClassDlgItem(ID_MYCONTROL, this);

//Let the base class do its thing.
CDialog::OnInitDialog();

// Perhaps do some more stuff

// Be sure to call Ctl3d last, or it will cause
// assertions from multiple subclassing.

Ctl3dSubclassDlg(m_hWnd, CTL3D_ALL);
}
-Mike Williams, mikew@marlin.ssnet.com, mfc-l 6/1/95

...........................................................................

6.2.3. Why do I get an ASSERT when I subclass a control?
---------------------------------------------------------
Make sure that you subclass the control BEFORE you call
Ctl3dSubclassDlg, if the 3-d control DLL is loaded first, it will
already have subclassed your controls and you will get an assert.
- Mike Williams, mikew@marlin.ssnet.com, mfc-l 6/1/95

...........................................................................

6.2.4. How do I validate the contents of a control when it loses focus?
------------------------------------------------------------------------
NOTE: This is in the Microsoft Software Library.

The FCSVAL sample application was created to show how an
application can do control-by-control validation in a dialog box.

The application itself is just a modal dialog box displayed by the
CWinApp::InitInstance(). After displaying the dialog box,
InitInstance() simply quits the application.

The important part of the sample takes place in the dialog-box
class implementation: There are two edit controls. The first takes
input of an integer between 1 and 20. The second takes a character
string as input with length less than or equal to 5. When you Tab or
mouse-click from control to control within the displayed dialog box,
the contents of the control that is losing focus are validated.

The CFocusDlg Class

The application's functionality centers around the CFocusDlg class
and its implementation of four message handlers (discussed below).
Normal data exchange (DDX) and validation (DDV) using the routines
provided by MFC take place in OnInitialUpdate(), when the dialog box
is first displayed, and when the user chooses the OK button to accept
the input. This is default behavior provided by ClassWizard when
member variables are connected to dialog-box controls and can be
examined in the dialog class DoDataExchange() function.

Validating control contents when switching focus from one control
to the next is done by handling the EN_KILLFOCUS notification sent by
the edit control that is losing focus. The idea here is to check the
contents and, if they are not valid, to display the message box,
inform the user, and then set the focus back to the control from which
it came. Unfortunately, some difficulties arise when trying to set the
focus (or display the message boxes) within a killfocus message
handler. At this point, Windows is in an indeterminate state as it is
moving focus from one control to the other. This is a bad place to do
the validation and SetFocus() call.

The solution here is to post a user-defined message to the dialog
box (parent) and do the validation and SetFocus() there, thus waiting
for a safer time to do the work. (See "CFocusDlg::OnEditLostFocus()"
in the file FOCUSDLG.CPP and "WM_EDITLOSTFOCUS user-defined message"
in the file FOCUSDLG.H.)

Another thing you will notice about this function is that it uses
TRY/CATCH to do the validation. The provided DDX/DDV routines throw
CUserExceptions when failing to validate or load a control's data. You
should catch these and do the SetFocus() in the CATCH block.

Note: This sample has other cool stuff, but this is the major one
I've seen asked about on the net.
-MS FAQ, 6/25/95

...........................................................................

6.2.5. How do I enable/disable a bank of checkboxes?
-----------------------------------------------------
I don't know about a magic way to do this using a single HWND, but there
is a simple and self-documenting technique that I've been using for a
long time. You can make a routine that accepts an array of UINTs (your
control IDs) and a visibility flag.

This function can be a stand-alone function, or you can put it inside a
class. I have been collecting little utility functions like this and keep
them in a CDialogBase class -- when I create a new dialog box in ClassWizard,
I fix up the code to derive from CDialogBase instead of CDialog.

For example, the function might look like this:

void CDialogBase::ShowControls(UINT* pControls, UINT cControls, BOOL fVisible)
{
for (UINT uIndex = 0; uIndex < cControls; uIndex++)
{
CWnd* pwnd = GetDlgItem(pControls[uIndex]);
if (pwnd)
{
pwnd->ShowWindow(fVisible ? SW_SHOW : SW_HIDE);
pwnd->EnableWindow(fVisible);
}
}
}

Then later, often in your OnInitDialog handler, you can call this
function with your control group:

#define SIZEOF_ARRAY(a) (sizeof(a) / sizeof(a[0]))
{
static UINT aGroup1[] = { DLG_CHBOX1, DLG_CHBOX2, DLG_STATIC1 };
static UINT aGroup2[] = { DLG_LABEL2, DLG_LABEL7 };

ShowControls(aGroup1, SIZEOF_ARRAY(aGroup1), TRUE);
ShowControls(aGroup2, SIZEOF_ARRAY(aGroup2), FALSE);
}

You can find many uses for these control arrays later too...
(Changing fonts in a series of controls, etc...) Good luck,
-jmccabe@portage1.portup.com, mfc-l, 7/18/95

...........................................................................

6.2.6. How do I change the background color of a control?
----------------------------------------------------------
Your dialog can trap the WM_CTLCOLOR message, look up the MFC help
file notes for CWnd::OnCtlColor(). Before a control is about to paint
itself, the parent window receives a chance to set its own default
text color and background brush.
-jmccabe@portage1.portup.com, mfc-l, 7/18/95

Also check out the MS KB article ID: Q117778
TITLE: Changing the Background Color of an MFC Edit Control
-Ramesh, MSMFC, 7/19/95

...........................................................................

6.2.7. How do I trap the key for my control?
-----------------------------------------------------
Handle WM_GETDLGCODE and return the appropriate value. Remember that
the listbox (or any other control) can only handle keyboard input when
it has the focus.
-joej@golddisk.com, programmer.misc, 8/21/95, programmer.misc

...........................................................................

6.2.8. How can I DDX with a multiple selection listbox?
--------------------------------------------------------
Download MLBDDX.ZIP from the MSMFC library on CIS. You'll get all
the necessary code. When the dialog closes, a provided CStringList
will be filled with the selected items. Freeware.
-Patrick Philippot, CIS email, 8/3/95

...........................................................................

6.2.9. How do I change the background color of a BUTTON???
-----------------------------------------------------------

NOTE: THE METHOD IN 6.2.6 WILL NOT WORK FOR BUTTONS!

If you want to change the color of a dialog button, you have to use
owner-draw button. (you can use bitmap buttons) Changing the color
through OnCtlColor() will not work for buttons.

The following Knowledge Base articles (GO MSKB on CIS) may be of help to you.

ID: Q32685
TITLE: Using the WM_CTLCOLOR Message

ID: Q64328
SAMPLE: Owner-Draw: 3-D Push Button Made from Bitmaps with Text

This article explains sample code for a owner-draw button.
-Ramesh, NetQuest., MSMFC, 8/3/95

...........................................................................

6.2.10. Why isn't CEdit putting things on separate lines?
----------------------------------------------------------
Make sure that the lines are separated with \r\n, not just \n.
-sutor@watson.ibm.com, mfc-l, 8/7/95

...........................................................................

6.2.11. How do I get to the CEdit in a combobox?
-------------------------------------------------
CComboCox combo;
CEdit edit;

// combobox creation ...
// ...

POINT tmpPoint = {1,1};
edit.SubclassWindow( combo.ChildWindowFromPoint(tmpPoint)->GetSafeHwnd());
-jahans@slb.com, mfc-l, 8/25/95

---------------------------------------------------------------------------

6.3. Dialogs
============

6.3.1. How do I center my dialog?
---------------------------------
Use the CWnd::CenterWindow method accomplish this. I usually put
it in my OnInitDialog overloaded function. Since CDialog is an
ancestor of CWnd, you can call the method directly->

BOOL CMyDialog::OnInitDialog()
{
//Perform any other dialog initialization up here.

CenterWindow();

return TRUE;
}
- scot_wingo@msn.com, 6/1/95.

...........................................................................

6.3.2. How do I get the 'old style' common dialogs on win95?
-------------------------------------------------------------
MFC detects if it is running on Win95, and if so, replaces the
standard FileOpen Dialog with an explorer version of the FileOpen
Dialog. You can prevent MFC from using this "explorer" version by
adding the following line to your CFileDialog derived class
constructor: m_ofn.Flags &= ~OFN_EXPLORER;
-andyd@andyne.on.ca (Andy DeWolfe), via programmer.win32, 5/10/95

...........................................................................

6.3.3. How do I subclass a win95 common dialog?
------------------------------------------------
You can do it but Microsoft has made it much more difficult in
Win95. You need to create a "child dialog template" (with the
WS_CHILD style) and set it to m_ofn.lpTemplateName (making sure
m_ofn.hInstance is set to your app instance). This template must
*only* contain the controls that you are adding to the dialog (ie. NOT
the whole dialog with the standard controls duplicated as in Win3.x).

When the dialog is invoked, your template will appear (by default)
below the regular file dialog controls. If you put a static control
with id stc32 (defined in include\dlgs.h), the common dialog code will
rearrange things so that the original controls will appear wherever
your put the stc32 control (you don't have to size it to match - the
common dlg code will do that for you).

You will need to supply m_ofn.lpfnHook and handle your additional
controls through the hook proc. Note that since the system puts your
dialog template ON TOP of the normal dialog, MFC message routing won't
get to your controls so you can't code them through a message map in
your CFileDialog derivative. If anybody has found a way around this,
I'd love to hear it!!

This is very messy and Microsoft knows it. They promise a fix in
MFC 4.0.
-joej@golddisk.com, Joe Janakovic, via programmer.win32, 6/10/95

...........................................................................

6.3.4. CDialog::Create fails, what could be wrong?
---------------------------------------------------
- Invalid HWND passed as a parent
- Invalid dialog resource ID passed (be careful about numeric IDs
vs. string IDs -- be careful with #define ID_MYDIALOG 0x1234 -- it is
a "string" ID to the resource compiler).
- one or more controls on your dialog could not be created, usually
because of the use of a custom control that was not registered.
- calling EndDialog during the OnInitDialog message (or some other
handler called early in the game)!
- NULL HWND passed as parent when dialog has WS_CHILD style

That's about all I can think of right now,
-Dean McCrory, MSMFC, 6/16/95

...........................................................................

6.3.5. How do I create a toolbar/statusbar in a dialog?
--------------------------------------------------------
There's a sample in the Microsoft Software Library, DLGCBR, that
demonstrates how to do this.

Basically there's four steps, outlined and then coded below->

To add a control bar to a dialog, you must create the control bar
as usual, and then make room for the control bar within the client
area of the dialog. For the control bar to function properly, the
dialog must duplicate some of the functionality of frame windows. If
you want ON_UPDATE_COMMAND_UI handlers to work for the control bars,
you also need to derive new control bar classes, and handle the
WM_IDLEUPDATECMDUI message. If your dialog is not the main window of
your application, you will also need to modify its parent frame window
to pass the WM_IDLEUPDATECMDUI message on to the dialog's control
bars.


To make room for a control bar within the client area of the dialog,
follow these steps in your dialog's OnInitDialog() function:
1. Create the control bars.
2. Figure out how much room the control bars will take by using the
reposQuery option of RepositionBars():

CRect rcClientStart;
CRect rcClientNow;
GetClientRect(rcClientStart);
RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,
0, reposQuery, rcClientNow);

3. Move all the controls in your dialog to account for space used
by control bars at the top or left of the client area. If your dialog
contains a menu, you also need to account for the space used by the
menu:

CPoint ptOffset(rcClientStart.left - rcClientNow.left,
rcClientStart.top - rcClientNow.top);
ptOffset.y += ::GetSystemMetrics(SM_CYMENU);

CRect rcChild;
CWnd* pwndChild = GetWindow(GW_CHILD);
while (pwndChild) {
pwndChild->GetWindowRect(rcChild);
rcChild.OffsetRect(ptOffset);
pwndChild->MoveWindow(rcChild, FALSE);
pwndChild = pwndChild->GetNextWindow();
}

4. Increase the dialog window dimensions by the amount of space used
by the control bars:

CRect rcWindow;
GetWindowRect(rcWindow);
rcWindow.right += rcClientStart.Width() - rcClientNow.Width();
rcWindow.bottom += rcClientStart.Height() - rcClientNow.Height();
MoveWindow(rcWindow, FALSE);

5. Position the control bars using RepositionBars().


To update the first pane of a status bar with menu item text, you
must handle WM_MENUSELECT, WM_ENTERIDLE, and WM_SETMESSAGESTRING in
your dialog class. You need to duplicate the functionality of the
CFrameWnd handlers for these messages. See the CModelessMain class in
the sample program for examples of these message handlers.

To allow ON_UPDATE_COMMAND_UI handlers to work for other status bar
panes and for toolbar buttons, you must derive new control bar classes
and implement a message handler for WM_IDLEUPDATECMDUI. This is
necessary because the default control bar implementations of
OnUpdateCmdUI() assume the parent window is a frame window. However,
it doesn't do anything but pass the parent window pointer on to a
function which only requires a CCmdTarget pointer. Therefore, you can
temporarily tell OnUpdateCmdUI() that the parent window pointer you
are giving it is a CFrameWnd pointer to meet the compiler
requirements. Here's an example:

LRESULT CDlgToolBar::OnIdleUpdateCmdUI(WPARAM wParam,LPARAM lParam)
{
if (IsWindowVisible()) {
CFrameWnd* pParent = (CFrameWnd*)GetParent();
if (pParent)
OnUpdateCmdUI(pParent, (BOOL)wParam);
}
return 0L;
}


To pass WM_IDLEUPDATECMDUI messages on to dialogs other than the
main window, save dialog pointers in your frame window class and
create a WM_IDLEUPDATECMDUI handler in that class. The handler should
send the WM_IDLEUPDATECMDUI message on to the dialog child windows by
using CWnd::SendMessageToDescendants(). Then perform default
processing for the message within the frame window.
-MS FAQ 6/25/95

...........................................................................

6.3.6. Why isn't my CDialog::PreCreateWindow getting called?
-------------------------------------------------------------
PreCreateWindow does not get called when you create a dialog box.
If you would like to init some data/controls for a dialog box you have
to trap the OnInitDialog message and do you stuff there.
PreCreateWindow is use to modify params for a window that you are
creating.
-ewalker@tezcat.com, mfc-l, 7/12/95

...........................................................................

6.3.7. How do I embed a common dialog in a property page?
-----------------------------------------------------------
This question comes up frequently on the "MFC" forum of CompuServe
and the simple answer - unfortunately - is that there is no way to do
it :-(
-chris@chrism.demon.co.uk, programmer.win32, 7/12/95

...........................................................................

6.3.8. Why can't I DDX/DDV to initialize my CDialog controls?
--------------------------------------------------------------
You can't do anything with the dialog controls until your dialog is
created - which doesn't happen until DoModal(). The standard way of
overcoming the problems is to create member variables for the data,
initialise them before calling DoModal and then transfer the values
in OnInitDialog. Or perhaps in UpdateData(). Much like the
ClassWizard member variables does it.

So have your dialog include a CStringList or CStringArray, put the
values for the listbox in that and transfer them to the listbox in
OnInitDialog. [etc...]
-null@diku.dk, programmer.controls, 7/11/95

Init your dialog in OnInitDialog. If neccessary pass a pointer to
your document to the constructor of your dialog (and save it in a
private/protected m_pDoc member).
-jhasling@gascad.co.at, programmer.controls, 7/11/95

...........................................................................

6.3.9. How do I change the captions of a CPropertyPage?
--------------------------------------------------------

You can change the label before adding the page to the property sheet
in the following way.

You have to derive a class from CPropertyPage and add a public function
SetCaption which sets the caption.

void CPage1::SetCaption(char *str)
{
m_strCaption = str; // m_strCaption is protected member of
//CPropertyPage
}

Now you can us the SetCaption() function in the following way.


CMySheet my("My PropSheet");
CPage1 p1;
p1.SetCaption(str); // Setting the caption
my.AddPage(&p1);

CAnotherSheet newps("New Sheet");
CPage1 p2;
p2.SetCaption(newstr);
newps.AddPage(&p2);
my.DoModal();
-Ramesh, NetQuest., MSMFC 8/3/95

...........................................................................

6.3.10. How do I trap F1 in my dialog?
---------------------------------------
The following Knowledge Base Article explains a way to trap the
WM_KEYDOWN messages in the dialog box.

ID: Q117563, TITLE: How to Trap WM_KEYDOWN Messages in a CDialog

The next article explains how to provide context sensitive help in
a dialog. It also points to sample code.

ID: Q110506, SAMPLE: Context Sensitive Help in a CDialog

-Ramesh, NetQuest., MSMFC, 8/31/95

---------------------------------------------------------------------------

6.4. Control bars, status bars, toolbars, dialog bars.
=======================================================

6.4.1. How do I add a combobox to my toolbar?
----------------------------------------------
You can do this using the CToolBar::SetButtonInfo method.
The MFC sample ctrlbars shows how to do this. Basically you call
SetButtonInfo with the resource ID of your combobox. You might
want to throw some separators in there too.
-scot_wingo@msn.com, 6/1/95

...........................................................................

6.4.2. How do I update the text of a pane in a status bar?
-----------------------------------------------------------
By default, a CStatusBar pane is not enabled when the pane is
created. To activate a pane, you must call the
ON_UPDATE_COMMAND_UI() macro for each pane on the status bar and
update the panes. Because panes do not send WM_COMMAND messages,
you cannot use ClassWizard to activate panes; you must type the
code manually. For example, suppose one pane has ID_INDICATOR_PAGE
as its identifier and that it contains the current page number in a
document. To make the ID_INDICATOR_PAGE pane display text, add the
following to a header file (probably the MAINFRM.H file):

afx_msg void OnUpdatePage(CCmdUI *pCmdUI);

Add the following to the application message map:

ON_UPDATE_COMMAND_UI(ID_INDICATOR_PAGE, OnUpdatePage)

Add the following to a source code file (probably MAINFRM.CPP):

void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
pCmdUI->Enable();

}

To display text in the panes, either call SetPaneText() or call
CCmdUI::SetText() in the OnUpdate() function. For example, you
might want to set up an integer variable m_nPage that contains the
current page number. Then, the OnUpdatePage() function might read
as follows:

void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
pCmdUI->Enable();
char szPage[16];
wsprintf((LPSTR)szPage, "Page %d", m_nPage);
pCmdUI->SetText((LPSTR)szPage);

}

This technique causes the page number to appear in the pane during
idle processing in the same manner that the application updates
other indicators.
- MSVC Knowledge Base 6/4/94

...........................................................................

6.4.3. How do I make my CToolBar customizable at run-time?
-----------------------------------------------------------
You might consider reading article "CToolBarCtrl :Handling
Customization Notifications" in the Product Documentation of VC++
2.1.

Here is the relevant extract :
"A Windows toolbar common control has built-in customization
features, including a system-defined customization dialog box, which
allow the user to insert, delete, or rearrange toolbar buttons. The
application determines whether the customization features are
available and controls the extent to which the user can customize the
toolbar. These customization features are available in the
CToolBarCtrl class but not in the current CToolBar class.

You can make these customization features available to the user by
giving the toolbar the CCS_ADJUSTABLE style. The customization
features allow the user to drag a button to a new position or to
remove a button by dragging it off the toolbar. In addition, the user
can double-click the toolbar to display the Customize Toolbar dialog
box, which allows the user to add, delete, and rearrange toolbar
buttons. The application can display the dialog box by using the
Customize member function."

- R.Rajendran (NetQuest), 76041.2245@compuserve.com,
MSMFC Forum, May-9-95

If you want to make a standard MFC CToolbar customizable, you can
download CUSBAR.ZIP from the MSMFC library on Compuserve. This
package implements CCustomTolbar, the run-time customizable toolbar
and also provides the necessary user tools (customization dialog
box including the code for a bitmapped listbox). Freeware.
-Patrick Philippot, 8/3/95 via email on CSERVE

...........................................................................

6.4.4. How do I turn off the toolbar or status bar?
----------------------------------------------------
You can turn the status bar off in any of your views (i.e. in the
OnViewStatusBar() method you describe above) with the following code:

if( ((CMainFrame*)GetParent())->m_wndToolBar.IsWindowVisible() )
GetParent()->SendMessage(WM_COMMAND, ID_VIEW_TOOLBAR, 0L);
if( ((CMainFrame*)GetParent())->m_wndStatusBar.IsWindowVisible() )
GetParent()->SendMessage(WM_COMMAND, ID_VIEW_STATUS_BAR, 0L);

Use 1L instead of 0L for the SendMessage's lParam to turn the bars on.
-JKBenjamin@aol.com via mfc-l, 5/16/95

...........................................................................

6.4.5. How do I create a toolbar/statusbar in a dialog?
--------------------------------------------------------
See section 6.3.5. of this FAQ

---------------------------------------------------------------------------

6.5. Menus
=======================================================

---------------------------------------------------------------------------

6.5.1. How do I get a pointer to the menu bar in a MDI app?
------------------------------------------------------------
Q>I'm writing a MDI application and I have problems to get a pointer to the
actual menu bar. The normal construction doesn't seem to work in MDI:

CMenu *menu;
menu = GetMenu()->GetSubMenu(0);

How can I get a pointer to the menu bar to update the menu?

A> AfxGetApp()->m_pMainWnd->GetMenu()->GetSubMenu(n)
-mlinar@pollux.usc.edu, Mitch Mlinar, 6/8/95

...........................................................................

6.5.2. How do I implement a right-mouse popup-menu?
----------------------------------------------------
//////////////////////////////////////////////////////////////////////
// WM_RBUTTONDOWN handler.
//
// Trap this message and display the button properties popup menu.
// The main frame receives the popup menu messages. This allows the
// status bar to be updated with the help text.
//
///////////////////////////////////////////////////////////////////////
void CAppButton::OnRButtonDown(UINT flags, CPoint point)
{

CMenu menu;
CMenu *submenu;

// load the menu
menu.LoadMenu(IDR_LAUNCH);

// get the popup menu
submenu = menu.GetSubMenu(0);

// convert to screen coordinates
ClientToScreen(&point);

// post the menu
submenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,
point.x,
point.y,
AfxGetApp()->m_pMainWnd,NULL);

}
-johnm@unipalm.co.uk, programmer.win32, 7/12/95

...........................................................................

6.5.3. How do I dynamically change the mainframe menu?
-------------------------------------------------------
CMenu newMenu;
newMenu.LoadMenu (IDR_MENU1);
AfxGetMainWnd()->SetMenu( &newMenu );
AfxGetMainWnd()->DrawMenuBar();
newMenu.Detach ();
-Arun Rao, MSMFC, 6/27/95

...........................................................................

6.5.4. How do I 'attach' a menu to a window's creation/destruction?
--------------------------------------------------------------------
{Note the original question talked about dialogs, but you can
interpolate this code to any kind of window that you want to have
change the menu.}

One of the ways to do this is as follows -

1. Declare a variable CMenu pNewMenu in one of the dialog class.
2. Handle the WM_INITDIALOG and WM_CLOSE messages in the
dialog class as follows.
3. BOOL CMydlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Load the IDR_MYFRAME menu
pNewMenu = new CMenu;
pNewMenu->LoadMenu(IDR_MYFRAME);
// Set the mainframe menu to mainframe.
((CMainFrame *)AfxGetMainWnd())->SetMenu(pNewMenu);

return TRUE;
}
And
void CMydlg::OnClose()
{
// Detach the previous HMenu handle from the object.
pNewMenu->Detach();
pNewMenu->LoadMenu(IDR_MAINFRAME);
// Restore the mainframe menu.
((CMainFrame *)AfxGetMainWnd())->SetMenu(pNewMenu);
CDialog::OnClose();
}
4. If there are other methods of closing the dialog (example-
By clicking a button in the Dialog), then The code given
above in OnClose handler, must be put in the button click
handler.
-Sanjeev Kumar, MSMFC, 6/23/95

---------------------------------------------------------------------------

6.6. Windows Common Controls (a.k.a. Windows 95 controls)
=======================================================

---------------------------------------------------------------------------

6.6.1. Can I use these controls under NT or Win32s?
------------------------------------------------------------
Windows NT 3.50 does not support the common controls, and will not
in the future. You must use Windows NT version 3.51 to gain the
common controls.
-blaszczak@BIX.com, mfc-l, 7/6/95

Version 1.30 of Win32s supports the Common controls.

6.6.2. Where's a demo of this wickedly cool controls?
------------------------------------------------------
Check out the MFC sample, fire, it features most of the controls in
action: MSVC20\samples\mfc\fire.
-scot_wingo@msn.com, 7/27/95
...........................................................................

6.6.3. How do you handle NM_DBLCLK for a CListCtl?
---------------------------------------------------
BEGIN_MESSAGE_MAP(CListView, CView)
ON_NOTIFY( NM_DBLCLK,ID_LISTCTRL,OnDblClick )
END_MESSAGE_MAP()

void CListView::OnDblClick(NMHDR* /*k*/, LRESULT* /*j*/)
{
int nItem, nFlags;
char szTest[80];

nFlags = LVNI_SELECTED;
nItem = m_ListCtrl->GetNextItem(-1, nFlags );
if ( nItem != -1 )
{
sprintf( szTest, "Selected Item %d", nItem);
AfxMessageBox(szTest);
}
}
-spolyak@interaccess.com, mfc-l, 7/21/95

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

7. Documents, Views and Frame Class Questions
=============================================

---------------------------------------------------------------------------

7.1. Views
===========

7.1.1. How do I size a view?
----------------------------
Normally, you can change the size of a window by calling
MoveWindow(). In an application developed with the Microsoft
Foundation Class (MFC) Library, the view window is a child window of
the frame window that surrounds the view. To change the size of the
view window, retrieve a pointer to the frame window of the view by
calling GetParentFrame(), then call MoveWindow() to change the size of
the parent. When the parent frame window changes size, it
automatically changes the size of the view window to fit in the parent
frame.
-MSVC Knowledge Base. 6/4/94

...........................................................................

7.1.2. How do I size a CFormView?
---------------------------------
See MS Knowledge Base article Q98598 for a very long answer.
Basically, you need to override OnInitialUpdate() in a CFormView
derived class. There's other details to deriving from CFormView
that the article goes into.
-MSVC Knowledge Base. 6/7/95

In the view ClikethisView declaration:
virtual void OnInitialUpdate();

In the ClikethisView code:

void ClikethisView::OnInitialUpdate()
{
// make the window the size of the main dialog
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit( /*FALSE*/ );
}
-andyr@gate.net, programmer.misc, 8/11/95

...........................................................................

7.1.3. How do I use new views with a doc template?
--------------------------------------------------
In an application created with AppWizard, you have two options:
change the derivation of the current view, or create a new view
and use the new view in your MDI application along with the
original view.

To create a new view, use ClassWizard to create a new class
derived from CView. After the class has been created, the steps
to use the new view or to modify the view provided by App
Wizard are the same.

1. Modify the header file for the view class to change all
references to CView to the name of the desired view class.
In this example, the class is derived from CScrollView.
Usually, this step involves changing the class the view
class is derived from as follows:

class CMyView : public CScrollView

2. Modify the implementation file for the view class to change
all references to CView to the name of the desired view
class. This involves changing the IMPLEMENT_DYNCREATE line
as follows:

IMPLEMENT_DYNCREATE(CMyView, CScrollView)

changing the BEGIN_MESSAGE_MAP as follows:

BEGIN_MESSAGE_MAP(CMyView, CScrollView)

and changing any other references to CView to CScrollView.

3. No further modifications are required if you are modifying a
view created by App Wizard. If you create a new view, find
the AddDocTemplate() call in the CWinApp::InitInstance()
function. The third parameter to AddDocTemplate() is
RUNTIME_CLASS(CSomeView). To replace the current view with
the new view class, change CSomeView to CMyView. In an MDI
application, you can use multiple view types by adding a
second AddDocTemplate() call that changes
RUNTIME_CLASS(CSomeView) to RUNTIME_CLASS(CMyView).

For more information, please see Knowledge Base article Q99562.
-MSVC Knowledge Base 6/7/95

...........................................................................

7.1.4. How do I change the background color of a view?
------------------------------------------------------
To change the background color for a CView, CFrameWnd, or CWnd
object, process the WM_ERASEBKGND message. The following code shows how:

BOOL CSampleView::OnEraseBkgnd(CDC* pDC)
{
// Set brush to desired background color
CBrush backBrush(RGB(255, 128, 128));

// Save old brush
CBrush* pOldBrush = pDC->SelectObject(&backBrush);

CRect rect;
pDC->GetClipBox(&rect); // Erase the area needed

pDC->PatBlt(rect.left, rect.top, rect.Width(),
rect.Height(), PATCOPY);
pDC->SelectObject(pOldBrush);
return TRUE;
}

...........................................................................

7.1.5. How do I get the current View?
-------------------------------------
The best thing to do is to pass the view along as a parameter.
If this is impractical, you can get the view if you KNOW, that it is
the currently active document and the currently active view. For
details, see Microsoft KB, article Q108587, "Get Current CDocument or
CView from Anywhere". In brief, use

(CFrameWnd*)(AfxGetApp()->m_pMainWnd)->GetActiveDocument()
and
(CFrameWnd*)(AfxGetApp()->m_pMainWnd)->GetActiveView()

to get the document and the view. It might be a good idea to wrap them
in static functions in your CMyDoc and CMyView and check that they are
of the correct RUNTIME_CLASS.

If the view isn't the currently active view or if you can run OLE
in-place, this won't work however.
-null@diku.dk, Niels Ull Jacobsen, programmer.misc, 6/8/95

...........................................................................

7.1.6. How do I create multiple views on one document?
-------------------------------------------------------
The CDocTemplate::CreateNewFrame() function creates additional
views of a document in an MDI application written with MFC.

To call this function, specify a pointer to a CDocument object (the
document for which the function will create a view) and a pointer to a
frame window that has the properties to duplicate. Typically, the
second parameter of this function is NULL.

When an application calls CreateNewFrame(), the function creates a
new frame window and a view in the frame window. The frame window type
and view type depend on the document template (CDocTemplate)
associated with the document specified in the CreateNewFrame() call.

The CHKBOOK MFC sample application that ships with Visual C++ also
demonstrates creating additional frames and views for documents.
Check out CHKBOOK.CPP, the CChkBookApp::OpenDocumentfile() function.

Another example of using CreateNewFrame() is the MULTVIEW sample
application. Also, Dale Rogerson's article, "Multiple Views for a
Single Document" located on the Microsoft Developer Network
Development Library CD-ROM, which explains in detail how to add
additional views to an existing document, is an excellent source of
information.

CreateNewFrame() creates both a frame and a view; not only a view.
If, for some reason, CreateNewFrame() does not quite address your
situation, the source code for CreateNewFrame() is quite useful to
demonstrate the steps required to create frames and views.
-MS FAQ with mods, 6/25/95

...........................................................................

7.1.7. How do I get all the views in an MDI app?
-------------------------------------------------
You need to use some functions which are undocumented:

CDocument::GetFirstViewPosition(); // DOCCORE.CPP
CDocument::GetNextView(); // DOCCORE.CPP
CMultiDocTemplate::GetFirstDocPosition(); // DOCMULTI.CPP
CMultiDocTemplate::GetNextDoc(); // DOCMULTI.CPP

You'll also need to mess with the m_templateList member of CWinApp.
-blaszczak@Bix.com, mfc-l, 7/11/95

...........................................................................

7.1.8. How do I make a CScrollView "mouse scrollable"?
-------------------------------------------------------
Download AUTOSV.LZH from the MSMFC library on CIS. This code shows
you how to implement a secondary message loop taking care of the
mouse activity. Hooks are provided to customize the code. Freeware.
-Patrick Philippot, CIS email, 8/3/95

----------------------------------------------------------------------

7.2. Documents
---------------

7.2.1. Do I have to use the Document/View architecture?
----------------------------------------------------
MFC does not force you to use document/views. Check out hello,
mdi, and helloapp samples, they don't use it at all. Most MFC
features can be used in non-document/view applications. You do
lose features like print preview and of many OLE features when you
don't go document/view.
-scot_wingo@msn.com 6/7/95

...........................................................................

7.2.2. How do I get the current Document?
-----------------------------------------
See section 7.1.5. for the details.

...........................................................................

7.2.3. When are documents destroyed?
-------------------------------------
In SDI applications, the document is deleted when the application
exits. In MDI applications, the document is deleted when the last
view on the document is closed. To help keep your document SDI/MDI
compatible, you should delete the document's data in the virtual
DeleteContents() function, not in the destructor.
-Richard Hazenberg, drmcode@euronet.nl, programmer.misc, 6/24/95

...........................................................................

7.2.4. How do I create multiple documents?
-------------------------------------------
To add support for additional document types, you can create and
register additional CMultiDocTemplate objects with your CWinApp
derived object. This technique is illustrated in the MULTDOCS sample
application. The general steps needed to add an additional document
type to an MFC application are listed below:

1. Use AppWizard to create a new document class and a new view class.
2. Use the Resource Editor to add a new resource string to support
the new document class. For more information on the format of the
document template string resource, see the topic How to Interpret a
Document Template String.
3. Use the Resource Editor to add an additional icon and menu
resource to the application. Note, the ID for each of these resources
needs to be the same ID as the resource ID used for the document
template string created in step 2. This ID is used by the
CMultiDocTemplate class to identify the resources associated with the
additional document type.
4. In the applications InitInstance() function, create another
CMultiDocTemplate object and register it with the
CWinApp::AddDocTemplate() function. For example:

CMultiDocTemplate* pDocTemplate2 = new CMultiDocTemplate(
IDR_DOC2TYPE, RUNTIME_CLASS(CDoc2),
RUNTIME_CLASS(CMDIChildWnd), RUNTIME_CLASS(CView2));
AddDocTemplate(pDocTemplate2);

5. And finally, add the custom serialization and painting code to
your new document and view classes.
-MS FAQ, 6/25/95

...........................................................................

7.2.5. How do I get a list of open documents?
----------------------------------------------
The code below demonstrates how to retrieve a list of pointers to
all CDocuments that were created using a CDocTemplate object.

In the code below, CMyApp is derived from CWinApp. The variable
m_templateList is a CPtrList object that is a member of CWinApp, and
it contains a list of pointers to all of the document templates
(CDocTemplates). The CDocTemplate functions GetFirstDocPosition() and
GetNextDoc() are used to iterate through the list of documents for
each document template.

Sample Code

void CMyApp::GetDocumentList(CObList * pDocList)
{
ASSERT(pDocList->IsEmpty());

POSITION pos = m_templateList.GetHeadPosition();

while (pos){
CDocTemplate* pTemplate =
(CDocTemplate*)m_templateList.GetNext(pos);
POSITION pos2 = pTemplate->GetFirstDocPosition();
while (pos2) {
CDocument * pDocument;
if ((pDocument=pTemplate->GetNextDoc(pos2)) != NULL)
pDocList->AddHead(pDocument);
}
}
}

There are two public member functions of the CDocTemplate class that
are not documented in the reference manual or the online help.
However, these are public member functions defined in the CDocTemplate
class and provide simple functionality for traversing the list of open
documents. These functions operate as follows:

Function: virtual POSITION GetFirstDocPosition() const;

Remarks: Call this function to get the position of the first
document in the list of open documents associated with
the template.
Return Value: A POSITION value that can be used for iteration with
the GetNextDoc member function.

Function: virtual CDocument* GetNextDoc(POSITION& rPosition) const;
rPosition: A reference to a POSITION value returned by a previous
call to the GetNextDoc or GetFirstDocPosition member
function. This value must not be NULL.

Remarks: Call this function to iterate through all of the
document template's open documents. The function
returns the document identified by rPosition and then
sets rPosition to the POSITION value of the next
document in the list. If the retrieved document is the
last in the list, then rPosition is set to NULL.

Return Value: A pointer to the view identified by rPosition.
-MS FAQ, 6/25/95

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

8. OLE Class Questions
======================

8.1. Structured Storage/Compound Files
======================================

8.1.1. When I upgraded, I could not read my files generated by
the old version of MFC. What do I do?
---------------------------------------------------------------
There may be an easier way, but here is how I did it:

Use VERSIONABLE_SCHEMA and GetObjectSchema to identify the version.
If old version, then it is stored in OLE 1.0 format. To read this
format, first read a WORD and a CString (type and name info). Next is
the OLE data itself (the hard part). Use the following steps:

1) use StgCreateDocfile to create a temporary Compound File.

2) use OleConvertOLESTREAMToIStorage to copy the data to the Compound
file, converting to OLE 2 format.

3) call OleLoad using the IStorage to get an IUnknown pointer, then call
QueryInterface to set the COleClientItem::m_lpObject member, and set
m_nDrawAspect to DVASPECT_CONTENT.

4) release the IUnknown pointer and the IStorage pointer

5) The OleConvertOLESTREAMToIStorage code requires an OLESTREAM
implementation. Copy the code from MSVC 1.0 MFC code.

This actually works. Theres some issues with messing with the schema
parameter, and I have not implemented writing OLE 1/MFC files.

Code available on request.
-ronjones@xnet.com, Ron Jones, via programmer.tools, 5/9/95

--------------------------------------------------------------------------
8.2. OLE Controls (previously called OCX's)
============================================

8.2.1. What is an OLE control?
-------------------------------
OLE controls are the 32-bit successor to 16-bit VBX controls.
Instead of being stored in a plain DLL and having functional
interfaces, OLE controls rely on OLE automation. Hopefully this
will make the interface more flexible and easier to use than VBXs.
-scot_wingo@msn.com, 6/25/95

...........................................................................

8.2.2. How do I write OLE controls?
------------------------------------
In VC++ 2.x, Microsoft released the CDK (OLE control developer
kit), you use that kit and it's tools to write OLE controls.
-scot_wingo@msn.com, 6/25/95

...........................................................................

8.2.3. What versions of MFC support OLE control containment?
-------------------------------------------------------------
To clarify the situation:

VC++ 2.x can create OCX controls.
VC++ 2.x does NOT yet have built-in "OCX container" support. That will
be added in VC++ 4, due out this autumn. The only popular application
I'm aware of which currently supports OCXs (albeit in only a limited
way) is Access 2.

The problem is that obviously the place you want OCX container support in
MFC is in classes like "CDialog" and (possibly) "CWnd" or "CView". As I'm
sure you know, OCX controls have to implement a LARGE number of OLE2
interfaces, which makes the support code large.

At present, OLE2 support in MFC happens in the "CCmdTarget" class, which
is the base class from which ALL "application architecture" classes are
derived. I guess the choice is to extend the OLE2 support in this class
to include OCX support (which would make ALL apps using OLE2 a LOT larger),
or to add OCX-specific support to certain specific classes such as
CDialog. Either way, it's a major undertaking!

-Chris Marriott, chris@chrism.demon.co.uk, programmer.tools, 6/24/95

TODO: Find out more about OLE control limitations/support in 4.0

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

9. WOSA Class Questions
=======================

9.1. CRecordSet
---------------

9.1.1. When I add a CRecordSet class, I get tons of linker errors..
--------------------------------------------------------------------

If you haven't told the AppWizard to use Database Support when you
created your project, the AppWizard doesn't include the database
headers. If you add "#include " in your stdafx.h,
CRecordSet will be "legalized".
Then open the Linker Options window and add the library: "odbc".
This avoids tons of linker errors.
-bessler@highland.swb.de (Wolfgang Bessler) 06/05/95, comp.lang.c++

--------------------------------------------------------------------------

9.2. WinSock
=============

9.2.1. I'm having problems with CSocket blocking, what's up?
-------------------------------------------------------------
I've worked around this by creating a dialog box that I pop up after
calling Connect()... ie:

CMySocket MySocket;
MySocket.Create();
MySocket.Connect("mysmtphost",25);
CDummyDlg DummyDialog;
MySocket.m_pDialog=&DummyDialog;
DummyDialog.DoModal();

This suspends the thread until MySocket sends a WM_CLOSE message to
DummyDialog.

I'd rather it look like:

MySocket.m_hEvent=CreateEvent(...);
WaitForSingleObject(MySocket.m_hEvent,INFINITE);

But that stops all processing of MySocket.

-Cynthia Jennings (idlewild@is.net), programmer.win32, 6/19/95

TODO: Find better answer.

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

10. DLL and Build Questions
===========================

If you have questions about extension and user DLLs, be sure to read
technical notes 11 and 33. Volume 2 of the documentation has more
info too. Finally, try searching on the sample names dllhusk
(extension DLL) and dlltrace (user DLL) in books on-line.

--------------------------------------------------------------------------

10.1. Do I need a CWinApp object in a DLL?
------------------------------------------
The Microsoft Foundation Class Library supports two types of DLLs:
_USRDLL and _AFXDLL. The _USRDLL model requires one CWinApp object
to perform the initialization and cleanup of the Microsoft
Foundation Class Library Windows classes that the DLL uses. This
requirement is described in MFC Tech Note 11; the DLLTRACE sample
demonstrates a _USRDLL that contains a CWinApp object.

An _AFXDLL does not require a CWinApp object. Because it shares the
Microsoft Foundation Class Library classes with the application, it
does not require a CWinApp to provide initialization and cleanup.
Instead, an _AFXDLL requires a special version of LibMain() and a
DLL initialization function.
-MSVC Knowledge Base 6/4/95

---------------------------------------------------------------------------

10.2. How should I define the WEP in a MFC DLL?
------------------------------------------------
In a dynamic-link library (DLL) built with Microsoft Foundation
Class Library version 2.0, the _USRDLL model uses the WEP()
(Windows exit procedure) function provided in the C run-time
library. Because the code uses the C library WEP() function,
the destructors for static and global objects in the DLL are
called and the CWinApp::ExitInstance() function for the DLL
application object is called.

See MSVC Knowledge Base article Q98374 and Tech notes 11 and 33.
-MSVC Knowledge Base 6/7/95

---------------------------------------------------------------------------

10.3. How do I build an 'extension DLL'?
------------------------------------------------

1. When you're building a 32-bit extension DLL, define _AFXEXT on the
compiler command line. If you look in AFXVER_.H, you'll see that this forces
_AFXDLL to also be defined. So an "AFXEXT" DLL is an AFXDLL.

2. When _AFXDLL is defined, AfxGetResourceHandle returns a value stored in
MFC's global data, which is shared by the EXE, the extension DLL and the MFC
DLL. The handle returned identifies the module which will be searched first
when looking for a resource.
(See the source code for AfxFindResourceHandle() if you're curious about the
order of the search.)

3. Strictly speaking, what we need to load a resource is a module handle
rather than an instance handle. (Instances share modules --- e.g., code and
resources --- but have different data.) A DLL has a module handle which is
distinct from the handle of the EXE.

4. You can use ::GetModuleHandle to get the handle for your DLL, then pass it
to AfxSetResourceHandle so that your DLL is the first place searched for
resources. But note that this removes the EXE module from of modules
searched. You'll probably want to save a copy of the handle returned by
AfxGetResourceHandle before calling AfxSetResourceHandle, then restore it
once you're done loading the DLL resource.
-Charlie Kester, Microsoft Developer Support, MSMFC, 7/19/95

---------------------------------------------------------------------------

10.4. How can I manage resources in a resource only DLL and still
benefit from ClassWizard?
==================================================================

The following text is available as RESDLL.ZIP in the MSMFC library
on Compuserve (applies to MSVC20):

How to manage an MFC project storing its resources into a resource-only DLL
***************************************************************************

Software localization is much easier when your project stores its
resources in a resource-only DLL. There area also many situations
where storing the project's resources in a DLL can be a good idea.

However, if this project is an MFC project, doing so will generate
a major drawback: you will not benefit from the Class Wizard
capabilities any longer because the resources will be managed in a
separate project.

However, there's a trick that you can use to develop your project
as if it were a standard project while being able to quickly switch
to the resource-only DLL model. Here's how to proceed:

METHOD 1
********
1. Create your project as usual using AppWizard (we'll name it TEST).

2. Close the project and create a new DLL project in the same
directory (call it RESDLL). When you click on the Create button,
VC++ opens the Add file dialog. Take this opportunity to add the
resource file of the previous project (TEST.RC) to this new project.

3. Before being able to compile the resources of the TEST project
as a resource-only DLL, you must add the /NOENTRY option to the
linker. Unfortunately, the settings dialog box of VC++ doesn't
allow to do that in a simple way:

3.1 Select Project|Settings from the man menu.
3.2 Click on the Link tab.
3.3 Select General from the category combobox.
3.4 In the Object/Library Modules field, remove all references to
any .LIB file (they are useless) and add /NOENTRY. This
option should then appear in the Common Options display area.
3.5 Click OK and compile. You now have a DLL containing only the
resources for your project.

4. Do not open the TEST.MAK project. Instead, copy TEST.MAK to
TEST_RES.MAK in your project directory.

5. Open TEST_RES.MAK and remove TEST.RC from the project files.

6. Select Project|Settings, click on the General tab and add
"USE_RESDLL" to the list of Preprocessor Definitions.

7. Open TEST.H and modify the class declaration of CTestApp this way:

public:
CTestApp();

#ifdef USE_RESDLL
public:
virtual int ExitInstance();
private:
HINSTANCE m_hInstDLL;
#endif

8. Open TEST.CPP and modify CTestApp::InitInstance as follows.
Also, add the newly declared ExitInstance member function:

BOOL CTestApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.

#ifdef USE_RESDLL
if ((m_hInstDLL = LoadLibrary("resdll.dll")) == NULL)
{
return FALSE; // failed to load the localized resources
}
else
{
AfxSetResourceHandle(m_hInstDLL); // get resources from the DLL
}
#endif
...

#ifdef USE_RESDLL
int CTestApp::ExitInstance()
{
FreeLibrary(m_hInstDLL);
return CWinApp::ExitInstance();
}
#endif

9. Compile. TEST_RES.EXE should work very nicely, loading its
resources from the DLL.

10. Close the project and open TEST.MAK. Compile. TEST.EXE shoudl
also work very well but this time, the resources are loaded from the
.EXE file because you had not defined USE_RESDLL in this version of
the project.

BEWARE: when switching from one model to another, you must either
Rebuild All