|
Running count is sensible thing to do. But Traversing from both ends sounds like a very alternative option - I'll look into that. Just wondering if it's actually more efficient than keeping count.. Thanks!
|
|
|
|
|
It's definitely less expensive (timewise) but more expensive (storagewise) to keep a count. But in today's world, time is more valuable than space.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
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
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
// 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 ..
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 ) 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()
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 )
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
if anyone made it this far, id love some guidance
thanks all.
josh
todo....
:: insert inspirational text here ::
|
|
|
|
|
I created a Win32 Application project to test some code for display of Unicode. In the main file, i have included <string.h> and <stdio.h>, <stdlib.h>, while when compiling, compiler reports strcpy and strtol as undeclared identifier.
Could you enlighten me what happens here and how to solve this problem?
Regards
World on the way
|
|
|
|
|
C++ requires funcitons to be declared before being used.
The Declaration: describes the interfasce of the function, which parameter types it takes, which type it returns, etc.
C/C++ library functions are declared in the standard headers you need to include.
For the two functions inquestion it's
#include <string.h>
"Vierteile den, der sie Hure schimpft mit einem türkischen Säbel."
sighist | Agile Programming | doxygen
|
|
|
|
|
But i have already included string.h and other header files. This is the point it is so wired.
Regards
World on the way
|
|
|
|
|
Hmm... ok... 1st off, functions ARE identifiers, so nothing weird about that. Now to your problem.
You said you want to use strcpy for Unicode, the correct function is wcscpy . But better yet, if you want to be able to compile with or without Unicode use _tcscpy .
Search for String Manipulation in the documentation for all related functions.
Hope this helps,
-Luis
|
|
|
|
|
How does one move MFC 4.2 MDIChild windows outside the application frame, anhywhere on the desktop? This is being done in one application I know of.
|
|
|
|
|
You can't. The app you are seeing that appears to do this must be changing the window type, or it isn't an MDI child to beging with. Have a look at the window with Spy++.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
I have a graphics app. I use CRectTracker to allow the user to select, move and resize graphic objects. I want to allow the user to have fine control over the moving of the CRectTracker using the arrow keys. I get the arrow keys in the OnKeyUp method of my view class. Does anybody know what method you call on the CRectTracker to make it move in response to the arrow keys. Thanks for any ideas.
|
|
|
|
|
I'm dynamicaly creating custom controls on a FormView. When the user clicks on a control (say to delete the control), I can't get the "click" message to map to the FormView. I'm trying to get a pointer to the selected control to the FormView for (deleting). I've found lots of examples for a Dialog. All of which use "SendMessage" and "RegisterWindowMessage", etc. These don't seem to work when using a FormView. The code compiles fine, but no message is sent. Can someone please point me to a good example sending messages from custom controls within a FormView. Any help would be greatly appreciated.
Thanks
Doug
|
|
|
|
|
I think you will find the message is being sent, but you aren't getting it at the other end. This can be because you aren't sending it to the correct window, or the Message Map in the targer window isn't set up right. A good tool to see what is going on is Spy++.
Sending messages around is a pain afaik. A much better approach imo is signals and slots. Have a look at libsigc++ at http://libsigc.sourceforge.net/[^] I use this wherever possible these days.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Hi.
My project needs a way to be able to dump information to a dialog (inside a multiline edit box or something similar), as well as to a file.
I've already implemented Dump method in all my entities and so i figured that in order to achive the above i could derive a class from CDumpContext - implement the << operator - which will stream the data into the edit box (or the file) - and in this way i don't need to deal with each entity apart.
Implementing the above i got into a problem :
In my Dump method i expect a CDumpContext refrence - and i'm passing
refrence to a derived class of it - so when trying to use insertion
operator, <<, CDumpContexts version gets called instead of the derived classes.
Any ideas, workaround ?
|
|
|
|
|
I coded my drawing using OpenGl rendering in my SDI view ON_PAINT handler event but because i need to take in user inputs from a dialog, what should i do such that my graphics will only appear after i have entered variables into the dialog and close the dialog?
|
|
|
|
|
Try putting your code in OnDraw() instead of OnPaint(); It will also make your life easier when you decide to print your drawing.
Here is some code from the CView class. As you can see, OnPaint() and OnPrint() both call OnDraw(). I hope this helps.
void CView::OnPaint()
{
CPaintDC dc(this);
OnPrepareDC(&dc);
OnDraw(&dc);
}
void CView::OnPrint(CDC* pDC, CPrintInfo*)
{
ASSERT_VALID(pDC);
OnDraw(pDC);
}
void CView::OnDraw(CDC*)
{
}
|
|
|
|
|
okie but erm won't the SDI view also show the image right at the beginning? let's say i have dialog A which contains the length, breadth of a rect and based on this, i draw the rect in the Cview.....so actually what i did was code the drawing in my dialog OnOK() so that when i click the ok button after i input the dimensions, after the dialog closes, my drawing will then appear in view, but unfotunately, windows doesn't auotmatically redisplay my rect coz dialog was in front of view....then I transferred my drawing into CView on_paint so that now refreshing is automatically done but now i have a problem of showing the rect when only after i close the dialog. hmmm..
|
|
|
|
|
After you close the dialog call InvalidateRect();
CMyDialog m;
m.DoModal();
InvalidateRect(); // This will send WM_PAINT message
|
|
|
|
|
i get an error for InvalidateRect():function does not take in zero parameters. Actually from my SDI,i have dialog A which has a child dialog B. It is only when dialog B is closed then i want to show the graphics in view.This is wat i did:
void CDialogB :: OnOK() //to show graphics when
{ //dialog is closed
CDialog::OnOK();
InvalidateRect();
}
void CDialog:: OnDraw()
{
UpdateData();
float l=m_length;
float b=m_breadth;
......
drawing code here
.....
}
void CView::OnPaint()
{
m_dialogB.OnDraw();
}
is this the correct approach?
|
|
|
|
|
|
I'm new to Windows programming but have some C++ experience. I need to create an application to display some data I'm receiving from another application via shared memory.
All I want is a display window with a slider so I can change the view of what data is in view.
I've looked around this site but haven't found a project that seems close. What I'll be displaying is a text lable followed by a variable of one of a couple of types (floating point, text, or integer).
JAM
|
|
|
|
|
|
Hey I Got your point!.
Ok,
Consider that u want to share a file with other program at the real time. Both Application should have all privilages than.
You can directly read contents of file by using CFile class and manipulate contents of the file which will have effect on bith application. I have never tried this before. But I guessed that you want this.
Let me know your comments.
God Knows Better
|
|
|
|
|
We're not there yet. All I'm trying to do is figure out how to write a visual C++ app that will will display my real-time data. I already know how to get the data, what I'm finding difficult to do is display it in a scrollable window.
I thought of using a listbox, but what I really need is just a display window.
Any thoughts?
|
|
|
|
|
Yes This is very simple
1) Inherit CFrameWnd class
2) Override the OnPaint() function, here you will get CPaintDC dc device context. By using dc u can draw anything like any shapes rectangle, ploygon, etc and also you can write any Text.
3) Create the Your inherited class on the heep where ever you want to call this application.
Later call your class ->ShowWindow(SW_SHOWMAXIMIZED);
->UpdateWindow();
Let us take an example.
class CAzg:public CFrameWnd
{
afx_msg OnPaint();
}
CAzg::OnPaint()
{
CPaintDC dc(this);
dc.TextOut("God is Great");
}
Suppose you want to display this window when next button is pressed.
Call CAzg *a;
int the declaration of class where you want to call
---::OnNext()
{
a = new CAzg;
a->ShowWindow(SW_SHOW);
a->UpdateWindow();
}
thats it.
Try this !.
bbye
God Knows Better
|
|
|
|
|
I have a code written by the previous version of VC++. I meet the difficulty to build it using .net. The error message is:
LINK : fatal error LNK1181: cannot open input file 'C:\Program.obj'
I don't know what this means. Thank you in advance for your help.
Build Log ------- Build started: Project: ShowDx, Configuration: Debug|Win32 -------
Command Lines Creating temporary file "c:\Research\Dymore\ShowDx\Debug\RSP000022.rsp" with contents
[
/Od /I "Head" /I "..\pgrm\Head" /I "f:\platformSDK\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FD /EHsc /RTC1 /MDd /Yc"stdafx.h" /Fp".\Debug/ShowDx.pch" /Fo".\Debug/" /Fd".\Debug/" /FR".\Debug/" /W3 /c /ZI
.\Head\StdAfx.cpp
]
Creating command line "cl.exe @c:\Research\Dymore\ShowDx\Debug\RSP000022.rsp /nologo"
Creating temporary file "c:\Research\Dymore\ShowDx\Debug\RSP000023.rsp" with contents
[
/Od /I "e:\mssdk\include" /I "Head" /I "..\pgrm\Head" /I "f:\platformSDK\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FD /EHsc /RTC1 /MDd /Yu"stdafx.h" /Fp".\Debug/ShowDx.pch" /Fo".\Debug/" /Fd".\Debug/" /FR".\Debug/" /W3 /c /ZI
Creating command line "cl.exe @c:\Research\Dymore\ShowDx\Debug\RSP000023.rsp /nologo"
Creating temporary file "c:\Research\Dymore\ShowDx\Debug\RSP000024.rsp" with contents
[
/Od /I "Head" /I "..\pgrm\Head" /I "f:\platformSDK\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FD /EHsc /RTC1 /MDd /Fp".\Debug/ShowDx.pch" /Fo".\Debug/" /Fd".\Debug/" /FR".\Debug/" /W3 /c /ZI
Creating command line "cl.exe @c:\Research\Dymore\ShowDx\Debug\RSP000024.rsp /nologo"
Creating temporary file "c:\Research\Dymore\ShowDx\Debug\RSP000025.rsp" with contents
[
/Od /I "e:\mssdk\include" /I "Head" /I "..\pgrm\Head" /I "f:\platformSDK\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /FD /EHsc /RTC1 /MDd /Fp".\Debug/ShowDx.pch" /Fo".\Debug/" /Fd".\Debug/" /FR".\Debug/" /W3 /c /ZI
]
Creating command line "cl.exe @c:\Research\Dymore\ShowDx\Debug\RSP000025.rsp /nologo"
Creating command line "rc.exe /d "_DEBUG" /d "_AFXDLL" /l 0x409 /I "Show" /I "e:\dymore\ShowDx\Head" /fo".\Debug/ShowDx.res" .\Show\ShowDx.rc"
Creating temporary file "c:\Research\Dymore\ShowDx\Debug\RSP000026.rsp" with contents
[
/OUT:".\Debug/ShowDx.exe" /INCREMENTAL:NO /NOLOGO /DEBUG /PDB:".\Debug/ShowDx.pdb" /SUBSYSTEM:WINDOWS /MACHINE:X86 C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Lib\ddraw.lib e:\mssdk\lib\dxguid.lib winmm.lib
Creating command line "link.exe @c:\Research\Dymore\ShowDx\Debug\RSP000026.rsp"
Output Window Compiling...
Generating Code...
Compiling resources...
Linking...
LINK : fatal error LNK1181: cannot open input file 'C:\Program.obj'
Results Build log was saved at "file://c:\Research\Dymore\ShowDx\Debug\BuildLog.htm"
ShowDx - 1 error(s), 0 warning(s)
|
|
|
|