|
Top coder is right, default values are not part of the standard. So it could be different from compiler to compiler, or completely random garbage.
Edit: changed my vote after your correction.
modified 15-Oct-11 20:12pm.
|
|
|
|
|
They are the same loops. both compile to a cmp to the value 0 instruction. you would get an unitialized variable warning when compiled. the default is whatever happened to be randomly in that location on the stack or in that register (optimized into a register) previously (usually true, but not specified).
|
|
|
|
|
If you are asking about default value, it will completely compiler dependent. Even if you work on release or debug build, don't surprise to see different results. Better idea is to explicitly initialize the value. Even in other cases, like by default Class members are private and structure members are public. Don't rely on defaults, explicitly write what you want.
Regards
|
|
|
|
|
never, Never, NEVER rely on any "default initialization" ever happening.
Always, and I cannot say this strongly enough, ALWAYS initialize your variables if you are depending on them having some value when you start.
Over your lifetime of programming, you will be far happier and successful if you burn that idea into your brain and you will spend far less time chasing "unitialized variable" bugs. Others will come to you for debugging help and you will say 'did you look for unitialized variables' and they will say 'no' and solve their problem and you will look like a genius.
Take this advice to heart.
|
|
|
|
|
I'm making a progress window for my Program, that is MDI. The progress window will show progress when a windows service is starting or stopping.
I wanted to make the progress window sort of universal, in which the Master Window owns it, and not the MDIChild Window,
I sort of confused here. I need the HWND from the master window to use in CreateWindowEx, but quite sure how to get it, Because I'm loading the Progress Windows from an MDIChild Window, and my create window fails. Actually I'm modeling the window first to make sure it works and looks right before I fully implement it.
BOOL ProgressBar_Popup::_show_ProgressWindow( HINSTANCE hInstance, HWND cWnd )
{
LPWSTR windowTitle = L"Progress";
HDC hdc;
gProgressBar_Popup_GAC = cWnd;
hdc = GetDC(cWnd);
hProgressBar_Popup_Instance = hInstance;
LoadString(hProgressBar_Popup_Instance, IDC_PROGRESSBAR_POPUP, sz_ProgressBar_Popup_Class, MAX_LOADSTRING);
_register_ProgressBar_Popup_Class(hInstance);
hProgressBar_Popup = _create_ProgressBar_Popup(hInstance, windowTitle);
_progressbar_Popup_Center( gProgressBar_Popup_GAC, hProgressBar_Popup );
return TRUE;
}
ATOM ProgressBar_Popup::_register_ProgressBar_Popup_Class(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC) _progressbar_Popup_WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_NASE2012_SUWIZARD));
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
wcex.lpszMenuName = NULL;
wcex.lpszClassName = sz_ProgressBar_Popup_Class;
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
if (!RegisterClassEx(&wcex))
{
MessageBox(NULL,
_T("Call to RegisterClassEx failed!"),
_T("Win32 Guided Tour"),
NULL);
}
return RegisterClassEx(&wcex);
}
HWND ProgressBar_Popup::_create_ProgressBar_Popup(HINSTANCE hInstance, LPWSTR windowTitle)
{
HWND hWnd = CreateWindowEx(
WS_EX_TOPMOST,
sz_ProgressBar_Popup_Class,
windowTitle,
WS_POPUPWINDOW,
10, 10,
200, 200,
gProgressBar_Popup_GAC,
NULL,
hInstance,
NULL
);
if ( !hWnd )
{
MessageBox(hWnd,
L"Progress Bar Popup has failed",
L"Progress Bar Popup",
MB_ICONEXCLAMATION | MB_OK);
}
else
{
ShowWindow(hWnd, SW_SHOW );
UpdateWindow(hWnd);
}
return hWnd;
}
|
|
|
|
|
Have you considered just showing progress bar in a status bar pane[^]?
"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
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
I went to lunch and came back, with a new idea, so I deleted the stuff I wrote, and will try to create a some sort of dialog box in the main.cpp.
I have a status bar, but haven't figured out what to put in it, or how to access it.
|
|
|
|
|
|
I thought it would be a good lesson for to learn how create various windows, and at the time, I was thinking in consumer mode. The progress bar looks very difficult for me now, so I will just create a message or popup window saying that the service is starting or stopping.
Thanks for the suggestion, I'm going to skip ahead to the next task, which is trying to figure out how to delete text I made with drawtext.
|
|
|
|
|
jkirkerx wrote: The progress bar looks very difficult for me now
I would suggest you look a bit harder. This is quite an easy control to implement and all the hard work of painting the bar is done for you; all you have to do is set the limits and update the amount completed from time to time. I'm sure if you do an article search here on CodeProject you will find some sample code to help you.
|
|
|
|
|
Or perhaps I will just trip over it by accident, Just Joking, and I like the motivational push forward you gave me. Actually after a complete day of failure or experimenting, Things are clearer for me now in the c++ windows world.
I went on to the next project, some sort of Label control in c++, and found that I can use CreateWindow to make a Label, Textbox, ComboBox, and a Progress Bar.
So I replaced my Drawtext and created a STATIC in the same place, and I will make a progress bar under it.
Since I painted by background white, I need to figure out how to paint the Label and Progress background white as well.
txt_Website_Default_Status = CreateWindow(TEXT("STATIC"), TEXT("Press Next to begin the programming"), WS_CHILD | WS_VISIBLE | SS_LEFT,
winWidth - 300,
winHeight - 250,
275, 20, hWebsite_Default, (HMENU)IDC_WEBSITE_DEFAULT_LABEL, GetModuleHandle(NULL), 0
);
SendMessage(txt_Website_Default_Status, WM_SETFONT, (WPARAM)hFont_Label, FALSE);
ShowWindow(txt_Website_Default_Status, SW_SHOW);
|
|
|
|
|
jkirkerx wrote: I need to figure out how to paint the Label and Progress background white as well.
I am not certain, but I think you have to use Subclassing[^] in order to do that.
|
|
|
|
|
I ended up adding this to the WndProc, Looks like it paints the background on STATIC.
Yesterday was a big day, I learned how to create controls, and handle them during the wizard process, in which the window updates with progress status text and the progress bar.
Today I will try to figure out how to paint the progress bar to the default theme.
case WM_CTLCOLORSTATIC:
SetBkMode(hdcStatic, TRANSPARENT);
return (LONG)hbrBackground_White;
break;
|
|
|
|
|
Good catch, I had forgotten about that message.
|
|
|
|
|
Hi ,
I am trying to get IP Address from an IP Control using below code. But I am getting an IP Address in Reverse Order , like if my IP Contrl has 123.45.67.89 , then inet_ntoa () method return address as 89.67.45.123. Can you provide any information on how to get IP Address from IP Control.
DWORD dwIPAddress ;
::SendMessage (hwndIPAddress,IPM_GETADDRESS,0, (LPARAM) (LPDWORD) &dwIPAddress ) ;
struct in_addr addr;
addr.S_un .S_addr = (ULONG)dwIPAddress ;
char *IPAddres = new char[9] ;
IPAddres = inet_ntoa (addr) ;
|
|
|
|
|
DWORD dwIPAddress = 0;
::SendMessage (hwndIPAddress, IPM_GETADDRESS, 0, (LPARAM)&dwIPAddress);
struct in_addr addr;
addr.S_un.S_addr = (ULONG)dwIPAddress ;
char IPAddress[16] ;
sprintf(IPAddress, "%d.%d.%d.%d", addr.S_un.s_b1, addr.S_un.s_b2, addr.S_un.s_b3, addr.S_un.s_b4);
|
|
|
|
|
Thanks you suparman....
|
|
|
|
|
htonl() converts an IPv4 address in host byte order (e.g. mac or pc format) to the IPv4 address in network byte order.
inet_ntoa() converts an (Ipv4) Internet network address into an ASCII string.
|
|
|
|
|
We know that MFC does not have Good UI controls. I am searching for a UI library either free or paid library(paid should have few days trial license so that I can test the performance).
My application is a Trading application so UI library must be fast and stable(No memory leaks). There will be immediate text updates, chart updates(LineCharts, bar, graphs), market-watch updates which show prices of shares and other details whith change of twice, thrice or sometimes 10times in a second.
Let me know if any other details are needed.
Thanks,
Rahul Kulshreshtha
|
|
|
|
|
I would prefer Qt Library[^]
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
Yes QtGui on Linux.
I's so easy to learn , like so:
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel label("Hello, world!");
label.show();
return app.exec();
}
more here
Why even use windows? Wall street trading systems all use Red Hat/SUSE.
Windows is mostly relegated to the back office, Windows typically has larger latency times than that of Linux.
|
|
|
|
|
My application is already ready for windows platforms, now I am tweaking the things and changing UI to catch more peoples. So I am bound to windows and Visual Studio
|
|
|
|
|
I had a little experience with QT, but I don't know if it has UI controls which I need. Can you suggest a website for that?
|
|
|
|
|
Well! The link I shared had some forward links to the examples for using the Qt Lib.
You talk about Being HUMAN. I have it in my name
AnsHUMAN
|
|
|
|
|
rahul.kulshreshtha wrote: know that MFC does not have Good UI controls.
I don't know this. why do you believe it is so ?
In my experience, most "generic" 3rd party UI kit turn out to be more pain than necessary and become hell to support after a few years.
I find that MFC (with the new-ish improvements) will satisfy 95% of our development need; the rest of our need will be filled by specialized controls (most of the time home-made)
Watched code never compiles.
|
|
|
|
|