In the past two years, the GUI program written in C I generally used the following routines:
In WinMain (), create a main window, followed by the creation of a child window (child control) below.
It may be because writing this aspect of the program is less, so there is no big problem, before the main window to enumerate all the child windows, and then set all the child window font when used: Enumchildwindows () will accidentally throw memory access errors, Remember that it was the enumchildwindows () in the WinMain () moved forward or backward position, there is no reported memory access error.
I thought I just had to move it. Enumchildwindows () in WinMain () in the execution position (order), this problem is solved.
But today, when modifying a previous program, there was a strange phenomenon that was inadvertently discovered:
The value of a local variable defined in WinMain () is unexpectedly modified , and after the local variable is initialized, the next code is not explicitly modified to modify the value of the variable, but after a few lines of code are executed, the value of the variable is output again. found that the value of this variable has been modified?
After a few 10 minutes of a row of troubleshooting, first find the relevant execution code again: Enumchildwindows ()
In Enumchildwindows () there is no place to modify the value of this local variable, if I write off the enumchildwindows () this line, then the value of this local variable will not be modified, it was baffled! Because of this problem, almost spent about 2 hours of continuous testing, and finally did not know how to initialize the child window and set the font of the child window to move the code to wm_create, but did not expect to move the code into Wm_create execution, the value of the local variable is no longer modified.
In fact, before I saw some code on the Internet, basically all in case wm_create: Add a Subwindow (initialize all the controls in the main window).
I didn't quite understand why I had to initialize the Subwindow in wm_create. I usually initialize it in WinMain ().
After this problem, write the new code later, the initialization of the window is also put in case wm_create: Execute it .
--------------------------------------------------------------------------------------------------------------- ------------------------
Another problem today is that the window flashes when a child window is refreshed.
In this case, there are 20 sub-windows in a child window A, and pull the vertical scrollbar of child window A, the 20 sub-windows will be moved at the same time, the move will need to refresh to display the latest position, but the refresh time will appear flashing.
In order to solve this problem, I tried various methods, because I am in the pure C (SDK) mode of development, online related information is not many.
Later accidentally found an article mentioned:Ws_clipchildren, said the window style set to Ws_clipchildren, you can solve the flashing flicker problem.
At first, I set the main window to Ws_clipchildren, the test found that it is effective, the refresh is basically invisible to the naked eye, but at the same time there are 2 new problems:
1. Some scroll bars in Classic mode, with the mouse click the up or Down button, not shown as the effect of press down, but in XP mode can see the effect
2. In the ListView control, when you drag the mouse to select multiple item, the selection dashed box flashes and disappears automatically, which is a bit of a hassle.
Originally thought to find a solution, did not think the original problem is solved, and now there are new problems.
Then I tried again, the main window is not set to Ws_clipchildren, and the child window A is set to Ws_clipchildren alone:
CreateWindowEx (Ws_clipchildren, "Codeblockswindowsapp", "Panel",//Note: Ws_clipchildren Ws_c Hild | ws_visible | Ss_bitmap | Ws_vscroll,//| ss_notify | Ws_border 650, 260, Hwnd_frame, (HMENU) Id_panel, g_ HINSTANCE, NULL);
This is somewhat similar to the JPanel in Java.
Through the test found that the handle window A is set to Ws_clipchildren, sub-window a scrollbar effect is still a bit of a problem, but when the ListView selection, the selection of the dashed box will not blink and automatically disappear. It also solves the problem of flashing flashes.
At present, this is the only way.
Another unexpected discovery, when the window style is set to: Ws_clipchildren, uses SetWindowPos (... Hwnd_top) Adjusts the z-order of the child window to be effective.
2013-05-10
NOTES: C Development GUI Program (WM_CREATE, Ws_clipchildren, SetWindowPos)