|
i have created a push button using Create Window. Now
1. how do i write text on the button?
2. how do i handle the button WM_COMMAND?
the code snippet is:
WNDCLASS wc;
memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = GetModuleHandle(NULL);
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH); wc.lpszClassName = "WndClassName";
if(!RegisterClass(&wc))
{
MessageBox(NULL,"Failed To Register The Window class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return (NULL);
}
HWND hWindow = CreateWindowEx(NULL, "WndClassName","DialogClassSample",WS_OVERLAPPEDWINDOW | WS_VISIBLE,0, 0, 320, 200, NULL, NULL, GetModuleHandle(NULL), NULL);
HWND ButtonWindow = CreateWindow("BUTTON",NULL, BS_TEXT|BS_PUSHBUTTON|WS_VISIBLE|WS_CHILD,50,50,30,20,hWindow,NULL,NULL,NULL);
MSG msg;
BOOL bDone = FALSE;
while(!bDone)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message==WM_QUIT)
{
bDone = TRUE;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
|
|
|
|
|
1. SetWindowText should help you put the text over the button
2. You need to give your Window Procedure where in you can handle the messages (In a way that we use to do in SDK)
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
My Window procedure is:
LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam) {
switch (uMsg)
{
case WM_COMMAND:
{
PostQuitMessage(0);
return 0;
}
break;
case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
}
break;
}
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}
Here i have handled the WM_COMMAND message.
but my problem is if i create 2 push buttons and i want seperate handling for the buttons, how do i distinguish the WM_COMMAND of one button from the WM_COMMAND of the second button?
|
|
|
|
|
1.Low-order of WParam would be having the button identifier, compare that with the list of id's that you gave at the time of creation
2. Compare your button handle with in coming hwnd parameter
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
how do i compare low-order of WParam. i did not create any list of ids. i checked the low-order of WParam. it outputs 0.
Secondly, how do i compare the handle. The button handle is declared in WinMain() and i need to compare in WndProc(i m not able to get the button handle in WinProc)
|
|
|
|
|
1. The LOWORD macro retrieves the low-order word from the specified value.
2. Instead of using createwindow try using create of CWnd this would allow you to set the control's id. Store thos id's in some array and check them in your wndproc function.
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
I want to use CreateFile for creating of new files, overidding existing ones or just simply open them in various modes (depending on my applications' requirements). I know that when it fails it returns INVALID_HANDLE_VALUE and I have to use the GetLastError to find why. However, the GetLastError is a generic system function. Is anywhere any documentation about what errors can be the result of CreateFile. How do I know e.g. if I failed 'cause tried to create an existing file, tried to open an non-existing file, do not have enough disk space, do not have access to the parent directory, lost connection with a remote file store etc.
A cross reference list function-possible failures would be usefull for any Win32 function (I am looking for it not only for the CreateFile).
Anyone can point me to such documentation (books, web pages, etc) will be much appreciated.
Life is a river with mist ahead...
|
|
|
|
|
I don't know if there is such a list but what you can do is use the Error Lookup tool. It is already in the tools in Visual C++ 6. You give the error code and it displays the corresponding error string.
|
|
|
|
|
Alternate to error lookup you can as well use FormatMessage API(Though output is same in either case ).
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Thanks for your help.
I am aware of the FormatMessage API. The Error Lookup is also a good tool. However, all these come from the wrong direction; once you know the error.
My problem is that I cannot find documentation about all possible errors. I would like to write a switch statement of the GetLastError numbers and direct my code to handle important errors in a more appropriate manner than reporting them to the user. And there is where my problem comes. I do not have a list of those errors; not only for CreateFile but for almost and window function.
Look the UNIX manual for open() (E.g. in http://www.rt.com/man/open.2.html) They have a list of all possible errno values that open may return, not all possible errno values in the whole O.S. Why Microsoft never does that for Win32?? Or if it did where can I find it?
Thanks for any help
Life is river with mist ahead...
|
|
|
|
|
Well, maybe because it's difficult to maintain such a documentation.
If you're interested, you can look into the <winerror.h> header, where most of errors are described (found in any good Windows SDK)
Don't know if it does any good to you, but at least tried
|
|
|
|
|
Consider using CFile::Open() instead. That will allow you to switch on these[^] error codes contained within a thrown CFileException .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Consider using CFile::Open() instead. That will allow you to switch on these[^] error codes contained within a CFileException .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
is there any alternative within eVC 4.0?
thx
|
|
|
|
|
How can I get the default printer which is connected on a pc directly or on a LAN?
Thanks in Advance
|
|
|
|
|
Have a look at CWinApp::GetPrinterDeviceDefaults()
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
Check out for EnumPrinters API, This should be able to get you available printers.
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
My application uses a socket to receive periodic UDP multicast messages (messages are send every 100 millisecs and theyr size is variable).
When I run my application in some PCs, I've seen that when it receives a long message (1360 bytes or more), that packet is correctly received but sometimes the next one is lost (the socket doesn't receive it) even if it is a small one. Using a network monitor application, I've seen that this problem happens when the packet is fragmented in more than 7 packets at UDP level.
In sinthesys, the problem is that long packets (fragmented in more that 7 packets at UDP level) are received but lets the socket loose the next one. It doesn't happen any time, and it doesn't happen on any PC.
Can someone tell me what is this problem due to ?
Are there some socket options usefull to solve this problem ?
Thanks a lot !!
|
|
|
|
|
Can anyone tell me what the maximum number of unsigned chars that can be read in from a file using the read method.
TIA,
Andy
|
|
|
|
|
Hello!
I'm using VC++ in .NET Studio. I made simple MFC dialog based application with resource builder. I know how to handle some button press and event is executed on button release. But I don't know how to handle button press and button release. For example if I press (mouse button down) "LIGHT" button, virtual light would start to shine and when I release button (mouse button up) virtual light would stop shineing.
Can it be done?
Regards,
Rostfrei
|
|
|
|
|
Hi,
Can anyone suggest a way to convert a text file to bmp at runtime ,
I was able to create and save the bitmap file but was unable to append text to it.
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Load (or create) the bitmap, select it into a memory DC and use DrawText or TextOut to draw your text onto the bitmap the same as you would draw text onto the screen DC. Select the bitmap out of the DC and save it.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
already tried that but I don't see any text in the saved bmp file
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|
|
Show your code.
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
<br />
CreateBitmap();<br />
<br />
m_pMemDC = new CDC;<br />
<br />
VERIFY( m_pMemDC->CreateCompatibleDC(m_pWinDC) );<br />
<br />
m_pOldBitmap = m_pMemDC->SelectObject( &m_Bitmap );<br />
<br />
CString str("This is a test message");<br />
<br />
CPen cp;<br />
cp.CreatePen(PS_SOLID, 2,RGB(255,255,255));<br />
<br />
CRect rect;<br />
GetClientRect(&rect);<br />
<br />
m_pMemDC->SelectObject(&cp);<br />
m_pMemDC->DrawText(str,str.GetLength(),rect,DT_LEFT);<br />
<br />
PBITMAPINFO pbi = getInfoStruct(m_Bitmap);<br />
<br />
CreateBMPFile("test.bmp",pbi,m_Bitmap,m_pMemDC->m_hDC);<br />
m_pMemDC->SelectObject(m_pOldBitmap);<br />
<bold>- Nilesh
<italics>
"Reading made Don Quixote a gentleman. Believing what he read made him mad" -George Bernard Shaw
|
|
|
|