|
Boy, i know ur problem and the exact solution.
First of all, you cant use SetFocos to focus child items on the MAIN WINDOW. You have to use a technique called WINDOW SUBCLASSING to solve it.
If you have access to the book "Programming windows" by charl's petzold, go through Window subclassing in chapter 9.
If u dont hav the book, tell me, i ll try to give a short tutorial
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
I can't do it even if I'm working with dialogs ????
Well, I know this book, but I don't have how to access it... If you can help me with some resources, I would be glad.
Thanks a lot.
__________
Chulips
|
|
|
|
|
Ignore the other poster. This is a feature of Windows 2000 and XP - focus is only drawn when the user actually interacts with the UI using the keyboard.
Note: I'm talking about focus rectangles, the dotted lines that appear inside the button. See later for information on the default push button highlight and automatically selecting the text in an edit control.
To get the UI to draw focus rectangles in response to a keyboard operation, Windows sends your window WM_CHANGEUISTATE and WM_UPDATEUISTATE messages. To get the standard controls to do their stuff, simply pass these messages along to DefWindowProc (which you should normally be doing anyway).
If you have a custom control that you want to draw focus rectangles on, handle these messages.
If you're dealing with a dialog, send a WM_NEXTDLGCTRL message to the dialog instead of using SetFocus . The dialog box code itself deals with selecting the text in an edit control and setting the default button, but it doesn't see the notifications to the child controls.
If you have a modeless dialog (created with CreateDialog or the Indirect /Param variants), your message loop needs to call IsDialogMessage to get this behaviour. You can also use IsDialogMessage with a regular window to get the same behaviour.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Hello Mike!
Your tip has helped me a lot! IsDialogMessage was my problem (I wasn't calling it...) But now, I have the same problem for static controls. There're two controls (static texts) that should receive the focus, since I'm treating them as links. So, I want tabstops and focus drawing on them. But Windows makes only tabstops, but doesn't draw it. Still, seems that I can't process WM_KILLFOCUS, WM_SETFOCUS or even WM_CHANGEUISTATE and WM_UPDATEUISTATE, because they are processed by IsDialogMessage. Do you have any comment about it? How do I get focus visible on those controls?
Regards,
Felipe
__________
Chulips
|
|
|
|
|
Hello Everyone,
In my current code, A program calls a function in B program using "Invoke" method. B program has an exposed COM interface. It works fine. Then I added another exposed method in B program, but everytime I call it, there is an error. I tried to go thru the code. In program B, the code for the two function are exactly the same. What should I do?
Thanks a lot in advance.
Bin
|
|
|
|
|
More information on the error would help!
Ant.
|
|
|
|
|
I can make wql requests but how can I place the requested value in a C++ variable, e.g. query = (SELECT capacity FROM Win32_PhysicalMemory WHERE BankLabel = "Bank0") and then get the value "capacity" and put it into an int variable in the C++ app.
Cheers for any help in advance.
Dave.
We have a mathematician, a different kind of mathematician, and a statistician!
|
|
|
|
|
Do these articles help any?
http://www.codeproject.com/csharp/wmi.asp?target=select
http://www.codeproject.com/useritems/PrntJobControllerUsingWMI.asp?target=select
Or this thread?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Hi there,
I am trying to implement a privacy control functionality to block cookies, somethign similar to what IE 6.0 is doing now. I can get to teh point of reading them throught IHTMLDocument interface, btu have not figured out how to stop them from writing onto the cookie folder.
has anybody done anything similar to thsi or can you suggest me soem ideas in this regard?
Thank you,
subbu
|
|
|
|
|
Hi Everybody,
I am tryieng to load bitmap dynamically from a perticular memory location. I am giving the patch of the bitmap to CBitmap::LoadBItmap(...) member function. But it is not working. I think CBitmap::LoadBItmap(..) does not take the patch of the bitmap. I think there is another procedure to achieve it. If any one konws how to load the bitmap dynamically. please let me know.
bbye
Salman
Live and Let live
|
|
|
|
|
CreateDIBSection .
Next!
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Well, i am not about MFC, but using API u can do it the following way. Go through the code and i hope you can easily port it to MFC.
If you want to dynamically load a bitmap included as a resouce, use the following code:
<br />
HDC hdc,bdc;<br />
bdc=CreateCompatibleDC(hdc);<br />
hBmp=LoadBitmap(gloInst,"BMP_SYSTRAY");
SelectObject(bdc,hBmp);<br />
BitBlt(hdc,0,0,200,100,bdc,0,0,SRCCOPY);<br />
DeleteDC(bdc);
The potential problem with this approach is that you cant pick bitmaps from the disk(any file) and bitmaps that have more than 256 colors.
Alternatively if you want to dynamically load any bitmap of any size and any bit-depth, use the following code:
When you process the WM_PAINT message, use the following code to draw the bitmap:
static BITMAPFILEHEADER * pbmfh ;
static BITMAPINFO * pbmi ;
static BYTE * pBits ;
static int cxDib, cyDib ;
static TCHAR szFileName [MAX_PATH], szTitleName [MAX_PATH] ;
HDC hdc ;
PAINTSTRUCT ps ;
WM_PAINT://For MFC use OnPaint(){//insert the following code}
hdc = BeginPaint (hwnd, &ps) ;
pbmfh = DibLoadImage (szFileName) ;//DEFINITION FOR THIS IS GIVEN BELOW, "szFileName is the PATH OF THE ".BMP" FILE e.g."c:\\test.bmp"
if (pbmfh == NULL)
{
MessageBox (hwnd, TEXT ("Cannot load DIB file"),"error",0) ;
return 0 ;
}
// Get pointers to the info structure & the bits
pbmi = (BITMAPINFO *) (pbmfh + 1) ;
pBits = (BYTE *) pbmfh + pbmfh->bfOffBits ;
// Get the DIB width and height
if (pbmi->bmiHeader.biSize == sizeof (BITMAPCOREHEADER))
{
cxDib = ((BITMAPCOREHEADER *) pbmi)->bcWidth ;
cyDib = ((BITMAPCOREHEADER *) pbmi)->bcHeight ;
}
else
{
cxDib = pbmi->bmiHeader.biWidth ;
cyDib = abs (pbmi->bmiHeader.biHeight) ;
}
SetDIBitsToDevice (hdc,
0, // xDst
0, // yDst
cxDib, // cxSrc
cyDib, // cySrc
0, // xSrc
0, // ySrc
0, // first scan line
cyDib, // number of scan lines
pBits,
pbmi,
DIB_RGB_COLORS) ;
EndPaint (hwnd, &ps) ;
BITMAPFILEHEADER * DibLoadImage (PTSTR pstrFileName)<br />
{<br />
BOOL bSuccess ;<br />
DWORD dwFileSize, dwHighSize, dwBytesRead ;<br />
HANDLE hFile ;<br />
BITMAPFILEHEADER * pbmfh ;<br />
<br />
hFile = CreateFile (pstrFileName, GENERIC_READ, FILE_SHARE_READ, NULL,<br />
OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL) ;<br />
<br />
if (hFile == INVALID_HANDLE_VALUE)<br />
return NULL ;<br />
<br />
dwFileSize = GetFileSize (hFile, &dwHighSize) ;<br />
<br />
if (dwHighSize)<br />
{<br />
CloseHandle (hFile) ;<br />
return NULL ;<br />
}<br />
<br />
pbmfh = malloc (dwFileSize) ;<br />
if (!pbmfh)<br />
{<br />
CloseHandle (hFile) ;<br />
return NULL ;<br />
}<br />
<br />
bSuccess = ReadFile (hFile, pbmfh, dwFileSize, &dwBytesRead, NULL) ;<br />
CloseHandle (hFile) ;<br />
if (!bSuccess || (dwBytesRead != dwFileSize) <br />
|| (pbmfh->bfType != * (WORD *) "BM") <br />
|| (pbmfh->bfSize != dwFileSize))<br />
{<br />
free (pbmfh) ;<br />
return NULL ;<br />
}<br />
return pbmfh ;<br />
}
Remember... testing & debugging are always part of programming ...so exterminate those stinking bugs
|
|
|
|
|
Hi
You can try to use the loadimage function ?
d
|
|
|
|
|
I am a VC++ freshman, pls help me! Thanx a lot!!
How can I derive a MFC class from CMenu thus I can use Message Reflection ?
"Insert" Menu -> "New Class"
but I cannot see CMenu (and many other classes) in the "Base Class" edit control!!!!!
To be or not to be!
|
|
|
|
|
You could select CObject from the list, then when the class is created replace all CObject references with CMenu.
Otherwise generate a generic class based on CMenu and do all the message stuffs manually.
Ant.
|
|
|
|
|
Thanx for you attention!
but it doesn't work.
1. No CObject in the Base Class list either.
2. What I want to do is using Message Reflection in my derived calss. If I choose generic class,I cannot use Class Wizard to add Message Reflection. I tried to derive from CStatic (or others),then replaced, but I got an error as follow:
error C2039: 'messageMap' : is not a member of 'CMenu'.
if no massagemap, how can I use Message Reflecion???
To be or not to be!
|
|
|
|
|
if no massagemap, how can I use Message Reflecion???
Quite, sorry the class has to be derived from CWnd in order to use message maps and reflection macros.
Ant.
|
|
|
|
|
God bless me!
I wanted to write a neat owner-draw menu class that can process WM_MEASUREITEM & WM_DRAWITEM in itselt, but.....
Must I give up???
I add a virtual func. MeasureItem()to my menu class, but it doesnot work with the menu item opened a submenu, why??
To be or not to be!
|
|
|
|
|
I have a DLL file that contains all the functions required to interact with a USB hardware interface device. There is also a corresponding header file which I got from the device manufacturer. I include the header file in my MFC application and put the DLL file in the debug folder of my project. But still I get compile error saying that it doesn't know anything about those functions I used from the DLL file. After some more research I think I need a .lib file and that I should link it to the project . Using an already compiled DLL seems not as straight forward to me and so I'd really appreciate your kind help.
I'm beginning to know that I don't know.
|
|
|
|
|
Yes you will need the .lib file and the .h file in order to use the fuctions in the DLL, this is by all means the easiest way.
Without either of these you can prototype all functions you use and use LoadLibrary() to load the corresponding DLL.
Ant.
|
|
|
|
|
Don't use static linking, use dynamic loading of the dll functions like this:
typedef bool (*t_pFunc1)(LPCTSTR Param1, long Param2, bool Param3, ....);
t_pFunc1 m_pfFunc1;
HINSTANCE m_hLibraryInstance;
//Load dll library
m_hLibraryInstance = ::LoadLibrary(_T("Sample.dll"));
//load function
m_pfFunc1 = (t_pFunc1)::GETFUNCADDRESS(m_hLibraryInstance,"Func1");
//Dll call
m_pfFuncDll(param1, param2, param3, ... );
were rgrtgrtvrtrt rtrtb brt tyuhjghj hbhbnh hnjm 1234567?
|
|
|
|
|
Thank you guys. I stumbled upon some article that will guide me through linking it to the project.
|
|
|
|
|
Can I load dll library from other computer in LAN, using:
HINSTANCE LoadLibrary(LPCTSTR lpLibFileName);
were rgrtgrtvrtrt rtrtb brt tyuhjghj hbhbnh hnjm 1234567?
|
|
|
|
|
The best way to answer that is to just try it. If LoadLibrary() fails, call GetLastError() to find out why.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
If you use a UNC path you should be able to, as long as your programming is running under a user context that has access to the network share.
For instance:
HINSTANCE h = ::LoadLibray(_T("\\\\Computer\\Share\\MyDLL.dll"));
Note that if you are running under some weird user context (e.g., the System account) you might not have access to the network at all, in which case you certainly won't be able to load the DLL.
Sometimes I feel like I'm a USB printer in a parallel universe.
|
|
|
|
|