|
this funny "fread" doing the job , exactly as i need , any way ,, how to make it not funny ?
|
|
|
|
|
Examine the printf() statement closely. You will see the following formatting:
%02x for buf[15]
%lu for size
The %02x formatting is meant for printing an unsigned int, but you are printing an unsigned char. In order to be certain that this works on all systems, cast buf[15] to unsigned int.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
then how to print the hexadecimal values in a format of two digits ?
|
|
|
|
|
Hello.
Here is another solution.
#include <iostream>
#include <fstream>
using namespace std;
int main (){
streampos size;
char * memblock;
cout<<" \n\n";
ifstream file ("myfile.bin", ios::in|ios::binary|ios::ate);
if ( file.is_open() ){
size = file.tellg();
memblock = new char [size+1];
file.seekg (0, ios::beg);
file.read (memblock, size);
file.close();
cout << "the entire file content of "<< size <<" bytes is in memory \n\n\n";
delete[] memblock;
}
else cout << "Unable to open file\n\n";
cout<<"Press ANY key to close.\n\n";
cin.ignore(); cin.get();
return 0;
}
modified 21-Aug-16 0:39am.
|
|
|
|
|
thank you for reply , but I use C language .
|
|
|
|
|
I am working on a C++ application.
In the header file:
typedef vector<CMyInfo*> CMyInfoBachelor;
CMyInfoBachelor* GetBachelorContained (ULONG MyID);
Now in the Cpp file
CMyInfoBachelor* CMyCache::GetBachelorContained (ULONG MyID)
{
for (..........)
{
CMyInfo* pS = GetMyInfo(RS.Get_UL("ulid",i));
if (pS)
pMyInfo->m_pUsedInTheseBachelor->push_back(pS);
}
return pMyInfo->m_pUsedInTheseBachelor;
}
The loop goes twice and i can see 2 separate values are been added to the Vector.
But for some reason it's not getting applied.
So if i look at debug window:-
m_pUsedInTheseBachelor->;***First*** has the correct value
m_pUsedInTheseBachelor->;***Last*** doesn't have the correct value, it's bunch of junk.
i.e., the Vector get's populated correctly only on the 1st loop iteration. The 2nd looping doesn't add the correct value to vector.
I am new to vector and have no idea how to fix it.
Also, how to make sure that it return properly?
The code that i tried is as follow:
In Header file:
vector<CMyInfo*> CMyInfoBachelor* GetBachelorContained (ULONG MyID);
And in Cpp file:
vector<CMyInfo*> CMyInfoBachelor* CMyCache::GetBachelorContained (ULONG MyID)
{
for (..........)
{
CMyInfo* pS = GetMyInfo(RS.Get_UL("ulid",i));
if (pS)
pMyInfo->m_pUsedInTheseBachelor->push_back(pS);
}
return pMyInfo->m_pUsedInTheseBachelor;
}
But i got a bunch of errors.
[edit]
Tidied up the formatting for you.
[/edit]
modified 10-Aug-16 2:52am.
|
|
|
|
|
Your function definitions are wrong in the second version as you are declaring two different return types. The first version was correct.
Also, in the first case you say the second value pushed onto the vector is a load of junk, so you need to look at the code of GetMyInfo(RS.Get_UL("ulid",i)); to check what it is returning.
|
|
|
|
|
Hi
The Frame of my Dialog has about 1.5" to 2" (I find it difficult to talk in pixels)
It seem like a nice enough area to add Text
Rather than using a CStatic object and CTEXT/LTEXT resource item
would processing a NCLIENT message and some how inserting a bitmap
(maybe I making problems for myself) work ?
|
|
|
|
|
A CStatic is pretty straight forward to use for displaying text, but if you need a bitmap you can put that in a CStatic control as well. See here[^] for an example.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
THANKS I need to connect it to the Dailog via DDX any kind Control, Text
Thanks
|
|
|
|
|
You should be able to do it from the WM_NCPAINT call which will give you the DC to place a bitmap or text in.
You will probably have to subclass the window (which means holding the current window handler) because you
will probably need to call the current handler then effectively draw over the top of everything. I think
if you just do your drawing and drop thru the existing handler will overwrite whatever you put on the DC.
Don't forget if you use text to set the background to transparent otherwise you will get a white box background
where the text is.
If you need to search for stuff technically what you are doing is skinning a dialog box.
In vino veritas
|
|
|
|
|
Hi
A couple of questions
First what call do I use to get the DC of the non-client area
GetDc GetWindowDC GetDcEx
Second in my message handler the first thing I should is call the default handler
CWnd::OnNcPaint
Calling it at the end will wipe out whatever I have done correct ?
|
|
|
|
|
ForNow wrote: Second in my message handler the first thing I should is call the default handler
CWnd::OnNcPaint
Calling it at the end will wipe out whatever I have done correct ? Seems like the best answer to this is to just try it and see.
"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
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
As always MSDN is the authoritive answer on that
WM_NCPAINT message (Windows)[^]
Quote: "The wParam value can be passed to GetDCEx as in the following example."
You need GetWindowLongPtr with index DWLP_DLGPROC to get the current dialog handler which you probably hold from WM_INITDIALOG. You use CallWindowProc with the held original handler to call the original handler when you need it. Can I offer you a routine to Safely get the dialog procedure because you can get caught with unicode/non unicode dialog windows, that is determined by the function called in the dialog creation and you can have both in the same application.
WNDPROC SafeGetDialogProc(HWND hwnd)
{
if(IsWindowUnicode(hwnd))
return (WNDPROC)GetWindowLongPtrW(hwnd, DWLP_DLGPROC);
else
return (WNDPROC)GetWindowLongPtrA(hwnd, DWLP_DLGPROC);
}
In your case you will call the old handler from within NC_PAINT and then do your special drawing routines over what they did and return zero as is required as you processed the call.
Here is a code hack to start with (the handler should really only be retrieved once at WM_INITDIALOG just for speed)
case WM_NCPAINT: {
WNDPROC OldHandler = SafeGetDialogProc(hwnd);
CallWindowProc(OldHandler, hwnd, Msg, wParam, lParam);
return(0);
}
In vino veritas
modified 10-Aug-16 23:36pm.
|
|
|
|
|
It's in middle of the night here I'll try it in the morning
In win32 version of WM_NCPAINT wparam has the HRGN value of the NC area no such information with MFC I did try to draw a bitmap with CStatic::SetBitMap all it did was draw a rectangle box I'll get back to this in the morning thanks
|
|
|
|
|
GetDCEx expects a HRGN which as you said is in the wParam and gives you back the DC.
HDC hdc;
hdc = GetDCEx(hwnd, (HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN);
Also remember that returned DC is a screen DC so you have to BitBlt the bitmap onto it to display anything, simply selecting the bitmap onto it will do nothing other than attach a pointer. The fact you got the white box makes me think you didn't do it right so lets give you the basics, which go like this
SETUP (usually in WM_INITDIALOG):
HBITMAP hBmp;
HDC hMemDC;
hBmp = (HBITMAP) LoadImage(0, "SomeName.Bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
hMemDC = CreateCompatibleDC(NULL);
if (hMemDC) SelectObject(hMemDC, hBmp);
BITMAP bm;
GetObject(hBmp, sizeof(bm), &bm);
BmpWth = bm.bmWidth;
BmpHt = bm.bmHeight;
USE (NC_PAINT):
HDC hdc = GetDCEx(hwnd, (HRGN)wParam, DCX_WINDOW|DCX_INTERSECTRGN);
BitBlt(hdc, ???, ???, BmpWth, BmpHt, hMemDC, 0, 0, SRCCOPY);
CLEANUP (usually WM_DESTROY):
DeleteObject(hBmp);
DeleteDC(hMemDC);
Finally if you want to add buttons etc there are a few more tricks and I will refer you to an article
Custom Titlebar | Catch22[^]
In vino veritas
modified 11-Aug-16 9:06am.
|
|
|
|
|
How about doing the same logic in an override of CStatic::DrawItem the ldrawitemstruct has a DC
I'll create a control with SS_OWNERDRAW DDX_Static or Control it
The frame work should then call my Drawitem ?
|
|
|
|
|
CStatic::Setbitmap didn't seem to do the trick and NCCLIENT encompasses the entire non client area of the dialog I am thinking of going with a owner draw SS_OWNERDRAW style
I think all I need to do is override CStatic::DrawItem
|
|
|
|
|
|
Looking for an idea solving following problem:
I have a "get()" function which returns the condition of an object stored in a member variable.
There is also some code that updates this _cond
int getCond() const { return _cond; }
void UpdateCond() { ... etc ... _cond=f(); ... }
In the whole code getCond() and UpdateCond() called are independetly, so that a "const" function could call "getCond()"
But there is one silly stupid use of the getCond() where the Update() is done in the getCond() code
So the former old coder maybe thought "update on request!"
int getCond() { UpdateCond(); return _cond; }
because UpdateCond() changes the member _cond getCond() cannot be const anymore.
Anyone an idea to overcome this problem?
(if not I have to change back this crunchy design into non-const getCond() functions...
There are about 100 in derived classes ...
|
|
|
|
|
FriendOfAsherah wrote: But there is one silly stupid use of the getCond() where the Update() is done in the getCond() code
There is only one clean solution:
Remove the wrong implementation and replace calls of it by two calls to UpdateCond() and getCond() .
You may also change UpdateCond() to return the state instead of returning nothing. This will not affect existing code calling UpdateCond() but allows you to use it instead of the non-const getCond() function.
|
|
|
|
|
seperating is really a work for months because this is somewhere in a 10x hierarchie and 100x parallel used chaotic class inheritance...
A { getCond() astract }; <- B <- C <-D ... about 10 Steps
A <-B1 ...
A <- B2 ...
and one of these C´s contains the thing with condUpdate()
I inherited this code ... hating it ..
maybe mutual or const_cast can help? but still update() is a non const function
I found another solution now which can work with the "non const" version which is used in the code...
But cleaning up this will be needed somedays..
|
|
|
|
|
I understand that it is a lot of work. But doing it the wrong way will make it even more complicated for future updates (especially when those have to be done by others).
The trick here is finding the code that calls this single non-const function (and expects that an update is performed) and replace that. You may use your development tools to find these calls (many have options like "Find Usages").
|
|
|
|
|
Hi
as a newbee to MFC C++ I have just been learning the hard way the number of corrections the visual studio debugger fixes for my mistakes
In addition when there is an exception in my code many times the exception address points to some windows DLL making it a challenge to track it to the User Code
Thanks for all those that have brought me to this point
|
|
|
|
|