Search Results

Search found 746 results on 30 pages for 'winapi'.

Page 16/30 | < Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >

  • Closing thread using ExitThread - C

    - by Jamie Keeling
    I have a simple program that creates a thread, loops twenty times and then makes a call to close itself and perform the necessary cleanup. When I debug the program it reaches the ExitThread(); method and pauses, ignoring the printf(); I have set up after it to signal to me it's closed. Is this normal or am I forgetting to do something? I'm new to threading using C. Main() void main() { Time t; int i = 0; StartTimer(); for(i = 0; i < 20; i++) { t = GetTime(); printf("%d.%.3d\n", t.seconds, t.milliseconds); Sleep(100); } StopTimer(); } Thread Creation void StartTimer() { DWORD threadId; seconds = 0; milliseconds = 0; // Create child thread hThread = CreateThread( NULL, // lpThreadAttributes (default) 0, // dwStackSize (default) ThreadFunc, // lpStartAddress NULL, // lpParameter 0, // dwCreationFlags &threadId // lpThreadId (returned by function) ); // Check child thread was created successfully if(hThread == NULL) { printf("Error creating thread\n"); } } Thread Close void StopTimer() { DWORD exitCode; if(GetExitCodeThread(hThread,&exitCode) != 0) { ExitThread(exitCode); printf("Thread closed"); if(CloseHandle(hThread)) { printf("Handle closed"); } } }

    Read the article

  • How to get the last windows active time by windows api

    - by Edwin Tai
    In general, the Screensaver will run when we do nothing for a period of time. Now i wanna know how to get the unactive time. In another word,i want to make a program which would run a function if we do nothing for a period of time. Now i can use mouse or keyboard hook to solve the problem. But you know,it needs administrator permissions. In another word,if in win vista or win 7,it is nauseating because of the UAC. I need an API such to get last windows active time.

    Read the article

  • Getting Clipboard data in raw format in c++

    - by qwertymk
    I've been playing around with the windows clipboard. I noticed that you can only view the clipboard if you supply a format. I've seen programs that can dump the raw contents of the clipboard. Look at http://www.autohotkey.com/docs/misc/Clipboard.htm#ClipboardAll for an example of what I mean. Is there a way to do something similar, what I want to do is be able to back up the clipboard, manipulate it, then restore it when my program is done. I'm looking for a non-.net solution if that's actually a thing

    Read the article

  • How to embed mp3 into .exe file & Play it?

    - by afriza
    I am used to embed WAV into .exe and Play it using PlaySound(). However, using this method causes the .exe to become pretty big. Is it possible to do the same with MP3 files and how to do it? I have taken a look at DirectShow but it seems to be able to play from files only? I am developing for Windows Mobile 6 Series

    Read the article

  • Application built using VS2010 does not work in VS-Express2008 - C

    - by Jamie Keeling
    Hello, I have wrote an application that consists of two projects in a solution, each project contains only 1 .c source file. I was using Visual Studio 2010 Ultimate but due to the University only supporting 2008 I decided to create a blank solution and copy the source files into the new one. After creating a new solution in VS2008 express, creating two projects and re-creating and adding the source files to the projects I ran the application. For some reason only one part of the application does not work, I use CreateProcess() to execute "Project1.exe" from Project 2. This works fine under vs2010 but for some reason it's not working under VS2008 express, GetLastError() is showing an Error 2: File Not Found. This is an image showing the same code in both IDE's: I'm not using anything special and I've made sure that both solutions/projects are using .Net 3.5. I can't work out why it would work for one IDE and not the other. Any suggestions? Thanks!

    Read the article

  • Does a modeless dialog processes WM_DESTROY Message?

    - by Dave17
    I'm trying to create a modeless dialog as the main window of a program but it doesn't seem to respond WM_DESTROY or WM_NCDESTROY Message. HWND hwnd=CreateDialogParamA(hInst,MAKEINTRESOURCE(IDD_DIALOG1),0,DialogProc,LPARAM(this)); if (!hwnd) { MessageBox(0, "Failed to create wnd", 0, 0); return NULL; } ShowWindow(hwnd,nCmd); UpdateWindow(hwnd); while (GetMessage (&msg, NULL, 0, 0) > 0) { if (!IsWindow(hwnd) || !IsDialogMessage(hwnd,&msg)) { TranslateMessage (&msg) ; DispatchMessage (&msg) ; } } Modeless Style format from Resource file STYLE DS_SETFONT | DS_FIXEDSYS | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU

    Read the article

  • Why Microsoft not provide for C# a static Win32 class with the most native functions and structures

    - by Oleg
    Everybody who used P/Invoke of Windows API knows a long list of declarations of static functions with attributes like [DllImport ("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] The declaration of structures copied from Windows headers like WinNT.h or from web sites like www.pinvoke.net take also a lot of place in our programs. Why we all have to spend our time for this? Why Microsoft not give us a simple way to include a line like in old unmanaged programs #include <windows.h> and we would be have access to a static class Native with all or the most Windows functions and structures inside?

    Read the article

  • Need help using the Windows IP Helper API & ParseNetworString in C#.

    - by JohnnyNoir
    I'm attempting to rewrite some C# web service code that uses the Windows IP Helper API call "SendARP" to retreive a remote system's MAC address. SendARP works great - until you cross a network segment as Arp requests aren't routed. I've been looking at the "ParseNetworkString" documentation after happening across its existance on StackOverflow. The quick & dirty algorithm I have in mind is: public static string GetMacAddress(string strHostOrIP) { if (strHostOrIP is IPAddress) { parse results of nbstat -A strHostOrIP return macAddress } if (strHostOrIP is Hostname) { IPHostEntry hostEntry = null; try { hostEntry = Dns.GetHostEntry(strHostOrIP); } catch { return null; } if (hostEntry.AddressList.Length == 0) { return null; } foreach (IPAddress ip in hostEntry.AddressList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { ipAddress = ip; break; } } } return GetMACAddress(ipAddress); } "ParseNetworkString" is new with Vista/Win2008 so I haven't been able to find example C# code demonstrating its use and I'm no C++ coder so if anyone can point me in the right direction...

    Read the article

  • How might I wrap the FindXFile-style APIs to the STL-style Iterator Pattern in C++?

    - by BillyONeal
    Hello everyone :) I'm working on wrapping up the ugly innards of the FindFirstFile/FindNextFile loop (though my question applies to other similar APIs, such as RegEnumKeyEx or RegEnumValue, etc.) inside iterators that work in a manner similar to the Standard Template Library's istream_iterators. I have two problems here. The first is with the termination condition of most "foreach" style loops. STL style iterators typically use operator!= inside the exit condition of the for, i.e. std::vector<int> test; for(std::vector<int>::iterator it = test.begin(); it != test.end(); it++) { //Do stuff } My problem is I'm unsure how to implement operator!= with such a directory enumeration, because I do not know when the enumeration is complete until I've actually finished with it. I have sort of a hack together solution in place now that enumerates the entire directory at once, where each iterator simply tracks a reference counted vector, but this seems like a kludge which can be done a better way. The second problem I have is that there are multiple pieces of data returned by the FindXFile APIs. For that reason, there's no obvious way to overload operator* as required for iterator semantics. When I overload that item, do I return the file name? The size? The modified date? How might I convey the multiple pieces of data to which such an iterator must refer to later in an ideomatic way? I've tried ripping off the C# style MoveNext design but I'm concerned about not following the standard idioms here. class SomeIterator { public: bool next(); //Advances the iterator and returns true if successful, false if the iterator is at the end. std::wstring fileName() const; //other kinds of data.... }; EDIT: And the caller would look like: SomeIterator x = ??; //Construct somehow while(x.next()) { //Do stuff } Thanks! Billy3

    Read the article

  • Windows splash screen using GDI+

    - by Luther
    The eventual aim of this is to have a splash screen in windows that uses transparency but that's not what I'm stuck on at the moment. In order to create a transparent window, I'm first trying to composite the splash screen and text on an off screen buffer using GDI+. At the moment I'm just trying to composite the buffer and display it in response to a 'WM_PAINT' message. This isn't working out at the moment; all I see is a black window. I imagine I've misunderstood something with regards to setting up render targets in GDI+ and then rendering them (I'm trying to render the screen using straight forward GDI blit) Anyway, here's the code so far: //my window initialisation code void MyWindow::create_hwnd(HINSTANCE instance, const SIZE &dim) { DWORD ex_style = WS_EX_LAYERED ; //eventually I'll be making use of this layerd flag m_hwnd = CreateWindowEx( ex_style, szFloatingWindowClass , L"", WS_POPUP , 0, 0, dim.cx, dim.cy, null, null, instance, null); SetWindowLongPtr(m_hwnd ,0, (__int3264)(LONG_PTR)this); m_display_dc = GetDC(NULL); //This was sanity check test code - just loading a standard HBITMAP and displaying it in WM_PAINT. It worked fine //HANDLE handle= LoadImage(NULL , L"c:\\test_image2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE); m_gdip_offscreen_bm = new Gdiplus::Bitmap(dim.cx, dim.cy); m_gdi_dc = Gdiplus::Graphics::FromImage(m_gdip_offscreen_bm);//new Gdiplus::Graphics(m_splash_dc );//window_dc ;m_splash_dc //this draws the conents of my splash screen - this works if I create a GDI+ context for the window, rather than for an offscreen bitmap. //For all I know, it might actually be working but when I try to display the contents on screen, it shows a black image draw_all(); //this is just to show that drawing something simple on the offscreen bit map seems to have no effect Gdiplus::Pen pen(Gdiplus::Color(255, 0, 0, 255)); m_gdi_dc->DrawLine(&pen, 0,0,100,100); DWORD last_error = GetLastError(); //returns '0' at this stage } And here's the snipit that handles the WM_PAINT message: ---8<----------------------- //Paint message snippit case WM_PAINT: { BITMAP bm; PAINTSTRUCT ps; HDC hdc = BeginPaint(vg->m_hwnd, &ps); //get the HWNDs DC HDC hdcMem = vg->m_gdi_dc->GetHDC(); //get the HDC from our offscreen GDI+ object unsigned int width = vg->m_gdip_offscreen_bm->GetWidth(); //width and height seem fine at this point unsigned int height = vg->m_gdip_offscreen_bm->GetHeight(); BitBlt(hdc, 0, 0, width, height, hdcMem, 0, 0, SRCCOPY); //this blits a black rectangle DWORD last_error = GetLastError(); //this was '0' vg->m_gdi_dc->ReleaseHDC(hdcMem); EndPaint(vg->m_hwnd, &ps); //end paint return 1; } ---8<----------------------- My apologies for the long post. Does anybody know what I'm not quite understanding regarding how you write to an offscreen buffer using GDI+ (or GDI for that matter)and then display this on screen? Thank you for reading.

    Read the article

  • Unable to Calculate Position within Owner-Draw Text

    - by Jonathan Wood
    I'm trying to use Visual Studio 2012 to create a Windows Forms application that can place the caret at the current position within a owner-drawn string. However, I've been unable to find a way to accurately calculate that position. I've done this successfully before in C++. I've now tried numerous methods in C#. Originally, I tried using .NET classes to determine the correct position, but then I tried accessing the Windows API directly. In some cases, I came close, but after some time I still cannot place the caret accurately. I've created a small test program and posted key parts below. I've also posted the entire project here. The exact font used is not important to me; however, my application assumes a mono-spaced font. Any help is appreciated. Form1.cs This is my main form. public partial class Form1 : Form { private string TestString; private int AveCharWidth; private int Position; public Form1() { InitializeComponent(); TestString = "123456789012345678901234567890123456789012345678901234567890"; AveCharWidth = GetFontWidth(); Position = 0; } private void Form1_Load(object sender, EventArgs e) { Font = new Font(FontFamily.GenericMonospace, 12, FontStyle.Regular, GraphicsUnit.Pixel); } protected override void OnGotFocus(EventArgs e) { Windows.CreateCaret(Handle, (IntPtr)0, 2, (int)Font.Height); Windows.ShowCaret(Handle); UpdateCaretPosition(); base.OnGotFocus(e); } protected void UpdateCaretPosition() { Windows.SetCaretPos(Padding.Left + (Position * AveCharWidth), Padding.Top); } protected override void OnLostFocus(EventArgs e) { Windows.HideCaret(Handle); Windows.DestroyCaret(); base.OnLostFocus(e); } protected override void OnPaint(PaintEventArgs e) { e.Graphics.DrawString(TestString, Font, SystemBrushes.WindowText, new PointF(Padding.Left, Padding.Top)); } protected override bool IsInputKey(Keys keyData) { switch (keyData) { case Keys.Right: case Keys.Left: return true; } return base.IsInputKey(keyData); } protected override void OnKeyDown(KeyEventArgs e) { switch (e.KeyCode) { case Keys.Left: Position = Math.Max(Position - 1, 0); UpdateCaretPosition(); break; case Keys.Right: Position = Math.Min(Position + 1, TestString.Length); UpdateCaretPosition(); break; } base.OnKeyDown(e); } protected int GetFontWidth() { int AverageCharWidth = 0; using (var graphics = this.CreateGraphics()) { try { Windows.TEXTMETRIC tm; var hdc = graphics.GetHdc(); IntPtr hFont = this.Font.ToHfont(); IntPtr hOldFont = Windows.SelectObject(hdc, hFont); var a = Windows.GetTextMetrics(hdc, out tm); var b = Windows.SelectObject(hdc, hOldFont); var c = Windows.DeleteObject(hFont); AverageCharWidth = tm.tmAveCharWidth; } catch { } finally { graphics.ReleaseHdc(); } } return AverageCharWidth; } } Windows.cs Here are my Windows API declarations. public static class Windows { [Serializable, StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct TEXTMETRIC { public int tmHeight; public int tmAscent; public int tmDescent; public int tmInternalLeading; public int tmExternalLeading; public int tmAveCharWidth; public int tmMaxCharWidth; public int tmWeight; public int tmOverhang; public int tmDigitizedAspectX; public int tmDigitizedAspectY; public short tmFirstChar; public short tmLastChar; public short tmDefaultChar; public short tmBreakChar; public byte tmItalic; public byte tmUnderlined; public byte tmStruckOut; public byte tmPitchAndFamily; public byte tmCharSet; } [DllImport("user32.dll")] public static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight); [DllImport("User32.dll")] public static extern bool SetCaretPos(int x, int y); [DllImport("User32.dll")] public static extern bool DestroyCaret(); [DllImport("User32.dll")] public static extern bool ShowCaret(IntPtr hWnd); [DllImport("User32.dll")] public static extern bool HideCaret(IntPtr hWnd); [DllImport("gdi32.dll", CharSet = CharSet.Auto)] public static extern bool GetTextMetrics(IntPtr hdc, out TEXTMETRIC lptm); [DllImport("gdi32.dll")] public static extern IntPtr SelectObject(IntPtr hdc, IntPtr hgdiobj); [DllImport("GDI32.dll")] public static extern bool DeleteObject(IntPtr hObject); }

    Read the article

  • Copy and Store LPTSTR in class causes crash

    - by Jake M
    I am attempting to copy a LPTSTR and store that string as a member variable in an object. But my attempts to copy the LPTSTR seem to fail and when I go to access/print the value of the copied LPTSTR I get a program crash. Is it possible to copy a LPTSTR and store it in my class below or is it better to just use a TCHAR*? class Checkbox { private: LPTSTR text; HWND hwnd; public: Checkbox(HWND nHwnd, LPTSTR nText) { lstrcpy(checkText, text); } void print() { // Causes a crash MessageBox(hwnd, text, text, MB_OK); } };

    Read the article

  • Get a font filename based on Font Name and Style (Bold/Italic)

    - by Brad
    This has been driving me crazy all day. I need to get a font filename (eg. Arial.ttf) based off of it's name (Arial in this case). The problem is, I am only supplied with the font name (Arial) and weather it's bold, italic or both. Using those pieces of information, I need to find the font file so I can use it for rendering. Some more examples: Calibri, Bold would resolve to calibrib.ttf Calibri, Italic would resolve to calibrii.ttf Any ideas on how I could achieve this in C++ (Win32)

    Read the article

  • How can I make one child window draw over another within the same form?

    - by Colen
    Let's say I have ten child windows within a form. How do I make sure one of those windows is drawn over all the others? For example, how do I make sure that window 6 always overdraws windows 1-5 and 7-10? I don't want the window to be drawn over everything else on the screen, just everything else within that form. I've already tried using HWND_TOPMOST and HWND_TOP (see http://stackoverflow.com/questions/2823700/how-can-i-make-a-child-window-topmost ) but it didn't work. :(

    Read the article

  • hidden forms and thr handles

    - by shraddha
    i am hiding the form using SetVisibleCore to false, but now i cant get the handle of this form in other application which i am retrieving using EnumWindow its giving me exception "Attempted to read or write protected memory. This is often an indication that other memory is corrupt." an ACCESS VIOLATION EXCEPTION. so i am searching on 2 ways 1. find out the other way to get handle here we cant use FindWindow cause its not returning any handle 2. find a another way to hide the form but this should be done before loading of the form so,,,plz help me if anybody can

    Read the article

  • Directory file size calculation - how to make it faster?

    - by Xinxua
    Using C#, I am finding the total size of a directory. The logic is this way : Get the files inside the folder. Sum up the total size. Find if there are sub directories. Then do a recursive search. I tried one another way to do this too : Using FSO (obj.GetFolder(path).Size). There's not much of difference in time in both these approaches. Now the problem is, I have tens of thousands of files in a particular folder and its taking like atleast 2 minute to find the folder size. Also, if I run the program again, it happens very quickly (5 secs). I think the windows is caching the file sizes. Is there any way I can bring down the time taken when I run the program first time??

    Read the article

  • How can I keep an event from being delivered to the GUI until my code finished running?

    - by Frerich Raabe
    I installed a global mouse hook function like this: mouseEventHook = ::SetWindowsHookEx( WH_MOUSE_LL, mouseEventHookFn, thisModule, 0 ); The hook function looks like this: RESULT CALLBACK mouseEventHookFn( int code, WPARAM wParam, LPARAM lParam ) { if ( code == HC_ACTION ) { PMSLLHOOKSTRUCT mi = (PMSLLHOOKSTRUCT)lParam; // .. do interesting stuff .. } return ::CallNextHookEx( mouseEventHook, code, wParam, lParam ); } Now, my problem is that I cannot control how long the 'do interesting stuff' part takes exactly. In particular, it might take longer than the LowLevelHooksTimeout defined in the Windows registry. This means that, at least on Windows XP, the system no longer delivers mouse events to my hook function. I'd like to avoid this, but at the same time I need the 'do interesting stuff' part to happen before the target GUI receives the event. I attempted to solve this by doing the 'interesting stuff' work in a separate thread so that the mouseEventHookFn above can post a message to the worker thread and then do a return 1; immediately (which ends the hook function but avoids that the event is handed to the GUI). The idea was that the worker thread, when finished, performs the CallNextHookEx call itself. However, this causes a crash inside of CallNextHookEx (in fact, the crash occurs inside an internal function called PhkNextValid. I assume it's not safe to call CallNextHookEx from outside a hook function, is this true? If so, does anybody else know how I can run code (which needs to interact with the GUI thread of an application) before the GUI receives the event and avoid that my hook function blocks too long?

    Read the article

  • Maximum Possible File Name Length in Windows Kernel

    - by Lambert
    I was wondering, what is the longest possible name length allowed by the Windows kernel? E.g.: I know the kernel uses UNICODE_STRING structures to hold all object paths, and since the byte length of a wide-character string is stored inside a USHORT, that allows for a maximum path length of 2^15 - 1 characters. Is there a similar, hard restriction on a file name (rather than path)? (I don't care if NTFS or FAT32 imposes a particular restriction; I'm looking for the longest possible theoretically allowed name in the kernel, assuming no additional file system or shell restrictions.) (Edit: For those wondering why this even matters, consider that normally, traversing a directory is achieved by FindFirstFile/FindNextFile calls, one call per file. Given the function named NtQueryDirectoryFile, which is the underlying system call and which returns multiple file names per call, it's actually possible to take advantage of this maximum-length restriction on the path to make an extremely-fast directory traverser that uses solely the stack as a buffer. Now I'm trying to extend that concept, and I need to know the maximum size of a file name.)

    Read the article

< Previous Page | 12 13 14 15 16 17 18 19 20 21 22 23  | Next Page >