|
Well, for starters, I don't see destructors to clean up those char * you're allocating, so you'll leak memory. HOwever, this is a lot of code to hope for people to read, you should really distill your post to a specific question, and a specific snippet that relates to it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hello, I need to draw graphics dnamically during runtime on a dialog box.
Being a VC++ noob, how is it best ot do this? Should I draw directly to the dialog box within a predefined area or draw to some other control. I can do this to a ListView object, but is it possible to use a ListView on a dialog box, or again, is there some other control that I should use?
Thanks much!
|
|
|
|
|
You don't provide enough details for what you are trying to accomplish.
ctroyp wrote: Should I draw directly to the dialog box
Usually no, but you didn't state what you are trying to do. Your mention of the listview is rather confusing since it doesn't sound like you want a listview. You can place controls on a dialog box via the dialog editor, and this would include the listview.
In most cases, if there is no common control that fits your purpose, you write your own custom control. There are various articles on codeproject about doing this.
|
|
|
|
|
Let me begin again... Sometimes it's hard to know how to ask the right question.
I have a dialog box that contains some textboxes and such, but also want to draw graphics in a pre-defined drawing area (canvas) using CPen during runtime. In addition, this canvas needs to be bound to the dialog box and should not change. I am not concerned with how I will actually draw to this canvas at this time (until I know what I am using), but I just need to know what object to use for the canvas. What are my options for this canvas? Or should I just define a section on the dialog itself that can be drawn on with predefined bounds?
Does this make any better sense?
|
|
|
|
|
Create a custom control and place it on your dialog at the size you want.
Here[^] is an article on creating custom controls.
|
|
|
|
|
Thank you, I'll give it a try...
|
|
|
|
|
You could place a static control, there are articles about controls based on statics.
Elaine
|
|
|
|
|
I am new to Windows Forms programming using Visual C++ 2005. I'd like your help in writing a simple application which does the following:
When the executable is run, a window opens up with a display of an image that depicts whether the network cable is connected or not. There will be no other controls at present other than a button to exit the app.
Where should I place the code that detects the connection? Should it be in the Form1.h file or the networkapp.cpp(name of the app) file. Since the first thing after the form is created will be to check the network connection, I'm thinking it will go in the network.cpp file right after the
Application::Run(gcnew Form1());
If you could show me some sample code I'd appreciate that.
|
|
|
|
|
This is the wrong forum for managed C++ programming. You should direct your questions here[^] instead.
samaruf wrote: I'm thinking it will go in the network.cpp file right after the
Application::Run(gcnew Form1());
And have you actually attempted this? Instead of asking this sort of question you should try it out. You would then notice that your code never runs until you exit your form as Application::Run() is actually running the message loop.
samaruf wrote: Where should I place the code that detects the connection?
If it just detects the connection on startup, then there is the Load event for the form you can use.
|
|
|
|
|
hie , i just got VS.NET 2005 pro.. and it seems that only C# , J# and VB have the office 2003 look... but when i build a resource in VC .. i dont have the new look.Everything in THE RESOURCE EDITOR is just the regular Xp style.I tried compiling an old VC6 project( i did choose to convert it to .NET) .And i dont even have the regular XP look!!! am i supposed to manually load the comclt 6.0? like VC6 ?
thank in advance!
Gideon
|
|
|
|
|
giddy_guitarist wrote: it seems that only C# , J# and VB have the office 2003 look
For the IDE? The IDE still looks office 2003ish in C++ mode. I guess the margin/ruler tool in the dialog editor does look rather dated, and they seem to have neglected to update the icons for the toolbox.
giddy_guitarist wrote: but when i build a resource in VC .. i dont have the new look
If you are referring to how your application looks, VS2005 does not come with a new version of the common controls. Those come with new Windows versions.
giddy_guitarist wrote: And i dont even have the regular XP look!!!
You need to include a manifest. VS2005 comes with a manifest tool which you can configure in your project properties to make it easier to embed the manifest. It embeds manifest by default on new projects.
|
|
|
|
|
um i dont mean the IDE at all... i 'm only talking about the look of the application i would be building in VS.
http://gideon.110mb.com/sshot.html[^] look at these screenies
??
|
|
|
|
|
That's a Windows Forms .NET control. Are you using the .NET framework?
That said, I was quite disappointed with the quality of the menustrip/toolstrip expecting it to be a bit more closer to the actual ones instead of a superficial paint job. Still it was better than nothing since you do little work to get it.
If you are not developing a commercial application then this[^] might be of interest to you. If are are developing a commercial app, you might want to fork out the license fees to get good UI components (from FOSS Software, Codejock etc)
If you want free, then you've got quite a bit of work to do. You can modify the existing controls like CMenuXP[^] but expect bugs.
|
|
|
|
|
This should convert characters to lower case, however, it is not compiling. Would I be able to work around this issue, since I’m using arrays of chars and not string objects? Type conversion?
#include <string>
..
string CSentenceAr::LowerCase(char stringtoConvert)
{//change each element of the string to lower case
for(unsigned int i=0;i<strToConvert.length();i++)
{
strToConvert[i] = tolower(strToConvert[i]);
}
return strToConvert;//return the converted string
}
..
This is a console application, by the way, does it make a difference?
In order to implement this code the /Ehsc option seems to be expected by the compiler (MSDN). Can this be done from VS 2003?
Jon
|
|
|
|
|
jon_80 wrote: string CSentenceAr::LowerCase(char stringtoConvert)
{//change each element of the string to lower case
for(unsigned int i=0;i < strToConvert.length();i++)
The parameter, strToConvert , is of type char . So you won't find the length() member function.
Maxwell Chen
|
|
|
|
|
in my app, I use new operator to alloc memory.
each "new" allocs 200k to 3 M bytes for multiple times, total size alloced around 20M.
the app crashes at a "new operator".
I am wondering why it crashes just for allocing total 20M bytes.
but in Debug mode, the app runs properly. it crashs only in Relese mode, why?
Question:
which way is the best for allocing memory? GlobalAlloc() or new? any explaination?
|
|
|
|
|
Can you add some message boxes (with debugging text) to pause step-by-step each time when it is trying to allocate in release build?
There should be something wrong in your code. Couple days ago I made an application which allocated many of small memory blocks to constitute a 1 GB disk file. I only used new in the code, and it worked just fine.
Maxwell Chen
|
|
|
|
|
includeh10 wrote: the app crashes at a "new operator".
does it give you any message when the crash happens ?
includeh10 wrote: GlobalAlloc() or new?
unless you need the specialized features that GlobalAlloc provides (ex. shared or locked memory), you should use new.
Why donchoo take a peekchur mayn?
OK, cleeeeek
|
|
|
|
|
For the application to crash in the call to "new" one or both of the situations below may be hapening:
1) You call new 1 and then trash the memory thus making new 2 fail because the heap memory list gets corrupted.
2) The new is creating an object which has an error in the constructor and so crashes the application during construction.
To determine what might be happening try the following code:
#include <stdio.h>
void main(void) {
long ttsz=0;
long bsz;
char* bp;
while(1) {
printf("Input size (in KB): ");
scanf("%d", &bsz);
bsz*=1024;
printf("Allocating a size of %d\n", bsz);
bp=new char[bsz];
printf("Allocated a size of %d into 0x%p\n", bsz, bp);
ttsz+=bsz;
printf("Total allocated size (in KB): %d\n", ttsz/1024);
printf("\n");
}
}
I tried this code several times and it works fine.
You should use GlobalAlloc only when strictly necessary. It is not as simple nor as portable as new.
I hope this helps,
Rilhas
-- modified at 17:10 Friday 4th August, 2006
|
|
|
|
|
now i had implemented through PfAddFiltersToInterface(ihandle,1,&inFilter,0,NULL,&fHandle) instead of addglobal filter to interface so that i could specify the ip port+ip to block of my pc.
but it did not work it depends only the parameter passed in pfcreateinterface rather then in addfilter to interface or i might be interpretting the src and destination as wrong. the complete code below
if(::PfCreateInterface(0,PF_ACTION_FORWARD,PF_ACTION_FORWARD,false,true,&ihandle)==NO_ERROR)
{
AfxMessageBox("Step 1 Done");
BYTE ip[4]={202,165,250,50};
BYTE msk[4]={255,255,255,0};
BYTE dm[4]={0,0,0,0};
inFilter.dwFilterFlags = FD_FLAGS_NOSYN; //always this value
inFilter.dwRule = 0; //always this value
inFilter.pfatType = PF_IPV4; //using ipV4 addresses
inFilter.SrcAddr = (PBYTE)dm;
inFilter.SrcMask = (PBYTE)dm; //mask for local ip
inFilter.DstAddr = (PBYTE)ip; //any destination
inFilter.DstMask = (PBYTE)msk;
inFilter.wSrcPort =0;//any source port
inFilter.wSrcPortHighRange=4000;
inFilter.wDstPort = 80; //destination port 80(http service)
inFilter.wDstPortHighRange=80;
inFilter.dwProtocol =(DWORD)FILTER_PROTO_ANY; //Tcp protocol
DWORD err;
err=::PfAddFiltersToInterface(ihandle,1,&inFilter,0,NULL,&fHandle);
if(err==NO_ERROR)
{
if(::PfBindInterfaceToIPAddress(ihandle,PF_IPV4,(PBYTE)ip)==NO_ERROR)
{
AfxMessageBox("IP Adress Binded");
}
}
}
i think input according to input filter it should block on port 80 but i can browse internet through that port.
either i m misunderstanding the src and destination or these api not working.
Tasleem Arif
|
|
|
|
|
Hi guys,
When I am doing my development on MFC, a weird case puzzled me.
I implemented a control which will send a windows message to its parent in some case. For example, it will send its parent a message about 'ON_KEYDOWN' using GetParent()->SendMessage(WM_KEYDOWN.... And I override OnPreTranslateMessage method in its parent control, which I suppose it can catch the WM_KEYDOWN mesasge and do some work on the message.
The code in OnPreTranslateMessage looks like:
void CParentControl::OnPreTranslateMessage(...)
{
if( pMsg->Message == WM_KEYDOWN)
{
....// do some thing here
}
CWnd::OnPreTranslateMessage(..);
}
However, the fact is, in most case OnPreTranslateMessage do can catch the message. But in some case it can not -- and I can sure that the child control absolutely had sent the message.
And I also tried another approach: I use message map to catch ON_KEYDOWN . This time the message can also be catched.
Is there any difference with this 2 approach? In what cases the message will escape from OnPreTranslateMessage but still can be catched by message map?
Sorry I may not describe the question clearly because the limitation of my English.
I really appreciate any one who can give me any clues.
Thanks!
Findekano@Shanghai, China
|
|
|
|
|
Try:
1)test PostMessage() to see what happends - SendMessage() is syncronizied (return after executing the message).
or
2)pass parent window to child, then test again.
such as in parent class, call child->GiveYou(this), in child window, use a class member to record the parent pointer, then use the pointer rather than GetParent().
|
|
|
|
|
Thank you very much for your nice reply.
Actually what your suggested are also my first response.
I tried PostMessage, things does not change...
For the second, I am afraid that invoking a method of a control's parent control is really not a good design. It will make the control only be used inside one certain type of parent control. And actually this is what I want to eliminated -- I think using Windows Message should decouple them a little bit.
Well, this Message Loop thing just remind me another question:
When we hava dialog with a lot of controls in it. And there are even more sub-controls in these controls. The whole tree of the controls could be complex. While we click a button which resides in some place of the control tree, how does the message broadcasted? Will the ON_MOUSE_CLICK bubbled up from the button to its parent, and to its parent's parent, until arrive to the root which is the dialog it self (or even go further) ? Or the message is start from the root node and traved down till the button? Is there any rules of how message is transferred?
I had work on Win32 SDK and MFC for several year, but I still have to say these knowledge is fuzzy to me Hope someone can pull me out from the swampland .
Findekano@Shanghai, China
|
|
|
|
|
Findekano wrote: For the second, I am afraid that invoking a method of a control's parent control is really not a good design. It will make the control only be used inside one certain type of parent control.
This is correct. However attempting to send WM_KEYDOWN isn't any better.
If your needs aren't particularly complicated you can send WM_NOTIFY[^] notification message to the parent. You will be limited to this set of notifications though. If your needs are more complicated define your own custom notification notification message using #define UWM_MYCONTROLNOTIFY WM_APP + x or RegisterWindowMessage() whichever is appropriate for your application.
Findekano wrote: And there are even more sub-controls in these controls
If your controls were properly written in the first place, the fact that a control contains subcontrols shouldn't matter to the parent. Eg. control receives notification from it's subcontrol, if this notification would be of interest to the control's parent, then the control should generate it's own notification message to the parent.
Findekano wrote: Will the ON_MOUSE_CLICK bubbled up from the button to its parent, and to its parent's parent, until arrive to the root which is the dialog it self (or even go further) ?
I'm assuming you mean the WM_LBUTTONDOWN message. Why would you need to bubble raw input messages up to the parent? What will the parent do with them? There is the WM_PARENTNOTIFY message which doesn't exactly bubble but sends to all ancestor windows and gives you notification of button clicks, but I'm sure there is a better way to handle what you are trying to do. (You might want to read the remarks section for WM_PARENTNOTIFY[^]. There aren't all that many messages that windows will forward around if not handled. One of them is WM_MOUSEWHEEL, the default window procedure bubbles it up to the parent if not handled, but this is the exception rather than the norm.
I notice you are trying to use PreTranslateMessage to do something, in most cases (and yours) it looks like a bad design. You might want to read this[^].
-- modified at 14:03 Saturday 29th July, 2006
|
|
|
|
|
Hey,
This is really a lot of help!
Thank you very much!
Jay Zhu@Shanghai, China
|
|
|
|
|