How to retrieve the "Regional Format" in Windows 10 - c++

I'm trying to find out how the "regional format" setting on Windows 10 can be retrieved (see picture below).
I tried GetLocaleInfoEx, with virtually all combinations of parameters, but this one showed up nowhere.
On the other hand this setting has an influence on what's returned by GetThreadLocale:
Some examples with expected return values from GetThreadLocale as per this Microsoft documentation, C++ code at the end of the question.
+--------------------------+-----------------------------------+
| Regional format | Value returned by GetThreadLocale |
+--------------------------+-----------------------------------+
| French (Switzerland) | 0x100c |
| French (France) | 0x040c |
| German (Germany) | 0x0407 |
| English (United states) | 0x0409 |
| English (United Kingdom) | 0x0809 |
+--------------------------+-----------------------------------+
Some examples with unexpected (and undocumented) return values from GetThreadLocale:
+-----------------------+-----------------------------------+
| Regional format | Value returned by GetThreadLocale |
+-----------------------+-----------------------------------+
| English (Switzerland) | 0x0c00 |
| English (Germany) | 0x0c00 |
| German (Italy) | 0x0c00 |
+-----------------------+-----------------------------------+
I really wonder what this 0x0c00 value returned by GetThreadLocale is?
C++ code
#include <windows.h>
#include <stdio.h>
int main()
{
printf("GetThreadLocale: %08x\n", GetThreadLocale());
}

Related

Detailed RAM report and usage of running program on linux

I would like to know how to monitor a specific program (with its pid) and get a report of it's RAM used, like with perf record -p <PID> sleep 15 && perf report, giving me instruction using the most of the memory.
I already heard about top commands, but it is not what I want.
Massif is a heap profiler included in the valgrind suite, and can provide some of this information.
Start it with valgrind --tool=massif <you program>. This will create a massif.out file that contains various "snapshots" of heap memory usage while the program ran. A simpler viewer ms_print is included and will dump all the snapshots with stack traces.
For example:
83.83% (10,476B) (heap allocation functions) malloc/new/new[], --alloc-fns, etc.
->30.03% (3,752B) 0x4E6079B: _nl_make_l10nflist (l10nflist.c:241)
| ->24.20% (3,024B) 0x4E608E7: _nl_make_l10nflist (l10nflist.c:285)
| | ->12.10% (1,512B) 0x4E5A091: _nl_find_locale (findlocale.c:218)
| | | ->12.10% (1,512B) 0x4E5978B: setlocale (setlocale.c:340)
| | | ->12.10% (1,512B) 0x4016BA: main (sleep.c:106)
| | |
| | ->12.10% (1,512B) 0x4E608E7: _nl_make_l10nflist (l10nflist.c:285)
| | ->09.41% (1,176B) 0x4E5A091: _nl_find_locale (findlocale.c:218)
| | | ->09.41% (1,176B) 0x4E5978B: setlocale (setlocale.c:340)
| | | ->09.41% (1,176B) 0x4016BA: main (sleep.c:106)
| | |
| | ->02.69% (336B) 0x4E608E7: _nl_make_l10nflist (l10nflist.c:285)
| | ->02.69% (336B) 0x4E5A091: _nl_find_locale (findlocale.c:218)
| | ->02.69% (336B) 0x4E5978B: setlocale (setlocale.c:340)
| | ->02.69% (336B) 0x4016BA: main (sleep.c:106)
| |
| ->05.83% (728B) 0x4E5A091: _nl_find_locale (findlocale.c:218)
| ->05.83% (728B) 0x4E5978B: setlocale (setlocale.c:340)
| ->05.83% (728B) 0x4016BA: main (sleep.c:106)
Check pmap :
pmap <PID>
With pmap , you can see all of resources which using by process. And in here there are many other techniques.

Python 2.7 - insert text into a file before closing the file

I am writing some text into a file:
import codecs
outfile=codecs.open("c:/temp/myfile.sps","w+","utf-8-sig")
#procedures for creating the text_to_write
outfile.write (text_to_write)
outfile.close()
Now, what I want to do is to insert into the file an additional text, always at a certain line (say line 10), but this additional text is final only after all the procedures for creating the text_to_write. So the code for inserting the additional text, at line 10, should be the last code:
Is this possible without closing the file, reopening, and then saving again ?
(the reopen-insert-close approach is detailed here, but I would like to avoid it). I am looking for something like this:
import codecs
outfile=codecs.open("c:/temp/myfile.sps","w+","utf-8-sig")
#procedures for creating the text_to_write
outfile.write (text_to_write)
#code for inserting additional text at line 10
outfile.close()
Since you don't know the exact position (in bytes) of the insertion point, you need to read the lines of the file content, insert the additional text after the line 10 and write the file a second time.
note: a Python 2+3 way to open a file is to use the io module instead of the codecs module.
For instance, you have the following text to write and additional text:
text_to_write = u"""\
| 1 | This
| 2 |
| 3 | text
| 4 |
| 5 | contains
| 6 |
| 7 | at
| 8 |
| 9 | least
| 10 |
| 11 | ten
| 12 |
| 13 | lines."""
additional_text = u"""\
| ++ | ADDITIONAL
| ++ | TEXT
"""
You can open the file for reading and writing. The file is created if it does not
exist, otherwise it is truncated. The stream is positioned at
the beginning of the file.
with io.open("file.txt", mode="w+", encoding="utf-8-sig") as f:
f.write(text_to_write)
f.seek(0)
lines = f.readlines()
lines[10:10] = additional_text.splitlines(keepends=True)
f.seek(0)
f.writelines(lines)
This solution is not very efficient because you read the content you just write.
You can also process everything in memory and then write the file.
The result is:
| 1 | This
| 2 |
| 3 | text
| 4 |
| 5 | contains
| 6 |
| 7 | at
| 8 |
| 9 | least
| 10 |
| ++ | ADDITIONAL
| ++ | TEXT
| 11 | ten
| 12 |
| 13 | lines.
Another solution using a list in memory:
lines = text_to_write.splitlines(keepends=True)
lines[10:10] = additional_text.splitlines(keepends=True)
with io.open("file2.txt", mode="w+", encoding="utf-8-sig") as f:
f.writelines(lines)

how to create a subcolumn inside a column in Gtk+ using C++

I am creating a listview with 5 columns in Gtk+ using C++. I was able to do that. But the problem is, I need subcolumns for the 2nd column which I'm not sure how to proceed.
firstcolumn | second column | third |
|SC1 | SC2 | SC3| |
| | | | |
Is this possible? Can you suggest how to go about it?

How should I implement sub-windows in my OpenGL viewport?

How should I implement sub-windows in my OpenGL viewport? Inside my viewport, I want to reserve some space on the left for labels, and some space around the edges as a border. I've got all the coordinates figured out and everything is displaying properly. My problem is clipping the things in one subwindow that are spilling over into the others. I can't seem to figure out what the OpenGL 3.3, core context way of doing things is. Is it to
use per-vertex clipping?
a scissor test?
a stencil test?
associate a framebuffer with different parts of my window?
Which commands should I be looking at?
Before I spend time writing a full answer, I would like you to confirm that this is what you were describing in your original question:
*---------------------------------------*
| ------------------------------------- |
| | | | |
| | | | |
| | | | |
|C| A | B |C|
| | | | |
| | | | |
| |___|_______________________________| |
*---------------------------------------*
A = Labels
B = Main Window
C = Border

"Attachment layout" of action is simply ignored! Why?

I publish an OG action/object but the attachment layout of the action (which has been set to "Item") is simply ignored. On my timeline, I click on the date/time link to see the action in full details (along with the attachment)... but all I see is a box with object image in the center and the object title at the bottom:
------------------
| |
| |
| Image |
| |
| |
------------------
| Object Title |
------------------
Instead I expect to see a smaller image at the left side along with the title and other captions on the right side (like what "Item" layout preview is showing):
-----------------------------------------
| | Object Title |
| | Caption 1 |
| Image | Caption 2 |
| | Caption 3 |
| | Caption 4 |
-----------------------------------------
And the OG tags of my object page, hosted on my website, are correct (at least the Facebook OG Debugger says so!).
Does anyone know what I'm missing here?
Thank you,