|
Just out of curiousity, do you mix MFC with std::vector.
I ask because on occasion, I have found hosting a vector as a member of a class sometimes causes false memory leak notifications via the elaborate MFC debug code.
|
|
|
|
|
If the size of the type is comparable to a pointer, then it doesn't matter. But if your using larger types, you will probably want to utilize...
CTypedPtrArray
CTypedPtrList
CTypedPtrMap
It's been a while since I examined the MFC source code but I found that it performed full memory copies when resizing (NOTE: this might different for the various MFC versions). This full memory copy would be negligible if your storing pointers.
Also, I think when you are passing in an object for CArray a separate copy is made of the object (when storing the element in the array) regardless of whether you pass it in by value or by reference. This would be some more overhead to consider.
|
|
|
|
|
Hi. I'm trying to save a web page as bitmap. I've created a simple Browser Helper Object but now I'm stuck at how to convert the web page to image. I've tried creating a bitmap screenshot of the browser but that didn't work with pages that require scrolling.
Please help.
|
|
|
|
|
|
|
Writing a simple Win32 Console App to read the header of a WAV file.
Aim was to test my understanding of File IO, but seem to have uncovered a problem with my understanding of strings instead when I got some unexpected output.
The code below results in output such as:
RIFF
RIFF╠╠╠╠¿ ↕
If char ch[4] defines ch as a character array of size 4, why does cout << ch appear to output additional bytes beyond the end of ch?
int main(int argc, char *argv[])
{
char ch[4];
register int i;
if(argc!=2)
{
cout << "Usage: WavInfo <filename>\n";
return 1;
}
ifstream in(argv[1], ios::in | ios::binary);
if(!in)
{
cout << "Cannot open file.\n";
return 1;
}
in.read(ch,4);
for(i=0; i<4; i++){cout << ch[i];}
cout << "\n";
cout << ch << "\n";
}
|
|
|
|
|
C/C++ use the null-character to indicate the end of a string, so in memory, the string would be stored as 'R' 'I' 'F' 'F' '\0'.
So to store 4 characters, you need a string char ch[5];
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Thanks Thaddeus.
Problem solved!
|
|
|
|
|
Strings have to be zero terminated.
Replace
char ch[4];
with
char ch[5];
ch[4] = 0;
or something similar to have a zero after the string data.
|
|
|
|
|
Thanks guyee.
Problem solved!
|
|
|
|
|
MVS 2010 – Errors – fatal error LNK1561: entry point must be defined
- Reason:
- You are using MFC and following linker option is missing: /SUBSYSTEM:WINDOWS
- Solution 1:
- If project is created as Win32 Project this linker option will be automaticly set:
- File – New Project ... – Visual C++ – Win32 – Win32 Project
- Solution 2:
- If projec is created as General Empty Project this linker option needs to be manually added:
- RC on ProjectName – Properties – Configuration Properties – Linker – Coommand Line
- Additional Options: /SUBSYSTEM:WINDOWS
OR LET IDE TO DO THIS:
In Visual Studio IDE enter:
Project -> Properties -> Linker -> System -> SubSystem
Now choose in option combox: Windows(/SUBSYSTEM:WINDOWS)
|
|
|
|
|
Is there a question embedded in here someplace?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi all,
i want to know currently how many threads running in my applcation?
please tell me what api or function use for this?
or please tell me how can i do this.
thanks in advance.
|
|
|
|
|
See here[^].
You can use the code from the link, just need to replace the printf call with conditional check - if the process ID matches your own process ID, obtained via GetCurrentProcessId[^].
modified on Wednesday, January 5, 2011 6:13 AM
|
|
|
|
|
|
I have a SDI app using FormView that's not resizable but will have a large and small size. I would like to create small and large dialogs and then have the view display the correct dialog depending on user choice. I don't want to use multiple views because I don't want to recode handlers, etc. My plan is to i.e. have button ID_OK1 in small dialog and button ID_OK2 in large dialog both to to OnOK() so my code only has to be written once. Any ideas would be appreciated. Thanks,
John
|
|
|
|
|
If it is just about the size of the dialog, isn't resizing the child windows based on the user selection a simpler choice? I have seen articles on CP that show how to do that.
|
|
|
|
|
I was thinking about doing resizing but I have another app that allows resizing and it was a bit tedious to change control sizes, rearrange based on the new window size and update font sizes. I was hoping to layout 2 dialogs in the resource editor and then just switch between the two. Is there an easier way to resize controls instead of calc window size, scale controls then move to new relative positions?
|
|
|
|
|
TBH, I never had to do resizing seriously, so I can't say anything useful about that.
About your original issue, I just felt that resizing would be a lot less code, and bloat, than mapping events from both the forms to some base class, friend class etc and processing them.
|
|
|
|
|
I actually did find something useful. Adding this line to the CFormView constructor lets you use any dialog for the form view:
CMFCView::CMFCView()
: CFormView(CMFCsdi2View::IDD)
{
m_lpszTemplateName = MAKEINTRESOURCE(View_IDD_TO_USE);
}
So at run time I can set View_IDD_TO_USE to the resource for IDD_DIALOG1 or IDD_DIALOG2. The form view then gets created with whichever of the resources I choose. I create the event handlers in the view, i.e. OnOK(). The controls in each dialog need to be the same including names so that when the view creates the handlers they can be mapped, i.e. there must be a control named ID_OK on each dialog so the view can correctly map ID_OK to OnOK().
That means no duplicated code, only two dialogs which doesn't add to much overhead. This works great for what I'm doing.
Thanks to Scott McPhillips for the direction.
|
|
|
|
|
My problem: I need to give to icons resources identifiers values based on other (buttons) identifiers values.
example, if i have a button with CM_TEST identifier, i need to have a corresponding icon with a resource ID = CM_TEST+xxxx
I tried the method explained below without success
Including Shared (Read-Only) or Calculated Symbols
http://msdn.microsoft.com/en-us/library/zakskay9.aspx
my rc file contains:
#define APSTUDIO_READONLY_SYMBOLS
#include "dialogh2.h"
#undef APSTUDIO_READONLY_SYMBOLS
my dialogh2.h content some icons identifiers as:
#define IDI_OK (IDOK+20000)
#define IDI_OK_DISABLED (IDOK+30000)
#define IDI_CANCEL (IDCANCEL+20000)
#define IDI_CANCEL_DISABLED (IDCANCEL+30000)
Result: all identifiers are not calculated and seems to get a value of 0.
some observations:
-icon property window show :
ID: "(IDOK+20000)"
(quotes are present)
-when displaying rc resource symbol dialog, my identifiers IDI_OK, IDI_OK_DISABLED ... don't appear (read-only symbols checkbox checked)
-I did some tests as :
#define IDI_OK (1+20000)
same result..
In all cases, identifiers seems to evaluate to 0 (because they become my app icon and i already have an app icon with ID = 1)
How to solve this problem ?
Thank you very much in advance
|
|
|
|
|
The evaluation of resource symbols does not appear to work when those symbols are used as labels in the resource script as:
#define ID_X 100
#define ID_Y (ID_X + 10)
ID_X ICON ...
ID_Y ICON ...
I suspect there is some information in the link you posted, but the comments from Microsoft are not very clear.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Your example is exactly what i see.
Microsoft seems to say that this should work but .... how???
|
|
|
|
|
Pascal_33 wrote: Microsoft seems to say that this should work but .... how???
It doesn't! I have tried this a number of different ways and it just does not work. The problem is that in the .rc file the 'calculated' value is replaced by the preprocessor but the rc compiler does not recalculate it but accepts it as a string value.
#define IDI_X 100
#define IDI_Y (ID_X + 100)
...
IDI_X ICON ...
IDI_Y ICON ...
100 ICON ...
(ID_X + 100) ICON
which is obviously wrong. It seems that rc will not recalculate expressions that are used as labels in resource scripts.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Pardon the silly question: "did you include dialogh2.h in your dialog's source (*.cpp ) file?"
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|