|
Hello,
I made a dll that has a bunch of functions called from a console application. One of them creates a CFrameWnd window. Inside the function that creates my CFrameWnd, I can create a CToolBar object. However I now want the user of the dll (the creator of the console application) to be able to attach a customized CToolBar object to that window (instead of the default CToolBar object that I created during window creation inside the dll). So I thought I simply create the customized CToolBar object in the client application (console application) in the same way I did in the dll function. That however does not seem to work: in release mode the toolbar appears, but doesn't have any bitmap, in debug mode, I get debug assertion errors because of unexisting resource or instance handles.
Following few lines in my console application are impossible to execute without assertion errors in debug mode:
CToolBar* toolBar=new CToolBar();
toolBar->CreateEx((CFrameWnd*)dllFunctionGetFrameWnd(),TBSTYLE_FLAT,WS_CHILD|WS_VISIBLE|CBRS_SIZE_DYNAMIC|CBRS_TOP|WS_CLIPCHILDREN|WS_CLIPSIBLINGS);
toolBar->LoadToolBar(IDR_TOOLBAR1);
toolBar->SetWindowText("Toolbar");
toolBar->EnableDocking(CBRS_ALIGN_TOP);
Anyone knows a workaround? Or can anyone propose an alternative solution to my problem?
|
|
|
|
|
FloatingMarc wrote: a bunch of functions called from a console application. One of them creates a CFrameWnd window
You need to look at the assertions and the code where they occur.
You should see what's going wrong.
You need to make sure you're making the right kind of DLL if
you're using MFC in a DLL. All the info you need to do this
can be found here: Kinds ofDLLs[^]
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hai all
Just i want to develop a apllication that track the amount of data transferred while I am on net, both sent and recieved. It will also keep monthly records on each time log-in basis, so that I can get my usage data.
If You have any Ideas pleas share with me
Thanks & Regards
Vicky000000
|
|
|
|
|
|
vicky00000 wrote: ...track the amount of data transferred while I am on net, both sent and recieved.
Have you looked here?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Dear all
how to save an excel file instead of .txt file in c++? anyone has such code or suggestion?thanks a lot
gentleguy
|
|
|
|
|
Excel.Application COM may be solve your problem.
Emimmortal
|
|
|
|
|
Try using the *.csv fileformat. (comma separated values). It is still a text file but can very easily be generated and imported into excel
|
|
|
|
|
My goal:
when user click on the 'close' red check button on the right top most dialog, I want to hide the main dialog of the app, show an icon in the tray(these codes work fine, not showing).
My codes are below, It exits the app anyway.
BOOL CMyVIPTestDlg::PreTranslateMessage(MSG* pMsgIn)
{
if (pMsgIn->message == WM_SYSCOMMAND)
{
if (pMsgIn->wParam == SC_CLOSE)
{
this->ShowWindow(FALSE);
return TRUE;
}
}
BOOL bRet = CDialog::PreTranslateMessage(pMsgIn);
return bRet;
}
|
|
|
|
|
If you're using MFC, why not respond to the message the MFC way?
ON_WM_SYSCOMMAND()
void CMyVIPTestDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if (nID == SC_CLOSE)
{
ShowWindow(SW_HIDE);
return;
}
CMyDialog::OnSysCommand(nID, lParam);
}
That works fine for me - I just tested it.
It's always curious to me how often the PreTranslateMessage() method is misused.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your reply.
Acctually, I think the PreTranslateMessage is the most misusable method.
When don't know where to handle the message, the first place to place the code is the PreTranslateMessage.
|
|
|
|
|
fantasy1215 wrote: When don't know where to handle the message, the first place to place the code is the PreTranslateMessage.
That's why it's a good idea to know how to use the documentation.
All the MFC message map macros for WM_ window messages start with
"ON_WM_". If the message map macro doesn't exist for a given message,
there's always ON_MESSAGE, which will handle any message.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
I was wondering if someone could clear this up for me.
Consider the below statement:
<br />
#define randomise(i) rand() % (i)<br />
The way I see this, both randomise and rand are functions.
But a search online made me think randomise could also be deemed a macro.
Is randomise, in computer science terms, a function or a macro (or both)?
Cheers,
|
|
|
|
|
randomize is a macro.
rand is a function in the CRT library, but in the code you've shown,
it's just a token used during expansion of the randomize macro by the
pre-processor.
The VC/VC++ docs call your randomize macro a "function-like macro".
That's my take on it
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi Mark,
Thanks for your reply.
Looking at the definition for a function:
"In computer science, a subroutine (function, method, procedure, or subprogram) is a portion of code within a larger program, which performs a specific task and can be relatively independent of the remaining code"
Could I argue that by calling randomise() it's performing a "specific task"?
The difference between a macro and a function seems to be vague.
Thanks,
|
|
|
|
|
MarkBrock wrote: Could I argue that by calling randomise() it's performing a "specific task"?
Of course you could, but you'd be wrong LOL - just kidding
The thing is, you can't "call" randomize. The compiler pre=processor replaces
occurrences of randomize(n) to the token (macro expansion), so the actual code
called at runtime is rand() % (i).
Note that more parenthesis should probably be used here...
#define randomize(i) (rand() % i)
... just in case you use it in a complex expression...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
MarkBrock wrote: The difference between a macro and a function seems to be vague.
Maybe for computer science, but not for the compiler (and developer) point of view.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
As far as the compiler is concerned, randomise() doesn't even exist.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Yeah I understand what you guys are saying now.
The preprocessor goes through and replaces randomise() with the defined macro before the code is compiled into a binary.
|
|
|
|
|
I want to write a small service program to hook the system events such as the system is being to shutdown. I want to intercept the user's select before the OS. For example, the user select to shutdown the system, then my service intercept the message first and check if the specified job has been done or not, if not, do it, otherwise left the message to the system directly. How to resolve it?
|
|
|
|
|
This is a service application, right? If so...
Starting in Vista, you can register for the SERVICE_CONTROL_PRESHUTDOWN
notification and take time to finish the job.
See HandlerEx Callback Function[^]
For XP and below, here's what the docs say about the
SERVICE_CONTROL_SHUTDOWN event:
The SERVICE_CONTROL_SHUTDOWN control code should only be
processed by services that must absolutely clean up during
shutdown, because there is a limited time (about 20 seconds)
available for service shutdown. After this time expires,
system shutdown proceeds regardless of whether service shutdown
is complete. Note that if the system is left in the shutdown
state (not restarted or powered down), the service continues
to run.
If the service requires more time to clean up, it should
send STOP_PENDING status messages, along with a wait hint,
so the service controller knows how long to wait before
reporting to the system that service shutdown is complete.
However, to prevent a service from stopping shutdown, there
is a limit to how long the service controller waits. If the
service is being shut down through the Services snap-in, the
limit is 125 seconds. If the operating system is rebooting,
the time limit is specified in the WaitToKillServiceTimeout
value of the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for your reply. I use xp. Yes, it should be a service app. I haven't began to write it so far, but i want to. Because i always forget to do something before i start and end oneday's work.
What i really want to is that, when i select to shutdown my system, it should pop up a messagebox to query the specified task has been done or not. If i know i had completed it, i would select yes to shutdown the system, and if not, i would select no, then the system would not receive shutdown message, so i would have the chance to return the system to complete the specified task.
|
|
|
|
|
If you need a user interface, a better, simpler solution
would be a GUI app with a hidden main window that responds to the
WM_QUERYENDSESSION Message[^].
I don't think you can prevent shutdown from a service...
I could be wrong
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
you meant i could not prevent shutdown from a service or a normal app, or only service couldn't?
|
|
|
|
|
Only a service.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|