|
OK, so accept a parameter and if it's false do not show the dialog, something like:
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pszCmdLine, int nCmdShow )
{
BOOL myParameter;
if (myParameter == TRUE)
{
DialogBoxParam(hInstance,
MAKEINTRESOURCE(IDD_DLG),
NULL,
(DLGPROC)DlgProc,
NULL
);
}
else
{
}
return TRUE;
}
Where is the problem?
Veni, vidi, abiit domum
|
|
|
|
|
Following Richard's idea , if you program based on MFC Dialog , I think you can change InitialInstance() like this
...........
BOOL myParameter;
CMFCApplication4Dlg *pMainWnd = new CMFCApplication4Dlg;
if(myParameter) {
pMainWnd->DoModal();
}else { pMainWnd->CreateEx(NULL,_T("STATIC"), L"Hi", WS_BORDER , CRect(-15, -15, -15, -15), NULL,NULL);
}
........
|
|
|
|
|
I wouldn't create the main window at all if no Dialog/MainFrame is needed. Just call the class doing the processing from InitInstance(), if no window is requested. The program will end automatically when the processing is complete.
In case of the windowed mode you can start the same processing from a button click or menu item click.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
Hi, dear all,
I solve this issue, thanks for all of you for your help.
inside InitInstance() function
m_nCmdShow = SW_HIDE;
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
.........
.......
.......
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();
return FALSE;
|
|
|
|
|
It seems no different compared with your original version. why it works?
|
|
|
|
|
Andraw111 wrote: Now I have another program which only want to use the calculation result stored in file Then why are you creating such overhead by making it an MFC app? Why not just create a console app with a hidden window? My guess would be 10-15 lines of code within main() .
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Hi,
I am a newbie in regard to modbus protocol.
I would like to make a communication between two MFC dialog application in VC++ using Modbus protocol.
Can somebody help me with a sample code of this .
I had been browsing for this for the past 4 days and I am lost..
|
|
|
|
|
Member 9990608 wrote: Can somebody help me with a sample code of this . Most unlikely, you are expected to write your own. You probably need to spend some time looking through some of these links[^] to gain a good understanding of the protocol.
Veni, vidi, abiit domum
|
|
|
|
|
MODBUS is actually a simple protocol, it shouldn't be too difficult for you to deal with it.
Two of the documents linked by Richard were enough for me, namely:
Modicon Modbus Protocol Reference Guide[^] where you may find reference documentations and, above all, the source code of the MODBUS CRC16 algorithm (see Appendix C at the very end of the document).
and
MODBUS APPLICATION PROTOCOL SPECIFICATION V1.1b[^] where you may find a somewhat cleaner explanation of the MODBUS functions.
Veni, vidi, vici.
|
|
|
|
|
can we make websites with c++ or do we really need knowledge regarding javascrpt and HTML5 ?
can we make apps in windows store with c++ or do we really need knowledge regarding c# and HTML5 ?
can we make apps in istore with c++ or do we need knowledge regarding cocoa programming ?
in iTunes-U, windows virtual academy, and many other online courses do not provide training in the feild of c++ ? why ?
is it sooo outdated and useless ?
why is it being devalued ?
is it still " all powerfull " or " just another programming launguage " ?
|
|
|
|
|
Please do not cross post. You have already posted this in QA, here[^]
|
|
|
|
|
Hello all,
I created a MFC dialog using CDHtmlDialog and added a HTML page with many controls and one of them is a IMAGE tag. I got a default image loaded from the hard drive displayed in the HTML page. Up to this part, everything works fine.
Now what i want to do is, dynamically change the image based on the user click on one of the HTML buttons. I don't want this image source to be hard coded in the HTML nor the image source send from the MFC app.
What i want is for the MFC app to send the image data to the HTML in some (binary) format and then the page to display the image.
The possible option i was thinking of was to read the image file which is already in my hard drive as a binary file and send the binary data across to the HTML as a memory buffer, and then use JavaScript to decrypt this binary data and display the image.
I am not even sure whether this is possible. So basically what i want is for the HTML page to display a image from the memory.
Can anyone guide me on how to do this? What approach needs to be taken?
Thanks in advance.
|
|
|
|
|
This is the same issue as all your other questions in this forum. Perhaps you should try some of the suggestions you have already been given.
Veni, vidi, abiit domum
|
|
|
|
|
Don Guy wrote: What approach needs to be taken?
What you're supposed to do is respond to the button click by generating new HTML on the fly, and telling the HtmlDialog to load it. I don't recall the exact function names, but you'll find it all in the documentation.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
To make the question much more simpler
1. Can i pass the Image file (JPG, PNG) as a memory buffer like "unsigned char *" from my MFC app to the HTML page and then use some JavaScript function to understand that it's a Image file and display on the HTML page. It can be done either by passing the JPG to the "src" of Image or drawing it on a CANVAS. But all JS/HTML should have is a memory buffer of Image file.
So the 1st question is,
1. How to read a Image file as memory buffer (unsigned char *) in MFC? i.e, making sure it doesn't loose any NULL terminators or any binary contents.
And 2nd question is,
1. How to pass this memory buffer to the JavaScript function in the HTML page?
And 3rd question is,
1. How can the JavaScript function decrypt this memory buffer into a Image file and display in the HTML page?
The reason why i want to do it this way is because the HTML should never be able to display the Image file from a file path or URL. That is a requirement for the project i am doing.
HTML page should only use a memory buffer containing the Image file info. Hope this information helps.
Thanks in advance. I appreciate the 2 earlier responses i got.
|
|
|
|
|
If you want/need to do it that way, then why use the html dialog at all? Why not just make a regular dialog box that shows the graphic, and you can pass the memory buffer to it.
As far as I know, there is no way to do it the way you are describing.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I am going to assume you will follow what Richard said and reload the HTML in the dialog. I am also going to assume that you are able to modify the HTML from within your code.
In this case, you should be able to achieve what you want by embedding the image as Base64 encoded data, but note that this process increases the size of your data. This is also know as The Data URI Scheme:
http://en.wikipedia.org/wiki/Data_URI_scheme[^]
Here is a CodeProject Tip on the subject: Embedded HTML Help File with Images[^]
Be careful not to overdo it. Notice how slow this article loads because the resulting HTML document is 6.7 MB large: Walks Of Life[^]
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Hello there,
I am writing an MFC app in Visual Studio 2012 that will open a JPG file as binary and read all the contents to a CString.
I am able to read it to a std::Vector, but that doesn't help me much as i need to pass all the binary content as a MFC CString to another function.
Can anyone help me with a sample code for that?
Thanks in advance
|
|
|
|
|
Don Guy wrote: binary content
Don Guy wrote: MFC CString
These terms generally don't mix, something sounds wrong. a CString is not a good way to pass binary data.
|
|
|
|
|
While a CString object can contain null (i.e., \0 ) characters, their presence may produce unexpected results. Is CString a requirement.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
That's totally the wrong way to do it. A jpg file is pure binary and as such may contain null bytes which would cause any characters following it to be lost when copying into a CString object. Use a pure byte array and deal with data in the manner best suited to its type.
Veni, vidi, abiit domum
|
|
|
|
|
Let me explain the problem a little more deeper.
I am trying to call a JavaScript (JS) function in a HTML page and then want to pass the binary date. The C++ function that calls the JS is given below.
bool CallJavaScript(const CString strFunc,CComVariant* pVarResult);
The 1st argument is the JS Function Name and 2nd is the one to pass the Binary Data. 1st argument works fine as i am able to call the JS fucntion called "LoadImage" without any problem. Problem is with 2nd argument that's supposed to take the Binary data of the JPG file.
If i try to pass a std::Vector or std::string then it will give me an error.
But it's happy if i pass CString. But then with CString there's a problem with NULL characters.
Actually my plan is to pass the binary of a JPG to a JS function and let it display the JPG in the HTML page.
Is there a better way of doing this?
Can i typecast a Vector or std::string to a CComVariant*?
Please help.
Thanks
|
|
|
|
|
The function wants a pointer to a CComVariant object. So you must create a CComVariant object and attach the data in a format that is supported by the receiving function (your LoadImage function). Binary data are mainly passed as SAFEARRAY variants (see Array Manipulation Functions[^] about functions to create and access such arrays).
|
|
|
|
|
Don Guy wrote: Is there a better way of doing this? Can you retool the JS function to accept the image filename and let it do the loading?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|