Click here to Skip to main content
15,920,053 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Is this a trick question? Pin
Gary R. Wheeler25-Oct-03 5:28
Gary R. Wheeler25-Oct-03 5:28 
GeneralRe: Is this a trick question? Pin
CillyMe25-Oct-03 8:01
CillyMe25-Oct-03 8:01 
GeneralLink List and Middle Node Pin
CillyMe24-Oct-03 21:31
CillyMe24-Oct-03 21:31 
GeneralRe: Link List and Middle Node Pin
Ravi Bhavnani25-Oct-03 4:15
professionalRavi Bhavnani25-Oct-03 4:15 
GeneralRe: Link List and Middle Node Pin
Michael Dunn25-Oct-03 7:16
sitebuilderMichael Dunn25-Oct-03 7:16 
GeneralRe: Link List and Middle Node Pin
CillyMe25-Oct-03 8:03
CillyMe25-Oct-03 8:03 
GeneralRe: Link List and Middle Node Pin
Ravi Bhavnani25-Oct-03 17:37
professionalRavi Bhavnani25-Oct-03 17:37 
Generalhumble request for more cp knowledge :) Pin
joshfl24-Oct-03 20:15
joshfl24-Oct-03 20:15 
ok first, some info on this needs to be given before i
can illustrate my confusion...
bonus tho , if you have the patience to read thru this, you'll probably get a pretty good laugh at the end when you read the creative errors
i have managed to whip up while trying to learn the most basic of MFC Smile | :)

I have code to only allow one instance only of my application, like below

// limit to one instance
::CreateSemaphore(NULL, 1, 1, "blah");
if (GetLastError() == ERROR_ALREADY_EXISTS)
{
CString caption;
caption = "blah";
HWND myhand = ::FindWindow(0, caption);
::SetForegroundWindow(myhand);
::ShowWindow(myhand, SW_RESTORE);
return FALSE;
}

than, i have in my CDlgApp 's InitInstance code to detect a parameter called 'startup'

(example)...
// cool code project commandline object Smile | :)
// command line parameters

CCommandLine pCmd;
CString strFlag,strParam;
for( BOOL bRet = pCmd.GetFirstParameter(strFlag, strParam); bRet; bRet = pCmd.GetNextParameter(strFlag, strParam) )
{
if (strParam == "startup") {

// questions come around this areas desired functionality

SetRegistryKey("blah");

CBlahDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
return FALSE;
}

}

// otherwise no parameters, launch app as normal...
SetRegistryKey("blah");

CBlahDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
return FALSE;

now after that said, here comes my confusion .. Smile | :)
the purpose of the 'startup' parameter, and the functionality i need to build
when it detects strParam as 'startup' as in code above, is
1) the ability to create my main application window instance but NOT draw it.
2)While its hidden I need to call a function dlg.function() to enable some startup functionality,
and keep my window hidden...
This way , when a user runs the .exe, it will just execute the code code that limits to one instance, calling
'
::SetForegroundWindow(myhand);
::ShowWindow(myhand, SW_RESTORE);
'

on the hidden window thats already been initialized properly and running at startup.
(the only time it gets the parameter 'startup' is on system startup...)

The second part i worked around fairly easily (i dont know if what i did was 'proper', im a hacker by nature Smile | :) ) by
putting a public member variable 'int isStartupOperation' inside CBlahDlg.

Then , when i detected parameter 'startup' in CBlahApp, i create my main dialog,
and flagged dlg.isStartupOperation to 1.
In CBlahDlg InitDialog , I said if (this->isStartupOperation == 1) { this->function(); }
which allowed me to accomplish the first of my two needs, calling the dialog function without drawing the dialog.

the other need which is to hide the window without drawing I'm still having problems with, a direct result
of of my lack of knowledge about the way things work in this area.

i tried to put in CBlahDlg's OnPaint() operation something that says '


if (this->isStartupOperation == 1) {
CString caption;
caption = "blah";
HWND myhand = ::FindWindow(0, caption);
::ShowWindow(myhand, SW_HIDE);
this->isStartupOperation = 0;
}

'
but that doesnt work as I hoped. first problem with this approach of course, is it flashes the window on the screen before it hides it.
I prefer it is never drawn on screen until the .exe is run w/ no parameters, and the SW_RESTORE is given to than draw the
previously created hidden dialog instance.

second thing i realized is that the call to OnPaint() happens multiple times w/ one DoModal() Smile | :)
so if I say
if (this->isStartupOperation == 1) {
CString caption;
caption = "blah";
HWND myhand = ::FindWindow(0, caption);
::ShowWindow(myhand, SW_HIDE);
this->isStartupOperation = 0;
}

the window gets shown because it doesnt run the hide code after the first call, and it seems to always
be called more than once on the domodal.

if I take out the ' this->isStartupOperation = 0; ' like
if (this->isStartupOperation == 1) {
CString caption;
caption = "blah";
HWND myhand = ::FindWindow(0, caption);
::ShowWindow(myhand, SW_HIDE);
}

even when it runs the SW_RESTORE code , the OnPaint just hides it again and again, and I can never retrieve it...

(this error / discovery really sucked because the app also hides from task list / ctrl -alt -delete so i could get the window! I couldnt recompile code because of conflict w/ running hidden application.
i had to reboot before I could make changes. Than I forgot that the app was still in my startup in registry, so again after
the first reboot, i couldnt access application / recompile changes in code.
i deleted the registry startup call,
had to reboot again, than edited and recompiled my code, and will remember NOT to do that again Smile | :) )

anyway, thats where im at, what im doing, where im confused and need words of wisdom from the windows gods.
thus, i come to codeproject and ask Smile | :)

if anyone made it this far, id love some guidance Smile | :)
thanks all.
josh


todo....
:: insert inspirational text here ::
Generalfunction was treated as identifier :( Pin
convert_sg24-Oct-03 18:47
convert_sg24-Oct-03 18:47 
GeneralRe: function was treated as identifier :( Pin
peterchen24-Oct-03 20:17
peterchen24-Oct-03 20:17 
GeneralRe: function was treated as identifier :( Pin
convert_sg24-Oct-03 21:33
convert_sg24-Oct-03 21:33 
GeneralRe: function was treated as identifier :( Pin
Luis Mejia25-Oct-03 6:59
Luis Mejia25-Oct-03 6:59 
QuestionHow to move MFC 4.2 MDIChild windows outside MDIClient? Pin
Mike Condra24-Oct-03 17:58
sussMike Condra24-Oct-03 17:58 
AnswerRe: How to move MFC 4.2 MDIChild windows outside MDIClient? Pin
Neville Franks24-Oct-03 23:43
Neville Franks24-Oct-03 23:43 
QuestionHow to move a CRectTracker in resppnse to the arrow keys? Pin
cdsmith24-Oct-03 16:20
cdsmith24-Oct-03 16:20 
GeneralUser-Defined Messages Pin
Douglass24-Oct-03 16:15
Douglass24-Oct-03 16:15 
GeneralRe: User-Defined Messages Pin
Neville Franks24-Oct-03 23:49
Neville Franks24-Oct-03 23:49 
GeneralDeriving from CDumpContext and << operator Pin
Ori K24-Oct-03 14:54
Ori K24-Oct-03 14:54 
Generalshowing graphics in view after closing dialog Pin
coda_x24-Oct-03 14:14
coda_x24-Oct-03 14:14 
GeneralRe: showing graphics in view after closing dialog Pin
vcplusplus24-Oct-03 15:28
vcplusplus24-Oct-03 15:28 
GeneralRe: showing graphics in view after closing dialog Pin
coda_x24-Oct-03 17:20
coda_x24-Oct-03 17:20 
GeneralRe: showing graphics in view after closing dialog Pin
vcplusplus25-Oct-03 6:18
vcplusplus25-Oct-03 6:18 
GeneralRe: showing graphics in view after closing dialog Pin
coda_x25-Oct-03 19:02
coda_x25-Oct-03 19:02 
GeneralRe: showing graphics in view after closing dialog Pin
vcplusplus25-Oct-03 23:49
vcplusplus25-Oct-03 23:49 
QuestionHow to display Real-Time data Pin
JAM0124-Oct-03 13:11
JAM0124-Oct-03 13:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.