Select all text in edit contol by clicking Ctrl+A - winapi

How to select all text in edit control by pressing Ctrl+A?
I can catch Ctrl+A for parent window in WndProc.
But I don't know how to catch ctrl+a which are applied for edit control.
Also I tried to use accelerators, but again it applies only for parent window.
Thanks.
EDIT: 1-st the simplest method
This method Based on #phord's answers in this question:
win32 select all on edit ctrl (textbox)
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
if (msg.message == WM_KEYDOWN && msg.wParam == 'A' && GetKeyState(VK_CONTROL) < 0)
{
HWND hFocused = GetFocus();
wchar_t className[6];
GetClassName(hFocused, className, 6);
if (hFocused && !wcsicmp(className, L"edit"))
SendMessage(hFocused, EM_SETSEL, 0, -1);
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
EDIT: 2-nd method
Need to use CreateAcceleratorTable + TranslateAccelerator functions:
//global variables:
enum {ID_CTRL_A = 1};
HACCEL accel;
//main procedure
ACCEL ctrl_a;
ctrl_a.cmd = ID_CTRL_A; // Hotkey ID
ctrl_a.fVirt = FCONTROL | FVIRTKEY;
ctrl_a.key = 0x41; //'A' key
accel = CreateAcceleratorTable(&ctrl_a, 1); //we have only one hotkey
//How GetMessage loop looks
while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
{
if (bRet == -1)
{
// handle the error and possibly exit
}
else
{
if (!TranslateAccelerator(hWnd, accel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
//in WndProc we must add next cases
case WM_COMMAND:
{
if (LOWORD(wParam) == ID_CTRL_A && HIWORD(wParam) == 1)
{
//on which control there was pressed Ctrl+A
//there is no way of getting HWND through wParam and lParam
//so we get HWND which currently has focus.
HWND hFocused = GetFocus();
wchar_t className[6];
GetClassName(hFocused, className, 6);
if (hFocudsed && !wcsicmp(className, L"edit"))
SendMessage(hFocused, EM_SETSEL, 0, -1);
}
}
break;
case WM_DESTROY:
{
DestroyAcceleratorTable(accel);
PostQuitMessage(0);
}
break;
As you can see this is pretty simple.

No need to handle WM_KEYDOWN! I know that most examples here (and CodeProject and many other places) all say there is, but it does not cure the beep that results whenever a WM_CHAR arises that is not handled.
Instead, try this:
LRESULT CALLBACK Edit_Prc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam){
if(msg==WM_CHAR&&wParam==1){SendMessage(hwnd,EM_SETSEL,0,-1); return 1;}
else return CallWindowProc((void*)WPA,hwnd,msg,wParam,lParam);
}
Remember to subclass the EDIT control to this Edit_Prc() using WPA=SetWindowLong(...) where WPA is the window procedure address for CallWindowProc(...)

First change the WindowProc for the edit control:
if (!(pEditProc = (WNDPROC)SetWindowLong(hEdit, GWL_WNDPROC, (LONG)&EditProc)))
{
assert(false);
return false;
}
Then in the new window proc, process the ctrl+a:
LRESULT CALLBACK EditProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
if (msg == WM_KEYDOWN) {
if (GetKeyState(VK_CONTROL) & 0x8000 && wParam == 'A') {
SendMessage(hwnd, EM_SETSEL, 0, -1);
}
}
return CallWindowProc(pEditProc, hwnd, msg, wParam, lParam);
}

Good News!
It seems Edit Controls (not multiline) now support Ctrl + A natively on Win10.
My current Windows SDK version is 10.0.17763.0.
Only tested on simple GUI APPs created with pure Windows API.
MFC APPs should have the same result.
The test binary platform is x86, and OS is Win10 x64.

Noob proof version?
I have written my own version using an accelerator table aswell.
This cleans out the WinMain a bit, and I tried to make everything as n00b proof as possible (since I am one).
Also the enum is ommited, since it is not needed.
As stated I am only a beginner in using the winapi, so please by all means
correct me if I am wrong.
In "Resource.h" I define two ID's
One for the accelerator table we will be using,
and one for the selectall command we will be using.
Inside Resource.h:
#define IDR_ACCEL1 101
#define ID_SELECT_ALL 9003
Then inside of the resource file (in vs2017 this is PROJECTNAME.rc)
we define the accelerator table.
PROJECTNAME.rc:
IDR_ACCEL1 ACCELERATORS
{
0x41, ID_SELECT_ALL, VIRTKEY, CONTROL // ctrl-A
}
Description
0x41 is virtkey 'a'.
ID_SELECT_ALL (will be the ID of the command, this should be the ID we defined in the Resource.h file.
The VIRTKEY keyword indicated that the 0x41 should be interpreted as a virtual key.
CONTROL is the modifier needed to combine the a with (ctrl+a).
Then inside the WinMain function load the accelerator:
HACCEL hAccel = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDR_ACCEL1));
if (hAccel == NULL)
{
MessageBox(NULL, _T("Failed to load accelerator table!"),_T("Error"), MB_OK | MB_ICONEXCLAMATION);
return 0;
}
Note: after trying to define hAccel we do a check to see if a valid handle has be assigned.
While this is not needed, I believe it's better convention.
After this we add the TranslateAccelerator function to the message loop, so the command can be processed in the window procedure:
BOOL bRet;
while (bRet = GetMessage(&Msg, NULL, 0, 0) > 0)
{
if (bRet == -1)
{
// Error handling can be done here.
}
else if (!TranslateAccelerator(hwnd, hAccel, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
Then finally inside the Window procedure
We add the code as follows:
switch(msg)
{
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case ID_SELECT_ALL:
{
HWND hEdit;
hEdit = GetDlgItem(hwnd, IDC_MAIN_EDIT) // Define IDC_MAIN_EDIT with an integer value in "Resource.h".
}
break;
}
break;
}
}
Note: The message passed to WM_COMMAND is the ID we defined for the ctrl+a accel.
I hope this will help fellow n00bies.

Related

SetWindowHookEx() returns NULL

I'm trying to create an application that will be notified about each active window change in Windows so it could do some tasks like detecting window titles, therefore "punishing" bad people accessing bad content on our PC machines. So, this is really important for the application because it's purpose is to log "bad" applications from history.
So, in my main function, I started a thread for my WindowLogger.
windowThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) WindowLogger,
(LPVOID) argv[0], 0, NULL );
if (windowThread)
{
// Also a bit of protection here..
return WaitForSingleObject(windowThread, INFINITE);
}
Then, here is my WindowLogger procedure:
// Function called by main function to install hook
DWORD WINAPI
WindowLogger(LPVOID lpParameter)
{
HHOOK hWinHook;
HINSTANCE hExe = GetModuleHandle(NULL);
if (!hExe)
{
return 1;
}
else
{
hWinHook = SetWindowsHookEx(WH_CBT, (HOOKPROC) CBTProc, hExe, 0);
MSG msg;
// I AM UNSURE ABOUT THIS PART..
// Probably wrong code :D ..
while (GetMessage(&msg, NULL, 0, 0) != 0)
{
if (msg.message == HCBT_ACTIVATE) {
// my code to log the window name
}
}
UnhookWindowsHookEx(hWinHook);
}
return 0;
}
And finally, my CBTProc callback function, it logs the windows using my log() function:
LRESULT CALLBACK
CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
switch (nCode)
{
case HCBT_ACTIVATE:
{
HWND foreground = GetForegroundWindow();
char window_title[50];
if (foreground)
GetWindowText(foreground, window_title, 25);
log("|");
log(&window_title[0]);
log("|");
}
}
}
So I had debugged the program and what I figured out is that hWinHook becomes NULL after SetWindowsHookEx() -- this is what probably causes my program to mailfunction..
.. Can you help me out with this?
Thanks in advance.
Passing 0 for the dwThreadId parameter to SetWindowsHookEx is used to register a hook for all threads in the system, i.e. a global hook. However to do this, your hook code needs to be located within a DLL (so that the DLL can be mapped into the address space of other processes). Since your hook code is in your main executable rather than a DLL the call is failing.

Redraw window using DirectX during move/resize

I've followed this tutorial and got it all working: http://www.braynzarsoft.net/index.php?p=InitDX11
The result is a window with a constantly changing background color. The trouble is that the color stops changing while the window is being dragged around. I've tried adding the following case statements (in various combinations) to the WndProc callback, but to no avail:
case WM_ENTERSIZEMOVE:
SetTimer(hwnd, 1, USER_TIMER_MINIMUM, NULL);
return 0;
case WM_EXITSIZEMOVE:
KillTimer(hwnd, 1);
return 0;
case WM_TIMER:
RedrawWindow(hwnd, NULL, NULL, RDW_INVALIDATE | RDW_INTERNALPAINT);
return 0;
case WM_PAINT:
UpdateScene();
DrawScene();
return 0;
The above causes an exception at d3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor), but I've also tried merging the WM_PAINT case into the WM_TIMER case, and all I got was flickering between the natural window background color and the current color of the DX scene (the color of the DX portion of the flicker never evolved, it stayed constant no matter for how long I dragged the window).
Any tips?
A better option is to just not draw while in a resize. There's not usually a lot of value in having the backbuffer resized over and over again. Just wait until the resize is complete to resize the buffer.
static bool s_in_sizemove = false;
static bool s_in_suspend = false;
static bool s_minimized = false;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
break;
case WM_SIZE:
if (wParam == SIZE_MINIMIZED)
{
if (!s_minimized)
{
s_minimized = true;
if (!s_in_suspend)
OnSuspending();
s_in_suspend = true;
}
}
else if (s_minimized)
{
s_minimized = false;
if (s_in_suspend)
OnResuming();
s_in_suspend = false;
}
else if ( !s_in_sizemove )
OnWindowSizeChanged();
break;
case WM_ENTERSIZEMOVE:
s_in_sizemove = true;
break;
case WM_EXITSIZEMOVE:
s_in_sizemove = false;
OnWindowSizeChanged();
break;
case WM_GETMINMAXINFO:
{
auto info = reinterpret_cast<MINMAXINFO*>(lParam);
info->ptMinTrackSize.x = 320;
info->ptMinTrackSize.y = 200;
}
break;
You have to release all the backbuffer and depth-buffer references and recreate them in OnWindowSizedChange.
The actual rendering is done as part of the message pump for most 'real-time' graphics apps:
// Main message loop
MSG msg = { 0 };
while (WM_QUIT != msg.message)
{
if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
Tick();
}
}
Here Tick handles a timer update and the render.
See the Direct3D Win32 Game Visual Studio template for a complete example.
Update: If the 'blank window' bothers you during the resize, but you are fine with the default behavior of DXGI_SCALING_STRETCH during the resize, you can replace the WM_PAINT above with:
case WM_PAINT:
if (s_in_sizemove)
{
game->Tick();
}
else
{
hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
}
break;
I had same problem. I thought solution would be complicated. However, no. That is about mesage pool. DX should use same thread and indeed you use your rendering (Ex: myRender(){..} ) in that loop In my case Frame(); is the bool returnable I use for rendering that contains all operatios :
MSG msg;
bool done, result;
// Initialize the message structure.
ZeroMemory(&msg, sizeof(MSG));
// Loop until there is a quit message from the window or the user.
done = false;
while (!done)
{
// Handle the windows messages.
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
// If windows signals to end the application then exit out.
if (msg.message == WM_QUIT)
{
done = true;
}
else
{
// Otherwise do the frame processing.
result = Frame();
if (!result)
{
done = true;
}
}
}
When you resize you can handle some messages WM_SIZE or WM_MOVE message. In your LRESULT CALLBACK handle:
LRESULT CALLBACK WndProc(HWND hwnd, UINT umessage, WPARAM wparam, LPARAM lparam) {
//...OTHERS...
if (umessage == WM_MOVE) {
/*Dont be confused ApplicationHandle is pointer of my SystemClass
which set ApplicationHandle = this in SystemClass.
to create a window/s and Graphics (contains all DirectX related operations).
Here GraphicsClass (contains all DX calls) initialized in
SystemClass as new class and SystemClass initialized as
new class at main.cpp in WINAPI. That makes a lot easier
for handling this kind of issues for me
In your case you will call your rendering loop instead Frame();*/
if (ApplicationHandle -> m_Graphics) {
RECT r;
GetClientRect(ApplicationHandle -> m_hwnd, & r);
ApplicationHandle -> m_Graphics -> clientSize = {
r.right - r.left,
r.bottom - r.top
};
//frame processing.
ApplicationHandle -> m_Graphics -> Frame();
}
if (umessage == WM_SIZING) {
if ((wparam == WMSZ_BOTTOM || wparam == WMSZ_RIGHT || wparam == WMSZ_BOTTOMRIGHT) && ApplicationHandle -> m_Graphics) {
/*IF WE DO NOT HANDLE wparam resize will be very laggy.*/
GetClientRect(ApplicationHandle -> m_hwndOWNER, & clientRect);
ApplicationHandle -> m_Graphics -> clientSize = {
clientRect.right - clientRect.left,
clientRect.bottom - clientRect.top
};
ApplicationHandle -> m_Graphics -> Frame();
}
}
}
//...OTHERS...
}
HERE IS A VIDEO OF RESULT: https://www.youtube.com/watch?v=vN_XPVRHuiw&feature=youtu.be
even if you are drawing custom window using Desktop Window Manager (WDM) you can handle WM_NCHITTEST for other click situations as that will only update if you resize and move but not if you click and hold caption or hold border only.
additionally, I did not get that why you handle WM_PAINT if you are using DirectX already.

MessageBox return without user input?

I am trying to implemente a close-save-file dialog into a Win32 project, but encouter a strange problem. Here is my solution.
Create a simple win32 project in Visual Studio.
Handle WM_COMMAND to create new window.
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_ABOUT:
InitInstance(hInst, SW_SHOW);
//DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
windowCount--;
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
Handle WM_SYSCOMMNAD to show the save-before-quit messagebox.
case WM_SYSCOMMAND:
if (wParam == SC_CLOSE) {
int ret = MessageBox(NULL, L"do you really want to close", L"question", MB_YESNO|MB_APPLMODAL);
if (ret == IDNO)
return 0;
closedCount++;
StringCchPrintf(buff, 256, L"hwnd %x user choose to close\n", hWnd);
OutputDebugString(buff);
}
return DefWindowProc(hWnd, message, wParam, lParam);
two variable closeCount and windowCount to ensure terminate after all windows are closed.
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0) || (closedCount != windowCount))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
windowCount++;
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
Full code: http://pastebin.com/EVWWMz8L
There are two bugs in above code:
Create two windows and click close button for each window, then confirm to close for one window would close both windows. Which means, close MessageBox in one window would cause MessageBox in the other window return without any user input.
Create two windows and click close button for each window. Then use aero thumbnail to activate one messagebox and confirm to close, but the associated window would not close. I need to confirm both messagebox to close window.
How could this happen, what's wrong with my code?
1, Handler for WM_DESTROY is wrong, right handler should be:
case WM_DESTROY: {
StringCchPrintf(buff, 256, L"%x recieved Wm-DESTROY\n", hWnd);
OutputDebugString(buff);
closedCount++;
if (closedCount == windowCount) {
PostQuitMessage(0);
}
}
FULL code: http://pastebin.com/EU7cVKUb
Root cause:
PostQuitMessage terminate the MessageBox/DialogBox message loop, cause them missing and return immediate. In conclusion, DO NOT call PostQuitMessage until you really need to do this.
2, MessageBox/DialogBox should have owner window, otherwise user could use alt+tab/aero-thumbnail to select the box. So create the messagebox with hwnd as parent could solve problem 2.

infinite loop inside the getmessage (DispatchMessage(& msg ); is not working)

I am creating a button application using resource editor. After creating button I try to do like this-
m_hwndPreview = CreateDialogParam( g_hInst,MAKEINTRESOURCE(IDD_MAINDIALOG), m_hwndParent,(DLGPROC)DialogProc, (LPARAM)this);
if (m_hwndPreview == NULL)
{
hr = HRESULT_FROM_WIN32(GetLastError());
}
MSG msg;
BOOL bRet;
while ( (bRet=GetMessage (& msg,0, 0,0)) != 0)
{// this msg always contains the data like -msg = {msg=0x0000c03e wp=0x0000000000000012//always 12 I don't know why ?? lp=0x0000000000000000}
if (bRet == -1)
{
bRet = HRESULT_FROM_WIN32(GetLastError());
MessageBox(NULL, L"Hurr i am the error",L"Error",MB_ICONERROR | MB_OK);
}
else if (!IsDialogMessage (m_hwndPreview, & msg))
{
TranslateMessage (&msg); //on debugging TranslateMessage = 0x000007feee615480 TranslateMessage
DispatchMessage(& msg ); //but show nothing when I put cursor on this method to know the value that means it's not called
MessageBox(NULL, L"there is no error in receiving before dispatch the message",L"Error",
MB_ICONERROR | MB_OK);//this messagebox repeats again and again after the call to DialogProc function and I am not able to come out of the loop and here I need to restart my PC
at some other place I define createdialog function like this-
//this function is called just on createDialogParam() function.after it the controls go to getmessage where everything loops.
BOOL CALLBACK AMEPreviewHandler::DialogProc(HWND m_hwndPreview, UINT Umsg, WPARAM wParam, LPARAM lParam)
{ //this dialogProc function is declares Static some where in the code otherwise the createdialogparam will give error DLGPROC is invalid conversion
//this Umsg alays creates strange value like 48 and 32 etc.. and Wparam contains a very big value like 12335423526 (I mean big and strange) and lparam contains 0.
switch(Umsg)
{
case WM_INITDIALOG:
{
MessageBox(NULL, L"Inside the WM_INITDIALOG function",L"Error",
MB_ICONERROR | MB_OK);
return TRUE;
}
break;
case WM_CREATE:
{
/////////////////
MessageBox(NULL, L"Inside the WM_CREATE",L"Error",
MB_ICONERROR | MB_OK);
/////////////////////////////////
}
break;
case WM_COMMAND:
{ //here are my two buttons created by me which should show messagebox on click
int ctl = LOWORD(wParam);
int event = HIWORD(wParam);//I don't know why this event is in blue colour .. but its not the pqrt of problem right now.
if (ctl == IDC_PREVIOUS && event == BN_CLICKED )
{
MessageBox(m_hwndPreview,L"Button Clicked is next inside WM_COMMAND ",L"BTN WND",MB_ICONINFORMATION);
return 0;
}
if (ctl == IDC_NEXT && event == BN_CLICKED )
{
MessageBox(m_hwndPreview,L"Button Clicked is previous inside WM_COMMAND",L"BTN WND",MB_ICONINFORMATION);
return 0;
}
return FALSE;
}break;
case WM_DESTROY:
{
////////////////::
MessageBox(NULL, L"Inside the WM_DESTROY",L"Error",
MB_ICONERROR | MB_OK);
//////////////////
PostQuitMessage(0);
return 0;
}
break;
case WM_CLOSE:
{
MessageBox(NULL, L"Inside the WM_CLOSE",L"Error",
MB_ICONERROR | MB_OK);
DestroyWindow (m_hwndPreview);
return TRUE;
}
break;
}
MessageBox(NULL, L"outside the DefWindowProc function",L"Error",
MB_ICONERROR | MB_OK);
return 0;
}
The problem occurring is that when I debut it the control first go to CreateDialogParam and then it go to getmessage where the control don't come out of the loop causing restart problem. And I have no display of button and image at preview pane. What I expect if everything go fine is after debugging it should show picture on preview pane and I have 2 buttons "Next" and "Previous" but it show just a blank window (the buttons and photo I have already created using Resource editor... That's correct I am sure about that) .. but I don't know why I am not coming out getmessage function and dispatchmessage is not called (because I saw on debugging).
so now you can try to comment the getmessage part code that will probably out if the problem because you are creating button using IDD_MAINDIALOG and your createdialogparam directly calls your dailogproc function where you receive WM_COMMAND and that you handle by your code behind.
you should write
return true;
just after the DispatchMessage(msg);
and tehn debug it and inform me about t he result on debugging.

Win32 TreeView AfterSelection

quick question...
I am working with treeview in win32 (VC++).
I want to remove selection facility provided for treeview. Can anyone tell what window message is posted onAfterSelect Event of tree view.
TV also has checkboxes. So disabling mouse click isn't an option...
Thanks in advance...
-
Varun
More Info
I am stuck at another point. My win32 application is essentially a modeless dialog - using CreateDialog & ShowWindow. After getting TVN_SELCHANGING, when I am returning 1, it isn't working. I think the default wndproc is getting called before I bypass the windows message. What should I do now?
I had this problem and just reversed the selection once it had already taken place. If you're not responding to it, anyway, then there shouldn't be any side effects.
case WM_NOTIFY:
{
if(wParam == IDC_TREE_MC)
{
LPNMHDR lpnmh = (LPNMHDR) lParam;
TVHITTESTINFO ht = {0};
if ((lpnmh->code == NM_CLICK) && (lpnmh->idFrom == IDC_TREE_MC)) // For Treeview Check Box Check Event
{
DWORD dwpos = GetMessagePos();
ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos);
MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
TreeView_HitTest(lpnmh->hwndFrom, &ht);
if(TVHT_ONITEMSTATEICON & ht.flags)
PostMessage(hDlg, UM_CHECKSTATECHANGE, (WPARAM)lpnmh->hwndFrom, (LPARAM)ht.hItem);
else
TreeView_SelectItem(lpnmh->hwndFrom, NULL);
}
else if ((lpnmh->code == TVN_SELCHANGED ) && (lpnmh->idFrom == IDC_TREE_MC))
TreeView_SelectNode(lpnmh->hwndFrom, NULL);
}
break;
}
to remove selection facility provided for treeview
Could you please clarify this?
Do you want to prevent user from changing selection?
If you really want to do it, insert WM_NOTIFY case handler in the parent window, check for NMTREEVIEW code member (lParam is a pointer to NMTREEVIEW).
If code is TVN_SELCHANGING return 1 if you want to prevent selection change.
Returning 0 will alow selection change.
int CALLBACK WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
hWndDialog = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, WndProc);
if (hWndDialog != NULL)
{
ShowWindow(hWndDialog, SW_SHOW);
}
while(GetMessage(&Msg, NULL, 0, 0))
{
if(!IsDialogMessage(hWndDialog, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return 0;
}
INT_PTR CALLBACK WndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_BTN_REFRESH:
RefreshButtonHandler();
break;
case IDC_BTN_ADD_INSTALL:
AddInstallBtnHandler();
break;
case IDOK:
case IDCANCEL:
DestroyWindow(hDlg);
PostQuitMessage(0);
return (INT_PTR)TRUE;
break;
}
case WM_NOTIFY:
{
if(wParam == IDC_TREE_MC)
{
LPNMHDR lpnmh = (LPNMHDR) lParam;
TVHITTESTINFO ht = {0};
if ((lpnmh->code == NM_CLICK) && (lpnmh->idFrom == IDC_TREE_MC)) // For Treeview Check Box Check Event
{
DWORD dwpos = GetMessagePos();
ht.pt.x = GET_X_LPARAM(dwpos);
ht.pt.y = GET_Y_LPARAM(dwpos);
MapWindowPoints(HWND_DESKTOP, lpnmh->hwndFrom, &ht.pt, 1);
TreeView_HitTest(lpnmh->hwndFrom, &ht);
if(TVHT_ONITEMSTATEICON & ht.flags)
PostMessage(hDlg, UM_CHECKSTATECHANGE, (WPARAM)lpnmh->hwndFrom, (LPARAM)ht.hItem);
else
TreeView_SelectItem(lpnmh->hwndFrom, NULL);
}
else if ((lpnmh->code == TVN_SELCHANGING ) && (lpnmh->idFrom == IDC_TREE_MC))
return (INT_PTR)TRUE;
}
break;
}
case UM_CHECKSTATECHANGE:
{
//Handle TreeView Check State Event
}
break;
}
return (INT_PTR)FALSE;
}
Sorry for the bad formatting... I am sleep deprived :-)

Resources