Normally a CSliderCtrl has its low values at the left/top end and its high values at the right/bottom end. I need a CSliderCtrl that has its low values at the right/bottom end and its high values at the left/top end. I've tried doing MyCSliderCtrl.SetRange(100,0) instead of MyCSliderCtrl.SetRange(0,100) but the thumb gets stuck at the left/top end. Surely there must be an easy way of getting CSliderCtrl to do this, but I can't work out what it is. Does anyone know? --- Thanks, Chris
Chris Hills
Posts
-
CSlider that works backwards -
Button size algorithmDoes anyone know the algorithm used by ::MessageBox() to work out how big to make the buttons in the dialog box? It seems to depend on the font size chosen in Display Properties -> Advanced -> Item = Message Box. Information about the font is available in ncm.lfMessageFont after doing: NONCLIENTMETRICS ncm; memset(&ncm, 0, sizeof(ncm)); ncm.cbSize = sizeof(ncm); ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0); but how does ::MessageBox() get from there to the default button width and height? I've had a look at all the Windows routines that give system information, but I can't find the answer. Cheers, Chris.
-
Font EmbeddingI did this for an MFC application recently. I guess it’ll be similar with Borland. I created a custom resource, gave it a name, and associated it with the .TTF file. Then when I built the .exe file, I found the byte sequence for the .TTF file inside. So that’s the first step – getting the .TTF file into the .exe file. The second step is to get the byte sequence at run time. Call
::FindResource()
, then::LoadResource()
, then::LockResource()
, then::SizeofResource()
. The third step is to tell Windows to use the byte sequence as a TrueType font. I haven’t found a good way of doing this. I don’t know if there is a good way. The method I use uses two indirections. Having found the byte sequence, write it out to a temporary file, then read in the file using::AddFontResource()
. Then call::CreateFontIndirect(&lf)
, having setlf.lfFaceName
to the name of your font, and hope that Windows chooses to use your font. Then call::FreeResource()
(I’m not sure if this is necessary, but some of the MSDN samples do it). And before your program ends, call::RemoveFontResource()
, otherwise your font will probably be in the system for ever more. HTH, Chris. -
Using a critical section in a high priority threadI want to share some data between a thread that has Realtime priority (24) with another thread that has Normal priority (8). The Realtime thread is sending events to a midiOut device, the Normal thread is telling the Realtime thread what volume to use for the events. I might be able to get away without using any sort of exclusion mechanism, but I want to play safe. I’m concerned that a timer interrupt might occur in the middle of a data write, causing the read to be corrupted. The obvious thing to do is to use a CRITICAL_SECTION, and to get both threads to do EnterCriticalSection()/LeaveCriticalSection() around the code that accesses the shared data. But I’m worried that doing EnterCriticalSection() in a Realtime thread will totally lock up Windows. So a few questions: 1) If the Normal thread calls EnterCriticalSection(), does that prevent timer interrupts from happening until it calls LeaveCriticalSection()? 2) If the Realtime thread runs when the Normal thread owns the critical section object, so that the call to EnterCriticalSection() in the Realtime thread cannot complete until the Normal thread has released ownership of the critical section object, will this cause any problems? I’m worried that the Normal thread won’t be able to run because it’s been interrupted, and the Realtime thread won’t be able to run because it’s waiting for the critical section object. 3) Will all 32-bit versions of Windows behave in the same way with regard to this possible problem? Thanks in advance. Chris.
-
Displaying build timesThanks very much for your speedy reply. It didn't seem to work at first, but a web search showed that it's not a project option but an option for the shortcut to msdev.exe . Where did you get this useful information?
-
Jumping out of a heavily-nested looping noy by using "goto" statement?Ravi Bhavnani wrote: If you can't get yourself to use a
goto
... you could insteadthrow
an exception I disagree. Ifgoto
is evil thenthrow
ing an exception just to avoid using agoto
is even worse! Which one is clearer to the person maintaining the code? Which one are you more likely to get wrong? Sometimes agoto
is the right way to do something so long as it's well commented and isn't abused. -
Displaying build timesHow can you get Microsoft Visual C++ version 6.0 to display the time it takes to compile and build a project? I don’t mean the /Bt option, that displays the time taken to compile each individual source file. There’s a way of displaying the time for the whole build. I know there is because I used to do it, but I’ve just reinstalled Visual C++ 6.0 and I can’t remember how I did it before!
-
Visual C++ 6.0 and backup filesIs there a way of getting Microsoft Visual C++ 6.0 (standard edition) to keep backup copies of files when you edit them? This is the only editor I’ve ever used that doesn’t keep backup files :|, unless there’s some option I don’t know about. I would expect such an option to be in Tools->Options->Editor, but it’s not there. :(
-
opening a web fileI did this sort of thing recently using class CInternetSession. Have a look at that. (And don't forget that any \s in a string have to be \\ )
-
Messages missing for slider controls (and also for spinbuttons etc.)?You can get ClassWizard to add handlers for UDN_DELTAPOS messages :), but I can't remember how :(. I think you just select the spinner control and add a message handler for it. Have a look at my article at http://www.codeproject.com/dialog/CRHChildDialog.asp . Although it's not specifically about spinner controls, it does use them. So if you search the source files for DELTAPOS you'll see what happens.
-
Messages missing for slider controls (and also for spinbuttons etc.)?A spinbutton control sends UDN_DELTAPOS to its parent window when it's spun. lParam is the address of "an NMUPDOWN structure that contains information about the position change" (to quote MSDN). Sliders send WM_HSCROLL and WM_VSCROLL messages.