The parent of the button receives a WM_COMMAND message to notify it of events including button clicks. If the high word of wParam is BN_CLICKED and the low word of wParam is the ID of the button, the button was clicked. Next time, to make it easier on us, go into greater detail if you can. Peter O.
Peter Occil
Posts
-
peekMessage and Getmessage relatedquestion -
Color BrightnessMy post at CodeGuru Forums[^] : A simple way to adjust the brightness of a color is to adjust a constant value of red, green, and blue in a color. Here is a function for this.
COLORREF Brighten(COLORREF cr, int val){
BYTE r,g,b;
r=(BYTE)min(255,max(0,GetRValue(cr)+val));
g=(BYTE)min(255,max(0,GetGValue(cr)+val));
b=(BYTE)min(255,max(0,GetBValue(cr)+val));
return RGB(r,g,b);
}A positive value for val brightens the color, and a negative value for val darkens the color. Be sure the val parameter is within the range -255 to 255. Peter O.
-
sendmessage helpTo reiterate a reply I made here: The SendMessage function sends a message to the window procedure of a window. It doesn't return until the window fully processes the message. You should never send messages to windows of other applications because it is possible that the application may be hung and SendMessage will never return. This is the prototype of SendMessage.
LRESULT SendMessage(
HWND hWnd, // handle of destination window
UINT Msg, // message to send
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
);The hwnd parameter, as you know, is the handle to a window to which to send a message. The Msg parameter identifies what type of message to send, and the wParam and lParam parameters specify additional information about the message. The system and applications communicate to windows via messages. Besides SendMessage, there is the PostMessage function, which sends a message to a window and returns immediately, making it ideal for communicating with windows in other applications. To answer the second question, to programmatically simulate a button click, make the following call:
SendMessage(hwndBtn,BM_CLICK,0,0);
Peter O.
-
Program expirationThere is an article on this site regarding this: CExpire Peter O.
-
Avoiding double postsWhen browsing the forums, I occasionally see two identical topics posted accidentally, usually by pressing the Submit button more than once. To prevent this, I suggest that after the user pushes the Submit button, that the button be disabled and that the user is notified that the post is being submitted. Peter O.
-
EnableWindowThe windows in the task list, as it's more correctly called, meet the following criteria:
- No parent
- Visible
- No owner and WS_EX_TOOLWINDOW, OR Owner and WS_EX_APPWINDOW
- At least one character of text
Peter O.
-
New beeI need to assume that this person doesn't know how to use GetVersionEx. The following example retrieves the current version of Windows.
OSVERSIONINFO vi;
WORD wWinVer;
vi.dwOSVersionInfoSize=sizeof(vi);
GetVersionEx(&vi);
wWinVer=MAKEWORD(vi.dwMinorVersion,
vi.dwMajorVersion);Besides the major and minor version numbers, the version information returned by GetVersionEx includes the build number of the OS, identifies the running platform, and contains additional information about the Windows version installed. Peter O.
-
Is there a similar functio to SetWindowActive to do this ??Before calling SetActiveWindow, use the AttachThreadInput function to attach the input states of the calling thread and the thread with the desired window:
DWORD tidThis,tidOther;
tidThis=GetCurrentThreadId();
tidOther=GetWindowThreadProcessId(hwnd,NULL);
if(tidThis!=tidOther)
AttachThreadInput(tidThis,tidOther,TRUE);
SetActiveWindow(hwnd); // or SetForegroundWindow
if(tidThis!=tidOther)
AttachThreadInput(tidThis,tidOther,FALSE);Peter O.
-
A stupid Win32 UI question - mouse trackingThere is an article in MSJ regarding this. Peter O.
-
Internet connection detectionThis function determines whether the user is connected to at least one RAS connection. Link with rasapi32.lib. You can use this function to start your program.
#include <windows.h>
#include <ras.h>BOOL IsUserConnected(){
RASCONN *rasc=malloc(1000);
DWORD bs,nc,i,j,dwRet;
RASCONNSTATUS rcs;
MSG msg;
TCHAR s[257];
rcs.dwSize=160;
rasc->dwSize=412;
dwRet=RasEnumConnections(rasc,&bs,&nc);
if(!bs)return 0;
rasc=realloc(rasc,bs);
if(RasEnumConnections(rasc,&bs,&nc))
return 0;
for(i=0;i<bs/412;i++){
HRASCONN hrc=rasc[i].hrasconn;
dwRet = RasGetConnectStatus(hrc, &rcs);
if (dwRet != ERROR_INVALID_HANDLE)
continue;
if (dwRet != ERROR_NOT_ENOUGH_MEMORY){
SetLastError(dwRet);
return 0;
}
if(rcs.rasconnstate==RASCS_Connected)
return 1;
}
return 0;
}Peter O.
-
help me#define RectWidth(lprc) ((lprc)->right-(lprc)->left)
#define RectHeight(lprc) ((lprc)->bottom-(lprc)->top)RECT rc;
int width,height;
GetWindowRect(hwndRichEdit,&rc);
width=RectWidth(&rc);
height=RectHeight(&rc);Peter O.
-
Help on multi-threadingIn the OnStart handler, you should start the thread, then loop the PeekMessage function until the thread exits or the user presses STOP.
void CThreadTestDlg::OnStart(){
// begin the thread
MSG msg;
DWORD threadec;
g_bAbort = FALSE;
m_pThread = ::AfxBeginThread(ThreadProc, NULL);
while(::PeekMessage(&msg,NULL,0,0,PM_REMOVE)){
// process any messages while the other thread does background
// processing
if(msg.message==WM_QUIT){ // quit this thread.
// Add code to break the other thread here.
::PostQuitMessage(msg.wParam);
break;
}
::TranslateMessage(&msg);
::DispatchMessage(&msg);
if(!::GetExitCodeThread(m_pThread->m_hThread,&threadec))
return;
if(threadec!=STILL_ACTIVE)break;
}
}I apologize it this isn't right; I'm much used to programming in C. Peter O.
-
left scroll barScroll bars can be aligned to the left (using the WS_EX_LEFTSCROLLBAR style), but they take effect only in Hebrew and Arabic versions of Windows 95 (and any languages whose characters can be read from the right). You give no reason for which a left-aligned scroll bar would be beneficial. Peter O.
-
GetWindowTextGetWindowText will not retrieve the text in an edit control in another application (thread?). GetWindowText retrieves the caption from the window's internal data. Even with a lot of text, edit controls always have an empty string as its caption. The workaround is to send the edit control a WM_GETTEXT message (preferably using SendMessageTimeout) to retrieve the text. Peter O.
-
Disconnect modem from appI wrote a function that disconnects the modem:
#include <windows.h>
#include <ras.h>void HangUp(){
RASCONN *rasc=malloc(1000);
DWORD bs,nc,i,j,dwRet;
RASCONNSTATUS rcs;
MSG msg;
TCHAR s[257];
rcs.dwSize=160;
rasc->dwSize=412;
dwRet=RasEnumConnections(rasc,&bs,&nc);
if(!bs)return;
rasc=realloc(rasc,bs);
if(RasEnumConnections(rasc,&bs,&nc))
return;
for(i=0;i<bs/412;i++){
HRASCONN hrc=rasc[i].hrasconn;
dwRet = RasGetConnectStatus(hrc, &rcs);
if (dwRet != ERROR_INVALID_HANDLE){
RasHangUp(hrc);
while (dwRet != ERROR_INVALID_HANDLE){
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
TranslateMessage(&msg);
DispatchMessage(&msg);
}
dwRet = RasGetConnectStatus(hrc, &rcs);
}
}
}
free(rasc);
}
Peter O.
-
Expanded viewCode Project's message board has an expanded view option that, I assume, allows a user to view all of the threads of a page in their entirety. Even though this option is for Supporters only, I believe this option would benefit more users because it saves time posting, replying, and looking for answers. Tell me what you think. Peter O.
-
Latest CAD/CAM/CAE/GIS/PCB/EDA/FEA software HERE!Christian Graus wrote: Is this URL to a shop, or a pirate site ? Definitely the latter. Such pages really shouldn't be allowed.
Peter O.
-
First steps in animation.. KindaThat's WM_ERASEBKGND, Christian. That'll cover up the problem with the remnants of windows on the ball. A simple app like yours doesn't need something fancy like DirectX. Keep working at it. Peter O.
-
List view and scroll barHello, I have a list view, and at run time I want to know if the horizontal scroll bar is visible. This is not so easy. Try this function.
// IsScrollBarVisible returns the show state of a
// scroll bar (TRUE if visible, FALSE if hidden)
// Params:
// HWND hwnd - window with scrollbar
// UINT fnBar - which scrollbar (SB_HORZ-horizontal,
// SB_VERT-vertical, SB_CTL-scrollbar control)
BOOL IsScrollBarVisible(HWND hwnd, UINT fnBar){
SCROLLINFO si;
if(fnBar==SB_CTL)
return IsWindowVisible(hwnd);
si.cbSize=sizeof(SCROLLINFO);
si.fMask=SIF_PAGE|SIF_RANGE;
GetScrollInfo(hwnd,fnBar,&si);
if(si.nMin==si.nMax)
return FALSE;
if(si.nMin>si.nMax)
return FALSE;
if(si.nPage>=(si.nMax-si.nMin))
return FALSE;
return TRUE;
}Call IsScrollBarVisible(hwndListView,SB_HORZ) to check if the horizontal scrollbar is visible. Written only a few minutes ago, untested, so beware. I would also like to get the height of the horizontal scrollbar. This, by comparison, is easy. Simply call
GetSystemMetrics(SM_CYHSCROLL)
. Peter O.
-
Filling a triangle with a gradientI need to know the algorithm used to fill a triangle with a color gradient given the position and color of the three vertices. I need it so I can port the GradientFill function for Windows 95. Peter O.