|
How much will you pay?!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi, I'm not a very knowledgable programmer in visual C++, as I've only learned from my Programming12 class which started in February. I hope that I can provide as much information as I can to help you understand my problem better. Thank you in advance for all of your help.
A bit about my program:
- It is a "Store" application, so I have Items and the user inputs the amount of money they have, and they buy which items they want accordingly. If they spend too much, when they try to go to the checkout, a messagebox tells them they have spent too much and must redo.
- I have 3 forms: "Form1", "Inventory", and "Checkout".
- I want to pass information between each (Prices/Quantities Bought/User's Name, etc.
To change forms, I was using
Inventory^ frm2 = gcnew Inventory();
and calling frm2 on the MAIN form (Form1), and on the "Inventory" form, I was using
Form^ frm1 = Application::OpenForms["Form1"];
I was having problems with that, so I decided to just use the following code to deal with it:
this->Size = System::Drawing::Size(124,20);
this->CenterToScreen();
this->TopMost = false;
This was to Change the Form1, and hide it behind the new form.
Then I would use this:
frm2->Show();
frm2->TopMost = true;
To show the 2nd form (Inventory)
Going between the Form1 and the Inventory forms was okay, but I can't seem to get to the 3rd form (Checkout) at all. I keep getting the error described in the title: "An unhandled exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dll Additional information: Object reference not set to an instance of an object."
Is there a better way I can go between forms than the ways described? How can I fix that error?
Any help will be much appreciated. I will provide as much information as necessary for you to understand better.
Thank you again,
Monkeyboy2009
|
|
|
|
|
This is not VC++ programming. this looks like C#
|
|
|
|
|
Chandrasekharanp wrote: This is not VC++ programming. this looks like C#
I am afraid, It is managed vc++.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hey thanks Alok. I was not knowing this.
|
|
|
|
|
|
I need a source code project SlidingPuzzle game by MFC C++.
Can you help me,plesae
My mail:hothi_vuong@yahoo.com
or: nhenden672000@yahoo.com
Thanks,
Vuong
|
|
|
|
|
|
nhenden67000 wrote: I need a source code project SlidingPuzzle game by MFC C++.
http://www.google.com[^] is your friend here...
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
What the differences in these code :
Write(address, size, data)
Write( address, size , &data)
The function basically write data into a address, with size is the size of the data to be written .
Thanks
|
|
|
|
|
it's really hard to say what will happen without knowing what Write is expecting for that 3rd parameter.
but, in general: C++ pointers[^]
|
|
|
|
|
dec82 wrote: Write(address, size, data)
Write( address, size , &data)
What function defination says? or you have to consult the function writer... as it very difficult to predict, what actually your write function do.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Only one of the two is correct, unless data is declared as an array (i.e., for instance char data[8]; ).
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]
|
|
|
|
|
My problem sounds like this:
I have to create a program that encrypts a file by taking each byte and increment it.
The problem is that the program should use multithreading to do the actual encrypting. The number of threads is variable, the user enters them in a Edit Control, and those “x” number of threads, simultaneously must encrypt the file.
What I’ve done so far is that I opened the file in binary mode and encrypt it by incrementing each byte in the file. So far so good, but now I can’t figure out how to create those threads and how should they encrypt the file simultaneously … a little help would be awesome.
Here is the code I done so far: when the user pushes the Ok button (the file has been selected by the user in a previous step), the selected file is encrypted
void CEncryptorView::OnBnClickedOk()
{
CString strControlText;
CWnd* pWnd = GetDlgItem(IDC_FILE);
pWnd->GetWindowText(_T(strControlText));
char buf[255];
ifstream fp_in(strControlText, ios_base::binary | ios_base::in);
unsigned int cntr = 0;
if(!fp_in)
{
++cntr;
MessageBox("The selected file couldn't be open for reading");
}
ofstream fp_out("temp.txt", ios_base::binary | ios_base::out);
if(!fp_out)
{
++cntr;
MessageBox("\tThe temp file couldn't be created \n(check you access privileges for default destination!)");
}
if ( fp_in && fp_out )
{
char ch;
while ( fp_in.get ( ch ) )
fp_out.put ( ++ch );
}
else
++cntr;
fp_in.close();
fp_in.clear();
fp_out.close();
fp_out.clear();
ifstream fs_in("temp.txt", ios_base::binary | ios_base::in);
if(!fs_in)
{
++cntr;
MessageBox("An error occured and the encryption failed");
}
ofstream fs_out(strControlText, ios_base::binary | ios_base::out);
if(!fs_out)
{
++cntr;
MessageBox("An error occured and the encryption failed");
}
if ( fs_in && fs_out )
{
char ch;
while ( fs_in.get ( ch ) )
fs_out.put ( ch );
}
else
++cntr;
fs_in.close();
fs_in.clear();
fs_out.close();
fs_out.clear();
CString fileToDelete("temp.txt");
if(remove(fileToDelete) == 0 && cntr == 0)
MessageBox("The file has ben encrypted successfully");
else
MessageBox("An error occured and the encryption failed");
}
Thank you
|
|
|
|
|
take a look at some of these articles on theading[^]
the basic goal is to:
1. turn your threading code in a function (you're almost there already)
2. when you need to run, create a thread and give it the address of your function
3. wait for the thread to finish - there are many ways to do this.
|
|
|
|
|
Can you be more speciffic, with some code example perhaps? Thanks
|
|
|
|
|
Hello,
I'm developing an MFC application, an enterprise database accessing program where the user is potentially denied access to some of the views that appear in the right hand splitter pane (all of which are classes derived from my own custom base class that is derived from CFormView). I call EnableWindow(FALSE) from within the right hand views where appropriate (from my custom base class) to disable the view entirely, including making it impossible to tab to the view. So far, so good.
However, the problem of there being no obvious visual indication of *why* the view is locked, and that it is supposed to be locked, persists. Examples of appropriate strong visual cues include:
1. Darkening the View
2. Making the view grayscale
3. Making the mouse cursor appear as a padlock or somesuch when it overlays the view.
4. When the user clicks on the view, display a messagebox that explains that access is denied.
How can I achieve any of these visual cues? The problem is, because I've disabled the view, through the call to EnableWindow(FALSE), I cannot do a whole lot. I cannot change the mouse cursor in the usual way. I can provide implementations of any Cview/CWnd virtual functions, such as OnDraw(), but I cannot seem to Draw to my CViews in any useful way, as can be done with a CScrollView.
How can I create any of these strong visual cues?
Regards,
Sternocera
|
|
|
|
|
You should still be able to change the cursor. Handle WM_SETCURSOR in the form class and return a different cursor if the form is disabled.
--Mike--
New sig under construction...
|
|
|
|
|
Mike,
Thanks for getting back to me. You're right - I made the mistake of not putting the message map entry in the derived class, just the base.
Thanks,
Sternocera
|
|
|
|
|
Hmm. It seems that the disabled CViews do not change cursor, only the enabled ones.
Are you sure that it is as you've described?
Regards,
Sternocera
|
|
|
|
|
How about overlaying the view with a 50% gray, 50% opaque window (see WS_EX_LAYERED[^] and SetLayeredWindowAttributes[^])? That's kind of what Safari (the web browser) does when you click on a bookmarked site that it has a preview for - looks kind of cool.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Stuart,
That's interesting. How could this overlaying effect be achieved? calls to CWnd::SetLayeredWindowAttributes() don't seem to be affect my CView in anyway:
SetLayeredWindowAttributes(RGB(50,50,50), 100, WS_EX_LAYERED);
Equally, calling the Win32 API equivalents doesn't have any discernable effect:
HWND hwnd = GetSafeHwnd();
::SetWindowLong(hwnd, GWL_EXSTYLE,
::GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
::SetLayeredWindowAttributes(hwnd, 0, (255 * 70) / 100, LWA_ALPHA);
Regards,
Sternocera
|
|
|
|
|
Sorry - wasn't quite clear enough. Create another window. Make it the same size and position as your view, but put it on top of it. Make it layered, 50% gray, 50% opaque.
The reason your trials didn't work is (I think) because you can't apply WS_EX_LAYERED to a child window - my own experiments (with a trial SDI app) indicate that. So, you'd need to set that style on your CMainFrame.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Sorry Stuart, but I'm going to need you to be clearer still. What sort of window class would I create, and how? What about resizing of my CMainFrame, wouldn't I have to resize my overlaying windows as my underlying view changed shape?
Regards,
Sternocera
|
|
|
|
|
Sternocera wrote: Sorry Stuart, but I'm going to need you to be clearer still. What sort of window class would I create, and how?
This (Win32 code) seems to work nicely enough and shows how to register the window class and create the window:
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_CLOSE) return 0;
return DefWindowProc(hWnd, message, wParam, lParam);
}
BOOL CreateLayeredWindow(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = &WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_BTNTEXT+1);
wcex.lpszMenuName = 0;
wcex.lpszClassName = _T("layered");
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
const DWORD screenWidth = GetSystemMetrics(SM_CXSCREEN);
const DWORD screenHeight = GetSystemMetrics(SM_CYSCREEN);
hWnd = CreateWindowEx(WS_EX_LAYERED|WS_EX_TOOLWINDOW, _T("layered"), _T("layered"), WS_POPUPWINDOW,
screenWidth/4, screenHeight/4, screenWidth/2, screenHeight/2, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
SetLayeredWindowAttributes(hWnd, 0, 0xc0, LWA_ALPHA);
ShowWindow(hWnd, nCmdShow);
return TRUE;
}
You will probably need to replace hInstance by AfxGetModuleState()->m_hCurrentInstanceHandle and there're probably advantages to making the layered windows parent be one of your application's windows (mainly ensuring the window z-order is sane).
Sternocera wrote: What about resizing of my CMainFrame, wouldn't I have to resize my overlaying windows as my underlying view changed shape?
Yes - that's not too much of a problem - in your view's OnSize handler, just get the view's window rect (GetWindowRect) and tell the overlay to move itself there. You also need to handle the main frame's OnMove handler similarly - here's what I've got in a sample app:
void CMainFrame::OnMove(int x, int y)
{
CFrameWndEx::OnMove(x, y);
if (const MSG* msg = GetCurrentMessage())
{
if (CView* activeView = GetActiveView())
{
activeView->SendMessage(msg->message, msg->wParam, msg->lParam);
}
}
}
void CsdihiderView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
OverlayHider();
}
void CsdihiderView::OnMove(int x, int y)
{
CView::OnMove(x, y);
OverlayHider();
}
void CsdihiderView::OverlayHider()
{
if (hider_)
{
CRect windRect;
GetWindowRect(&windRect);
::SetWindowPos(hider_, HWND_TOP, windRect.left, windRect.top, windRect.Width(), windRect.Height(), SWP_NOACTIVATE);
}
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|