|
You could just divide by 10 in a loop and count how many times you executed the loop until the result was zero.
/ravi
"There is always one more bug..."
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
int val;
int len = 0;
for (int i = val;i;i = i / 10)
len++
|
|
|
|
|
count how many times you can divide by ten before you get a 0 answer.
-c
<font size=-2>
o(int O){putchar(O);}main(){float _[8],O,I=.05;char l;for(_[6]=15;_[6]<':';o
(10),_[5]=-'$'*I+_[6]++*I)for(_[7]=-5;_[7]<'@';_[4]=-'('*I+_[7]++*I,o(l?'?':':'))
for(*_=O=0,l=1;++l&&((_[2]=*_**_)+(_[3]=O*O)<4);O=*_*O+_[5]+O**_,*_=_[2]-_[3]+_[4]);}</font>
|
|
|
|
|
Chris Losinger wrote:
count how many times you can divide by ten before you get a 0 answer.
... then add 1.
J
"I am wise enough to therefore not spout my ill informed opinion as if it were remotely related to fact." - Christian Graus
|
|
|
|
|
numDigits = 1; while (intNumber /= 10) ++numDigits;
ar
|
|
|
|
|
I have a COM dll and VC++6 IDE hangs while performing registration. I even tried registering using "regsvr32" from command prompt and still no luck. I see the process "regsvr32" in the task manager and it's idle...
Any pointers. Thanks.
|
|
|
|
|
I found the problem..
After completing the build process, VC registers the COM dll. ie it makes a call to DLLRegisterServer(). I overrided the "InitInstance" and the code in Initinstance is resposible for this problem. I have deleted my code from InitInstance() every thing works fine.
|
|
|
|
|
Hello,
I need a bit of help writing a batch file. In the line below where I have %1 instead of reading only one word I need to to read an entire string. So to do this I persume that I'll have to read the string from a file. So my question is how do I tell it to read from the file. Lets say the line I need to read is in c:\line.txt
echo %1 | C:\myexecutable --sendsms %2
Thanks.
Aoife
|
|
|
|
|
I have made an app in Visual C++, but i can't move or close it, it's like it doesen't react on mouseclicks (but the controls on the window works fine). however, the only thing that doesen't seem to work is mouseclicks on the app, when i right click on the app in the taskbar and press the "Move" menu item and then move it, it works, and the close command also works in that menu... here's the winmain code:
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
ghWnd = CreateDialog (hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, WndProc);
ShowWindow (ghWnd, SW_SHOW);
UpdateWindow (ghWnd);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam;
}
and here's the WndProc:
BOOL CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_DESTROY:
RegSave(hWnd);
PostQuitMessage (0);
break;
default:
return DefWindowProc (hWnd, uMsg, wParam, lParam);
break;
}
return (0L);
}
anyone know what could be wrong?
thanks all!
|
|
|
|
|
You should try handle WM_CLOSE (too).
WM_CLOSE is the first message that will be sent when you hitt 'X' (close) button in the upper-right corner of your app, and then you have to handle close functionality for that message, e.g. PostQuitMessage(0); and that function will cause a WM_DESTROY (I think)...
Understand!?
------------------------------------
Rickard Andersson, Suza Computing
ICQ#: 50302279
I'm from the winter country SWEDEN!
------------------------------------
|
|
|
|
|
Thanks man! But i don't think that that's the problem. Cause it just doesen't respond when i click it, ie. the button doesen't even look like it's being pressed, it's just dead.
Thanks
|
|
|
|
|
Here is your code slightly modified. Take note at the modified message pump and that I don't call DefWindowProc.
BOOL CALLBACK MyDlgWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
return TRUE;
case WM_CLOSE:
DestroyWindow(ghWnd);
ghWnd = NULL;
return TRUE;
case WM_DESTROY:
RegSave(hWnd);
PostQuitMessage (0);
break;
}
return FALSE;
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
BOOL bRet;
ghWnd = CreateDialog (hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, MyDlgWndProc);
ShowWindow (ghWnd, SW_SHOW);
while ( (bRet = GetMessage(&msg, NULL, 0, 0)) != 0 )
{
if (bRet == -1 )
{
}
else if (!IsWindow(ghWnd) || !IsDialogMessage(ghWnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
Creating a Modeless Dialog Box
You have problems in your message loop.
Tim Smith
I know what you're thinking punk, you're thinking did he spell check this document? Well, to tell you the truth I kinda forgot myself in all this excitement. But being this here's CodeProject, the most powerful forums in the world and would blow your head clean off, you've got to ask yourself one question, Do I feel lucky? Well do ya punk?
|
|
|
|
|
Plain and simple has anyone got : Quit, DocChange to work?
Now I've been using ATL IDispEventImpl with Word 97 with no problems what so ever.
I have changed the import libraries:
#import "r:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\MSO9.DLL" rename("RGB", "WordRGB") rename("DocumentProperties", "WordDocumentProperties")raw_interfaces_only
#import "c:\PROGRAM FILES\COMMON FILES\MICROSOFT SHARED\VBA\VBA6\VBE6EXT.OLB" raw_interfaces_only
#import "r:\PROGRAM FILES\MICROSOFT OFFICE\OFFICE\MSWORD9.OLB" rename("ExitWindows", "WordExitWindows") rename("FindText", "WordFindText") raw_interfaces_only
The version and the new interface ApplicationEvents2
IDispEventImpl
and I have tried the MSoft sample
ms-help://MS.MSDNQTR.2002JAN.1033/vcsample/html/vcrefATLEventHandlingSample.htm
but even that doesnt work
Oh and I have given myself permissions to the Word Document component via Dcomcnfg so I can launch Word.
So basically I can launch word - load Docs etc no probs however I cant get my app to respond to any events - has anyone been able to do this with Word 2000? and how plz
|
|
|
|
|
In my app I have generated some temporary files and when the app closes I need to promp the user to save the files with new names. Then I would like to delete these temporary files. I have found the function 'CDoc::OnCloseDocument' and called the 'CDocument::OnFileSaveAs();' function. This is all fine except that it comes up in what ever directory the temporary files are stored in. I don't want the user to put his/her files in the temporary directory.
I can't find any help on 'OnFileSaveAs', is this because I should not be using it?
Anyone know how to change the directory that 'OnFileSaveAs' starts in?
Or am I just going about this in the wrong way?
Any help appreciated, Regards Ali
ali p
|
|
|
|
|
Oh just read Nish's message about more info, so here it is...
Platform :- XP
Dev Tool :- VC++ 6.0
Libraries :- MFC
Cheers,
ali p
|
|
|
|
|
Hi, hope this helps. The Load & Save Dialogs are the same just put save insted of open. This code works as one chunk, lpstrInitialDir is the dir that it starts in to answer your question:
OPENFILENAME OpnFileStruct; // structure for GetOpenFileName
char szFile[256] = "\0";// Buffer for the filename
// Size of structure
OpnFileStruct.lStructSize = sizeof(OPENFILENAME);
// Handle to the parent window
OpnFileStruct.hwndOwner = this->GetSafeHwnd();
// Filters
OpnFileStruct.lpstrFilter = "GIF or JPEG Image\0*.gif;*.jpg";//"GIF Image\0*.gif\0JPEG Image\0*.jpg";
// Index for the filter
OpnFileStruct.nFilterIndex = 2;
// Buffer which will recieve filename
OpnFileStruct.lpstrFile = szFile;
// Size of buffer which will recieve filename
OpnFileStruct.nMaxFile = sizeof(szFile);
// Title of the open dialog
OpnFileStruct.lpstrTitle = "Select a Background Image";
// Flags
OpnFileStruct.Flags = OFN_FILEMUSTEXIST;
OpnFileStruct.hInstance = NULL;
OpnFileStruct.nFileOffset = 0;
OpnFileStruct.nFileExtension = 0;
OpnFileStruct.lpstrDefExt = NULL;
OpnFileStruct.lCustData = NULL;
OpnFileStruct.lpfnHook = NULL;
OpnFileStruct.lpTemplateName = NULL;
OpnFileStruct.lpstrFileTitle = NULL;
OpnFileStruct.nMaxFileTitle = 0;
OpnFileStruct.lpstrInitialDir = "C:\\media\\"; //!!!!! This wot u mean?
OpnFileStruct.lpstrCustomFilter = NULL;
OpnFileStruct.nMaxCustFilter = 0;
// Next line stops read only button showing & stops moving to selected dir
OpnFileStruct.Flags = OFN_NOCHANGEDIR|OFN_HIDEREADONLY;
// Show open dialog box
GetOpenFileName(&OpnFileStruct);
// Update the edit box with the selected file
m_Back_Image=szFile;
UpdateData(false);
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
|
|
|
|
|
Cheers, I tried this and it worked a treat. Its great, I can control the 'File Save As Dialog' now and so I have replaced the 'FileSaveAs' from the main menu with my own version.
As there is no help on the function and you have shown me that I can generate the dialog box myself, I wonder if I should have been calling 'CDocument::OnFileSaveAs' at all. I am relatively new to Visual C++ as you have probably guessed and I certainly find it very confusing.
Many Thanks for the great help,
ali p
|
|
|
|
|
CDocument::OnFileSaveAs is just the function that gets called when you click 'on' the 'Save As' button in the 'File' menu. CDocument is the Class that contains it. Im new too, you will pick it up, just keep trying
An Expert is somone who has previously made ALL the Mistakes, I dream of this day. - Lucky
|
|
|
|
|
How should i load a DOM object in a MFC application?
I've tried with "add class...from a type library" and some classes are attempting to override the corresponding from msxml2.h. So, it doesn't work this way.
Wish for help!
rechi
|
|
|
|
|
There are multiple examples of this kind of thing available here on CodeProject. However, as in most things C++, the details are rarely easy. In general though:
#include "msxml.h"
#import "msxml3.dll" named_guids raw_interfaces_only
using namespace MSXML2;
IXMLDOMDocument *pDoc;
if ( SUCCEEDED (CoCreateInstance(CLSID_DOMDocument, NULL, CLSCTX_INPROC_SERVER,
IID_IXMLDOMDocument, reinterpret_cast<void**>(&pDoc))))
{
//
// Tell the "doc" that we're not going to load asynchronously.
//
if ( SUCCEEDED(pDoc->put_async(VARIANT_FALSE)) )
{
CComVariant vFile(strFileName);
VARIANT_BOOL vBool;
pDoc->load(vFile,&vBool);
if ( vBool == VARIANT_TRUE )
{
IXMLDOMNode *pNode;
if ( SUCCEEDED(pDoc->QueryInterface(IID_IXMLDOMNode,
reinterpret_cast<void**>(&pNode))))
{
CTreeCtrl *pTree = static_cast<ctreectrl*>(GetDlgItem(IDC_XMLTREE));
HTREEITEM hItem = pTree->GetChildItem(TVI_ROOT);
while( hItem != NULL )
{
HTREEITEM hNext = pTree->GetNextSiblingItem(hItem);
pTree->DeleteItem(hItem);
hItem = hNext;
}
IterateChildNodes(pNode,pTree);
pNode->Release();
pNode = NULL;
}
}
else
CheckLoad(pDoc);
}
pDoc->Release();
pDoc = NULL;
}
|
|
|
|
|
Thanks!
And a question: is it allways the best to use "import", instead of creating the classes from a type library?
rechi
|
|
|
|
|
Using #import is the easiest way I know of to load a COM object. It's my preferred method. You can load the type library of the COM object you wish to load or the DLL itself (which will contain it's own type library anyway).
|
|
|
|
|
I'm writing a SDI application, which allows users to create models, and then save them. I've implemented most of the create functionalities, and I'm in the progress to working on saving the models.
The problem I'm having is that when I try to add a message handler for 'Save' or 'Save As' from the menu, they don't seem to work??? I mean, the program doesn't even go through those bits of code??? I've put messageboxes, and breakpoints at different places, but the program just never gets there??? I think, is because of some code the MFC wizard has put there, e.g, built in code when using the wizard to create the project.
For some strange reason, 'File Open' works fine???
Any help would be much appreciated
Robert
|
|
|
|
|
Could probably help you out but I'd need to see the code. I don't do well in generalities for these kinds of problems. Up to you.
mphilmon@pobox.com
|
|
|
|