|
A vector is a dynamic array, part of the stl ( standard template library ). If you search for 'vector STL', there are plenty of articles on the site on how to use them.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Just a simple example of what Christian suggested:
CStatic m_Statics[1000];
for (int i = 0; i < 1000; i++)
{
m_Statics[i].Create(...);
m_Statics[i].LoadBitmap(...);
m_Statics[i].ShowWindow(SW_HIDE);
}
You can acces the m_Statics[] member variable of your dialog from any function of your dialog.
void CYourDialog::ShowMeOneStatic(void)
{
m_Statics[112].ShowWindow(SW_SHOW);
}
But my problem is with your design. A dialog window has a very limited space. How do you wanna show dozens of control on it at a time?
Is it possible that you don't need them all at a time? Do you just wanna use those CStatic's to store data, and show a FEW of them on your dialog?
Give more details about your project so that we can provide you with more help.
Peter Molnar
|
|
|
|
|
I'd first like to say that this website and you people who help me out are amazing and wonderful, and I'm thankful for you. Well, the program I'm making is a report generator for doctors. Basically, the visual part for the user will be kinda like Microsoft Publisher. They can make squares, rectangles, and lines, each with whatever thickness or color, and the shapes will have borders and frames. Plus, there'll of course be text boxes. The reason I want to change how I'm doing it is: if I have to plan ahead for ANY possible way someone might want to use this, I'd have to setup at least like 10 of each type of thing from the get go, which I'm assuming uses more overhead than would be good. But, then what if they want 11 text boxes, or 11 ovals? Well, maybe I should create 20 of each? See the issue, there? So, I figured that a dynamic way of creating them would be better, so I'm only using the space needed for what the user wants, and they can create as many whatevers as they so desire.
A question: CStatic m_Statics[1000];
Wouldn't that use a ton of memory, or is there really no way to avoid it? Is this an stl vector? Or is that something different?
halblonious
|
|
|
|
|
halblonious wrote:
Wouldn't that use a ton of memory
No, not an issue. You will hardly notice it in the memory footprint of your app.
halblonious wrote:
is there really no way to avoid it?
There are two ways for storing multiple values of the same type (like those of your shapes):
1.List
2.Array
Theoritically both can replace each other, but there are rules of thumbs for their usage:
A list should be preferred if the number of elements is not known, and an array if their number is well known.
The reson for the why lies in the memory management of them (i.e. the way the stored items are organised in memory).
Using a list you can easily (i.e: quickly) access the next or previous element but you can only slowly access the elemnt at a given number from the begining. Arrays can access elements at given position quickly but they are slow if you change their size.
If you allocated 1000 CStatic's in an array and later it turns out that you will need 1001 of them, all the stored data in the 1000 CStatic's must be reordered by the memory management which might go slowly.
In MFC they are called array and list(e.g see CObArray and CObList in MSDN), but in STL (Satandard Template Library - which is Microsoft independent) they are called vector and list.
BTW: ask another question on this forum about your app's design describing what in detail what you want. You will save a bunch of time by not trying to go unachievable ways.
Peter Molnar
|
|
|
|
|
Hi,
For days now I've been trying to make my gui happen - and it's just not. Please help if you can!
I have what is essentially a floating tool palette (just as you'd see in Photoshop etc). The palette contains a series of tabs which hold various controls, all implemented as a CPropertySheet with CPropertyPages attached. This works fine except that I have to make it a TopMost window for it to act like a palette - but this sucks! Every time I open a dialog, the dialog sits beneath the palette, unless I switch of the palette's TopMost status, but then it disappears behind the main window! And when I select a different application (eg Visual Studio) my palette even sits above this.
I can't believe it's this painful to manage a little old floating palette. Someone suggested using a CDialogBar to contain the palette but how do I add the CPropertySheet to the CDialogBar? Is it even possible?
Any advice would be so, so appreciated.
Thanks a lot,
Simon
|
|
|
|
|
|
Peter,
This was exactly what I was looking for - I just didn't know it at the time. Thanks so much for your help.
Simon
|
|
|
|
|
I have a program (C) where I am reading the data from file. For some reason it is not reading the all rows in file. Is some limitation exists? What should I look for in order to fix this problem?
while (!feof(stream))
{...}
|
|
|
|
|
A few questions first.
1. Is it intermittently(sp?) missing data or only at certain points in the file?
2. What functions are you using to read from the file?
3. Is your buffer that you are reading into large enough?
4. Have you tried debug code to output what gets read in to the screen or debug window so that you can verify the data being read in?
5. If you are just using C functions to read have you thought about using the Win32 API functions?
|
|
|
|
|
Adam Gritt wrote:
If you are just using C functions to read have you thought about using the Win32 API functions?
Or maybe C++ ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I am trying to develop Console based application with Modless Dialog box.
This application has many class which does different operations like sending messages,
getting messages and various update process which I have to display on the modless dialog box.
I have created console based project with MFC support using App Wizard. Also able to create modless dialog
CModlessDlg *pDlg = new CModlessDlg;
pDlg->Create(IDD_DIALOG_MODLESS);
pDlg->ShowWindow(SW_SHOW);
..
call ClassA which gets messages and updates modless dlg on how many messges were received
call ClassB which sends messages and updates modless dlg on how many messges were sent
..
delete pDlg;
PROBLEM: I have to update this modless dialog box with how many messages recieved, how many messages sent etc from different class.
I tried GetDlgItem, GetDlgCtrlID in ClassA, ClassB but I am unsuccessfull and I am unable to get the handle of ModlessDlg and access its variable to update.
I think I am not using it in right way!!!
What is the best way do it?
As my application is console based unlike dialog based.
what extra plumbing is required to update the modless dlg ?
If anyone knows a better approach (other than modless) do let me know.
Thanks for all your help.
|
|
|
|
|
One option to look at would be to add custom message handler(s) to your dialog class, then use PostMessage to communicate with it.
All your classes then need to know about the dialog is its HWND [edit - and, of course, the new message #defines]. Let the dlg class itself update the controls based on the messages lParam and wParam.
|
|
|
|
|
Thanks for your reply.I think I would understand better with some code snippets.
Thanks.
|
|
|
|
|
This article[^] should help - [edit again - the part on WM_APP constants messaging in particular, though there is lots more stuff to look at here.]
|
|
|
|
|
Hi, does anyone know how to obtein the IP of the computer using visual c++?
And the physical direction?
Thanks
|
|
|
|
|
maskaseb wrote:
Hi, does anyone know how to obtein the IP of the computer using visual c++?
gethostname() followed by gethostbyname() .
maskaseb wrote:
And the physical direction?
???
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thank you David, but I got this message:
"error C2065: 'gethostname' : undeclared identifier"
"error C2065: 'gethostbyname' : undeclared identifier"
Could you tell me the #include I have to put and make an example?
Thank you for your help
For phisical direction I refer to the first information that you get if you do a ipconfig/all in a ms-dos window.
Thank you another time
|
|
|
|
|
maskaseb wrote:
Could you tell me the #include I have to put...
See here and here.
maskaseb wrote:
For phisical direction I refer to the first information that you get if you do a ipconfig/all in a ms-dos window.
Don't you mean physical address?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Yes, you are ok.
Sorry, but I don´t have a very good english.
Thanks.
|
|
|
|
|
here is an example:
//AdaptersInfo.h
#if !defined __ADAPTERSINFO_H
#define __ADAPTERSINFO_H
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <assert.h>
#include <windows.h>
#include <Iphlpapi.h>
#define MYLIB_IP_MAX 5 // Max # of IP bind on ONE-adapter
#define MYLIB_GATEWAY_MAX 3 //Max # of Gateway for ONE-adapter
struct AdapterInfo{
char name[MAX_ADAPTER_NAME_LENGTH + 4];
char des[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];//Description
UINT mac_len;
BYTE mac[MAX_ADAPTER_ADDRESS_LENGTH];
DWORD index;
UINT type;
int ips;
char ip[MYLIB_IP_MAX][16];
char ip_mask[MYLIB_IP_MAX][16];
int gateways;
char gateway[MYLIB_GATEWAY_MAX][16];
char gateway_mask[MYLIB_GATEWAY_MAX][16];
};
DWORD GetAdaptersInfo(struct AdapterInfo infos[], int& nArraySize);
#endif // !defined __ADAPTERSINFO_H
//AdaptersInfo.cpp
#include "AdaptersInfo.h"
DWORD GetAdaptersInfo(struct AdapterInfo infos[], int& nArraySize)
{
DWORD dwRet;
IP_ADAPTER_INFO pai[10];
ULONG ulSize = sizeof(pai);
int nAdapters = 0;
memset(infos, 0, sizeof(struct AdapterInfo) * nArraySize);
dwRet = ::GetAdaptersInfo(pai, &ulSize);
if(dwRet == ERROR_SUCCESS){
IP_ADAPTER_INFO* p = &pai[0];
while(p){
//Fill general info
strcpy(infos[nAdapters].name, p->AdapterName);
strcpy(infos[nAdapters].des, p->Description);
//Fill mac-address info
infos[nAdapters].mac_len = p->AddressLength;
memcpy(infos[nAdapters].mac, p->Address, p->AddressLength);
infos[nAdapters].index = p->Index;
infos[nAdapters].type = p->Type;
//Get IP info
int nIPs = 0;
IP_ADDR_STRING* pipList = &p->IpAddressList;
while(pipList && nIPs < MYLIB_IP_MAX){
strcpy(infos[nAdapters].ip[nIPs], pipList->IpAddress.String);
strcpy(infos[nAdapters].ip_mask[nIPs], pipList->IpMask.String);
nIPs++;
pipList = pipList->Next;
}
infos[nAdapters].ips = nIPs;
//Get gateway info
int nGateways = 0;
IP_ADDR_STRING* pGatewayList = &p->GatewayList;
while(pGatewayList && nGateways < MYLIB_GATEWAY_MAX){
strcpy(infos[nAdapters].gateway[nGateways], pGatewayList->IpAddress.String);
strcpy(infos[nAdapters].gateway_mask[nGateways], pGatewayList->IpMask.String);
nGateways++;
pGatewayList = pGatewayList->Next;
}
infos[nAdapters].gateways = nGateways;
nAdapters++;
p = p->Next;
}
}
nArraySize = nAdapters;
return dwRet;
}
//main.cpp
#include <iostream.h>
#include "../AdaptersInfo.h"
//DWORD GetHostIPs(struct AdapterInfo infos[], int& nArraySize)
int main()
{
struct AdapterInfo infos[10];
int n = 10;
DWORD dwEC;
dwEC = GetAdaptersInfo(infos, n);
for(int i = 0; i < n; i++){
int j;
cout << "Adapter [" << i + 1 <<"] info:" << endl;
cout << "\tName:" << infos[i].name << endl;
cout << "\tDescription:" << infos[i].des << endl;
cout << "\tMac address:";
cout.flush ();
for(j = 0; j < infos[i].mac_len ; j++)
printf("%02x%c", infos[i].mac[j], (j == (infos[i].mac_len - 1)) ? '\n' : ':');
cout << "\tIndex:" << infos[i].index << endl;
cout << "\tType:" << infos[i].type << endl;
for(j = 0; j < infos[i].ips; j++){
cout << "\tIP[" << j << "]:" << infos[i].ip[j];
cout << "(" << infos[i].ip_mask [j] << ")" << endl;
}
for(j = 0; j < infos[i].gateways; j++){
cout << "\tGateway[" << j << "]:" << infos[i].gateway[j];
cout << "(" << infos[i].gateway_mask [j] << ")" << endl;
}
cout << "-------------------------------------------" << endl;
}
return 0;
}
//---------- The End -----------------
|
|
|
|
|
Thank you very much. I´ll try it
|
|
|
|
|
It really works!!
Thank you very much.
Only one thing. It doesn´t work under Windows NT
Do you know if it will be possible to make it work under this OS?
Thanks another time
|
|
|
|
|
Hi All!
Problem in VC++ 6.0 with such error:
tmp2.obj : error LNK2005: "struct VLCtabTag * TMNMVtab0" (?TMNMVtab0@@3PAUVLCtabTag@@A) already defined in tmp1.obj
I got such files:
tmp1.cpp
<br />
#include "tmp1.h"<br />
VLCtab l;<br />
int main()<br />
{<br />
return 0;<br />
}<br />
------------------
tmp2.cpp
<br />
#include "tmp1.h"<br />
------------------
tmp1.h
#ifndef _TMP1_H<br />
#define _TMP1_H<br />
<br />
<br />
typedef struct VLCtabTag<br />
{<br />
int val, len;<br />
} VLCtab;<br />
<br />
VLCtab TMNMVtab0[] = { {1,1}, {2,2}, {3,3} };<br />
<br />
#endif // _TMP1_H
------------------
...uff that's all.
Any ideas? I'm really confused since #ifndef is used!
|
|
|
|
|
Ares2 wrote:
I'm really confused since #ifndef is used!
Which only matters when you are pre-compiling, not linking. tmp1.obj and tmp2.obj both have definitions for VLCtab TMNMVtab0 .
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
...so what should i do in order to go on without this error?
|
|
|
|