CreateCompatibleDC - Do It Once, Or Each Time?
My usercontrol has an option to tile the background with a bitmap. This is an owner-drawn control so the actual bitmap will not be saved in something with a hdc property. Should I...
1. create a memory dc each time the control is redrawn using only local variables and destroy them at the end of the sub?
2. or just create a module-level memory dc if/when a backgroundbitmap is assigned and reuse it each time.
I am not sure what kind of resources it would use up, and I am new enough at all this GDI stuff that I am still confused about how to prevent memory leaks. Thanks
God Bless America
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
When you use CreatecompatibleDC(&0) create a compatible with the screen.
Few years ago the screen was 24bpp today the screems are 32bpp.
What happen with this.
We use to create a compatible and then draw and work with the DC, in 24bpp because the frame grabber work with 24bpp, what will happen when I use BitBlt to paint in the screen.
Could I use Create CompatibleDC(&0) and create the binfo with bitsperpixel=24 in order to receive the frame capture?
hdc as long
hdc = CreateCompatibleDC(0)
I'm getting a negative result in hdc. Is this an error condition?
I'm having a GetDIBits call crash VB later in the program and I'm wondering if this is the problem?
I have been learning the different aspects of game programming in VB lately before I undertake a larger game project. Currently I am trying to learn how to open graphics straight into memory (no picture boxes involved) and then use them with BitBlt from there. It makes sense how it CAN work but for me it just WON'T work. I have downloaded 3 different examples and tried to use them but none of them seem to work the way I want them too. I know that I use some API's like CreateCompaitbleDC, DeleteDC, BitBlt, ect. But I can't seem to get the image into memory. So can anybody point me to a good tutorial or help explain the different steps that need to happen? Thanks.
Well, I've heard of it, read a little bit about it, can't really find much about it on the forums.. so
How do I use it??
I have a bitmap, that i want to load into memory, so I can bitblt using the DC in memory..
how can I acheive this?
Thanks in advance,
Problem With CreateCompatibleDC()
I am using CreateCompatibleDC() in my code, and the problem is that it is only working to load the picture half the time. Here is the function I use.
Public Function CreateDC(FileName As String) As Long
Dim DC As Long
Dim hBitmap As Long
'Create a Device Context
DC = CreateCompatibleDC(frmZeldaMapEditor.picTileset.hdc)
If DC < 1 Then 'Failed
GenerateDC = 0
MsgBox "Error creating DC"
hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION)
If hBitmap = 0 Then 'Failed
GenerateDC = 0
MsgBox "Error loading image"
'Loads the image into the DC
SelectObject DC, hBitmap
'Returns the DC
CreateDC = DC
The problem is that I am getting the "Error creating DC", indicating a problem with CreateCompatibleDC(), approximately 50% of the time. Obviously this is unacceptable as the program is unuseable when this happens. Is there something I am doing wrong. If you need more info please let me know, Thanks.
CreateCompatibleDC Always Returns 0
I am just experimenting with CreateCompatibleDC, in order to BitBlt from memory, but it always returns 0. I am using VB6 and running on Windows 2000 Pro.
As I have never used these APIs before, I don't even know where to look, can anyone help me?
Thanks in advance
GDI CreateCompatibleDC - Hatched Styles?
OK this is driving me crazy:
I wrote this code to create a back buffer DC and fill it with a colour:
GetWindowRect hwnd, WinR
aRect.Right = 40
aRect.Bottom = WinR.Bottom - WinR.Top
hDC = GetWindowDC(hwnd)
mDC = CreateCompatibleDC(hDC)
hBitmap = CreateCompatibleBitmap(mDC, 40, WinR.Bottom - WinR.Top)
DeleteObject SelectObject(mDC, hBitmap)
hBrush = CreateSolidBrush(RGB(222, 222, 222))
FillRect mDC, aRect, hBrush
Technically, this works, but when I Blt it to a control, it appears that the DC has some hatched style over the top, even though I used CreateSolidBrush
Can't seem to find a way around this, hoping someone knows.
EDIT: Sorry, posted the thread in the wrong place... Can someone move it?
A Problem With CreateCompatibleDC, My Computer, Or My Brain?
A good 3-4 times out of 5, when using CreateCompatibleDC (Context included later), a handle is returned whose value is < 1. I've made my own set of code from scratch, tried various examples from here on xVBt, and I'm consistantly encountering this problem. While I can work around it, it's certainly a hassle, slower, and I'd prefer to understand why it's happening, even if I can't fix it.
The following is code from SOMEONE's mDC tutorial from here, just spent 15 minutes looking for where I got it from, can't find it.
Public Function GenerateDC(FileName As String) As Long
Dim DC As Long
Dim n As Integer
Dim hBitmap As Long
'Create a Device Context, compatible with the screen
DC = CreateCompatibleDC(0)
If DC < 1 Then
GenerateDC = 0
'Load the image....BIG NOTE: This function is not supported under NT, there you can not
'specify the LR_LOADFROMFILE flag
hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE Or LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
'If hBitmap = 0 Then 'Failure in loading bitmap
' DeleteDC DC
' GenerateDC = 0
' Exit Function
'Throw the Bitmap into the Device Context
SelectObject DC, hBitmap
'Return the device context
GenerateDC = DC
'Delte the bitmap handle object
Where the line 'DC = CreateCompatibleDC(0)' often produces negative numbers. What is causing this?
How To Convert My GMT Time To U.S.Central Time And Daylight Saving Time
How to convert my GMT date and time to Central Standard and Daylight Saving Time.
For example I have GMT Time as:
02/29/2004 1:00:00 AM
I want as:
02/28/2004 8:00:00 PM
When I give date aswhich is falling under daylight saving time)
04/08/2004 1:00:00 AM
I want to get as 04/07/2004 9:00:00 PM
How to do that and how to determine wheather it is falling under daylight or standard time.
It should not do based on my Computer date and time though. If it is then it is going
to calculate everything based on daylight saving time because right now I'm under daylight
I appreciate your help.
REQ Help: Calculating Elapsed Time From Date/time Began From Date/time Ended
I have four controls, two are Date-Time Pickers set for Date and the last two are text boxes set for Time with the "...If Not IsTime()..." validation.
It is the standard Date and Time problem began, Date and Time problem ended.
I am trying to calculate the elapsed time between these in "" DAYS "" HOURS ""MINUTES.
I coded this in Lotus Notes yet exporting my knowledge to VB is problematic.
Has anyone a code snippet of how to do this in VB - yes, I know about the DateDiff.
Many, MANY thanks!
Format Time As Time Not Date Time
I am trying to insert just the current Time into my SQL Server 2000 database but it keeps being returned as Date Time. How can I set up the SQL Statement to just insert the current time? Currently I am using the " & Time & " function. I would appreciate any help. Thank you.
Microsoft Date Time Picker Bug - Resizes Every Time I Open The Form !
I've created and published a custom form in Outlook 2000 which includes 5 DTpicker controls.
Every time I open a new item using this form, the controls resize to a very small size. Subsequently when I close the item (with or without saving any changeS) and open the form in design mode, the controls have stayed in the small size.
ANy ideas what is causing this behaviour and how to solve it? Any help would be greatly appreciated - the ap is ready for deployment and this is the only thing I am not able to solve !
Multiple Socket Udp Query And Ping From Senddata Time To Dataarryval Time
again a question
I am using a udp socket to query a bunch of game servers ,that part is ok but i cant get the server ping unless i use the ping api,that makes it go alot slower because i have to wait for one server ping in orther to get the next, i was wondering if someone know the secret of how to query the servers and get the ping from the time i send the data to the time the data arrives, like the professional server query tools do (All seeing eye ,xfire,and others).ive managed to get part of that working using gettickcount from the time i send to the time it arryves but still it doesnt work properly...
Converting UNIX Time In Milliseconds To Normal Date Time Format?
Hi all. Dont know if this is common or not. Did a search, but found nothing.
I have got a 48 bit date and time value represented in hex being generated on a unix system. The 8 byte date and time is measured from epoch 1(1 Jan 1970, midnight) in milliseconds, ie. the Unix hex data is one extra long number in milliseconds.
I want to convert this to a readable format such as: mm/dd/yy hh:mm:ss.sss
I have some examples taken from some other program runing on Unix system:
Unix data - 7E E6 64 B7 FF 00 (no idea how to convert this to equivalent)
equivalent - 10/20/04 17:31:43.614
Unix data - 5D 2D 26 F5 00 01
equivalent - 12/21/04 10:22:27.677
Universal Coordinated Time UTC Seconds To Current Date And Time (Local)
Hi All. Never had to do this one, looking to see if some else has done it.
I haven't seen exactly what I need out on the net under free code
locations, but have come close.
I need to convert a LONG INTEGER of UTC Seconds ( universal coordinated
time UTC which is the number of seconds since midnight on January 1, 1970),
to a local date and time.
If anyone has written source to do this, and doesn't mind sharing, I'd love
to get a copy.
Sorry Wrong Forum Precision Of Elapsed Time Using Time Span
In my application Iam using a label that shows the elapsed time.
Iam using TimeSpan Class.The TimeSpan has several constructors and Iam using the long constructor.
ts = new TimeSpan((long) (ts.Ticks*(((double) iFilesTotal/(double) iFilesProcessed) - 1)));
lblTimeRemaining.Text = ts.ToString();
The result is this "00:12:23:59:6754346"
I dont need the milliseconds for 7 decimal places, and only 2.
What is the solution?
Can I use a String Format?If yes how?
Convert A Decimal Time To An Actual Time Using Visual Basic
Does any one know how to convert a decimal time (e.g. 1.5) into an actual time (e.g. 1:30)?
I have a database where people specify the number of hours a job should take; this is in decimal format (e.g. 1.25). I have another database that contains the actual number of hours a job takes this is in normal time (e.g. 1:15). I need to get them in the same format (preferably normal time) in order to compare the two.
Does anyone know how this can be achieved? Any suggestion would be much appreciated.
Edited by - jonathanw on 6/21/2005 9:11:59 AM
How To Tell If An ActiveX Property Changed, Design-Time And/or Run-Time?
Can someone tell me what sub is responsible for handling property changes, especially those that are custom properties? I thought it would be in the UserControl_AmbientChanged Sub, but that sub isn't catching any changed at all in Design-Time.
Any help, I'd really appreciate it. I'm kinda really lost here!
Convert 10 Digit Time String To Normal Time
i get this for a date
probably the number of seconds from a particular starting point (maybe 1/1/1970)
is there vb code that can convert the string to regular date/time?
Differentiate From Run-time And Design-time (temporarily Resolved)
is there a way to differentiate between running an application from the IDE and designing it? the property Ambient.UserMode returns always True in both cases.
my problem is that i have a control which is initialized if i draw it on another control, but i need it to be initialized only when i run the program.
Excel's Sort Function Works Only The First Time, Not A Second Time
I have a problem with some Office Excel (2003) automation in VB. My 'Sort' method works fine the first time, but not when executing it a second time.
The problem causing line looks like this
Call xlsSheet.Cells.Range("A2", "D7").SortSpecial(xlPinYin,Cells(2, 4), xlAscending, 1, Cells(2, 1), xlAscending, Cells(2, 3), xlAscending)
I included the problem in zip, just click the 2 buttons (to execute it a first and a second time).
Subtracting A Time Interval From A Date Time Value (RESOLVED)
I know I am asking something really silly, but I have not got my thinking cap on this issue yet, since there are heavier ones I am preoccupied with, and at these times, the lighter ones slip your mind.
I need to subtract a time interval from a date and get the resultant date time . For Instance, I need a function that would return to me a date time value which is the result of subtracting 20 minutes from the date time value 7th June 2003 4:29 00 PM.
Do I have to write one?
Is There A Time Control Like The One In Windows Date & Time Properties?
I want a user to be able to enter in a start time and end time just like if they were doing it to ajust the system clock time. So they can only enter in a valid time of day. Is there anything out there that I can use that will do this or am I going to have to code combo boxes or something? This info will be stored in a access database in a Time/Date field and will be used to do a Time Sheet for an employee.
Easy Way To Convert Standard Time To 24 Hr Military Time
I am writing a bit of code and I need an EASY, fast way t convert Normal 12 hr time to 24 Hr time. I have thought abou looking for PM on the end of the TIME Variable and adding 12 t the first 1 or 2 Numbers and Truncing every thing after the 5t letter. But I would still have to manipulate the AM time. I there an Easier way?
Date Time Picker - Custom Time Question
I have a dateTime Picker on a form that is bound to a field in an Access Db. I have both the control and the field configured to handle UTC Time. That is, the control's .Format property is 3 -dtpCustom and the .CustomFormat is "HH:mm". Furthermore, the database field is set to Date/Time and the Format is set to ShortTime. This seems to work fine, because the Db field is storing the correct time.
However, when I try to pass dtPicker.Value to a variable with the Date data type, it's not showing the correct time when the original time was above 12:59. For example, 19:06 in the dtPicker stores 19:06 in the Db, but it's storing 07:06 in a variable of Date type.
Am I missing something?!?
How To Track Server Time And Client Machinge Time
I m creating lan based application... but my application is totally based and time and date .... but in case accidentlay client machine date and time is wrong... thn my application would be get fail.. so i want to prevent it...
so i want to take date and time from server... i dont want to take local system date and time.
so anybody can replies me in this case
Access - Convert Short Time To 24 Hour Time
I have table fields that are formatted with short time input mask.
I need to convert the data to twenty-four hour time (without AM/PM).
Example - 4:30 AM converted to 04:30.
If need be, I can change the Date fields of the table to text, or whatever. I have the form fields formatted with a short date input mask.
I was able to convert the short date to YYYY/MM/DD, with some googling, but I can't find anything on converting the time to twentyfour hour time.
Creating A Real-time 'TIME' Textbox.
Ok. On my main form I want to place a textbox that shows the time (updating every second). The format is set to be in "Long Time". I have the TimeInterval set to 1000 (1 second?) and the "OnTimer" property has:
txtFtime.Text = Format (Now, "Long Time")
Now, when the form loads up, all I get is an error. It states:
Run-time error '2135':
This property is read-only and can't be set.
I looked up MSDN and couldn't find ANYTHING on this error and when I click on Help, nothing can be found. I click on Debug and this line highlights:
txtFTime.Text = Format(Now, "long time")
What am I doing wrong? Is there another approach to doing this? I'm stumped. I verified that the textbox property is set to Long Time and everything else matches like it should.
Time Zone And Setting System Time
When we are using SetSystemTime API , how can we adjust the system time with respect to Time Zone?
I am living Eastern Time ( GMT - 5 ) , When I use the SetSystemTime API, windows calibrates the hour value ( expressed in UTC ) in SYSTEMTIME structure I pass and I get incorrect results.
Reading Time IN And Time Out From Multiple Entries
im currently working on a project where i would retrieve the data from an existing database (MS Access) used by another program (Time and Attendance with Finger Scan attached), what im trying to do is create a program where the routine of retrieving the data throwing it to another database for manipulation would seem like realtime. i had no problem reading and saving it in this approach except that in some cases it might give an incorrect data
1 - read all Time IN and save it to the target database (delete Time OUT if Time IN exist)
2 - read all Time OUT and save it to the target database aligned to the closest Time IN (with no Time OUT)
it works fine but im was wondering if theres another way or a better way to approach this, since the said approach might give incorrect data if ever one person forgot to Time IN or Time OUT, this wouldnt be a problem if the source has the data aligned but since the entries for both Time IN and Time OUT is on different entries aligning it makes it harder
source database structure:
Employee Code (text) | Action Flag - Time IN/Time OUT (boolean/int) | Date (date) | Time (time)
target database structure:
Employee Code (text) | Time IN (datetime) | Time OUT (datetime)
any thoughts is appreciated!
Closing All Forms At Same Time (at Design Time)
I am working in a project where there is several forms, and as I am working, the screen becomes populated with windows and more windows with forms and codes. At determined moment it starts to mess my vision and I must to stop my work to "clean" the screen closing the windows one by one until remains the one that I am working on.
So my question is: there is an option to close all windows at the same time and back VB editor to the startup situation (all forms and window code closed)?
How To Change System_local Time To System_utc Time?
Hi, I want to write module that change local time to UTC time.
systime_local is set using User input.
state: function use state to findout time difference of timezon from UTC
applyDateLightSaving: when True, have to apply it depending on DateLightSaving rule..
Does anyone know this kind of function ?
Public Function GetUTCTime(systime_local As SystemTime, state As String, applyDateLightSaving As Boolean)
'-- convert local time to UTC time
'-- apply Dailylight saving time
Dim system_utc As SystemTime
GetUTCTime = system_utc
Time / System Time / Timer Questions
I actually have two questions, both related to time...
1) I figured out how to show the current system time, but i was wondering how i can compare it to a given time (eg for an alarmclock)
2) I wanted to create a clock, that starts at 00:00 and runs ten times as fast as a normal clock, and that i can adjust while its running (eg + 1h, -1h, etc...)
Many thx in advance!
(i would also really appreciate tutorials that are related to time, timers, etc)
Finding A Time Inside A Time Range
i use a timer to tell the server when to start sending me time. 'theoretically' it is supposed to start on-time and look like this
11:22:54 - 11:22:49
11:22:59 - 11:22:54
11:23:04 - 11:22:59
11:23:09 - 11:23:04
where i compare the current time on the left (what just came in) with the time on the right (the time stamp just prior)
but sometimes the server 'hiccups' and i might see this instead
11:22:57 - 11:22:49
11:23:02 - 11:22:57
11:23:08 - 11:22:02
11:23:12 - 11:23:08
or something like that
the server is geared to send out a time stamp every 5 seconds (its minimum) but i need to make a change at :59
basically i need to evaluate the current time stamp and the one just prior and see if my :59 is somewhere either in between or at either end (where it 'usually' but not always is)
"if somewhere in between the current time and the last time a time with :59 seconds can be found
How To Converts Military Time To Regular Time In Vb 6.0
how to converts military time to regular time in vb 6.0
Private Sub Command1_Click()
txtTime = Time
myValue = InputBox("Enter The Ending Time")
God = myValue - txtTime
Private Sub Command2_Click()
Time And Date Not Changed With Real Time??
i used the code below but the time not changed with real time.how to solve this problem?
Private Sub Form_Load()Label5.Caption = Format(Now, "long date")Label6.Caption = Format(Now, "long time")End Sub
Stamp The Time On An Exe At Build Time And Display It.
I would like to be able to display the build time of an exe on the about screen...and as an added bonus..perhaps capture the logged in username that built the application.
So...if I build an exe....at the moment.... I would like the current time/date stamp to be embedded in the exe and displayed on the about form of the exe at anytime to show when the exe was actually built....and of course..if possible....who built it.
Where do I start?
Date Time Picker - Remove Time
I have a bunch of datetime pickers on my form.
When I step through my program using F8 I notice that when the dtPicker is not changed by the user it writes a value to the database such as "07/25/2005".
The problem I'm having is that when the user changes the date on the dtPicker it shows up in the program as "07/25/2005 9:40:45AM" which is not working because my database field is not a datetime.
How can I trim the time off the end?
Is there a property that does this or do I have to resort to something like a MID or LEFT function to get the values I want?
Strip Time From Time/Date **Resolved**
Hello, I'm bringing in a time/date stamp in the following format:
m/d/y h:m:s am/pm. If one of the m/d/y/h or /m isnt a 2 digit character, it doesnt add a zero to it (ie 9/8/2004 never becomes 09/08/2004). How can I make the time/stamp of "9/8/2004 2:34:24 PM" for example DUMP the "2:34:24 PM" and just display the date portion? I need this portion because I need to use it in a function to tell whether the date is in Daylight Savings Time.
--Edit The function doesnt care if theres a time in there too.