Click here to Skip to main content
15,867,453 members
Everything / WinAPI

WinAPI

WinAPI

Great Reads

by SimbirSoft
C++: love and intrigue
by Axel Rietschin
Import photos & videos directly from smart phones and digital cameras using the Windows Photo Import API, for Windows Universal Apps and Classic Win32 applications on Windows 10 and beyond.
by David MacDermot
This article describes adding checkboxes to the standard combobox and listbox control.
by Alexander Eremeev
The Windows kernel-hacking library and development framework written on C++17

Latest Articles

by ColleagueRiley
A multi-platform single-header very simple-to-use framework library for creating GUI Libraries or simple GUI programs.
by AbdulRahman A. Badry
Alter your display gamma-ramp to correct & calibrate it
by David MacDermot
This article describes adding checkboxes to the standard combobox and listbox control.
by honey the codewitch
Diving into some of the core plumbing behind the Windows operating system

All Articles

Sort by Score

WinAPI 

28 Apr 2015 by Mario Z
Note that both GetPrivateProfileString and WritePrivateProfileString Win APIs are very buggy and have been deprecated long time ago.You see these functions where provided only for compatibility with 16-bit applications, which I'm fairly certain that you are not developing so you should really...
15 Aug 2019 by SimbirSoft
C++: love and intrigue
4 Jun 2017 by Axel Rietschin
Import photos & videos directly from smart phones and digital cameras using the Windows Photo Import API, for Windows Universal Apps and Classic Win32 applications on Windows 10 and beyond.
23 Dec 2021 by David MacDermot
This article describes adding checkboxes to the standard combobox and listbox control.
1 Nov 2018 by Alexander Eremeev
The Windows kernel-hacking library and development framework written on C++17
7 Nov 2018 by Apriorit Inc, gamapat
Take a look at how to intercept HTTP traffic in order to inject custom code into Windows HTML markup
29 Dec 2018 by Kfir Eichenblat
Learn how to create Global Hotkeys properly in a C# desktop application (e.g. Windows Forms or WPF)
15 Dec 2016 by Farhad Reza
This tip describes how we can design application interface using Win32 API in Rust Programming language.
27 Nov 2021 by Rick York
The problem is you have one instance of the variables of interest. If you want each window to have a unique number then they each have to a unique variable. There are several ways this could be implemented. Among them are a map that associates...
22 Oct 2020 by CPallini
Quote: Do i have to define UNICODE in every single source file? Yes, you have to. You might, however, define it as a compiler option, see /D (Preprocessor Definitions)- To set this compiler option in the Visual Studio development environment |...
21 Nov 2021 by Richard MacCutchan
When dystate == 1 (first time), you do the drawing into inhdc, and then blit it to the Window DC. But then before you leave, you do this: SelectObject(inhdc, hPreBmp); thus losing the BitMap that contains the drawing. Then when you come back...
29 Sep 2023 by Richard MacCutchan
See Native Wifi API Sample - Win32 apps | Microsoft Learn[^]
12 Mar 2010 by Cédric Menzi
In this article we see that we can parse well-formed binary data to our data structures using different approaches.
17 Apr 2014 by Martin Solovey
Simple API to Register/Listen for HotKey in .NET applications
5 Jan 2015 by Jeremy Falcon
Assuming you're not trying to write a virus...What you're asking for is impossible without a receiver program on the remote machine. Nowhere does Windows automatically process sockets and execute them as a Windows API call. You'd need a program to receive the packets and them process...
5 Jan 2015 by Dave Kreskowiak
1) You can launch a remote process using WMI, but it can NOT be an interactive process. This means that the user logged into the console will NOT see it running at all. For example, you can launch Notepad, but it'll sit there waiting for input it'll never get and the user will not see it.2)...
17 Feb 2015 by Jochen Arndt
There is no function to move items inside the list. So the move process has to splitted into delete and insert operations. For multiple items this can be done in two ways: Deleting all selected items first before inserting them at the new position or perform the delete / insert for each...
22 Aug 2016 by Jochen Arndt
You are using blocking sockets. When receiving and there are no more data, the recv function will block (not return) until new data are received or the connection is closed (as triggered with your third try).The simplest method to avoid this is using some kind of indication that all current...
31 Oct 2016 by Jochen Arndt
I have not used ReadDirectoryChanges so far but it should be sufficient to call it only once outside the loop. That should solve the problem.If not, you have to wait for both events using a single call. But I recommend to do that anyway:HANDLE ahWait[2] = { p.hEvent, ovl.hEvent };BOOL...
20 Dec 2016 by Jochen Arndt
You are trying to use the Windows SDK version 7.1A with Visual Studio 6. This won't work. The last SDK that supports Visual Studio 6 is the Microsoft Platform SDK February 2003 (version 5.2.3790.0) (source: Microsoft Windows SDK - Wikipedia[^]). Note that you have to install the full SDK to...
25 Dec 2016 by Jochen Arndt
There is theoretically no difference. But this assumes that all systems use identical hardware.There may be differences when changing the project CPU settings (minimum supported CPU) and there are differences between 32 and 64-bit builds. But these are negligible.Setting the minimum...
25 Dec 2016 by KarstenK
Normally the problem point of actual Windows versions is Windows XP (32 bit). If it works on that, everything should be fine. The speed isnt a real issue because the difference are very small. The best optimization is to minize the drawing process, reloading app resource (like bitmaps) and the...
13 Nov 2017 by Dave Kreskowiak
All it means is that any messages your hookProc code gets passed into it should be passed to the next hook in the chain using CallNextHookEx. You can find an example of that here[^] in globalKeyboardHook.cs. Usually, you don't modify the values you get passed into your hookProc, but there's...
29 Jul 2020 by RLebeau
According to the Registry, {26EE0668-A00A-44D7-9371-BEB064C98683} is for the "Control Panel", whereas {21EC2020-3AEA-1069-A2DD-08002B30309D} is for "All Control Panel Items". See the HKEY_CLASSES_ROOT\CLSID\{26EE0668-A00A-44D7-9371-BEB064C98683}...
19 Sep 2020 by Richard MacCutchan
The only thing I can see that may be an issue is the following: FillRgn(hdc, hrgnClip, CreateSolidBrush(color)); DeleteObject(SelectObject(hdc, GetStockObject(WHITE_BRUSH))); Are you certain that DeleteObject is actually deleting the solid brush?
22 Oct 2020 by Richard MacCutchan
You can define it in the Project Properties in the Advanced -> Character Set box. This will ensure that all source files will be compiled with /D "UNICODE" as standard.
1 Feb 2022 by CHill60
If you want spaces in a path then you must surround the entire path with double quotation marks - see Long paths with spaces require quotation marks - Windows Server | Microsoft Docs[^] E.g. HtmlHelpW(mainWnd,...
18 May 2023 by merano99
The use of _beginthreadex() is explained in detail here _beginthread, _beginthreadex | Microsoft Learn Here you can read that the function creates a thread which starts the execution of a routine at start_address. If you set almost all...
9 Jun 2023 by AbdulRahman A. Badry
Alter your display gamma-ramp to correct & calibrate it
5 Feb 2024 by OriginalGriff
I'd suggest that you move the data files to a "all users" data folder: Windows has a data folder which is available to all users: ProgramData. This is a hidden folder, normally in the root of the C: drive (but can be moved - open File Explorer...
10 Mar 2024 by Pete O'Hanlon
I'm making an assumption here that you are talking about converting the two SYSTEMTIME structures in the DYNAMIC_TIME_ZONE_INFORMATION object. To accomplish this, I believe that you are going to start by converting the SYSTEMTIME structure to a...
15 May 2014 by CPallini
As Sergey pointed out, dumping the memory directly accessible by the process is really simple, e.g.#include using namespace std;int main(){ int a[] = {1,2,3,4,5,6,7,8,9,10}; unsigned char *p; p = (unsigned char *)&a[3]; printf("%p", p); for (int n=0;...
27 May 2014 by Dave Kreskowiak
You don't call that in your default case handler. You call it always, either at the top of your override code or at the bottom, depending on if you want the base default code to handle the message you're overriding or not. But, it either case, the base code must be called to handle all of the...
29 May 2014 by AlwaysLearningNewStuff
After further testing, I have decided to put this as an answer so others can clearly spot it.The solution is in using EM_SHOWBALLOONTIP and EM_HIDEBALLOONTIP messages. You do not need to create tooltip and associate it to an edit control! Therefore, all I need to do now is simply subclass...
10 Jun 2014 by AlwaysLearningNewStuff
INTRODUCTION AND RELEVANT INFORMATION:I am trying to bypass another problem in my application by trying to do printing/print preview on my own.I am trying to create a table that would look like in this picture[^].I am using C++ and WinAPI, on WindowsXP SP3. I work in MS Visual Studio...
16 Jun 2014 by Richard MacCutchan
Take a look at GDI Drawing and Printing[^].
16 Jun 2014 by Richard MacCutchan
I have discovered that the issue is to do with the default unit settings in the Graphics class, as described in http://msdn.microsoft.com/en-us/library/ms535812(v=vs.85).aspx[^]You need to use the following line of code to set it to pixels.g.SetPageUnit(UnitPixel);That now works in XPS...
19 Jun 2014 by LooseBan
hWnd = CreateWindow(szAppName, _T("my window"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);The third parameter should be WS_OVERLAPPEDWINDOW,then you will see the buttons.
28 Jul 2014 by Muhammad Muddasar Yamin
The article is about launching elevated processes through command line
3 Sep 2014 by Igor-84
I've used this article (http://msdn.microsoft.com/en-us/library/windows/desktop/hh298369%28v=vs.85%29.aspx[^]) to add a tooltip for two regions.Firstly, I graphically draw two regions://first rectangleHBRUSH brush1 = CreateSolidBrush(RGB(225, 0, 0));RECT a = {20, 20, 70,...
23 Sep 2014 by Sergey Alexandrovich Kryukov
Please see my comment to the question.Please see this open-source cross-platform library: http://libharu.org[^].You can try to find something else: http://bit.ly/1smWWyZ[^].—SA
12 Nov 2014 by barneyman
from some distant memory of this, try doing the adjustRect and child movewindow AFTER the insertion ... the tab control changes size ISTRBTW, you'll have to do an adjustRect, movewindow for all children after each insert (or once after a block insert), because the tabControl header resizes...
19 Nov 2014 by JJMatthews
I just did this in a project myself. What I had to do was Create the DB field as an "OLE Object" (field type). To read/write the field I used a SafeArray packed in a COleVariant (vt = VT_ARRAY | VT_UI1). Heres some example code:// ADO - 2.7 comes with WinXP#import "msado27.tlb"...
23 Nov 2014 by Jochen Arndt
The LoadImage function returns a bitmap with colors mapped to those of the display device. This can't be used to be selected into a printer compatible device context because the color depth is usually not the same. Use the LR_CREATEDIBSECTION flag when loading the image to get a device...
25 Nov 2014 by enhzflep
As mentioned, LoadImage loads an image ready for output on a screen. You have the alternative already given, or to use GDI+ to load the image. The advantage of using GDI+ is that not only is a DIB created, but you can also load formats including png, jpg and gif.Provided you have already...
28 Nov 2014 by AlwaysLearningNewStuff
I have dialog box which should act as tab page. My application uses Visual Styles.I ran into background painting problem when tried to properly center child dialog box into tab's display area. Asking for help, I got an advice to resize the child dialog box to fit the tab control's entire...
30 Dec 2014 by Sergey Alexandrovich Kryukov
I would advise to consider an alternative design: each contract is represented by a separate tree view. All annexes and reports, and other "drill-down" views are represented by some child nodes of the view. If you select the "detail" node, you have to use some are (panel) on the right of the...
2 Mar 2015 by AlwaysLearningNewStuff
INTRODUCTION:I am implementing rearranging of listview items without using OLE drag and drop.PROBLEM:I have successfully solved most of this task, except scrolling up/down when user wants to drop items at the position that is not currently visible.QUESTION:I am able to scroll...
5 Mar 2015 by Sergey Alexandrovich Kryukov
Please see: https://msdn.microsoft.com/en-us/library/windows/desktop/ms633541%28v=vs.85%29.aspx[^].Pay attention for the note in "Remarks" about the requirement to change the styles and synchronize the UISTATE.—SA
29 Jun 2015 by Richard MacCutchan
Whatsapp, like all similar apps uses sockets to communicate between the mobile and a central server. Each message will contain routing information to pass it to the required client. The actual mechanics of such a program are more complex than could be explained in a Quick Answers forum.
4 Nov 2015 by Duncan Edwards Jones
You cannot - it is a system unique identifier created when the window itself is created, and it is not persisted from run to run.
4 Nov 2015 by Sergey Kizyan
Process doesn't have property called HWND. HWND is the handle to Window and process may work with several Windows. What is your requirement and what are you trying to do? It is not clear.
4 May 2016 by Sergey Alexandrovich Kryukov
It is impossible to do for the already executing process. You can only start one more process (even if this is the same application). Another approach is to add appropriate application manifest which would force the runtime system to request the user for UAC elevation confirmation from the very...
30 May 2016 by Maciej Los
I think, the answer depends on what kind of game you want to develop and what is destination platform... I'm sure that WinApi is still used in game developement (directly or indirectly).Please, read this: Video game development - Wikipedia, the free encyclopedia[^] and this: List of game...
22 Aug 2016 by MyOldAccount
INTRODUCTION:I have studied the MSDN examples for blocking TCP server[^] and blocking TCP client[^].I wanted to try something simple, in view of modifying those examples to create simple chat application.I have tried to implement the following, for a start:send message from...
22 Oct 2016 by «_Superman_»
You cannot call a case statement.However, you can let it fall through.case Execute_Button: // INPUT_FIELD; // break;case INPUT_FIELD: if (HIWORD(wParam) == EN_MAXTEXT) { char cText[INPUT_CHAR_LIMIT]; SendMessage((HWND)lParam, WM_GETTEXT, INPUT_CHAR_LIMIT,...
14 Nov 2016 by Jochen Arndt
You must call GetOverlappedResult() because that is handling the completion of the ReadDirectoryChanges() call. If not doing so and calling ReadDirectoryChanges() again, you are using up system resources until no more available as indicated by the error code.The last parameter should not...
11 Jun 2017 by OriginalGriff
Winforms isn't like a console app, there is a "main" proc, but it's not where you put most of your code (if any). And there isn't a loop in the sense you mean! Instead it's job it to process Windows messages, and call the appropriate function when a particular message is received - and it...
11 Jun 2017 by Richard MacCutchan
See EFNet #Winprog[^] and Win32 Programming - FunctionX[^] for some useful tutorials.
29 Sep 2017 by Ravi Bhavnani
I think you may need to build a Windows hook to process messages destined for the desktop window. See this[^] MSDN article and this CP article: Using Window Messages to Implement Global System Hooks in C#[^]. /ravi
18 Oct 2017 by OriginalGriff
Call this: MSDN: keybd_event function[^] Pass it two virtual key down codes: CTRL, and then ESC. Then pass it two virtual key up codes: ESC and then CTRL There is a link to the Virtual key codes in the link, as well as a basic example.
24 May 2018 by OriginalGriff
Just like there is no "Paste Event", there is no "Paste Registry key" or even "Paste Context menu item" - Context menus are free text, they aren't "windows standard items" where all apps use the same items (like they do for Open and Save dialogs). You can create your own context menu which uses...
31 Oct 2018 by CPallini
As suggested, use the (generic-text variant of) strtol: void StrToByte2(LPCTSTR str, BYTE * dest) { LONG u16 = _tcstol( str, NULL, 16); dest[0] = (BYTE) (u16 >> 8); dest[1] = (BYTE) (u16); } or at least, write a sensible hand-crafted one. Try void StrToByte2Alt(LPCTSTR str, BYTE dest[])...
18 Feb 2019 by Gerry Schmitz
Text is text. The "font" (e.g. mono, size, weight, etc.) is controlled by the receiver / document / "container" / email client / browser / font availability. Unless there are features to allow for pasting "as is" (like for mono), the stuff gets which ever font the OS "thinks" is closest for a...
16 Sep 2019 by Richard MacCutchan
It is all described at Hooks Overview - Windows applications | Microsoft Docs[^].
8 Jul 2020 by Dave Kreskowiak
It's capturing exactly what your code is telling it to capture. You have no choice but to run this code under the debugger, examining variables to make sure the values are what they are supposed to be. The code isn't doing what you think it's...
29 Jul 2020 by Richard MacCutchan
You need to create two child Windows in the client space. The one on the left is your tab, and the one on the right is your main processing space. Handle the WM_SIZE message in your WndProc, and resize the two child windows based on the client...
29 Jul 2020 by MyOldAccount
I am trying to filter IShellFolder::EnumObjects result, by following instructions from this[^] question. Although links from the highest voted answer are invalid, I was able to find them and apply Mr.Chen's code in my own. Everything worked fine...
19 Sep 2020 by Patrice T
your code is very simple minded, and it is bad. Quote: i use Timer which redraws the digits every 100 milliseconds. A simple test can divide by 10 the workload of redraw: if (LastTime != NewTime) { redrawClock(); LastTime = NewTime; } ...
8 Mar 2021 by KarstenK
Read Installing a Service documentation from Microsoft. Must must apply the correct credentials in CreateService. It is best practice to log all error in the error console or write some log. Test all features on some test target machine and NOT...
4 May 2021 by Richard MacCutchan
This is essentially the same question you already posted at List windows services in a file using C[^]. And I already explained how you need to allocate the memory for the returned data. And again you are trying to extract data from a buffer that...
23 May 2021 by Richard MacCutchan
Maybe using EnumDesktopWindows function (winuser.h) - Win32 apps | Microsoft Docs[^] would be a better call.
13 Jul 2021 by Dave Kreskowiak
Save yourself the pain of this not working at all in future versions of Windows and create a small application that launches on user login. This app can "register" itself with the service application, receiving notification from it and launching...
19 Nov 2021 by KarstenK
Threading is a good idea, but it also creates overhead, so you should avoid the so called thread explosion where a lot of threads are waiting for execution. It is up to you to test how many threads are useful. Better is to have some stabile...
20 Nov 2021 by merano99
Of course, that doesn't make much sense. HANDLE thread = CreateThread(NULL, NULL, VUIShadowBoxThread, &p, 0, 0); if (thread) { WaitForSingleObject(thread, INFINITE); CloseHandle(thread); } It makes no sense to start a thread and then wait...
21 Nov 2021 by Rick York
Richard is correct. Here's a memory DC class I use. It was adapted from one I found here written by Keith Rule a long time ago but this does not use MFC. class CMemoryDC { private: HBITMAP m_hbitmap; HBITMAP ...
28 Nov 2021 by merano99
As Rick York suggested numbering the windows with SetWindowLongPtr () seems to be a good solution if you write a consecutive number after creating the window. Insted of using a MessageBox it is better to use the StatusBar: BOOL...
29 Nov 2021 by merano99
Based on my first suggestion, here is another solution if you have to close windows in between. case WM_CREATE: { SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); SetLayeredWindowAttributes(hWnd,...
12 Sep 2022 by Rick York
I have done a bit of searching and I have seen this sequence of code several times : HRSRC resrc = FindResource( hInstance, MAKEINTRESOURCE( resource ), TEXT("PNG") ); HGLOBAL hPng = LoadResource( hInstance, resrc ); PVOID pByte =...
28 Dec 2022 by CPallini
When you try to compile such (ill formed) code, there is a mismatch between TCHAR (resolved to char) and wstring. You may easily verify that trying to compile the following #include #include using namespace std; int main() { ...
25 Mar 2023 by OriginalGriff
You can use GetDC on the NULL window to get a device context for the whole screen, and can follow that up with a call to GetPixel: HDC dc = GetDC(NULL); COLORREF cr = GetPixel(dc, x, y); ReleaseDC(NULL, dc);
30 Mar 2023 by Richard MacCutchan
You seem to be confused about the correct use of pointers in your code. You define lpsh as: SHFILEOPSTRUCTA lpsh{}; But that is not an array, it is a structure, so you need to pass its address to the SHFileOperationA function. You should...
14 May 2023 by OriginalGriff
This isn't necessarily a C++ solution - I haven't played with C++ for over a decade - but there is a .NET way to get some video info direct from the OS provided a suitable codec is installed - I use it to get video duration and resolution, using...
14 May 2023 by KarstenK
So Derell wrote the ffmpeg is a solution. You have to learn to handle the code, but it has a lot of features and it is some "workhorse" library. Your tasks are challengig so it is also challenging to get some library to do the job. tip: the...
16 May 2023 by virtualnik
Try MediaInfo: MediaInfo - Download MediaInfo for Microsoft Windows[^] It ships with a simple to use Dll interface that can be used to gather information about nearly all video and audio files. In the Zip-File you will find a directory called...
9 Jul 2023 by Richard MacCutchan
See the Remarks section at WM_SETREDRAW message[^].
9 Jul 2023 by Avtem
Unfortunately i couldn't figure out how to use WM_SETREDRAW with ListView controls, but since MDSN describes us how it's implemented i decided to do what they do - remove or add WS_VISIBLE style from the window without invalidating its rectangle....
5 Feb 2024 by KarstenK
To get the pathes windows has some special API named Known folder interfacesa or the more recente SHGetFolderPath. The parameters are useda as an identifier which path returns. But first you need some concept for your data. Best is when every...
11 Mar 2024 by Andre Oosthuizen
you can make use of the 'SystemTimeToTzSpecificLocalTime' function to achieve what you are trying - MS Learn | SystemTimeToTzSpecificLocalTime function (timezoneapi.h)[^] Your code will look like - #include #include void...
N 27 Mar 2024 by Rick York
Firstly, there are no limits to DLL sizes or capacities. Secondly, it is important to note what is emitting that error message. It could be the compiler or the linker. If it is from the compiler then you have not defined a prototype for the...
9 May 2014 by Viacheslav Kukhta
Minidamp files isn't created. Where mistake?FunctionLONG __stdcall MyCustomFilter( EXCEPTION_POINTERS* pep ); void CreateMiniDump( EXCEPTION_POINTERS* pep ); LONG __stdcall MyCustomFilter( EXCEPTION_POINTERS* pep ) { CreateMiniDump( pep ); return...
9 May 2014 by KarstenK
you have no write right in "C:". Use a directory where you can write.call GetLastError() if any error has occured ;-)
9 May 2014 by Viacheslav Kukhta
Thanks :) but the file is not created in the project folder too. Where there may be a problem?
13 May 2014 by Viacheslav Kukhta
Hi, prompt please how i can create dump heap? What functions should be used to receive the dump heap?
13 May 2014 by Code-o-mat
This is probably what you are looking for: MiniDumpWriteDump[^], good luck.Please note that creating full memory dumps might take a longer time and it might create quite a large file, so handle with care.
13 May 2014 by Viacheslav Kukhta
I try.. but nothing is written to the filecase IDC_BUTTON2:hFile = CreateFile( TEXT("minidump.dmp"), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); if( hFile!=NULL && hFile!=INVALID_HANDLE_VALUE ) { MINIDUMP_EXCEPTION_INFORMATION eInfo; ...
15 May 2014 by Tony Hallett
Hi, I have been writing some Pinvoke code for lower level WinAPI Access Control functions. I have a pointer to Privileges associated with my access token from the TOKEN_ACCESS_INFORMATION and I am looking at the privileges. I have working code but decided to refactor part of it to a...
15 May 2014 by Viacheslav Kukhta
How display memory dump starting from a certain address?IE i enter the address and display dump starting that address. Its possible?
20 May 2014 by Tony Hallett
Hi,The DirectorySecurity instance that I have passed to the Directory.Create method has had SetAccessRuleProtection(false,false) explicitly called ( which should not be necessary ). When I retrieve from GetAccessControl the AreAccessRulesProtected property is true.I assume that it is...