|
Do you need to use Flexgrid ? Chris Maunders grid control canes it, you can get it here on CP.
Christian
The tragedy of cyberspace - that so much can travel so far, and yet mean so little.
And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002
|
|
|
|
|
Yeah, the assignment calls for FlexGrid.
|
|
|
|
|
Hi All,
A Quick question. I am trying to create controls on a form at run time, in a CFormView derived class. I have got the following code, which is trying to create a static label on the form, that should display the word "Test". I got the styles and extended styles for the window from looking at another static labels properties in Spy++. This is in my CFormView derived class's OnInitialUpdate:
HWND hWndTest = CreateWindowEx(
WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOPARENTNOTIFY, // extended window style
"Static", // registered class name
"Test", // window name
WS_VISIBLE | WS_CHILDWINDOW | WS_GROUP | SS_LEFT, // window style
30, // horizontal position of window
30, // vertical position of window
40, // window width
20, // window height
m_hWnd, // handle to parent or owner window
NULL, // menu handle or child identifier
NULL, // handle to application instance
NULL // window-creation data
);
The thing is, I get a static label on the form, that is in fact displaying the word "Test", but it looks different than the static labels that I put on the dialog template. The font is bold, or something.
Anybody ever done this before? Why would this produce a different lookin label than doing it the normal way?
Thanks,
Aaron
|
|
|
|
|
You need to set the font for the created control. When you design a form using the resource editor it sets a default font for you (you can change it). This is not the standard system font which is the default for controls to draw with. You need to GetFont() from your dialog and SetFont(GetFont()) for your created control.
|
|
|
|
|
Thanks! That worked like a charm.
|
|
|
|
|
Hi all, I just want wanted to know what the best way of loading a binary file was without using MFC (I can do it using CFile and CArchive). At the moment I want to load in a file format that composes of 7 integers into 7 different variables. I'm also a bit worried about the robustness of the procedure. At the moment I have:
#include fstream
ifstream fin(FilePath, ios::binary)
if (fin)
{
fin.read(var1, sizeof(int));
fin.read(var2, sizeof(int));
etc.
}
fin.close();
but this seems remarkably inefficient as opposed to using the (arrow, arrow)operator as with MFC. Is this the best way to do this kind of thing? I know there is a function fin.eof() which tests for the end of the file, but surely I can't add that before each variable extraction? Its more used for text files and character extraction isn't it? I just need the best way of going about loading the data in this format into the seven different variables WITHOUT MFC. Thanks to all who are thinking about a solution.
Alan.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
If the numbers are stored in binary format, then your code is just fine, and probably is as efficient as any MFC method. iostreams also have operators << and >> , but these are meant to handle numbers expressed in text mode. The code can be refined a little with the use of exceptions:
ifstream fin;
fin.exceptions(ifstream::eofbit|ifstream::failbit|ifstream::badbit);
try{
fin.open(FilePath, ios::binary);
fin.read(var1, sizeof(int));
fin.read(var2, sizeof(int));
...
}
catch(ifstream::failure& e){
}
fin.close();
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Thanks for the reply Joaquin, I was wondering how to use the try catch exceptions without MFC (I have used CException but obviously can't if I'm not using MFC) and you have given it to me on a plate, so many thanks for that . I also thank you for reaffirming the loading method, you know sometimes when you get that feeling when something doesn't quite feel right (thats what I got)? I think your example looks a lot sweeter, mind, with the try catch stuff in it, its exactly what I was looking for. Again, many thanks Joaquin, may the code be with you.
Alan.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
I have a problem converting a CComBSTR to LPCTSTR with CW2CT. Eveything works fine until my CComBSTR gets around 64 caracters... then the result of the convertion is a long "corrupted" string: "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþ...."
Please help me !
-----
See comments between /* */ for more info
-----
LRESULT CListBoxDlg::OnBnClickedBtngetselitems(WORD , WORD , HWND , BOOL& )
{
LPCTSTR sTitle;
int arrSelList[12];
TCHAR pszBuf[128] = "";
int iMaxNum = 12;
LRESULT iSelCount = 0;
LPCTSTR sMsg = 0;
CComBSTR bsMessage;
iSelCount = this->SendDlgItemMessage(IDC_AVSCODES, LB_GETSELITEMS, WPARAM(iMaxNum), LPARAM(arrSelList));
if (iSelCount != LB_ERR) {
bsMessage.Append("You have selected the fields: ");
_stprintf(pszBuf, "%li", arrSelList[0]);
bsMessage.Append(pszBuf);
for (int i = 1; i < iSelCount; i++) {
bsMessage.Append(", ");
_stprintf(pszBuf, "%li", arrSelList[i]);
bsMessage.Append(pszBuf);
}
bsMessage.Append(".");
sMsg = CW2CT(bsMessage.m_str);
sTitle = _T("Selected Items List");
::MessageBox(this->m_hWnd, sMsg, sTitle, MB_OK);
}
return 0;
} ompared to ATL 3.0
*/
sMsg = CW2CT(bsMessage.m_str);
/*
// The following two lines makes it work fine but USES_CONVERSION is not supposed
// to be needed with ATL 7.0
USES_CONVERSION;
sMsg = W2CT(bsMessage.m_str);*/
sTitle = _T("Selected Items List");
::MessageBox(this->m_hWnd, sMsg, sTitle, MB_OK);
}
return 0;
}
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
J.-C. Gauthier - http://www.grandmenhir.com/
|
|
|
|
|
This is the problem:
TCHAR pszBuf[128] = "";
buffer size is for 64 wide char's
soptest
|
|
|
|
|
even with 1024 it doesn't work
TCHAR pszBuf[1024] = "";
maybe there is something else I need to do.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
J.-C. Gauthier - http://www.grandmenhir.com/
|
|
|
|
|
Use thi9s code:
inline char* ConvertBSTRToString(BSTR pSrc)
{
if(!pSrc) return NULL;
DWORD cb,cwch = ::SysStringLen(pSrc);
char *szOut = NULL;
if(cb = ::WideCharToMultiByte(CP_ACP, 0, pSrc, cwch + 1, NULL, 0, 0, 0))
{
szOut = new char[cb];
if(szOut)
{
szOut[cb - 1] = '\0';
if(!::WideCharToMultiByte(CP_ACP, 0, pSrc, cwch + 1, szOut, cb, 0, 0))
{
delete []szOut;
szOut = NULL;
}
}
}
return szOut;
};
soptest
|
|
|
|
|
I'm trying to open a pipe to traverse through a list of files retrieved using a "dir" command. I have everything set up the way I used to have it in one of my other applications; but, for some reason, it's not working.
Here's the code:
if( (fp = _popen( szCommand, "r" )) == NULL )
exit( 1 );
Where fp is defined as FILE* and szCommand is a a CString containing the Short Path to the directory I'm trying to look at. The function returns NULL and shuts the app down. I'm not sure what I'm doing wrong or if it's something caused by Windows 2000 or what. Does anyone have any ideas?
|
|
|
|
|
Is yours a Windows app? Seems like _popen works only for console apps.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
you must pass "dir" command to szCommand not a path
* POPEN.C: This program uses _popen and _pclose to receive a
* stream of text from a system process.
*/
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
char psBuffer[128];
FILE *chkdsk;
if( (chkdsk = _popen( "dir *.c /on /p", "rt" )) == NULL )
exit( 1 );
while( !feof( chkdsk ) )
{
if( fgets( psBuffer, 128, chkdsk ) != NULL )
printf( psBuffer );
}
printf( "\nProcess returned %d\n", _pclose( chkdsk ) );
}
soptest
|
|
|
|
|
I've got a really strange keyboard hooking issue that is causing problems between the debug and release versions of the test code, namely the debug version is working globally while the release version seems to only work within the context of the test app window. Below is the source code for the test app. Any insight into this would be greatly apprecaited.
----------------------------------------------
#include "stdafx.h"
static HHOOK KeyboardHookHandle = NULL;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK KeyboardHookProc(int code, WPARAM wParam, LPARAM lParam)
{
MessageBox(NULL, "Keystroke Detected", "Memorex", MB_OK);
return CallNextHookEx(KeyboardHookHandle, code, wParam, lParam);
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof (wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_WINLOGO);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "KeyboardHookTest";
wndclass.hIconSm = LoadIcon (NULL, IDI_WINLOGO);
RegisterClassEx (&wndclass);
hwnd = CreateWindow ("KeyboardHookTest",
"KeyboardHookingTest",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_CREATE:
KeyboardHookHandle = SetWindowsHookEx(WH_KEYBOARD, KeyboardHookProc, 0, 0);
break;
case WM_SIZE:
break;
case WM_PAINT:
break;
case WM_DESTROY:
if (KeyboardHookHandle)
UnhookWindowsHookEx(KeyboardHookHandle);
PostQuitMessage(0);
break;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam);
}
----------------------------------------------
I can't seem to isolate what is causing such anomalous behavior and I also apologize for the 'messiness' of my code. Again, any help would be apprecaited.
Can you imagine Darth Maul on speed?
|
|
|
|
|
First of all, I'd say your code is clear as water
The docs are rather obscure in this point, but it could be that you have to pass hInstance as the hMod parameter of SetWindowsHookEx --giving it a try is cheap, anyway.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Paying closer attention to the docs, there's a line that says:
All global hook functions must be in libraries
So, you've got to move your code to a DLL. As for why it seemed to work on Debug mode, I guess it is because the executable is run in the context of the debugger process, acting like a sort of DLL on the eye of the system (To check this out, symply execute your debug .EXE by double clicking it outside the IDE. If my theory proves right, you'll get the same behavior as in release mode --no global hooking.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
In my owner draw combobox, MeasureItem doesn't get called (at least when I use AddString ). However DrawItem does get called. But without MeasureItem, the heights are screwed up.
What's wrong?
|
|
|
|
|
Are you using a fixed size combo box?
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I'm not.
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~( CBS_OWNERDRAWFIXED | CBS_SORT );
cs.style |= ( CBS_OWNERDRAWVARIABLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS );
Even if I am, MeasureItem should still be able to determine the height of each entry, just not separately.
|
|
|
|
|
How do you make it so any file with a certain extension is opened with your program?
-Raffi
|
|
|
|
|
I answered this question in other thread... here is
THE LINK
Mauricio Ritter - Brazil
Sonorking now: 100.13560 Trank
The alcohol is one of the greatest enemys of man, but a man who flee from his enemys is a coward.
|
|
|
|
|
Does anyone know the maximum value of an unsigned long and a signed long variable in Windows NT ?
Thanks,
Hoang
Hoang Le
|
|
|
|
|
4,294,967,295 (232-1) and 2,147,483,647 (231-1) respectively.
These are declared for your convenience as the macros ULONG_MAX and LONG_MAX in <limits.h> , so you'd better use those rather than the crude numbers.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|