|
BSTR a = SysAllocString (L"asdfghj12345");
MessageBoxW (NULL,(LPCWSTR)a,NULL,NULL);
|
|
|
|
|
hello @all,
how can i convert a double value into a string?
can anybody help me???
thank you very much!
sunny
|
|
|
|
|
With this function I think
_gcvt();
Convert double number to string; store string in buffer
|
|
|
|
|
Try using sprintf (or _stprintf to support UNICODE as well):
char buf[16];
sprintf(buf, "%f", doubleValue);
TCHAR tbuf[16];
_stprintf(buf, _T("%f"), doubleValue); If you're using MFC, you can do this:
CString str;
str.Format(_T("%f"), doubleValue); Hope this helps,
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
sprintf()
[EDIT]
Ryan answered the question while I had the thread open. He has a very good answer.
[/EDIT]
John
|
|
|
|
|
John M. Drescher wrote:
answered the question while I had the thread open
Don't you hate it when that happens
Ryan
Being little and getting pushed around by big guys all my life I guess I compensate by pushing electrons and holes around. What a bully I am, but I do enjoy making subatomic particles hop at my bidding - Roger Wright (2nd April 2003, The Lounge)
Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late - John Nichol "Point Of Impact"
|
|
|
|
|
This was the first time I noticed it.
John
|
|
|
|
|
I don't know if this will solve your problem (you're not explaining it exactly) but be carrefull when you read data directly from memory and store it in the strucuture. If you use a memcpy, you will probably have some troubles because the default byte alignement in the structure is 8 (take a look at the msdn documentation about the #pragma pack directive).
That means in fact that all your member variables after the first are stored on the smaller member type or 8-byte boundaries. So, if it's not the case in memory, you will have some serious troubles when you want to "read" your data.
|
|
|
|
|
Thanks cedric,
I realized what I was doing wrong, but I didn't know about 8-byte boundry.
sj
|
|
|
|
|
could you publish the code?
You might consider usage of MS specific __declspec(property) and ignore alignment example
#include <stdexcept>
typedef struct TSimSignal
{
TSimSignal(void * pData = 0) : m_pData(pData){}
__declspec(property(get=GetSimWriteFlag,put=PutSimWriteFlag))
int SimWriteFlag;
__declspec(property(get=GetDisplayReadFlag,put=PutDisplayReadFlag))
int DisplayReadFlag;
__declspec(property(get=GetValue,put=PutValue))
double Value[45];
__declspec(property(get=GetTimeStamp,put=PutTimeStamp))
double TimeStamp;
int GetSimWriteFlag()
{
if(!m_pData)
throw std::out_of_range(__FUNCSIG__);
int * pValue = reinterpret_cast<int*>(m_pData);
return *pValue;
}
void PutSimWriteFlag(int value)
{
if(!m_pData)
throw std::out_of_range(__FUNCSIG__);
int * pValue = reinterpret_cast<int*>(m_pData);
*pValue = value;
}
int GetDisplayReadFlag()
{
if(!m_pData)
throw std::out_of_range(__FUNCSIG__);
int * pValue = reinterpret_cast<int*>(m_pData) + 1;
return *pValue;
}
void PutDisplayReadFlag(int value)
{
if(!m_pData)
throw std::out_of_range(__FUNCSIG__);
int * pValue = reinterpret_cast<int*>(m_pData) + 1;
*pValue = value;
}
double GetValue(long index)
{
if(!m_pData || index < 0 || index >= 45)
throw std::out_of_range(__FUNCSIG__);
double * pArray = reinterpret_cast<double*>(reinterpret_cast<char*>(m_pData) + sizeof(int) * 2);
return pArray[index];
}
void PutValue (long index, double value)
{
if(!m_pData || index < 0 || index >= 45)
throw std::out_of_range(__FUNCSIG__);
double * pArray = reinterpret_cast<double*>(reinterpret_cast<char*>(m_pData) + sizeof(int) * 2);
pArray[index] = value;
}
double GetTimeStamp()
{
if(!m_pData)
throw std::out_of_range(__FUNCSIG__);
double * pValue = reinterpret_cast<double*>(reinterpret_cast<char*>(m_pData) + sizeof(int) * 2 + sizeof(double) * 45);
return *pValue;
}
void PutTimeStamp(double value)
{
if(!m_pData)
throw std::out_of_range(__FUNCSIG__);
double * pValue = reinterpret_cast<double*>(reinterpret_cast<char*>(m_pData) + sizeof(int) * 2 + sizeof(double) * 45);
*pValue = value;
}
protected:
void * m_pData;
}TSimSignal;
|
|
|
|
|
I've posted a couple times before about this problem, and I seemed to be making some progress, but I now seem to have hit a wall. This is for an onscreen keyboard to be used to input text into textboxes in other windows. I'm using a global WH_GETMESSAGE hook to capture messages, and when the message is a WM_LBUTTONDOWN and the window it is being sent to is the keyboard, I use AttachInputThread and a keybd_event to simulate keyboard input. This works, but I have to call SetFocus() every time. Since I am capturing the WM_LBUTTONDOWN message, why is the focus changing? I tried capturing the WM_LBUTTONUP message too, just ignoring it by passing 1 to CallNextHookEx (Yes I pass 1 to CallNextHookEx on the WM_LBUTTONDOWN too...) ... I've tried capturing messages like WM_SETFOCUS, WM_KILLFOCUS, and WM_ACTIVATE... None of those ever seem to actually be called though, or if they are, they aren't being seen by my hook... but its global!!
hook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC)MessageProc, hHookDll, 0);
If there is any other snippets of code I can post that might help, let me know. Thanks!
|
|
|
|
|
Perhaps you need to go deeper and earlier in the message sequence. Have a look at WM_NCHITTEST and WM_HITTEST. Good Luck!
onwards and upwards...
|
|
|
|
|
I just set up a CBTProc Hook that prevents the Keyboard window from gaining focus... But now the focus just evaporates! Here is the CBTProc:
<br />
LRESULT CBTHOOK_API CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)<br />
{<br />
<br />
if((nCode == HCBT_SETFOCUS || nCode == HCBT_ACTIVATE) && (HWND)wParam == hKeyWin)<br />
{<br />
return 1;<br />
}<br />
<br />
return CallNextHookEx(HHOOK(0), nCode, wParam, lParam);<br />
}<br />
Where hKeyWin is a handle to the onscreen keyboard. Really, I dont want to keep the keyboard from gaining focus, I want to prevent the last window from losing it... As it stands, it seems that the current window loses focus, and the keyboard is prevented from gaining it, and thus it just evaporates... Like I said, I don't want to re-call SetFocus, I want to prevent the window from ever losing the focus... This is mainly because, in the Internet Explorer Address bar, if you lose focus, and regain it, the text is selected, and what you type is over written, so you cant ever type more than one letter using the onscreen keyboard...
|
|
|
|
|
Maybe you should send a WM_SETCAPTURE to the window which has the focus.
~RaGE();
|
|
|
|
|
WM_ACTIVATE should do it, however ... a window "losing the focus" receives a WM_ACTIVATE with a WA_INACTIVE parameter... A silly question maybe, but are you sure your hook is global ? have you compiled it in the right area using #pragma s ?
~RaGE();
|
|
|
|
|
Heh... Not silly... Because I don't know what a #pragma is I just thought that you had to send SetWindowsHookEx 0 as the last parameter to make it global... So what is this #pragma stuff ?
|
|
|
|
|
... OK ... maybe you should check this article by Joseph M. Newcomer:
Hooks and DLLs[^]
~RaGE();
|
|
|
|
|
Oh .. and a #pragma is a compiler command, mainly to set up a lot of things at compilation time (disabling warnings, choosing memory location for putting your variables, stuff liek that)...
~RaGE();
|
|
|
|
|
We have a LAN and are connected to the internet through a router, how do i get the internet connection ip on one of the computers in the LAN??
Kuniva
--------------------------------------------
|
|
|
|
|
One solution is via registry. Search the registry for the key that holds the system internet IP.
Kuphryn
|
|
|
|
|
Hi,
How can i load a monochrome image from a bmp file ?
Also i want to save the part of that image in an another file. How can i do that?
Regards
Neha
|
|
|
|
|
What do you mean exactly with "Load" ?
Look at the CxImage article here on CP (make a search), it should have all the features you need.
~RaGE();
|
|
|
|
|
Ok, this is kinda intense, but if anyone could help me out, i'd greatly appreciate it. My main problem is that all my integer values for my CEdit boxes are coming up as -858993460. i know whats the default value for an int, but it shouldnt be coming up like that.
Here's whats going on:
i have CPropertySheet class, CMySheet containing 5 CPropertyPage (CPage1 - CPage5) thingies. I have m_page1 - m_page5 defined as CMySheet things. I have m_sh defined as a CMySheet thing in MyProgView.h. now, when i want to get data into an edit box on page1, say its variable name is my_edit, and its an int, then in the constructor for CMyProgView::CMyProgView, i put
CPropsView::CPropsView() : m_sh("")<br />
{<br />
m_sh.m_page1.my_edit= 0;<br />
}
this makes the number 0 show up in the edit boxes. This works fine. However, i'm having trouble with another section. On page4, i have a list of radio buttons. When a user clicks on a button, a new dialog window pops up with some edit boxes.
the dialog boxes are from base class CDialog, they aren't defined as antyhing to do with my CPropertypage or CPropertysheet. I have one dialog box class names New_dialog_box.
Now, here's how i set it up.
in one cpp file, i have the domodal of the dialog box...
<br />
void CPage4::OnBnClickedRadio10()<br />
{<br />
New_dialog_box dlg;<br />
dlg.DoModal();<br />
}
I have a variable defined in New_dialog_box as an integer, its named new_dialog_edit.
Now, back in MyProgVew.h, i tried putting in the constructor of CMyPropgView the line:
m_new_dialog_box.new_dialog_edit = 0;
I declared m_new_dialog_box in
class CPropsView : public CView<br />
{<br />
private:
the exact same spot as m_sh;
I've added m_new_dialog_box(0) to the top of the constructos in MyProgView.cpp, right next to m_sh("").
When i launch the program, go to page4, click on the radio button, the value of new_dialog_edit is teh default value for an integer, -858993460. But, i've set it = 0 in the CMyProgView constructor, just like i did in all the other proeperty pages.
I've been working on this for hours, and i'm really stumped. any help would be hugely appreciated.
*.*
|
|
|
|
|
I'm not sure if I understand your problem very well, but why don't you initialise new_dialog_edit in the constructor of the New_dialog_box class ????
If I understood what you wrote, you have a New_dialog_box variable that is called m_new_dialog_box in your CPropsView but that is never used just in the constructor?? Instead of that, you declare a new instance of New_dialog_box (called dlg) in void CPage4::OnBnClickedRadio10() ??
I don't really understand what you want to do ???
|
|
|
|
|
The instance of New_dialog_box that you have in MyProgView.cpp is not the same one that is instantiated in CPage4::OnBnClickedRadio10().
|
|
|
|
|