|
Let's say I have an application that has an icon added in IE's toolbar. When I click the icon, I'd like it to open my app along with the current URL so my app can use it. Is there a way to do this?
Thanks!
|
|
|
|
|
My dialog bar has various controls, that don't take up the whole screen. When the main frame resizes, I want these controls to reposition themselves so they are relatively centered. For example, if a control's left side, is 150 left of the center of the main frame, I want it to always be 150 left of the center of the main frame, no matter what size the main frame is. I can't seem to come up with a simple way to do this, whereas I do not want to have to create variables for each control.
|
|
|
|
|
I have built a Wizard Dialog and on the front page have 3 drop down boxes and one edit box at the top.
I am trying to force the edit box to take the focus on initdialog but I am having no luck.
I have an edit Control variable and I am setting it to focus and I am setting the return value of OnInitDialog to false, just like you do with normal dialogs, but the second item which is a dropdown list continues to have the foucs.
Any idea why this problem is occuring.
thanks
|
|
|
|
|
Hello, the codegurus around the world.;)
Generally speaking, your approaches should work only when the dialog is created.
In a wizard dialog, if we click the back button to go back to the first page,
OnInitDialog is never called since the dialog is already created.
So, try to chanage the tab order to make Edit box the number one by the resource editor.
Try to put the code - m_MyEdit.SetFocus() before return FALSE;
Try to put the same code in CMyPropertyPage::OnSetActive() for clicking the back
button.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Hi, I'm wondering if anyone knows how I can get rid of the initial document window that displays when an MFC MDI program first starts up? I am writing a program that would acquire images from a scanner. It would not make sense to have an empty white canvas before acquring any scans.
I believe there's a function OnDocumentClose function I can use, but I have no idea where I can place such a call. Also, how would I create a new canvas? Is there a "OnDocumentOpen" of sort?
Thanks!
Jerry
|
|
|
|
|
You can suppress this 'new file' action with
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
in your apps InitInstance.
Doesn't work for SDI though.
|
|
|
|
|
To answer your second question the way I've always done it is as follows:
1) Find the document template (each template is a different doc/view class - you probably only have one in which case just ignore the last two lines)...
POSITION DocPosition;
DocPosition = GetFirstDocTemplatePosition();
CDocTemplate* first_template = GetNextDocTemplate(DocPosition);
CDocTemplate* second_template = GetNextDocTemplate(DocPosition);
CDocTemplate* third_template = GetNextDocTemplate(DocPosition);
2) Create a new file
CSomethingDoc* newdoc = STATIC_DOWNCAST(CSomethingDoc, first_template->CreateNewDocument());
3) Do any work in the Document class you need to and then show the new file
CFrameWnd* newframe = first_template->CreateNewFrame(newdoc, NULL);
newframe->InitialUpdateFrame(newdoc, TRUE);
Hope that helps.
-Dave
|
|
|
|
|
Hi Dave, it's been a while, but thanks for your posted reply on how to create a new document in CWinApp. I didn't get a chance to implement it until now.
I have a follow up question I hope you can help me with. The code you described to me is for CWinApp class. How would I be able to do the same thing inside MainFrm class? Obiously GetFirstDocTemplatePosition() is only exsistant in CWinApp, and I do not know of a way to acquire a pointer to CWinApp from MainFrm. Would you know a way to do that? I appreciate it. Thank you.
Jerry
|
|
|
|
|
Use AfxGetApp(); This can be called from your main frame class.
HTH
Jignesh
|
|
|
|
|
Worked like a charm!!
Thank you thank you.
|
|
|
|
|
No problem...
Try looking into AfxGetApp()
-Dave
|
|
|
|
|
try replacing your calls with;
SaveModified();
AfxGetApp()->OpenDocumentFile ( _T ( "C:\\your_document.ext" ) );
BTW: OnOpenDocument() should not be called directly, it is used by the framework in response to the File Open command... the framework does allot of initialization before and after it calls this.
Ben Burnett
---------
On the topic of code with no error handling -- It's not poor coding, it's "optimistic"
|
|
|
|
|
I have a function which returns the Window-handle of the foreground-window like this:
CWnd* pWnd = GetForegroundWindow();
Now I want to check whether there's a CEdit-Control within that window.
How can I achieve this?
thanks in advance
|
|
|
|
|
You need to use EnumChildWindows and then GetClassName to check for the EDIT class of window.
|
|
|
|
|
Something seems to be wrong with this code
BOOL CALLBACK FindEdit(HWND hwnd, LPARAM lParam)
{
BOOL ret = TRUE;
HWND child = ::GetWindow(hwnd,GW_CHILD);
if(child != NULL)
{
char classname[128];
GetClassName(child,classname,sizeof(classname));
MessageBox(NULL,classname,"Class",MB_OK);
}
return ret;
}
HWND child always is NULL
Or do I need to do in a different way?
|
|
|
|
|
You need the GetWindow line. The hwnd parameter passed to the callback function is the child window handle. Just call GetClassName on hwnd.
|
|
|
|
|
OK, now I have this one:
BOOL CALLBACK FindEdit(HWND hwnd, LPARAM lParam)
{
char classname[80];
GetClassName(hwnd,classname,80);
if((strcmp(classname,"edit")) == 0)
{
::SetWindowText(hwnd,"Test");
::CloseWindow(hwnd);
return 0;
}
return 1;
}
this does not work either, altough a window with class "edit" has been found
|
|
|
|
|
I have found the problem
|
|
|
|
|
Hey everyone,
I'm having a problem deleting a dynamically allocated array of strings.
I do something like this to allocate the array of strings:
.
.
.
char** arrayofstrings = new char*[stringcount];
for(int i = 0; i < stringcount; i++)
{
arrayofstrings[i] = new char[MAX_STRING];
}
.
.
.
I do something like this to delete the array of strings:
.
.
.
for(i = 0; i < stringcount; i++)
{
delete [] arrayofstrings[i];
arrayofstrings[i] = NULL;
}
delete [] arrayofstrings;
arrayofstrings = NULL;
The deletion code always crashes. I've done this before with no problem, but its early and I've got a splitting hangover(damn Thirsty Thursday) and can't seem to make sense of it.
Can anyone point me in the right direction?
Oh yeah, what's the tag to format my code in the forums?
Thanks for any help....
Josh
josh@that-guy.net
|
|
|
|
|
A bad stringcount of zero for new char*[stringcount] would cause problems. Good place for an assert, if stringcount is being passed in.
Use the <pre> tag to format code - for more info, see the C++ FAQ
|
|
|
|
|
And writing more than MAX_STRING chars to one of the strings would do it too:
int stringcount = 2;
char** arrayofstrings = new char*[stringcount];
for(int i = 0; i < stringcount; i++)
{
arrayofstrings[i] = new char[10];
}
strcpy(arrayofstrings[0], "This is entirely too many chars");
for(i = 0; i < stringcount; i++)
{
delete [] arrayofstrings[i];
arrayofstrings[i] = NULL;
}
delete [] arrayofstrings;
arrayofstrings = NULL;
|
|
|
|
|
I'm using BCB5 and I'm delay-loading a couple of DLL's which I have put copies of in both my /windows/ and /windows/system/ directories. I'm getting an error when compliling...
[Linker Error] Delay load module <name> was not found
I have the library loaded into my project. Anyone have any ideas?
|
|
|
|
|
How to remove the maximize button, minimize button and the title bar of a window from a specified window?
Thanks.
|
|
|
|
|
Remove WS_MINIMIZE, WS_CAPTION styles
Zolee
|
|
|
|
|
Thanks for your reply. But I still have a question.
Here is my source codes in a dialog based program, but it does not work.
void CTestStyleDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
this->ModifyStyle(WS_MINIMIZE,0);
CDialog::OnLButtonDown(nFlags, point);
}
I have already added the minimized button to the window before running the program. But nothing happens when clicking the left button of the mouse.
How to resolve the trouble?
Thanks again.
Maer
|
|
|
|