|
Hello!
I've made a simple application. When I click a button in mian window a modal popup window shows up:
Ustawienia modalne;
modalne.DoModal();
I want that when I click OK in this modal wnd. it changes a Static Text in main wnd.:
void Modalne::OnBnClickedOk()
{
UpdateData(true);
((CNoweOknoDlg*)m_pParent)->m_text1 = "tekst";
((CNoweOknoDlg*)m_pParent)->UpdateData(false);
OnOK();
}
When I press this button the app crasches
When I made this popup wnd. as modeless using Create() funtion everything is OK. :/
|
|
|
|
|
You should expose the string on your dialog and set the text in your main window. Apart from anything else, your approach makes the two forms tightly coupled for no good reason.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
|
Which bit are you confused by ? Expose a parameter to store the value you want to return, do the rest in your main dialog if the modal call returns OK.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
m_text1 is a CString value that represents static text in mian window. To change it I have to call this:
((CNoweOknoDlg*)m_pParent)->m_text1 = "text"
on button click. I don't have any idea how to do this in a different way.
I'm confused why it works with modeless window.
|
|
|
|
|
OK, so you didn't understand anythign I said ?
I'm not sure why it doesn't work, but either way, when class 1 needs to know about the internals of class 2, they are tightly coupled, and thus cannot work without each other. You're doing this in your OnOK method, so I assume it happens as the dialog closes. so, what you want to do is, the code in CNowkOKnoDlg, your main class, will create this child form and show it. Assuming that "text" is going to become a variable, add a public string variable, then set m_text1 inside the class that holds that variable, and created the dialog that sets it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: Assuming that "text" is going to become a variable, add a public string variable, then set m_text1 inside the class that holds that variable, and created the dialog that sets it
Christian I think even I am misunderstanding you.
Are you suggesting something of the following nature?
CFoo dlg
Dlg.m_text1 = "the test string"
Dlg.Domodal();
Isn’t is safer to
CFoo dlg<br />
<br />
<br />
Dlg.SetMyText("the test string");<br />
Dlg.Domodal();
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
Yes, you are misunderstanding me. Or I'm misunderstanding you. I thought you were setting a string in the main window from the modal dialog. I am saying, set the string in the main window, and expose a property on the dialog to tell you what the string is.
A get method makes more sense than a public property, that much is true. I was just trying to keep it simple.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian Graus wrote: I thought you were setting a string in the main window from the modal dialog. I am saying, set the string in the main window, and expose a property on the dialog to tell you what the string is.
Wasn't me, I was just bored perusing the message boards noticed the question and which made no sense (at least to me)
Posting a string back a parent dialog is always a pain, so far I have always found it better to just wait until the modal child closes then follow what you said and use a getter. Shrugs, lol not really my problem I was just confused by the question and responses.
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
What I believe Christian is trying to say here is do something to the following affect.
CFoo Chlddlg<br />
<br />
<br />
if(IDOK == Chlddlg.Domodal())<br />
{<br />
CString str = Chlddlg.GetMyText();<br />
SetWindowText(str);<br />
}
Dont try and post the string back to the parent dialog, let the parent collect it from the child. This protects the inner workings of both classes. GetMyText() could return any variation of data. (this is just a simple example).
I'd love to help, but unfortunatley I have prior commitments monitoring the length of my grass. :Andrew Bleakley:
|
|
|
|
|
if you want to change the text of a control you can do this :
void CMdlDlg::OnOkButton()
{
CWnd *parent = this->GetParent();
parent->SetDlgItemText(" control ID ","new text");
}
or if you want to change the main dialog tilte then do this :
void CMdlDlg:;OnOkButton()
{
(this->GetParent())->SetWindowText("new text");
}
|
|
|
|
|
Hi all,
I have a strange and annoying problem with LoadMenu, I use eVC++ 4.0 for mobile apps:
When I call LoadMenu(IDR_RESOURCENAME), it fails, and when call GetLastError it gives me the error code 1814, which in MSDN says "The specified resource name cannot be found in the image file. ", so , whats the problem!! its really annoying.
my code looke like:
mnuCtxt.LoadMenu(IDR_MAIN_TOOL)
Thanx,
Mohammad
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
Ok...
After being annoyed for 4 hours, I solved the problem 2 minutes after I posted this question... just for information the problem is that u cant load a specific menu resource using LoadMenu, u must load a menu bar resource, yeaaaaaaaaaaaaaaaah!!
;P;P;P;P;P
Mohammad
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
can you give me more information about this?
i want to open a menu of a dialog without mouse .
thanks
-- modified at 5:20 Monday 18th September, 2006
|
|
|
|
|
if u want to open it without a mouse u should follow these steps:
1. create a new menu bar using resource editor
2. Define CMenu object and use MyMenu.LoadMenu(IDR_MENUBAR) to load the menu resource.
3. to get a specific popup menu from the bar use: pMenu=MyMenu.GetSubMenu(iIndex);
4. Use the function: TrackPopupMenu to make a popup (context menu).
Regards
And ever has it been that love knows not its own depth until the hour of separation
|
|
|
|
|
Hello Everyone, First time posting on this forum but I've been lurking for a long time. I'm starting to teach myself some basic windows programming as I want to get started on DirectX. I can create a window but I'm getting a strange error when I try to run it. The window name is coming out as a series of squares instead of the name. Here's my code:
WNDCLASSEX windowClass = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
(LPCWSTR)"Barry's D3D BaseClass", NULL };
RegisterClassEx( &windowClass );
HWND hWnd = CreateWindow( (LPCWSTR)"Barry's D3D BaseClass", (LPCWSTR)"test",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
GetDesktopWindow(), NULL, windowClass.hInstance, NULL );
if( 1 )
{
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );
MSG mssg;
PeekMessage( &mssg, NULL, 0, 0, PM_NOREMOVE);
while (mssg.message!=WM_QUIT)
{
if (PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&mssg);
DispatchMessage(&mssg);
}
else
{
}
}
}
UnregisterClass( (LPCWSTR)"Barry's D3D BaseClass", windowClass.hInstance );
Its a bit of a strange problem and I'm not sure why its happening as its mainly code I've taken from text books and the msdn. Any help would really be appreciated.
|
|
|
|
|
What is obviously a problem in your code is that you cast ASCII strings to UNICODE strings everywhere.
Instead of
(LPCWSTR)"Barry's D3D BaseClass"
you better write
_T("Barry's D3D BaseClass")
If you want to have unicode strings use
L"Barry's D3D BaseClass")
And don't forget to include the header file tchar.h if you haven't already done that.
|
|
|
|
|
Thanks for the reply, I'll try this when I get home and see if that's what's causing the errors.
|
|
|
|
|
Yes that works a treat, So CreateWindowEx takes in UNICODE strings/chars as default and by just using "" I was using ASCII. Then using _T() converts ASCII to UNICODE automatically for you and that's why it works? Great to get the code fix but I'd like to understand why it worked as well.
I'm also trying something else I want to be able to use a string instead of hard coding the string parameter in quotes. Here's the code I want to use:
HWND hWnd = CreateWindow( _T("Barry's D3D BaseClass"), _T(windowName),
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,GetDesktopWindow(),
NULL, windowClass.hInstance, NULL );
This gives me the follow compile error:
c:\documents and settings\barryod\my documents\visual studio 2005\projects\directx1\directx1\directxbase.cpp(38) : error C2065: 'LwindowName' : undeclared identifier
I'm really not sure what's happening here, any help would be appreciated.
|
|
|
|
|
Just reinstalled VC++ 6.0 (with SP5) and now I am getting this ..fatal error RC1015: cannot open include file 'afxres.h'. After I put “include files” in Tools…Directories ... include ... I get “ ..fatal error RC1015: cannot open include file winres.h .
I have been reading this TN035 and cannot figure it out. I am lost.
Can anybody give me a simple sample what MFC wants to see in Tools … Directories…
Thanks very much
|
|
|
|
|
I want to create my own cursor image by importing an exsiting .ico file, but every time the VS6.0 automatically imported it into resources as ICON file, even I name it as IDC_CURSOR1, I can not use " wndclass.hCursor = LoadCursor (hInstance, MAKEINTRESOURCE (IDC_CURSOR1)) ;" to create my own cursor
|
|
|
|
|
Hi
I am trying to develop an application to capture the screen and save it into a bitmap, every thing was working fine but when I tried to capture the screen of an application that runs in a dos window it did not succeed, does any body know how to do that.
Thanx in advnace
K.A
|
|
|
|
|
Hi,
Im kinda playing with strings.
Im trying to generate this output in the console:
****
******
********
**********
************
**************
****************
And this is my code:
int _tmain(int argc, _TCHAR* argv[])
{
for( int row = 1; row <= 10; row++ )
{
for( int col = row*4; col < row*12; col+=4 )
//{
cout << '*';
cout << endl;
//}
}
system("pause");
return 0;
}
I was wondering what it is im doing wrong.
If anyone can tell me, plz do so.
Thanks in advance!
|
|
|
|
|
for(int i=4; i<=16; i+=2)
{
for(int j=0; j<i; j++)
{
cout << "*";
}
cout << "\r\n";
}
|
|
|
|
|
|