|
Netvisdom wrote: What if we convert smaller type to bigger
No problem. In fact, some types are automatically promoted.
Netvisdom wrote: how is it done?
char c;
int n = c; Netvisdom wrote: And bigger to smaller?
There is potential loss of data.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Thanks, but I ment what there would be if we convert, for example, int to char - truncated or maximum number? And what about other convertion cases?
|
|
|
|
|
Netvisdom wrote: ...but I ment what there would be if we convert, for example, int to char...
There would be loss of data if the int value was 128 or greater.
Netvisdom wrote: And what about other convertion cases?
Such as?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
I think he is asking, if you cast an int down to a char, does the char take on the value of the least significant byte of the original int, or does the char take on the value of the highest value that a char can hold.
For instance, if the int held the value 50, then it's clear that the char would take on the value 50, but if the int held the value 356, would the char take on the value 128 since 128 is the highest number a char can hold?
|
|
|
|
|
Troposphere wrote: ...but if the int held the value 356, would the char take on the value 128 since 128 is the highest number a char can hold?
No, it would "wrap" all the way back around to (positive) 100. The leftmost 16 bits would go away. A better example would be if the int value was something like 200. The resulting char value would be -56. The leftmost 16 bits still go away, but now the sign bit is 1, indicating a negative.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
I am not able to read & write to serial port in WINDOWS CE using embedded visual c++. i am including the code i have tried.it showing no.of bytes written as 1 but while reading it is showing as no.of bytes read as 0.
//writing
DWORD dwError,dwNumBytesWritten;
int rc;
HANDLE hPort;
BYTE B;
TCHAR* pFileName = TEXT("COM1:");
B='a';
hPort =CreateFile(pFileName,GENERIC_READ| GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
rc=WriteFile (hPort,&B,1,&dwNumBytesWritten,NULL);
CloseHandle (hPort);
//reading
DWORD dwError,dwNumBytesRead;
int rc;
HANDLE hPort;
BYTE B;
TCHAR* pFileName = TEXT("COM2:");
hPort =CreateFile(pFileName,GENERIC_READ| GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
rc=ReadFile (hPort,&B,1,&dwNumBytesRead,NULL);
MessageBox(NULL,TEXT(""+B),NULL,MB_OK);
CloseHandle (hPort);
can anyone please halp me
Thanks for your reply in advance.
Neha
|
|
|
|
|
I'm looking for a quick template or sample code to write a quick "installer" type program in (not managed) C++ to install items to the PROGRAMS folder that simply are links to a website.
For example, START / ALL PROGRAMS / MY FOLDER / Link 1, Link 2, etc.
Does anyone have anything like this?
|
|
|
|
|
See here and here.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
A link to CodeGuru?!! Blasphemy!!
|
|
|
|
|
I'm using toolbars in a couple dialogs (actually property pages). I can get them transparent by setting that in OnErase in the derived CToolbar class, but I always get a border on the top.
I've played around with the flags to try and get rid of that top border, no luck, and I think I've forgotten everything I've tried at this point - brain fry Here's the code that creates the toolbar:
m_Toolbar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_FIXED);
Any ideas how to get rid of that top line/border?
|
|
|
|
|
Hi, me again...
a few days a go I posted a problem with showing tooltips in a modeless dialog in a dll. I got a hint which seems to solve the problem.
I have done several tests in the meantime and unfortunatelly there is still a small problem with the tooltip.
To setup the tooltips for the modeless dialog in my dll I use this function:
//////////////////////////////////////////
void CMyDialog::SetToolTip(CWnd* pWnd, LPCTSTR lpszText)
{
if((pWnd != NULL) && (m_pTip != NULL)){
TOOLINFO ti;
ti.cbSize = sizeof(TOOLINFO);
ti.lpszText = (LPTSTR)lpszText;
ti.hinst = AfxGetInstanceHandle();
ti.hwnd = pWnd->m_hWnd;
ti.uFlags = TTF_SUBCLASS | TTF_IDISHWND;
ti.uId = (UINT)pWnd->m_hWnd;
m_pTip->SendMessage(TTM_ADDTOOL, 0, (LPARAM)&ti);
}
}
//////////////////////////////////////////
THe tooltip is shown and this works without (!) any call to CMyDialog::PreTranslateMessage(MSG* pMsg) and RelayEvent. But I need this call, because there is an MFC bug with tooltips for disabled controls and I used in my other modal dialogs this code:
//////////////////////////////////////////
BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
{
TRACE("PreTranslateMessage\n");
if(m_pTip != NULL){
// The following code is a workaround for a MFC tooltip bug which
// prevents the popup of a tooltip for a disabled control in a modal dialog.
// Transate the message based on TTM_WINDOWFROMPOINT
MSG msg = *pMsg;
msg.hwnd = (HWND)m_pTip->SendMessage(TTM_WINDOWFROMPOINT, 0, (LPARAM)&msg.pt);
CPoint pt = pMsg->pt;
if((msg.message >= WM_MOUSEFIRST) && (msg.message <= WM_MOUSELAST))
::ScreenToClient(msg.hwnd, &pt);
msg.lParam = MAKELONG(pt.x, pt.y);
// Let the ToolTip process this message.
m_pTip->RelayEvent(&msg);
} // if
return CDialog::PreTranslateMessage(pMsg);
}
//////////////////////////////////////////
Then I tried to use the message hook which was neccessary to use accellerators in CMyDialog to call PreTranslateMessage:
//////////////////////////////////////////
// Hook procedure for WH_GETMESSAGE hook type.
LRESULT CALLBACK GetMessageProc(int nCode, WPARAM wParam, LPARAM lParam)
// If this is a keystrokes message, translate it in controls'
// PreTranslateMessage().
LPMSG lpMsg = (LPMSG)lParam;
if((nCode >= 0) &&
(PM_REMOVE == wParam) &&
(lpMsg->message >= WM_KEYFIRST && lpMsg->message <= WM_KEYLAST) &&
(AfxGetApp()->PreTranslateMessage((LPMSG)lParam)) == TRUE){
// The value returned from this hookproc is ignored, and it cannot
// be used to tell Windows the message has been handled. To avoid
// further processing, convert the message to WM_NULL before
// returning.
lpMsg->message = WM_NULL;
lpMsg->lParam = 0L;
lpMsg->wParam = 0;
}
// Process WM_MOUSE messages for tooltips here ????
if((nCode >= 0) &&
(PM_REMOVE == wParam) &&
(lpMsg->message >= WM_MOUSEFIRST && lpMsg->message <= WM_MOUSELAST) &&
(AfxGetApp()->PreTranslateMessage((LPMSG)lParam)) == TRUE){
// Do nothing ???
}
// Passes the hook information to the next hook procedure in
// the current hook chain.
return ::CallNextHookEx(g_hHook, nCode, wParam, lParam);
}
//////////////////////////////////////////
When I use the above code the tooltips for disabled controls work, but something with the mousemessage handling is wrong, because CCombobox controls can't be opened (They open very short and automatically close again).
Does anyone know how to solve my problem?? I think somehow I must call RelayEvent of the tooltip.
THX
|
|
|
|
|
Is it safe to say that every user-mode process is a child of either the Services Controller (services.exe) or the Shell (explorer.exe) ??
Does the User32::ShellExecute function ultimately resolve to a call to CreateProcess, or does ShellExecute ultimately create the given process with calls to native functions??
|
|
|
|
|
I have an edit box on my property page that I want to check to make sure the user is putting the proper data in. In order to do this I use OnKillFocus() and set the focus back to edit box which has a problem. This works fine.
My problem is that when I switch to a different page on my property sheet, it does not keep the previous page up front. I still get the message box that I throw for errors, but the page still becomes inactive. I tried to use a ShowWindow(SW_SHOWNORMAL) but it looks like the new tab is still selected even though it show the contents of the previous tab.
Thanks in advance!
|
|
|
|
|
In the OnKillActive() method, what value are you returning?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
that method returns a void. All I really do is throw a MessageBox("Error") message in there.
|
|
|
|
|
NYTSX wrote: that method returns a void.
For a window/control, yes. OnKillActive() should return non-zero if losing focus is allowed, 0 otherwise.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
OK, maybe I am really unclear.
I am using the OnKillFocus() for an EditBox. My problem is that when I switch tabs, it throws the error but still allows for the tab to be changed. I ideally would like for the tab not to be switched at all.
Thanks for all your help.
|
|
|
|
|
NYTSX wrote: I ideally would like for the tab not to be switched at all.
Which is why I suggested overriding OnKillActive() .
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
I was trying to do use SetActiveWindow() and/or ShowWindow() in the OnKillActive() and neither do what I want. Should I be doing something else?
Thanks for being so patient!
|
|
|
|
|
NYTSX wrote: I was trying to do use SetActiveWindow() and/or ShowWindow() in the OnKillActive() and neither do what I want.
There's no need to do any of that. Simply return 0 from OnKillActive() if you do not want the tab to change. A value of 1, which is the default, will allow the tab to be changed.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
How to define and use 3 sockets which should be always open to 3 different locations and work as TCP/IP listening and sending messages which come in XML format like <start><id>id<id><name>name<name>.... Do I have to write three different socket class?
Thanks,
nahitan
|
|
|
|
|
I'm no Lord of Sockets, but I can tell you that if you want to have continuous connections to 3 different hosts, then you will need 3 separate sockets.
A TCP/IP socket does not know anything about XML. It is up to your program to interpret the XML. The only thing the socket does is send and receive packets of bytes.
|
|
|
|
|
Hello!
I make simple dialog based programs. I make them with resource editor VS.NET 2003. When I create dialog it is grey. After I put some other controls on it. What is the easiest way to make Dialog based application with some background of some predefined background (picture)? Instead of grey there would be some picture.
Best regards,
Rostfrei
|
|
|
|
|
Hi Rostfrei ,
if you need to paint dialog use WM_CTLCOLOR
and if you want to draw picture I suggestion that use picture's in the WM_PAINT and the use handle dc
|
|
|
|
|
include ->atlImage.h //in h file
CImage m_Image;//in h file
m_Image.Load("c:\\picture.bmp");//[in the OnInitDialog(example)]
in function Onpaint
CPaintDC dc(this); // device context for painting
m_Image.BitBlt(dc.m_hDC,CRect(0,0,800,600),CPoint(0,0));
|
|
|
|