Your example worked great! I see now that I was trying to use the handle to the DateTimePicker instead of the MonthCalendar component. I still don't completely understand the code, but it will give me something to study. Thank you for the help!
smithriver
Posts
-
Problems porting an API call from VB6 to C# -
Problems porting an API call from VB6 to C#In VB6 I was able to use MCM_SETFIRSTDAYOFWEEK to set Monday as the first day of the week in the DateTimePicker calendar (in the dtp.DropDown event). My attempts to port the same API call to the C# version have been unsuccessful; it compiles and runs, but it doesn't change the first day of the week in the calendar. I've included both the VB6 and C# code below. (Note: the declarations and DropDown code are in the same form). 'VB6
'**************************************************************************
'Needed for DateTimePicker calendar "first day of week"
Const DTM_FIRST = &H1000
Const DTM_GETMONTHCAL = DTM_FIRST + 8
Const MCM_FIRST = &H1000
Const MCM_SETFIRSTDAYOFWEEK = MCM_FIRST + 15Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Any) As Long
'**************************************************************************In the VB6 DTPicker DropDown event
'Get a reference to the handle of the DateTimePicker control
lCalHwnd = SendMessage(ctlDateTimePicker.hWnd, DTM_GETMONTHCAL, 0&, ByVal 0&)'Send an API message to change the presentation
' lCalHwnd = handle to the control
' MCM_SETFIRSTDAYOFWEEK = Flag for message to send
' 0& = Unused parameter
' 0& = Day of week (0 = Monday … 6 = Sunday)
SendMessage lCalHwnd, MCM_SETFIRSTDAYOFWEEK, 0&, ByVal 0&// C#
//*************************************************************************
// Needed for DTPicker calendar "first day of week"
private const int DTM_FIRST = 0x1000;
private const int DTM_GETMONTHCAL = DTM_FIRST + 8;
private const int MCM_FIRST = 0x1000;
private const int MCM_SETFIRSTDAYOFWEEK = MCM_FIRST + 15;[DllImport("user32.dll",EntryPoint="SendMessageA")]
extern static IntPtr SendMessageFirstDayOfWeek(IntPtr hWnd, int wMsg, int wParam, int lParam);
//*************************************************************************In the C# DateTimePicker DropDown event
// Send an API message to change the presentation
// dtpStartDate.Handle = handle to the control
// MCM_SETFIRSTDAYOFWEEK = Flag for message to send
// 0 = Unused parameter
// 0 = Day of week (0 = Monday … 6 = Sunday)
SendMessageFirstDayOfWeek(dtpStartDate.Handle, MCM_SETFIRSTDAYOFWEEK, 0, 0);Any help would be greatly appeciated!
-
A timer problem?Have you been able to get the timer working? I apologize for overlooking the possibility that you were probably trying to learn about handlers, more so than getting the timer to work. As fate would have it, I have had to work with timers and handlers in the past week. So, I took another look at the original code posted. I made three changes and was able to get the program to work: 1) Modify nextvalue()
private void nextValue() { int i = listBox1.SelectedIndex + 1; if ( i == listBox1.Items.Count ) i = 0; listBox1.SetSelected( i, true ); }
2) Add a call to InitializeTimer() in the form constructor: This is a public method, so another program could have been calling it. But since I cannot tell, I added a call in the form constructor:// TODO: Add any constructor code after InitializeComponent call InitializeTimer();
3) Modify the handler definition and code: The definition of the handler is still in InitializeTimer(). I was only able to find a handler for "Tick", not "Elapsed".this.timerClock.Tick += new EventHandler(timerClock_Tick);
The neat thing about adding the handler is that Visual Studio will do most of the work for you. After typing "+=" you will be prompted to "Press TAB to insert" the remaining of the command. You will immediately be prompted a second time to "Press TAB to generate handler". After generating the handler, add the call to nextvalue() within that event handler.private void timerClock_Tick(object sender, EventArgs e) { nextValue(); }
Hope this helps! -
Error with OleDb not foundTo determine if a driver is installed on your system, go to: Control Panel, Administrative Tools, Data Sources (ODBC), Select the "Drivers" tab. If the driver is not listed, your best bet would be to download and register the driver from Microsoft's site. But, I think the problem could be punctuation ... there needs to be a semi-colon (";") on the inside of the ending quote mark of the connection string (as well as one outside the quote mark to end the command line). For example: sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=databaseName;"; If you are still having trouble, I would look at the "OleDb.VarWChar" variable in the Parameters statement where the error is occurring. I have not dealt with parameters, but I might hazard a guess that the the OleDb needs to be qualified (i.e. System.Data.OleDb.OleDbType.VarWChar). I have had items come up in intellisense, but did not run until qualified. Hope this helps!
-
A timer problem?Two things: 1) Make sure the nextvalue() has the code I included earlier: private void nextvalue() { int i = listBox1.SelectedIndex + 1; if ( i == listBox1.Items.Count ) i = 0; listBox1.SetSelected( i, true ); } 2) The timer event that is being used could be incorrect. When I add a timer to my test project, then click on the Events button (the "lightning bolt") in the Properties grid, the only event displayed is the Tick event. Double-click on the Tick title and it will auto-magically add the event to the code. Put the "nextvalue()" call in that subroutine, then try running it. Hope this helps!
-
Error with OleDb not foundI have just spent the last month fighting with OleDb, so you have my sympathy! :) 1) Have you tried "using System.Data.OleDb;" instead of "System.OleDb"? (If you're using VB.NET, doesn't it use the term "Imports" instead of "using"?) 2) Make sure the driver (in your case the MS Jet OleDb driver dll) has been installed on your system. 3) I have read that if you use a DataAdapter you do not need to do an explicit open on the connection (i.e. cnnTeacher.Open()), but if all else fails, I would give it a try. Hope this helps!
-
A timer problem?I am no guru, but it looks like the problem may be in nextvalue(). Perhaps it was a cut & paste error, but the "for" statement is incomplete. The other problem could be the statement "listBox1.Items.Count-i"; if i is 0, the command would error because the count is always 1 larger than the indexing. How I would attempt to rotate through the items would be: int i = listBox1.SelectedIndex + 1; if ( i == listBox1.Items.Count ) i = 0; listBox1.SetSelected( i, true ); Hope this helps!
-
Embed and play an AVI fileI have a process that can take over ten minutes to complete. So, I added an update dialog box with an axAnimation (axMSComCtl2) control. I update a label as the little wheels spin in the AVI. Works great (using an explicit path in the Open method)! Here's the current code that works: string sAppPath = Path.GetDirectoryName(Application.ExecutablePath); string sAviFile = sAppPath + "\\PleaseWait.avi"; axPleaseWait.Open( sAviFile ); axPleaseWait.Play(0, 0, 0); The problem is the file distribution. I have been asked by the powers that be to embed the AVI file in the project. I have found two ways to embed an AVI file: 1) right-click on the project, select "Add existing item", then browse to and select the AVI file (found by trial & error); 2) create a resource file, add the AVI, and then add the .resource file to the project (found in the MSDN). But I have yet to figure out how to get either of these methods to work! The problem with the first method is that I have no way to get a path to the AVI file listed in the Solution Explorer. I thought about writing it to a temp file, but I have not figured out how to read in the AVI file. (I think this would be the most straight foward method to use). The problem with the second method is that the resource file will not let me explicitly state that this is an AVI file. So, I selected Bitmap. I don't even know if the AVI has been added to the .resource correctly. Likewise, I have not figured out how to get the AVI file back out of the .resource file. Any help would be greatly appreciated. Thanks!